From ee9abd496072c87a8374296c365b152b46f32565 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Tue, 9 Aug 2016 20:56:09 +0200 Subject: [PATCH] Packet Handler helper --- .../mod/booklet/GuiBooklet.java | 12 +---- .../mod/event/CommonEvents.java | 7 +-- .../mod/inventory/gui/EnergyDisplay.java | 7 +-- .../mod/inventory/gui/GuiCoffeeMachine.java | 10 +--- .../mod/inventory/gui/GuiGiantChest.java | 10 +--- .../mod/inventory/gui/GuiInputter.java | 10 +--- .../gui/GuiLaserRelayItemWhitelist.java | 10 +--- .../mod/inventory/gui/GuiMiner.java | 10 +--- .../mod/inventory/gui/GuiPhantomPlacer.java | 11 +--- .../mod/inventory/gui/GuiRangedCollector.java | 10 +--- .../mod/inventory/gui/GuiXPSolidifier.java | 10 +--- .../mod/items/ItemLaserWrench.java | 6 +-- .../mod/network/PacketHandler.java | 5 +- .../mod/network/PacketHandlerHelper.java | 52 +++++++++++++++++++ 14 files changed, 77 insertions(+), 93 deletions(-) create mode 100644 src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandlerHelper.java diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/GuiBooklet.java b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/GuiBooklet.java index d0f29b5cc..726c4c74a 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/GuiBooklet.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/GuiBooklet.java @@ -26,6 +26,7 @@ import de.ellpeck.actuallyadditions.mod.items.ItemBooklet; import de.ellpeck.actuallyadditions.mod.misc.SoundHandler; import de.ellpeck.actuallyadditions.mod.network.PacketClientToServer; import de.ellpeck.actuallyadditions.mod.network.PacketHandler; +import de.ellpeck.actuallyadditions.mod.network.PacketHandlerHelper; import de.ellpeck.actuallyadditions.mod.proxy.ClientProxy; import de.ellpeck.actuallyadditions.mod.update.UpdateChecker; import de.ellpeck.actuallyadditions.mod.util.AssetUtil; @@ -392,11 +393,6 @@ public class GuiBooklet extends GuiScreen implements IBookletGui{ NBTTagCompound extraData = new NBTTagCompound(); extraData.setBoolean("BookAlreadyOpened", true); - NBTTagCompound dataToSend = new NBTTagCompound(); - dataToSend.setTag("Data", extraData); - dataToSend.setInteger("WorldID", Minecraft.getMinecraft().theWorld.provider.getDimension()); - dataToSend.setInteger("PlayerID", Minecraft.getMinecraft().thePlayer.getEntityId()); - PacketHandler.theNetwork.sendToServer(new PacketClientToServer(dataToSend, PacketHandler.CHANGE_PLAYER_DATA_HANDLER)); } else{ BookletUtils.openLastBookPage(this, data.theCompound.getCompoundTag("BookletData")); @@ -463,11 +459,7 @@ public class GuiBooklet extends GuiScreen implements IBookletGui{ NBTTagCompound extraData = new NBTTagCompound(); extraData.setTag("BookletData", bookletData); - NBTTagCompound dataToSend = new NBTTagCompound(); - dataToSend.setTag("Data", extraData); - dataToSend.setInteger("WorldID", mc.theWorld.provider.getDimension()); - dataToSend.setInteger("PlayerID", mc.thePlayer.getEntityId()); - PacketHandler.theNetwork.sendToServer(new PacketClientToServer(dataToSend, PacketHandler.CHANGE_PLAYER_DATA_HANDLER)); + PacketHandlerHelper.sendChangePlayerDataPacket(extraData); } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/event/CommonEvents.java b/src/main/java/de/ellpeck/actuallyadditions/mod/event/CommonEvents.java index 90718fbc7..34110eb72 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/event/CommonEvents.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/event/CommonEvents.java @@ -17,6 +17,7 @@ import de.ellpeck.actuallyadditions.mod.data.PlayerData; import de.ellpeck.actuallyadditions.mod.data.WorldData; import de.ellpeck.actuallyadditions.mod.items.InitItems; import de.ellpeck.actuallyadditions.mod.network.PacketHandler; +import de.ellpeck.actuallyadditions.mod.network.PacketHandlerHelper; import de.ellpeck.actuallyadditions.mod.network.PacketServerToClient; import de.ellpeck.actuallyadditions.mod.util.ItemUtil; import de.ellpeck.actuallyadditions.mod.util.ModUtil; @@ -97,11 +98,7 @@ public class CommonEvents{ EntityPlayerMP player = (EntityPlayerMP)event.player; PlayerData.PlayerSave data = PlayerData.getDataFromPlayer(player); if(!data.theCompound.hasNoTags()){ - NBTTagCompound compound = new NBTTagCompound(); - compound.setUniqueId("UUID", player.getUniqueID()); - compound.setTag("Data", data.theCompound); - compound.setBoolean("Log", true); - PacketHandler.theNetwork.sendTo(new PacketServerToClient(compound, PacketHandler.PLAYER_DATA_TO_CLIENT_HANDLER), player); + PacketHandlerHelper.sendPlayerDataToClientPacket(player, data.theCompound, true); ModUtil.LOGGER.info("Sending Player Data to player "+player.getName()+" with UUID "+player.getUniqueID()+" with info "+data.theCompound+"."); } else{ diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/EnergyDisplay.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/EnergyDisplay.java index a1d8d60a5..91106ddcc 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/EnergyDisplay.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/EnergyDisplay.java @@ -14,6 +14,7 @@ import cofh.api.energy.EnergyStorage; import de.ellpeck.actuallyadditions.mod.data.PlayerData; import de.ellpeck.actuallyadditions.mod.network.PacketClientToServer; import de.ellpeck.actuallyadditions.mod.network.PacketHandler; +import de.ellpeck.actuallyadditions.mod.network.PacketHandlerHelper; import de.ellpeck.actuallyadditions.mod.util.AssetUtil; import de.ellpeck.actuallyadditions.mod.util.ModUtil; import de.ellpeck.actuallyadditions.mod.util.StringUtil; @@ -110,10 +111,6 @@ public class EnergyDisplay extends Gui{ this.displayTesla = !this.displayTesla; data.setBoolean("DisplayTesla", this.displayTesla); - NBTTagCompound dataToSend = new NBTTagCompound(); - dataToSend.setTag("Data", data); - dataToSend.setInteger("WorldID", Minecraft.getMinecraft().theWorld.provider.getDimension()); - dataToSend.setInteger("PlayerID", Minecraft.getMinecraft().thePlayer.getEntityId()); - PacketHandler.theNetwork.sendToServer(new PacketClientToServer(dataToSend, PacketHandler.CHANGE_PLAYER_DATA_HANDLER)); + PacketHandlerHelper.sendChangePlayerDataPacket(data); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiCoffeeMachine.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiCoffeeMachine.java index 85cc26edb..212e1a0f4 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiCoffeeMachine.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiCoffeeMachine.java @@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.inventory.gui; import de.ellpeck.actuallyadditions.mod.inventory.ContainerCoffeeMachine; import de.ellpeck.actuallyadditions.mod.network.PacketClientToServer; import de.ellpeck.actuallyadditions.mod.network.PacketHandler; +import de.ellpeck.actuallyadditions.mod.network.PacketHandlerHelper; import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase; import de.ellpeck.actuallyadditions.mod.tile.TileEntityCoffeeMachine; import de.ellpeck.actuallyadditions.mod.util.AssetUtil; @@ -130,13 +131,6 @@ public class GuiCoffeeMachine extends GuiContainer{ @Override public void actionPerformed(GuiButton button){ - NBTTagCompound compound = new NBTTagCompound(); - compound.setInteger("X", this.x); - compound.setInteger("Y", this.y); - compound.setInteger("Z", this.z); - compound.setInteger("WorldID", this.world.provider.getDimension()); - compound.setInteger("PlayerID", Minecraft.getMinecraft().thePlayer.getEntityId()); - compound.setInteger("ButtonID", button.id); - PacketHandler.theNetwork.sendToServer(new PacketClientToServer(compound, PacketHandler.GUI_BUTTON_TO_TILE_HANDLER)); + PacketHandlerHelper.sendButtonPacket(this.machine, button.id); } } \ No newline at end of file diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiGiantChest.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiGiantChest.java index e556a286b..f433da4ef 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiGiantChest.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiGiantChest.java @@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.inventory.gui; import de.ellpeck.actuallyadditions.mod.inventory.ContainerGiantChest; import de.ellpeck.actuallyadditions.mod.network.PacketClientToServer; import de.ellpeck.actuallyadditions.mod.network.PacketHandler; +import de.ellpeck.actuallyadditions.mod.network.PacketHandlerHelper; import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase; import de.ellpeck.actuallyadditions.mod.tile.TileEntityGiantChest; import de.ellpeck.actuallyadditions.mod.tile.TileEntityGiantChestLarge; @@ -63,14 +64,7 @@ public class GuiGiantChest extends GuiContainer{ @Override protected void actionPerformed(GuiButton button) throws IOException{ if(button.id >= 0 && button.id < 3){ - NBTTagCompound compound = new NBTTagCompound(); - compound.setInteger("X", this.chest.getPos().getX()); - compound.setInteger("Y", this.chest.getPos().getY()); - compound.setInteger("Z", this.chest.getPos().getZ()); - compound.setInteger("PlayerID", Minecraft.getMinecraft().thePlayer.getEntityId()); - compound.setInteger("WorldID", this.chest.getWorld().provider.getDimension()); - compound.setInteger("ButtonID", button.id); - PacketHandler.theNetwork.sendToServer(new PacketClientToServer(compound, PacketHandler.GUI_BUTTON_TO_TILE_HANDLER)); + PacketHandlerHelper.sendButtonPacket(this.chest, button.id); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiInputter.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiInputter.java index 19ccfce25..b1625d522 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiInputter.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiInputter.java @@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.inventory.gui; import de.ellpeck.actuallyadditions.mod.inventory.ContainerInputter; import de.ellpeck.actuallyadditions.mod.network.PacketClientToServer; import de.ellpeck.actuallyadditions.mod.network.PacketHandler; +import de.ellpeck.actuallyadditions.mod.network.PacketHandlerHelper; import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase; import de.ellpeck.actuallyadditions.mod.tile.TileEntityInputter; import de.ellpeck.actuallyadditions.mod.util.AssetUtil; @@ -256,14 +257,7 @@ public class GuiInputter extends GuiContainer{ this.setVariable(this.fieldPullEnd, 3); } else{ - NBTTagCompound compound = new NBTTagCompound(); - compound.setInteger("X", this.x); - compound.setInteger("Y", this.y); - compound.setInteger("Z", this.z); - compound.setInteger("WorldID", this.world.provider.getDimension()); - compound.setInteger("PlayerID", Minecraft.getMinecraft().thePlayer.getEntityId()); - compound.setInteger("ButtonID", button.id); - PacketHandler.theNetwork.sendToServer(new PacketClientToServer(compound, PacketHandler.GUI_BUTTON_TO_TILE_HANDLER)); + PacketHandlerHelper.sendButtonPacket(this.tileInputter, button.id); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiLaserRelayItemWhitelist.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiLaserRelayItemWhitelist.java index 60e054bfe..4240bf1b4 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiLaserRelayItemWhitelist.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiLaserRelayItemWhitelist.java @@ -14,6 +14,7 @@ import de.ellpeck.actuallyadditions.mod.inventory.ContainerLaserRelayItemWhiteli import de.ellpeck.actuallyadditions.mod.inventory.gui.GuiInputter.SmallerButton; import de.ellpeck.actuallyadditions.mod.network.PacketClientToServer; import de.ellpeck.actuallyadditions.mod.network.PacketHandler; +import de.ellpeck.actuallyadditions.mod.network.PacketHandlerHelper; import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase; import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelayItemWhitelist; import de.ellpeck.actuallyadditions.mod.util.AssetUtil; @@ -75,14 +76,7 @@ public class GuiLaserRelayItemWhitelist extends GuiContainer{ @Override public void actionPerformed(GuiButton button){ - NBTTagCompound compound = new NBTTagCompound(); - compound.setInteger("X", this.tile.getPos().getX()); - compound.setInteger("Y", this.tile.getPos().getY()); - compound.setInteger("Z", this.tile.getPos().getZ()); - compound.setInteger("WorldID", this.tile.getWorld().provider.getDimension()); - compound.setInteger("PlayerID", Minecraft.getMinecraft().thePlayer.getEntityId()); - compound.setInteger("ButtonID", button.id); - PacketHandler.theNetwork.sendToServer(new PacketClientToServer(compound, PacketHandler.GUI_BUTTON_TO_TILE_HANDLER)); + PacketHandlerHelper.sendButtonPacket(this.tile, button.id); } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiMiner.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiMiner.java index 026bc51a6..8de798e65 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiMiner.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiMiner.java @@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.inventory.gui; import de.ellpeck.actuallyadditions.mod.inventory.ContainerMiner; import de.ellpeck.actuallyadditions.mod.network.PacketClientToServer; import de.ellpeck.actuallyadditions.mod.network.PacketHandler; +import de.ellpeck.actuallyadditions.mod.network.PacketHandlerHelper; import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase; import de.ellpeck.actuallyadditions.mod.tile.TileEntityMiner; import de.ellpeck.actuallyadditions.mod.util.AssetUtil; @@ -72,13 +73,6 @@ public class GuiMiner extends GuiContainer{ @Override public void actionPerformed(GuiButton button){ - NBTTagCompound compound = new NBTTagCompound(); - compound.setInteger("X", this.miner.getPos().getX()); - compound.setInteger("Y", this.miner.getPos().getY()); - compound.setInteger("Z", this.miner.getPos().getZ()); - compound.setInteger("WorldID", this.miner.getWorld().provider.getDimension()); - compound.setInteger("PlayerID", Minecraft.getMinecraft().thePlayer.getEntityId()); - compound.setInteger("ButtonID", button.id); - PacketHandler.theNetwork.sendToServer(new PacketClientToServer(compound, PacketHandler.GUI_BUTTON_TO_TILE_HANDLER)); + PacketHandlerHelper.sendButtonPacket(this.miner, button.id); } } \ No newline at end of file diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiPhantomPlacer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiPhantomPlacer.java index 717e6b385..c92a311c7 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiPhantomPlacer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiPhantomPlacer.java @@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.inventory.gui; import de.ellpeck.actuallyadditions.mod.inventory.ContainerPhantomPlacer; import de.ellpeck.actuallyadditions.mod.network.PacketClientToServer; import de.ellpeck.actuallyadditions.mod.network.PacketHandler; +import de.ellpeck.actuallyadditions.mod.network.PacketHandlerHelper; import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase; import de.ellpeck.actuallyadditions.mod.tile.TileEntityPhantomPlacer; import de.ellpeck.actuallyadditions.mod.util.AssetUtil; @@ -82,15 +83,7 @@ public class GuiPhantomPlacer extends GuiContainer{ @Override protected void actionPerformed(GuiButton button) throws IOException{ if(!this.placer.isBreaker){ - NBTTagCompound compound = new NBTTagCompound(); - BlockPos pos = this.placer.getPos(); - compound.setInteger("X", pos.getX()); - compound.setInteger("Y", pos.getY()); - compound.setInteger("Z", pos.getZ()); - compound.setInteger("WorldID", this.placer.getWorld().provider.getDimension()); - compound.setInteger("PlayerID", Minecraft.getMinecraft().thePlayer.getEntityId()); - compound.setInteger("ButtonID", button.id); - PacketHandler.theNetwork.sendToServer(new PacketClientToServer(compound, PacketHandler.GUI_BUTTON_TO_TILE_HANDLER)); + PacketHandlerHelper.sendButtonPacket(this.placer, button.id); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiRangedCollector.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiRangedCollector.java index f4e7205ec..5ea765795 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiRangedCollector.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiRangedCollector.java @@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.inventory.gui; import de.ellpeck.actuallyadditions.mod.inventory.ContainerRangedCollector; import de.ellpeck.actuallyadditions.mod.network.PacketClientToServer; import de.ellpeck.actuallyadditions.mod.network.PacketHandler; +import de.ellpeck.actuallyadditions.mod.network.PacketHandlerHelper; import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase; import de.ellpeck.actuallyadditions.mod.tile.TileEntityRangedCollector; import de.ellpeck.actuallyadditions.mod.util.AssetUtil; @@ -89,13 +90,6 @@ public class GuiRangedCollector extends GuiContainer{ @Override public void actionPerformed(GuiButton button){ - NBTTagCompound compound = new NBTTagCompound(); - compound.setInteger("X", this.x); - compound.setInteger("Y", this.y); - compound.setInteger("Z", this.z); - compound.setInteger("WorldID", this.world.provider.getDimension()); - compound.setInteger("PlayerID", Minecraft.getMinecraft().thePlayer.getEntityId()); - compound.setInteger("ButtonID", button.id); - PacketHandler.theNetwork.sendToServer(new PacketClientToServer(compound, PacketHandler.GUI_BUTTON_TO_TILE_HANDLER)); + PacketHandlerHelper.sendButtonPacket(this.collector, button.id); } } \ No newline at end of file diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiXPSolidifier.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiXPSolidifier.java index 089ffc6f1..e7f24555e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiXPSolidifier.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiXPSolidifier.java @@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.inventory.gui; import de.ellpeck.actuallyadditions.mod.inventory.ContainerXPSolidifier; import de.ellpeck.actuallyadditions.mod.network.PacketClientToServer; import de.ellpeck.actuallyadditions.mod.network.PacketHandler; +import de.ellpeck.actuallyadditions.mod.network.PacketHandlerHelper; import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase; import de.ellpeck.actuallyadditions.mod.tile.TileEntityXPSolidifier; import de.ellpeck.actuallyadditions.mod.util.AssetUtil; @@ -94,14 +95,7 @@ public class GuiXPSolidifier extends GuiContainer{ @Override public void actionPerformed(GuiButton button){ - NBTTagCompound compound = new NBTTagCompound(); - compound.setInteger("X", this.x); - compound.setInteger("Y", this.y); - compound.setInteger("Z", this.z); - compound.setInteger("WorldID", this.world.provider.getDimension()); - compound.setInteger("PlayerID", Minecraft.getMinecraft().thePlayer.getEntityId()); - compound.setInteger("ButtonID", button.id); - PacketHandler.theNetwork.sendToServer(new PacketClientToServer(compound, PacketHandler.GUI_BUTTON_TO_TILE_HANDLER)); + PacketHandlerHelper.sendButtonPacket(this.solidifier, button.id); this.solidifier.onButtonPressed(button.id, Minecraft.getMinecraft().thePlayer); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemLaserWrench.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemLaserWrench.java index 78645b6b4..4fcbbf3a3 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemLaserWrench.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemLaserWrench.java @@ -14,6 +14,7 @@ import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.mod.data.PlayerData; import de.ellpeck.actuallyadditions.mod.items.base.ItemBase; import de.ellpeck.actuallyadditions.mod.network.PacketHandler; +import de.ellpeck.actuallyadditions.mod.network.PacketHandlerHelper; import de.ellpeck.actuallyadditions.mod.network.PacketServerToClient; import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelay; import de.ellpeck.actuallyadditions.mod.util.ModUtil; @@ -95,10 +96,7 @@ public class ItemLaserWrench extends ItemBase{ save.theCompound.setInteger("LaserWrenchMode", currMode); if(player instanceof EntityPlayerMP){ - NBTTagCompound compound = new NBTTagCompound(); - compound.setUniqueId("UUID", player.getUniqueID()); - compound.setTag("Data", save.theCompound); - PacketHandler.theNetwork.sendTo(new PacketServerToClient(compound, PacketHandler.PLAYER_DATA_TO_CLIENT_HANDLER), (EntityPlayerMP)player); + PacketHandlerHelper.sendPlayerDataToClientPacket(player, save.theCompound, false); } player.addChatComponentMessage(new TextComponentString("Mode changed to "+WrenchMode.values()[currMode].name+"!")); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandler.java index 955211d8d..0fdadce21 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandler.java @@ -156,10 +156,7 @@ public final class PacketHandler{ PlayerData.PlayerSave playerData = PlayerData.getDataFromPlayer(player); playerData.theCompound.merge(data); if(player instanceof EntityPlayerMP){ - NBTTagCompound tag = new NBTTagCompound(); - tag.setUniqueId("UUID", player.getUniqueID()); - tag.setTag("Data", playerData.theCompound); - PacketHandler.theNetwork.sendTo(new PacketServerToClient(tag, PLAYER_DATA_TO_CLIENT_HANDLER), (EntityPlayerMP)player); + } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandlerHelper.java b/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandlerHelper.java new file mode 100644 index 000000000..9c1643a58 --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/network/PacketHandlerHelper.java @@ -0,0 +1,52 @@ +/* + * This file ("PacketHandlerHelper.java") is part of the Actually Additions mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://ellpeck.de/actaddlicense + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015-2016 Ellpeck + */ + +package de.ellpeck.actuallyadditions.mod.network; + +import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; + +public final class PacketHandlerHelper{ + + public static void sendButtonPacket(TileEntity tile, int buttonId){ + NBTTagCompound compound = new NBTTagCompound(); + BlockPos pos = tile.getPos(); + compound.setInteger("X", pos.getX()); + compound.setInteger("Y", pos.getY()); + compound.setInteger("Z", pos.getZ()); + compound.setInteger("WorldID", tile.getWorld().provider.getDimension()); + compound.setInteger("PlayerID", Minecraft.getMinecraft().thePlayer.getEntityId()); + compound.setInteger("ButtonID", buttonId); + PacketHandler.theNetwork.sendToServer(new PacketClientToServer(compound, PacketHandler.GUI_BUTTON_TO_TILE_HANDLER)); + } + + public static void sendChangePlayerDataPacket(NBTTagCompound data){ + NBTTagCompound compound = new NBTTagCompound(); + compound.setTag("Data", data); + Minecraft mc = Minecraft.getMinecraft(); + compound.setInteger("WorldID", mc.theWorld.provider.getDimension()); + compound.setInteger("PlayerID", mc.thePlayer.getEntityId()); + PacketHandler.theNetwork.sendToServer(new PacketClientToServer(compound, PacketHandler.CHANGE_PLAYER_DATA_HANDLER)); + } + + public static void sendPlayerDataToClientPacket(EntityPlayer player, NBTTagCompound data, boolean log){ + if(player instanceof EntityPlayerMP){ + NBTTagCompound compound = new NBTTagCompound(); + compound.setUniqueId("UUID", player.getUniqueID()); + compound.setTag("Data", data); + compound.setBoolean("Log", log); + PacketHandler.theNetwork.sendTo(new PacketServerToClient(compound, PacketHandler.PLAYER_DATA_TO_CLIENT_HANDLER), (EntityPlayerMP)player); + } + } +}