Skip to content

Commit

Permalink
Fix some mods providing empty item stacks in item groups, which is no…
Browse files Browse the repository at this point in the history
…t valid!
  • Loading branch information
Patbox committed Sep 18, 2024
1 parent 32b8304 commit 1ed60d0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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-"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()));
}
}
}
}
Expand Down

0 comments on commit 1ed60d0

Please sign in to comment.