Posted September 29, 201311 yr Hello, I'm trying to figure out how to change a variable in my TileEntity, when a button is pressed and updating all the players about that change. I have 1 number and 2 buttons one for increment the other for decrement. I think, i need packets. So i'm sending a packet when a button is pressed like this: @Override protected void actionPerformed(GuiButton par1GuiButton) { switch (par1GuiButton.id) { case 0: PacketDispatcher.sendPacketToServer(PacketHelper.SendPacket(1, Arrays.asList(1, tileentity.xCoord, tileentity.yCoord, tileentity.zCoord))); break; case 1: PacketDispatcher.sendPacketToServer(PacketHelper.SendPacket(1, Arrays.asList(2, tileentity.xCoord, tileentity.yCoord, tileentity.zCoord))); break; } } My PacketHelper class is like this: public static Packet SendPacket(int id, List<Integer> data) { ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream(; DataOutputStream dataoutputstream = new DataOutputStream(bytearrayoutputstream); try { dataoutputstream.writeInt(id); for (int element : data) { dataoutputstream.writeInt(element); } } catch (Exception ex) { ex.printStackTrace(); } Packet250CustomPayload packet = new Packet250CustomPayload(); packet.channel = "brickcraft"; packet.data = bytearrayoutputstream.toByteArray(); packet.length = bytearrayoutputstream.size(); return packet; } It just creates a packet with a integer list for data storing. Here is my PacketHandler class: @Override public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) { DataInputStream datainputstream = new DataInputStream(new ByteArrayInputStream(packet.data)); int id; ArrayList<Integer> data = new ArrayList<Integer>(); try { id = datainputstream.readInt(); while (datainputstream.available() > 0) { data.add(datainputstream.readInt()); } } catch (IOException ex) { ex.printStackTrace(); return; } HandlePacket(id, data, (EntityPlayer)player); } void HandlePacket(int id, ArrayList<Integer> data, EntityPlayer player) { if (id == 1) { if (player.worldObj.getBlockTileEntity(data.get(1), data.get(2), data.get(3)) != null) { PoseblockTileEntity tileentity = (PoseblockTileEntity)player.worldObj.getBlockTileEntity(data.get(1), data.get(2), data.get(3)); if (data.get(0) == 1) { tileentity.SetScale(tileentity.scale - 1); } if (data.get(0) == 2) { tileentity.SetScale(tileentity.scale + 1); } } } } I checked if a packet is incoming and it is, but the var in the GUI is not updating. I've tried it with world.markBlockForUpdate(x, y, z) but that doesn't worked. Thank you in advance! ss7 You sir are a god damn hero.
September 29, 201311 yr Author Hello, Yes, i have overridden that already and tried both markBlockForUpdate() and onInventoryChanged() but none of them works. ss7 You sir are a god damn hero.
September 29, 201311 yr Author Hello, Problem SOLVED it was that if (scale > 0 && scale > 11) { this.scale = scale; } that was wrong, now it works Thank you! ss7 You sir are a god damn hero.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.