From 1ed60d0520e6f1a2a4a6de1e35d031c279edcfdf Mon Sep 17 00:00:00 2001 From: Patbox <39821509+Patbox@users.noreply.github.com> Date: Wed, 18 Sep 2024 11:44:11 +0200 Subject: [PATCH] Fix some mods providing empty item stacks in item groups, which is not valid! --- gradle.properties | 2 +- .../core/mixin/item/ItemGroupMixin.java | 2 ++ .../item/ServerPlayNetworkHandlerMixin.java | 18 ++++++++++++++---- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/gradle.properties b/gradle.properties index 4eb28f10..89a15e26 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,7 +13,7 @@ fabric_version=0.102.1+1.21.1 maven_group = eu.pb4 -mod_version = 0.9.15 +mod_version = 0.9.16 minecraft_version_supported = ">=1.21-" diff --git a/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/item/ItemGroupMixin.java b/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/item/ItemGroupMixin.java index f3d57238..4da4679d 100644 --- a/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/item/ItemGroupMixin.java +++ b/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/item/ItemGroupMixin.java @@ -39,6 +39,8 @@ public abstract class ItemGroupMixin implements ItemGroupExtra { var parent = new LinkedList<>(collector.parentTabStacks); var search = new LinkedList<>(collector.searchTabStacks); PolymerImplUtils.callItemGroupEvents(id, (ItemGroup) (Object) this, parent, search, context); + parent.removeIf(ItemStack::isEmpty); + search.removeIf(ItemStack::isEmpty); return new PolymerItemGroupUtils.Contents(parent, search); } diff --git a/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/item/ServerPlayNetworkHandlerMixin.java b/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/item/ServerPlayNetworkHandlerMixin.java index e6d84a07..3dc46109 100644 --- a/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/item/ServerPlayNetworkHandlerMixin.java +++ b/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/item/ServerPlayNetworkHandlerMixin.java @@ -8,6 +8,7 @@ import eu.pb4.polymer.core.impl.interfaces.PolymerPlayNetworkHandlerExtension; import eu.pb4.polymer.core.impl.networking.PolymerServerProtocol; import eu.pb4.polymer.networking.api.server.PolymerServerNetworking; +import net.minecraft.entity.EquipmentSlot; import net.minecraft.item.BlockItem; import net.minecraft.item.BucketItem; import net.minecraft.item.Equipment; @@ -90,10 +91,19 @@ public ServerPlayNetworkHandlerMixin(MinecraftServer server, ClientConnection co if (itemStack.getItem() instanceof PolymerItem polymerItem) { var data = PolymerItemUtils.getItemSafely(polymerItem, itemStack, this.player); - if (data.item() instanceof Equipment equipment && equipment.getSlotType().isArmorSlot()) { - this.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(this.player.playerScreenHandler.syncId, this.player.playerScreenHandler.nextRevision(), packet.getHand() == Hand.MAIN_HAND ? 36 + this.player.getInventory().selectedSlot : 45, itemStack)); - - this.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(this.player.playerScreenHandler.syncId, this.player.playerScreenHandler.nextRevision(), 8 - equipment.getSlotType().getEntitySlotId(), this.player.getEquippedStack(equipment.getSlotType()))); + if (data.item() instanceof Equipment equipment) { + if (equipment.getSlotType().getType() == EquipmentSlot.Type.HUMANOID_ARMOR) { + this.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(this.player.playerScreenHandler.syncId, this.player.playerScreenHandler.nextRevision(), + packet.getHand() == Hand.MAIN_HAND ? 36 + this.player.getInventory().selectedSlot : 45, itemStack)); + + this.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(this.player.playerScreenHandler.syncId, this.player.playerScreenHandler.nextRevision(), + 8 - equipment.getSlotType().getEntitySlotId(), this.player.getEquippedStack(equipment.getSlotType()))); + } else if (equipment.getSlotType().getType() == EquipmentSlot.Type.ANIMAL_ARMOR && packet.getHand() == Hand.OFF_HAND) { + this.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(this.player.playerScreenHandler.syncId, this.player.playerScreenHandler.nextRevision(), + 45, itemStack)); + this.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(this.player.playerScreenHandler.syncId, this.player.playerScreenHandler.nextRevision(), + 36 + this.player.getInventory().selectedSlot, this.player.getMainHandStack())); + } } } }