From 42444f0a0afa84fb315b455522feb26f958c584f Mon Sep 17 00:00:00 2001 From: Rob3r8 Date: Sun, 21 Jul 2024 11:36:58 +0200 Subject: [PATCH] Added 1.17, 1.18 and 1.19 Stonecutter's versioned comments --- .../net/rober/robercarpet/RoberCarpet.java | 3 +- .../robercarpet/mixin/FallingBlockMixin.java | 18 +++++- .../mixin/SleepInBedSetRespawnMixin.java | 57 +++++++------------ .../robercarpet/mixin/SleepingDelayMixin.java | 5 +- .../robercarpet/mixin/ThunderWarnMixin.java | 16 ++++-- 5 files changed, 55 insertions(+), 44 deletions(-) diff --git a/src/main/java/net/rober/robercarpet/RoberCarpet.java b/src/main/java/net/rober/robercarpet/RoberCarpet.java index 2918209..b491968 100644 --- a/src/main/java/net/rober/robercarpet/RoberCarpet.java +++ b/src/main/java/net/rober/robercarpet/RoberCarpet.java @@ -19,7 +19,8 @@ public class RoberCarpet implements ModInitializer, CarpetExtension { @Override public void onInitialize() { - FarmableClayBehavior.init(); + //? if <1.19 + /*FarmableClayBehavior.init();*/ RoberCarpet extension = new RoberCarpet(); CarpetServer.manageExtension(extension); } diff --git a/src/main/java/net/rober/robercarpet/mixin/FallingBlockMixin.java b/src/main/java/net/rober/robercarpet/mixin/FallingBlockMixin.java index 366ef66..f50db53 100644 --- a/src/main/java/net/rober/robercarpet/mixin/FallingBlockMixin.java +++ b/src/main/java/net/rober/robercarpet/mixin/FallingBlockMixin.java @@ -15,17 +15,29 @@ @Mixin(FallingBlockEntity.class) public abstract class FallingBlockMixin { - @Redirect(method = "tick()V",at=@At(value="INVOKE",target="Lnet/minecraft/block/BlockState;isOf(Lnet/minecraft/block/Block;)Z",ordinal = 1)) + //? if =1.17 { + /*@Redirect(method = "tick()V",at=@At(value="INVOKE",target="Lnet/minecraft/block/BlockState;isOf(Lnet/minecraft/block/Block;)Z",ordinal = 1)) + *///?} else { + @Redirect(method = "tick()V",at=@At(value="INVOKE",target="Lnet/minecraft/block/BlockState;isOf(Lnet/minecraft/block/Block;)Z",ordinal = 0)) + //?} private boolean FallingBlockBehaviorMixin(BlockState blockHitResult, Block arg){ FallingBlockEntity self = (FallingBlockEntity) (Object) this; - BlockPos pos = new BlockPos(self.getPos().getX(),Math.ceil(self.getPos().getY()),self.getPos().getZ()).down(); + //? <1.19 { + /*BlockPos pos = new BlockPos(self.getPos().getX(),Math.ceil(self.getPos().getY()),self.getPos().getZ()).down(); + *///?} else { + BlockPos pos = new BlockPos((int) self.getPos().getX(), (int) Math.ceil(self.getPos().getY()), (int) self.getPos().getZ()).down(); + //?} Block underneath = self.world.getBlockState(pos).getBlock(); return blockHitResult.isOf(arg)||(underneath==Blocks.AIR&& RoberCarpetSettings.OldFallingBehavior); } @Redirect(method="tick()V",at=@At(value="INVOKE",target = "Lnet/minecraft/util/math/Vec3d;multiply(DDD)Lnet/minecraft/util/math/Vec3d;",ordinal = 0)) private Vec3d FrictionMixin(Vec3d vec,double x,double y,double z){ FallingBlockEntity self = (FallingBlockEntity) (Object) this; - BlockPos pos = new BlockPos(self.getPos().getX(),Math.ceil(self.getPos().getY()),self.getPos().getZ()).down(); + //? <1.19 { + /*BlockPos pos = new BlockPos(self.getPos().getX(),Math.ceil(self.getPos().getY()),self.getPos().getZ()).down(); + *///?} else { + BlockPos pos = new BlockPos((int) self.getPos().getX(), (int) Math.ceil(self.getPos().getY()), (int) self.getPos().getZ()).down(); + //?} Block underneath = self.world.getBlockState(pos).getBlock(); return underneath==Blocks.AIR&&RoberCarpetSettings.FallingBlockNoFrictionWithWalls?vec:vec.multiply(x,y,z); } diff --git a/src/main/java/net/rober/robercarpet/mixin/SleepInBedSetRespawnMixin.java b/src/main/java/net/rober/robercarpet/mixin/SleepInBedSetRespawnMixin.java index 97f5c2c..d0dbfc2 100644 --- a/src/main/java/net/rober/robercarpet/mixin/SleepInBedSetRespawnMixin.java +++ b/src/main/java/net/rober/robercarpet/mixin/SleepInBedSetRespawnMixin.java @@ -1,9 +1,7 @@ package net.rober.robercarpet.mixin; import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.LiteralText; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.registry.RegistryKey; import net.minecraft.world.World; import net.rober.robercarpet.RoberCarpetSettings; import org.jetbrains.annotations.Nullable; @@ -14,63 +12,52 @@ import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - import java.util.Objects; +//? if <1.19.4 { +/*import net.minecraft.text.LiteralText; +import net.minecraft.util.registry.RegistryKey;*/ +//?} else { +import net.minecraft.registry.RegistryKey; +import net.minecraft.text.Text; +//?} + @Mixin(value = ServerPlayerEntity.class, priority = 100) public abstract class SleepInBedSetRespawnMixin { - //@Redirect(method = "trySleep", at = @At(value = "INVOKE", - //target = "Lnet/minecraft/server/network/ServerPlayerEntity;setSpawnPoint(Lnet/minecraft/util/registry/RegistryKey;Lnet/minecraft/util/math/BlockPos;FZZ)V")) - @Unique - private void setSpawnPointRedirect(ServerPlayerEntity player, RegistryKey dimension, @Nullable BlockPos pos, float angle, boolean spawnPointSet, boolean sendMessage){ - switch(RoberCarpetSettings.SleepInBedSetRespawn){ - case "always": - player.setSpawnPoint(dimension, pos, angle, spawnPointSet, sendMessage); - if(RoberCarpetSettings.SendSetRespawnFeedback)player.sendMessage(new LiteralText("You have set your respawn point"),true); - break; - case "sneaking": - case "no-sneaking": - boolean sneaking = player.isSneaking(); - if(sneaking && (Objects.equals(RoberCarpetSettings.SleepInBedSetRespawn, "sneaking"))) { - player.setSpawnPoint(dimension, pos, angle, spawnPointSet, sendMessage); - player.sendMessage(new LiteralText("You have set your respawn point"),false); - } - else{ - player.sendMessage(new LiteralText("You have slept without setting your spawn point"),false); - } - break; - case "never": - player.sendMessage(new LiteralText("You have slept without setting your spawn point"),false); - } - } @Inject(method="setSpawnPoint", at=@At(value="HEAD"), cancellable = true) - private void setSpawnPointInjector(RegistryKey dimension, @Nullable BlockPos pos, float angle, boolean spawnPointSet, boolean sendMessage, CallbackInfo ci){ + private void setSpawnPointInjector(RegistryKey dimension, BlockPos pos, float angle, boolean forced, boolean sendMessage, CallbackInfo ci){ ServerPlayerEntity player = (ServerPlayerEntity) ((Object) this); - switch(RoberCarpetSettings.SleepInBedSetRespawn){ + switch(RoberCarpetSettings.SleepInBedSetsRespawn){ case "always": - if(RoberCarpetSettings.SendSetRespawnFeedback)player.sendMessage(new LiteralText("You have set your respawn point"),true); + if(RoberCarpetSettings.SendSetRespawnFeedback)send("You have set your respawn point",player); return; case "sneaking": if(player.isSneaking()){ - player.sendMessage(new LiteralText("You have set your respawn point"),false); + send("You have set your respawn point",player); return; }else{ - player.sendMessage(new LiteralText("You have slept without setting your spawn point"),false); + send("You have slept without setting your spawn point",player); ci.cancel(); } break; case "no-sneaking": if(!player.isSneaking()){ - player.sendMessage(new LiteralText("You have set your respawn point"),false); + send("You have set your respawn point",player); return; }else{ - player.sendMessage(new LiteralText("You have slept without setting your spawn point"),false); + send("You have slept without setting your spawn point",player); ci.cancel(); } break; case "never": - player.sendMessage(new LiteralText("You have slept without setting your spawn point"),false); + send("You have slept without setting your spawn point",player); ci.cancel(); } } + private static void send(String mes, ServerPlayerEntity player){ + //? if <1.19 { + /*player.sendMessage(new LiteralText(mes),false);*/ + //?} else + player.sendMessage(Text.of(mes),false); + } } \ No newline at end of file diff --git a/src/main/java/net/rober/robercarpet/mixin/SleepingDelayMixin.java b/src/main/java/net/rober/robercarpet/mixin/SleepingDelayMixin.java index a13b1ba..90bfd69 100644 --- a/src/main/java/net/rober/robercarpet/mixin/SleepingDelayMixin.java +++ b/src/main/java/net/rober/robercarpet/mixin/SleepingDelayMixin.java @@ -10,7 +10,10 @@ @Mixin(PlayerEntity.class) public abstract class SleepingDelayMixin { - @ModifyConstant(method = "isSleepingLongEnough",constant = @Constant(intValue = 100)) + //? if =1.17 { + /*@ModifyConstant(method = "isSleepingLongEnough",constant = @Constant(intValue = 100)) + *///?} else + @ModifyConstant(method = "canResetTimeBySleeping",constant = @Constant(intValue = 100)) public int SleepingDelayMixin(int a){ return RoberCarpetSettings.SleepingDelay; } diff --git a/src/main/java/net/rober/robercarpet/mixin/ThunderWarnMixin.java b/src/main/java/net/rober/robercarpet/mixin/ThunderWarnMixin.java index f07acc5..d6827d8 100644 --- a/src/main/java/net/rober/robercarpet/mixin/ThunderWarnMixin.java +++ b/src/main/java/net/rober/robercarpet/mixin/ThunderWarnMixin.java @@ -1,9 +1,8 @@ package net.rober.robercarpet.mixin; -import net.minecraft.network.MessageType; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; -import net.minecraft.text.LiteralText; +import net.minecraft.text.Text; import net.minecraft.world.level.ServerWorldProperties; import net.rober.robercarpet.RoberCarpetSettings; import org.spongepowered.asm.mixin.Mixin; @@ -12,18 +11,27 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +//? <1.19.4 { +/*import net.minecraft.network.MessageType; +import net.minecraft.text.LiteralText; +*///?} + import java.util.function.BooleanSupplier; @Mixin(ServerWorld.class) public abstract class ThunderWarnMixin { - @Shadow protected ServerWorldProperties worldProperties; + @Shadow + private ServerWorldProperties worldProperties; @Inject(method = "tick",at=@At("TAIL")) private void tickMixin(BooleanSupplier shouldKeepTicking,CallbackInfo ci){ if(RoberCarpetSettings.ThunderWarn!=-1) { ServerWorld server = (ServerWorld) (Object) this; if((willBeThunderstorm(RoberCarpetSettings.ThunderWarn,worldProperties))){ for (ServerPlayerEntity player : server.getPlayers()){ - player.sendMessage(new LiteralText("A storm will begin in "+RoberCarpetSettings.ThunderWarn/60+" minutes"), MessageType.CHAT,player.getUuid()); + //? >=1.19.4 { + player.sendMessage(Text.of("A storm will begin in " + RoberCarpetSettings.ThunderWarn / 1200 + " minutes"), false); + //?} else + /*player.sendMessage(new LiteralText("A storm will begin in "+RoberCarpetSettings.ThunderWarn/60+" minutes"), MessageType.CHAT,player.getUuid());*/ } } }