From 8e145cddfbbea0cdbf818e30a070f1d7cf0702f4 Mon Sep 17 00:00:00 2001 From: TheRealWormbo Date: Tue, 7 May 2024 08:53:17 +0200 Subject: [PATCH] Restrict Ring of Correction to block breaking Fixes #4317, and also makes things less weird e.g. with scraping copper blocks or tilling soil. --- .../item/equipment/bauble/RingOfCorrectionItem.java | 7 ++++--- .../botania/mixin/ServerPlayerGameModeAccessor.java | 12 ++++++++++++ Xplat/src/main/resources/botania_xplat.mixins.json | 1 + 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 Xplat/src/main/java/vazkii/botania/mixin/ServerPlayerGameModeAccessor.java diff --git a/Xplat/src/main/java/vazkii/botania/common/item/equipment/bauble/RingOfCorrectionItem.java b/Xplat/src/main/java/vazkii/botania/common/item/equipment/bauble/RingOfCorrectionItem.java index 092ffe9a3b..3c5dbfe785 100644 --- a/Xplat/src/main/java/vazkii/botania/common/item/equipment/bauble/RingOfCorrectionItem.java +++ b/Xplat/src/main/java/vazkii/botania/common/item/equipment/bauble/RingOfCorrectionItem.java @@ -8,9 +8,9 @@ */ package vazkii.botania.common.item.equipment.bauble; +import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.BlockHitResult; @@ -18,6 +18,7 @@ import vazkii.botania.api.item.SortableTool; import vazkii.botania.common.item.equipment.tool.ToolCommons; +import vazkii.botania.mixin.ServerPlayerGameModeAccessor; public class RingOfCorrectionItem extends BaubleItem { @@ -27,13 +28,13 @@ public RingOfCorrectionItem(Properties props) { @Override public void onWornTick(ItemStack stack, LivingEntity entity) { - if (entity.level().isClientSide || !(entity instanceof Player player)) { + if (entity.level().isClientSide || !(entity instanceof ServerPlayer player)) { return; } ItemStack currentStack = player.getMainHandItem(); if (currentStack.isEmpty() || !(currentStack.getItem() instanceof SortableTool tool) - || !player.swinging) { + || !((ServerPlayerGameModeAccessor) player.gameMode).botania_isDestroyingBlock()) { return; } diff --git a/Xplat/src/main/java/vazkii/botania/mixin/ServerPlayerGameModeAccessor.java b/Xplat/src/main/java/vazkii/botania/mixin/ServerPlayerGameModeAccessor.java new file mode 100644 index 0000000000..a1f19a6bb0 --- /dev/null +++ b/Xplat/src/main/java/vazkii/botania/mixin/ServerPlayerGameModeAccessor.java @@ -0,0 +1,12 @@ +package vazkii.botania.mixin; + +import net.minecraft.server.level.ServerPlayerGameMode; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(ServerPlayerGameMode.class) +public interface ServerPlayerGameModeAccessor { + @Accessor("isDestroyingBlock") + boolean botania_isDestroyingBlock(); +} diff --git a/Xplat/src/main/resources/botania_xplat.mixins.json b/Xplat/src/main/resources/botania_xplat.mixins.json index 32c7e27573..74287d5f38 100644 --- a/Xplat/src/main/resources/botania_xplat.mixins.json +++ b/Xplat/src/main/resources/botania_xplat.mixins.json @@ -47,6 +47,7 @@ "RecipeManagerAccessor", "RecipeProviderAccessor", "ServerLevelMixin", + "ServerPlayerGameModeAccessor", "ServerPlayerMixin", "SpawnPlacementsMixin", "StatsAccessor",