From 4b782a9e99ce103150fccd71ed297d33c24456f3 Mon Sep 17 00:00:00 2001 From: Azanor Date: Thu, 17 Apr 2014 15:30:09 +0200 Subject: [PATCH] some fixes for syncing between client and server When the inventory was being changed outside the gui the itemstacks were not being synced to client. --- build.gradle | 2 +- src/main/java/baubles/common/Baubles.java | 2 +- .../common/container/InventoryBaubles.java | 14 ++++++ .../common/network/EventHandlerNetwork.java | 2 + .../common/network/PacketPipeline.java | 1 + .../common/network/PacketSyncBauble.java | 49 +++++++++++++++++++ src/main/resources/changelog.txt | 3 ++ 7 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 src/main/java/baubles/common/network/PacketSyncBauble.java diff --git a/build.gradle b/build.gradle index 0b0e25b..4c07de8 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ buildscript { apply plugin: 'forge' -version = "1.7.2-1.0.0.7" +version = "1.7.2-1.0.0.8" group= "com.azanor.baubles" archivesBaseName = "Baubles" diff --git a/src/main/java/baubles/common/Baubles.java b/src/main/java/baubles/common/Baubles.java index 37ed8e9..9c91571 100644 --- a/src/main/java/baubles/common/Baubles.java +++ b/src/main/java/baubles/common/Baubles.java @@ -26,7 +26,7 @@ public class Baubles { public static final String MODID = "Baubles"; public static final String MODNAME = "Baubles"; - public static final String VERSION = "1.0.0.7"; + public static final String VERSION = "1.0.0.8"; @SidedProxy(clientSide = "baubles.client.ClientProxy", serverSide = "baubles.common.CommonProxy") public static CommonProxy proxy; diff --git a/src/main/java/baubles/common/container/InventoryBaubles.java b/src/main/java/baubles/common/container/InventoryBaubles.java index 222b95c..4235c9e 100644 --- a/src/main/java/baubles/common/container/InventoryBaubles.java +++ b/src/main/java/baubles/common/container/InventoryBaubles.java @@ -3,6 +3,7 @@ package baubles.common.container; import java.lang.ref.WeakReference; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; @@ -10,7 +11,9 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import baubles.api.BaubleType; import baubles.api.IBauble; +import baubles.common.Baubles; import baubles.common.lib.PlayerHandler; +import baubles.common.network.PacketSyncBauble; public class InventoryBaubles implements IInventory { public ItemStack[] stackList; @@ -96,6 +99,7 @@ public class InventoryBaubles implements IInventory { } if (eventHandler!=null) this.eventHandler.onCraftMatrixChanged(this); + syncSlotToClient(par1); return itemstack; } else { itemstack = this.stackList[par1].splitStack(par2); @@ -108,6 +112,7 @@ public class InventoryBaubles implements IInventory { ((IBauble)itemstack.getItem()).onUnequipped(itemstack, player.get()); } if (eventHandler!=null) this.eventHandler.onCraftMatrixChanged(this); + syncSlotToClient(par1); return itemstack; } } else { @@ -126,6 +131,7 @@ public class InventoryBaubles implements IInventory { ((IBauble)stack.getItem()).onEquipped(stack, player.get()); } if (eventHandler!=null) this.eventHandler.onCraftMatrixChanged(this); + syncSlotToClient(par1); } /** @@ -220,7 +226,15 @@ public class InventoryBaubles implements IInventory { if (this.stackList[i] != null) { player.dropPlayerItemWithRandomChoice(this.stackList[i], true); this.stackList[i] = null; + syncSlotToClient(i); } } } + + public void syncSlotToClient(int slot) { + try { + if (Baubles.proxy.getClientWorld()==null) + Baubles.packetPipeline.sendTo(new PacketSyncBauble(player.get(),slot), (EntityPlayerMP) player.get()); + } catch (Exception e) { e.printStackTrace(); } + } } diff --git a/src/main/java/baubles/common/network/EventHandlerNetwork.java b/src/main/java/baubles/common/network/EventHandlerNetwork.java index 26005fe..f00636f 100644 --- a/src/main/java/baubles/common/network/EventHandlerNetwork.java +++ b/src/main/java/baubles/common/network/EventHandlerNetwork.java @@ -15,6 +15,8 @@ public class EventHandlerNetwork { Side side = FMLCommonHandler.instance().getEffectiveSide(); if (side == Side.SERVER) { PlayerHandler.loadPlayerBaubles(event.player); + for (int a=0;a<4;a++) + PlayerHandler.getPlayerBaubles(event.player).syncSlotToClient(a); } } diff --git a/src/main/java/baubles/common/network/PacketPipeline.java b/src/main/java/baubles/common/network/PacketPipeline.java index 975fccc..cab5afa 100644 --- a/src/main/java/baubles/common/network/PacketPipeline.java +++ b/src/main/java/baubles/common/network/PacketPipeline.java @@ -118,6 +118,7 @@ public class PacketPipeline extends MessageToMessageCodec