From d788b1b69722dd58566530c57bedb0a9060a518f Mon Sep 17 00:00:00 2001 From: Azanor Date: Tue, 6 May 2014 07:34:45 +0200 Subject: [PATCH] multiple client sync update --- build.gradle | 2 +- src/main/java/baubles/common/Baubles.java | 2 +- .../common/container/InventoryBaubles.java | 12 ++++---- .../baubles/common/lib/PlayerHandler.java | 28 ------------------- .../common/network/EventHandlerNetwork.java | 4 +-- src/main/resources/changelog.txt | 3 ++ 6 files changed, 12 insertions(+), 39 deletions(-) diff --git a/build.gradle b/build.gradle index f9f8f95..aab8e66 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ buildscript { apply plugin: 'forge' -version = "1.7.2-1.0.0.10" +version = "1.7.2-1.0.0.11" 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 c2f099d..e79ec89 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.10"; + public static final String VERSION = "1.0.0.11"; @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 f55f00a..a42d2e2 100644 --- a/src/main/java/baubles/common/container/InventoryBaubles.java +++ b/src/main/java/baubles/common/container/InventoryBaubles.java @@ -99,7 +99,7 @@ public class InventoryBaubles implements IInventory { } if (eventHandler!=null) this.eventHandler.onCraftMatrixChanged(this); - syncSlotToClient(par1); + syncSlotToClients(par1); return itemstack; } else { itemstack = this.stackList[par1].splitStack(par2); @@ -112,7 +112,7 @@ public class InventoryBaubles implements IInventory { ((IBauble)itemstack.getItem()).onUnequipped(itemstack, player.get()); } if (eventHandler!=null) this.eventHandler.onCraftMatrixChanged(this); - syncSlotToClient(par1); + syncSlotToClients(par1); return itemstack; } } else { @@ -131,7 +131,7 @@ public class InventoryBaubles implements IInventory { ((IBauble)stack.getItem()).onEquipped(stack, player.get()); } if (eventHandler!=null) this.eventHandler.onCraftMatrixChanged(this); - syncSlotToClient(par1); + syncSlotToClients(par1); } /** @@ -234,15 +234,15 @@ public class InventoryBaubles implements IInventory { if (this.stackList[i] != null) { player.dropPlayerItemWithRandomChoice(this.stackList[i], true); this.stackList[i] = null; - syncSlotToClient(i); + syncSlotToClients(i); } } } - public void syncSlotToClient(int slot) { + public void syncSlotToClients(int slot) { try { if (Baubles.proxy.getClientWorld()==null) - Baubles.packetPipeline.sendTo(new PacketSyncBauble(player.get(),slot), (EntityPlayerMP) player.get()); + Baubles.packetPipeline.sendToAll(new PacketSyncBauble(player.get(),slot)); } catch (Exception e) { e.printStackTrace(); } } } diff --git a/src/main/java/baubles/common/lib/PlayerHandler.java b/src/main/java/baubles/common/lib/PlayerHandler.java index 6c52114..6e3bf0a 100644 --- a/src/main/java/baubles/common/lib/PlayerHandler.java +++ b/src/main/java/baubles/common/lib/PlayerHandler.java @@ -100,34 +100,6 @@ public class PlayerHandler { playerBaubles.put(player.getCommandSenderName(), inventory); if (save) savePlayerBaubles(player); } - - -// if (file1 == null || !file1.exists()) -// { -// Baubles.log.warn("Baubles inventory not found for "+player.getCommandSenderName()+". Trying to load backup baubles data."); -// file1 = getBackupFileFromPlayer(player); -// } -// if (file1 != null && file1.exists()) -// { -// FileInputStream fileinputstream = new FileInputStream(file1); -// NBTTagCompound data = CompressedStreamTools.readCompressed(fileinputstream); -// fileinputstream.close(); -// -// InventoryBaubles inventory = new InventoryBaubles(player); -// inventory.readNBT(data); -// playerBaubles.put(player.getCommandSenderName(), inventory); -// -// } else { //legacy data -// Baubles.log.warn("Baubles inventory not found for "+player.getCommandSenderName()+". Trying to load legacy baubles data."); -// NBTTagCompound data = player.getEntityData(); -// if (!data.hasKey("Baubles")) { -// data.setTag("Baubles", new NBTTagCompound()); -// } -// InventoryBaubles inventory = new InventoryBaubles(player); -// inventory.readNBT(player); -// playerBaubles.put(player.getCommandSenderName(), inventory); -// savePlayerBaubles(player); -// } } catch (Exception exception1) { diff --git a/src/main/java/baubles/common/network/EventHandlerNetwork.java b/src/main/java/baubles/common/network/EventHandlerNetwork.java index b6799eb..b9682dc 100644 --- a/src/main/java/baubles/common/network/EventHandlerNetwork.java +++ b/src/main/java/baubles/common/network/EventHandlerNetwork.java @@ -1,7 +1,5 @@ package baubles.common.network; -import java.util.HashMap; - import baubles.common.lib.PlayerHandler; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.eventhandler.SubscribeEvent; @@ -16,7 +14,7 @@ public class EventHandlerNetwork { if (side == Side.SERVER) { PlayerHandler.loadPlayerBaubles(event.player); for (int a=0;a<4;a++) - PlayerHandler.getPlayerBaubles(event.player).syncSlotToClient(a); + PlayerHandler.getPlayerBaubles(event.player).syncSlotToClients(a); } } diff --git a/src/main/resources/changelog.txt b/src/main/resources/changelog.txt index a6ff012..a234efb 100644 --- a/src/main/resources/changelog.txt +++ b/src/main/resources/changelog.txt @@ -1,3 +1,6 @@ +1.0.0.11 +- baubles are now synced to all clients on a server, allowing modders to add visual components or other client-side stuff for baubles. + 1.0.0.10 - moved baubles data from player data to custom savefiles (*.baub) - a backup file is also saved each time in case the main one becomes corrupt.