Skip to content

Commit

Permalink
fix server not properly syncing bag contents to client
Browse files Browse the repository at this point in the history
  • Loading branch information
Olfi01 committed Jul 25, 2022
1 parent c1cc666 commit f5bf855
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,13 @@ public void onContainerClosed(@NotNull EntityPlayer playerIn) {
super.onContainerClosed(playerIn);

if (playerIn instanceof EntityPlayerMP) {
ItemStack stack = playerIn.getHeldItem(EnumHand.MAIN_HAND);
if (pouch instanceof ItemStackHandler) {
stack.setTagCompound(((ItemStackHandler) pouch).serializeNBT());
}
((EntityPlayerMP) playerIn).connection.sendPacket(
// this assumes the player is holding the pouch in their main hand
new SPacketEntityEquipment(playerIn.getEntityId(), EntityEquipmentSlot.MAINHAND,
playerIn.getHeldItem(EnumHand.MAIN_HAND)));
new SPacketEntityEquipment(playerIn.getEntityId(), EntityEquipmentSlot.MAINHAND, stack));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import de.crazypokemondev.pixelmongenerations.pouch.client.gui.GuiHandler;
import de.crazypokemondev.pixelmongenerations.pouch.common.capabilities.PouchItemHandler;
import de.crazypokemondev.pixelmongenerations.pouch.common.config.PixelmonItemPouchConfig;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
Expand All @@ -24,6 +25,7 @@
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.items.ItemStackHandler;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -46,6 +48,17 @@ public ItemPouch() {
return ActionResult.newResult(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn));
}

@Override
public void onUpdate(@NotNull ItemStack stack, @NotNull World worldIn, @NotNull Entity entityIn, int itemSlot, boolean isSelected) {
super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected);
if (worldIn.isRemote && stack.hasTagCompound() && stack.hasCapability(ITEM_POUCH, null)) {
IPouchItemHandler pouch = Objects.requireNonNull(stack.getCapability(ITEM_POUCH, null));
if (pouch instanceof ItemStackHandler) {
((ItemStackHandler) pouch).deserializeNBT(stack.getTagCompound());
}
}
}

public static class CapabilityProvider implements ICapabilitySerializable<NBTBase> {
private final PouchItemHandler inventory;

Expand Down

0 comments on commit f5bf855

Please sign in to comment.