From f0b4dc0b348023165520436f41284a78514e988f Mon Sep 17 00:00:00 2001 From: RubixDev Date: Tue, 18 Jul 2023 10:09:43 +0800 Subject: [PATCH] chore: support MC 1.20 --- build.gradle | 6 +- gradle.properties | 22 ++++---- src/main/java/de/rubixdev/rug/RugServer.java | 16 +++--- .../rug/commands/MaxEffectCommand.java | 2 +- .../de/rubixdev/rug/commands/ModsCommand.java | 3 +- ...a => AbstractPressurePlateBlockMixin.java} | 10 ++-- .../rug/mixins/EnderDragonEntityMixin.java | 2 +- .../rug/mixins/FallingBlockEntityMixin.java | 56 ++++++++++--------- .../rug/mixins/LivingEntityMixin.java | 2 +- .../rug/mixins/PotionEntityMixin.java | 4 +- .../rug/mixins/ServerPlayerEntityMixin.java | 5 -- src/main/resources/fabric.mod.json | 1 + src/main/resources/rug.accesswidener | 3 + src/main/resources/rug.mixins.json | 2 +- 14 files changed, 72 insertions(+), 62 deletions(-) rename src/main/java/de/rubixdev/rug/mixins/{PressurePlateBlockMixin.java => AbstractPressurePlateBlockMixin.java} (67%) create mode 100644 src/main/resources/rug.accesswidener diff --git a/build.gradle b/build.gradle index 695032c..19b7d9b 100644 --- a/build.gradle +++ b/build.gradle @@ -20,12 +20,16 @@ repositories { } } +loom { + accessWidenerPath = file("src/main/resources/rug.accesswidener") +} + dependencies { // To change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" - modImplementation "carpet:fabric-carpet:${project.minecraft_version}-${project.carpet_core_version}" + modImplementation "carpet:fabric-carpet:${project.carpet_core_version}" // Fabric API. This is technically optional, but you probably want it anyway. modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" diff --git a/gradle.properties b/gradle.properties index 84a2013..423d481 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,28 +3,28 @@ org.gradle.jvmargs = -Xmx4G # Fabric Properties # check these on https://fabricmc.net/versions.html -minecraft_version = 1.19.4 -minecraft_minimum_version = 1.19.4 -yarn_mappings = 1.19.4+build.2 -loader_version = 0.14.19 +minecraft_version = 1.20.1 +minecraft_minimum_version = 1.20.1 +yarn_mappings = 1.20.1+build.8 +loader_version = 0.14.21 # check available versions on maven (https://masa.dy.fi/maven/carpet/fabric-carpet/) for the given minecraft version you are using -carpet_core_version = 1.4.101+v230319 +carpet_core_version = 1.20-1.4.112+v230608 # Mod Properties -mod_version = 1.4.1 +mod_version = 1.4.2 maven_group = de.rubixdev.rug archives_base_name = rug # Dependencies -fabric_version = 0.77.0+1.19.4 +fabric_version = 0.84.0+1.20.1 # Check on https://maven.nucleoid.xyz/eu/pb4/sgui/ or https://github.com/Patbox/sgui/releases -sgui_version = 1.2.1+1.19.3 +sgui_version = 1.2.2+1.20 # Release Action properties -release_curse_versions = Minecraft 1.19:1.19.4 -release_modrinth_versions = 1.19.4 -release_display_version = 1.19.4 +release_curse_versions = Minecraft 1.20:1.20.1 +release_modrinth_versions = 1.20.1 +release_display_version = 1.20+ release_extra_branch = false release_extra_branch_name = 1.18 diff --git a/src/main/java/de/rubixdev/rug/RugServer.java b/src/main/java/de/rubixdev/rug/RugServer.java index 671b9a4..5cf7144 100644 --- a/src/main/java/de/rubixdev/rug/RugServer.java +++ b/src/main/java/de/rubixdev/rug/RugServer.java @@ -26,12 +26,7 @@ import java.util.stream.Stream; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.event.player.UseBlockCallback; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.block.CocoaBlock; -import net.minecraft.block.CropBlock; -import net.minecraft.block.NetherWartBlock; +import net.minecraft.block.*; import net.minecraft.command.CommandRegistryAccess; import net.minecraft.item.BlockItem; import net.minecraft.item.HoeItem; @@ -457,8 +452,13 @@ private static boolean isMature(BlockState state) { } private static IntProperty getAgeProperty(Block block) { - if (block instanceof CropBlock) { - return ((CropBlock) block).getAgeProperty(); + // UPDATE: check for new classes overriding CropBlock.getAgeProperty() + if (block instanceof BeetrootsBlock) { + return BeetrootsBlock.AGE; + } else if (block instanceof TorchflowerBlock) { + return TorchflowerBlock.AGE; + } else if (block instanceof CropBlock) { + return CropBlock.AGE; } else if (block instanceof NetherWartBlock) { return NetherWartBlock.AGE; } else if (block instanceof CocoaBlock) { diff --git a/src/main/java/de/rubixdev/rug/commands/MaxEffectCommand.java b/src/main/java/de/rubixdev/rug/commands/MaxEffectCommand.java index e804584..bc96aff 100644 --- a/src/main/java/de/rubixdev/rug/commands/MaxEffectCommand.java +++ b/src/main/java/de/rubixdev/rug/commands/MaxEffectCommand.java @@ -47,7 +47,7 @@ public static void register( } source.sendFeedback( - Text.translatable( + () -> Text.translatable( "commands.effect.give.success.single", effect.getName(), player.getDisplayName(), diff --git a/src/main/java/de/rubixdev/rug/commands/ModsCommand.java b/src/main/java/de/rubixdev/rug/commands/ModsCommand.java index 8f09774..1e1092c 100644 --- a/src/main/java/de/rubixdev/rug/commands/ModsCommand.java +++ b/src/main/java/de/rubixdev/rug/commands/ModsCommand.java @@ -42,7 +42,8 @@ private static int execute(CommandContext context, boolean } chatMessageJson += String.join(",\"\\n \",", modJsons) + "]"; - context.getSource().sendFeedback(Text.Serializer.fromJson(chatMessageJson), false); + String finalChatMessageJson = chatMessageJson; + context.getSource().sendFeedback(() -> Text.Serializer.fromJson(finalChatMessageJson), false); return 1; } diff --git a/src/main/java/de/rubixdev/rug/mixins/PressurePlateBlockMixin.java b/src/main/java/de/rubixdev/rug/mixins/AbstractPressurePlateBlockMixin.java similarity index 67% rename from src/main/java/de/rubixdev/rug/mixins/PressurePlateBlockMixin.java rename to src/main/java/de/rubixdev/rug/mixins/AbstractPressurePlateBlockMixin.java index 98d2ace..41987cd 100644 --- a/src/main/java/de/rubixdev/rug/mixins/PressurePlateBlockMixin.java +++ b/src/main/java/de/rubixdev/rug/mixins/AbstractPressurePlateBlockMixin.java @@ -1,19 +1,19 @@ package de.rubixdev.rug.mixins; import de.rubixdev.rug.RugSettings; -import net.minecraft.block.PressurePlateBlock; +import net.minecraft.block.AbstractPressurePlateBlock; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -@Mixin(PressurePlateBlock.class) -public class PressurePlateBlockMixin { +@Mixin(AbstractPressurePlateBlock.class) +public class AbstractPressurePlateBlockMixin { @Redirect( - method = "getRedstoneOutput(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;)I", + method = "method_52209", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;canAvoidTraps()Z")) - private boolean disableItemFrames(Entity entity) { + private static boolean disableItemFrames(Entity entity) { if (!RugSettings.itemFramesActivatePressurePlates && entity.getType() == EntityType.ITEM_FRAME) { return true; } diff --git a/src/main/java/de/rubixdev/rug/mixins/EnderDragonEntityMixin.java b/src/main/java/de/rubixdev/rug/mixins/EnderDragonEntityMixin.java index 7ae57e7..24dbc0c 100644 --- a/src/main/java/de/rubixdev/rug/mixins/EnderDragonEntityMixin.java +++ b/src/main/java/de/rubixdev/rug/mixins/EnderDragonEntityMixin.java @@ -31,7 +31,7 @@ public EnderDragonEntityMixin(EntityType type, World world) { ordinal = 1)) private void onUpdatePostDeath(CallbackInfo ci) { String rugSetting = RugSettings.dragonDrops; - if (!rugSetting.equals("none") && this.world.getGameRules().getBoolean(GameRules.DO_MOB_LOOT)) { + if (!rugSetting.equals("none") && this.getWorld().getGameRules().getBoolean(GameRules.DO_MOB_LOOT)) { boolean dropAll = rugSetting.equals("all"); if (rugSetting.contains("elytra") || dropAll) { diff --git a/src/main/java/de/rubixdev/rug/mixins/FallingBlockEntityMixin.java b/src/main/java/de/rubixdev/rug/mixins/FallingBlockEntityMixin.java index 52839f1..19ad540 100644 --- a/src/main/java/de/rubixdev/rug/mixins/FallingBlockEntityMixin.java +++ b/src/main/java/de/rubixdev/rug/mixins/FallingBlockEntityMixin.java @@ -40,62 +40,68 @@ public FallingBlockEntityMixin(EntityType type, World world) { cancellable = true) private void onTick(CallbackInfo ci, Block block, BlockPos pos) { BlockPos posBelow = this.getBlockPos().down(); - BlockState blockStateBelow = world.getBlockState(posBelow); + BlockState blockStateBelow = getWorld().getBlockState(posBelow); Block blockBelow = blockStateBelow.getBlock(); if (this.block.isIn(BlockTags.ANVIL)) { if (blockBelow == Blocks.FROSTED_ICE && RugSettings.anvilledIce > 0) { if (++frostedIceCount < RugSettings.anvilledIce) { - world.breakBlock(posBelow, false); - onGround = false; + getWorld().breakBlock(posBelow, false); + setOnGround(false); ci.cancel(); } else { - world.breakBlock(posBelow, false); - world.setBlockState(posBelow, Blocks.ICE.getDefaultState(), 3); + getWorld().breakBlock(posBelow, false); + getWorld().setBlockState(posBelow, Blocks.ICE.getDefaultState(), 3); } } else if (blockBelow == Blocks.ICE && RugSettings.anvilledPackedIce > 0) { if (++iceCount < RugSettings.anvilledPackedIce) { - world.breakBlock(posBelow, false); - onGround = false; + getWorld().breakBlock(posBelow, false); + setOnGround(false); ci.cancel(); } else { - world.breakBlock(posBelow, false); - world.setBlockState(posBelow, Blocks.PACKED_ICE.getDefaultState(), 3); + getWorld().breakBlock(posBelow, false); + getWorld().setBlockState(posBelow, Blocks.PACKED_ICE.getDefaultState(), 3); } } else if (blockBelow == Blocks.PACKED_ICE && RugSettings.anvilledBlueIce > 0) { if (++packedIceCount < RugSettings.anvilledBlueIce) { - world.breakBlock(posBelow, false); - onGround = false; + getWorld().breakBlock(posBelow, false); + setOnGround(false); ci.cancel(); } else { - world.breakBlock(posBelow, false); - world.setBlockState(posBelow, Blocks.BLUE_ICE.getDefaultState(), 3); + getWorld().breakBlock(posBelow, false); + getWorld().setBlockState(posBelow, Blocks.BLUE_ICE.getDefaultState(), 3); } } else if (blockBelow == Blocks.COBBLESTONE && RugSettings.cobbleCrushing) { - world.breakBlock(posBelow, false); - world.setBlockState(posBelow, Blocks.GRAVEL.getDefaultState(), 3); + getWorld().breakBlock(posBelow, false); + getWorld().setBlockState(posBelow, Blocks.GRAVEL.getDefaultState(), 3); } else if (blockBelow == Blocks.GRAVEL && RugSettings.gravelCrushing) { - world.breakBlock(posBelow, false); - world.setBlockState(posBelow, Blocks.SAND.getDefaultState(), 3); + getWorld().breakBlock(posBelow, false); + getWorld().setBlockState(posBelow, Blocks.SAND.getDefaultState(), 3); } } else if (this.block.isOf(Blocks.DRAGON_EGG)) { String rugSetting = RugSettings.dragonEggConvertsCobbleToEndstone; if (blockBelow == Blocks.COBBLESTONE && (rugSetting.equals("both") || rugSetting.equals("on_landing"))) { - world.breakBlock(posBelow, false); - world.setBlockState(posBelow, Blocks.END_STONE.getDefaultState(), 3); + getWorld().breakBlock(posBelow, false); + getWorld().setBlockState(posBelow, Blocks.END_STONE.getDefaultState(), 3); } } else if ((this.block.isOf(Blocks.SAND) && blockStateBelow.isOf(Blocks.GRAVEL)) || (this.block.isOf(Blocks.GRAVEL) && blockStateBelow.isOf(Blocks.SAND))) { - BlockState concreteBlock = world.getBlockState(posBelow.down()); + BlockState concreteBlock = getWorld().getBlockState(posBelow.down()); if (isConcrete(concreteBlock) && RugSettings.concreteMixing) { - world.syncWorldEvent( - WorldEvents.BLOCK_BROKEN, posBelow, Block.getRawIdFromState(Blocks.SAND.getDefaultState())); - world.syncWorldEvent( - WorldEvents.BLOCK_BROKEN, posBelow, Block.getRawIdFromState(Blocks.GRAVEL.getDefaultState())); + getWorld() + .syncWorldEvent( + WorldEvents.BLOCK_BROKEN, + posBelow, + Block.getRawIdFromState(Blocks.SAND.getDefaultState())); + getWorld() + .syncWorldEvent( + WorldEvents.BLOCK_BROKEN, + posBelow, + Block.getRawIdFromState(Blocks.GRAVEL.getDefaultState())); Block powderBlock = getCorrespondingPowder(concreteBlock); assert powderBlock != null; - world.setBlockState(posBelow, powderBlock.getDefaultState(), 3); + getWorld().setBlockState(posBelow, powderBlock.getDefaultState(), 3); this.discard(); ci.cancel(); } diff --git a/src/main/java/de/rubixdev/rug/mixins/LivingEntityMixin.java b/src/main/java/de/rubixdev/rug/mixins/LivingEntityMixin.java index b26cf19..cdcbc61 100644 --- a/src/main/java/de/rubixdev/rug/mixins/LivingEntityMixin.java +++ b/src/main/java/de/rubixdev/rug/mixins/LivingEntityMixin.java @@ -41,7 +41,7 @@ private void onDrop(DamageSource source, CallbackInfo ci) { if (dyingEntity.getType().equals(EntityType.SHULKER) && RugSettings.strictShulkerShells > 0 - && dyingEntity.world.getGameRules().getBoolean(GameRules.DO_MOB_LOOT)) { + && dyingEntity.getWorld().getGameRules().getBoolean(GameRules.DO_MOB_LOOT)) { ItemStack stack = new ItemStack(Items.SHULKER_SHELL); stack.setCount(RugSettings.strictShulkerShells); dyingEntity.dropStack(stack); diff --git a/src/main/java/de/rubixdev/rug/mixins/PotionEntityMixin.java b/src/main/java/de/rubixdev/rug/mixins/PotionEntityMixin.java index 34f03bf..5d22efb 100644 --- a/src/main/java/de/rubixdev/rug/mixins/PotionEntityMixin.java +++ b/src/main/java/de/rubixdev/rug/mixins/PotionEntityMixin.java @@ -30,12 +30,12 @@ protected PotionEntityMixin(EntityType entityType, World ordinal = 0)) private void ageCopper(BlockHitResult blockHitResult, CallbackInfo ci) { BlockPos blockPos = blockHitResult.getBlockPos(); - BlockState blockState = this.world.getBlockState(blockPos); + BlockState blockState = this.getWorld().getBlockState(blockPos); Block block = blockState.getBlock(); if (block instanceof Oxidizable && RugSettings.splashOxidize) { Optional oxidized = ((Oxidizable) block).getDegradationResult(blockState); - oxidized.ifPresent(state -> this.world.setBlockState(blockPos, state)); + oxidized.ifPresent(state -> this.getWorld().setBlockState(blockPos, state)); } } } diff --git a/src/main/java/de/rubixdev/rug/mixins/ServerPlayerEntityMixin.java b/src/main/java/de/rubixdev/rug/mixins/ServerPlayerEntityMixin.java index cb722f6..d8d53ce 100644 --- a/src/main/java/de/rubixdev/rug/mixins/ServerPlayerEntityMixin.java +++ b/src/main/java/de/rubixdev/rug/mixins/ServerPlayerEntityMixin.java @@ -11,11 +11,9 @@ import net.minecraft.registry.RegistryKey; import net.minecraft.registry.tag.BlockTags; import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -26,9 +24,6 @@ public ServerPlayerEntityMixin(World world, BlockPos pos, float yaw, GameProfile super(world, pos, yaw, gameProfile); } - @Shadow - public abstract ServerWorld getWorld(); - @Inject( method = "onDeath", at = diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index fafb7fa..1bc5d1a 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -26,6 +26,7 @@ "mixins": [ "rug.mixins.json" ], + "accessWidener": "rug.accesswidener", "depends": { "fabricloader": ">=0.14.6", diff --git a/src/main/resources/rug.accesswidener b/src/main/resources/rug.accesswidener new file mode 100644 index 0000000..34c7787 --- /dev/null +++ b/src/main/resources/rug.accesswidener @@ -0,0 +1,3 @@ +accessWidener v1 named + +accessible method net/minecraft/entity/Entity setWorld (Lnet/minecraft/world/World;)V diff --git a/src/main/resources/rug.mixins.json b/src/main/resources/rug.mixins.json index 25abf30..4694dda 100644 --- a/src/main/resources/rug.mixins.json +++ b/src/main/resources/rug.mixins.json @@ -10,6 +10,7 @@ "AbstractCauldronBlockMixin", "AbstractFurnaceBlockEntityMixin", "AbstractPlantStemBlockMixin", + "AbstractPressurePlateBlockMixin", "AbstractRedstoneGateBlockMixin", "BambooBlockMixin", "BlockItemMixin", @@ -46,7 +47,6 @@ "PlayerEntityMixin", "PointedDripstoneBlockMixin", "PotionEntityMixin", - "PressurePlateBlockMixin", "RedstoneLampBlockMixin", "RepeaterBlockMixin", "SculkBlockMixin",