diff --git a/Common/src/main/java/tschipp/carryon/CarryOnCommonClient.java b/Common/src/main/java/tschipp/carryon/CarryOnCommonClient.java index d2b50e1..9a29896 100644 --- a/Common/src/main/java/tschipp/carryon/CarryOnCommonClient.java +++ b/Common/src/main/java/tschipp/carryon/CarryOnCommonClient.java @@ -47,14 +47,15 @@ public class CarryOnCommonClient } - public static void onCarryClientTick() - { + public static void onCarryClientTick() { Player player = Minecraft.getInstance().player; - if(player != null) { + if (player != null) { CarryOnData carry = CarryOnDataManager.getCarryData(player); - if(carry.isCarrying()) - { - player.getInventory().setSelectedSlot(carry.getSelected()); + if (carry.isCarrying()) { + int wantedSlot = carry.getSelected(); + if (player.getInventory().getSelectedSlot() != wantedSlot) { + player.getInventory().setSelectedSlot(wantedSlot); + } } } } @@ -63,4 +64,4 @@ public class CarryOnCommonClient { return Minecraft.getInstance().player; } -} +} \ No newline at end of file diff --git a/Common/src/main/java/tschipp/carryon/mixin/MinecraftMixin.java b/Common/src/main/java/tschipp/carryon/mixin/MinecraftMixin.java index da24a56..622a79b 100644 --- a/Common/src/main/java/tschipp/carryon/mixin/MinecraftMixin.java +++ b/Common/src/main/java/tschipp/carryon/mixin/MinecraftMixin.java @@ -28,11 +28,24 @@ import org.spongepowered.asm.mixin.injection.At; import tschipp.carryon.common.carry.CarryOnDataManager; @Mixin(Minecraft.class) -public class MinecraftMixin -{ - @WrapWithCondition(method = "handleKeybinds()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Inventory;setSelectedSlot(I)V", ordinal = 0)) - private boolean allowSlotSelection(Inventory inv,int slot) - { - return !CarryOnDataManager.getCarryData(inv.player).isCarrying(); - } +public class MinecraftMixin { + + @WrapWithCondition( + method = "handleKeybinds()V", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/entity/player/Inventory;setSelectedSlot(I)V", + ordinal = 0 + ) + ) + private boolean allowSlotSelection(Inventory inv, int slot) { + boolean carrying = CarryOnDataManager.getCarryData(inv.player).isCarrying(); + + // Allow if not carrying + if (!carrying) return true; + + // Block only if trying to switch away + return inv.getSelectedSlot() == slot; + } } +