From 5a12999ad86eaf2b1dd89354304e3ad3db1b281d Mon Sep 17 00:00:00 2001 From: Barnaby <22575741+barnabwhy@users.noreply.github.com> Date: Sun, 23 Jun 2024 21:07:50 +0100 Subject: [PATCH] fix: hotbar switch on 1.20.6 --- .../packet/SwitchActiveHotbarPacketListener.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/moulberry/axiom/packet/SwitchActiveHotbarPacketListener.java b/src/main/java/com/moulberry/axiom/packet/SwitchActiveHotbarPacketListener.java index f1056ef..0779063 100644 --- a/src/main/java/com/moulberry/axiom/packet/SwitchActiveHotbarPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/SwitchActiveHotbarPacketListener.java @@ -62,10 +62,20 @@ public class SwitchActiveHotbarPacketListener implements PluginMessageListener { } else { stack = stack.clone(); } - containerHotbarItems.set(new NamespacedKey("axiom", "slot_"+index), ItemStackDataType.INSTANCE, stack); + + if (stack.isEmpty()) { + containerHotbarItems.remove(new NamespacedKey("axiom", "slot_" + index)); + } else { + containerHotbarItems.set(new NamespacedKey("axiom", "slot_" + index), ItemStackDataType.INSTANCE, stack); + } } int index = activeHotbarIndex*9 + i; - containerHotbarItems.set(new NamespacedKey("axiom", "slot_"+index), ItemStackDataType.INSTANCE, hotbarItems[i].clone()); + ItemStack hotbarItem = hotbarItems[i].clone(); + if (hotbarItem.isEmpty()) { + containerHotbarItems.remove(new NamespacedKey("axiom", "slot_" + index)); + } else { + containerHotbarItems.set(new NamespacedKey("axiom", "slot_"+index), ItemStackDataType.INSTANCE, hotbarItem); + } if (player.getGameMode() == GameMode.CREATIVE) player.getInventory().setItem(i, hotbarItems[i]); }