Ermans Posted March 24, 2016 Share Posted March 24, 2016 I'm trying to send GUI-only things (like progress bar update or energy stored) with a custom packet only to player who have the gui open. Obviously I can do this: for (playersWithGuiOpen) PacketHandler.INSTANCE.sendTo(new myCustomMessage(), playerWhoHaveTheGuiOpen); but from my tile I don't know the players, so I decided to use my container: ///////////////Inside myTile///////////////////// protected void syncMachine() { container.sendMessageToCrafters(new MessageTile(this)); markDirty(); } /////////////Inside myContainer////////////// public void sendMessageToCrafters(IMessage message) { for (Object crafter : this.crafters) { EntityPlayerMP player = (EntityPlayerMP) crafter; if (player != null) { PacketHandler.INSTANCE.sendTo(message, player); } } } But this code works fine with just a player (this.crafters contains just a player even there are three different players with the gui open), if I use open to LAN feature and I join with other different players, only the last player who opened the gui is updated. Basically I need to sync only the players who have the gui open, so I can't use "PacketHandler.INSTANCE.sendToAllAround" but I need to use "sendTo". The problem is that I don't know the players who need to be updated. I hope I made it clear. Quote Link to comment Share on other sites More sharing options...
Choonster Posted March 24, 2016 Share Posted March 24, 2016 This should probably be done from your override of Container#detectAndSendChanges . Look at how ContainerFurnace uses this to send progress updates for the burn/cook time. Quote Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future. Link to comment Share on other sites More sharing options...
Ermans Posted March 24, 2016 Author Share Posted March 24, 2016 This should probably be done from your override of Container#detectAndSendChanges . Look at how ContainerFurnace uses this to send progress updates for the burn/cook time. I fixed my post, I submitted it uncompleted Quote Link to comment Share on other sites More sharing options...
Choonster Posted March 24, 2016 Share Posted March 24, 2016 Container#crafters is a list of ICrafting objects, it may contain implementations of ICrafting other than EntityPlayerMP . It's not safe to cast to EntityPlayerMP without checking. Every player with the GUI open will have their own Container on the client and server, so Container#crafters will usually contain 0 players on the client and 1 player on the server. Your TileEntity shouldn't interact with your Container directly, it certainly shouldn't be storing an instance of it. Quote Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future. Link to comment Share on other sites More sharing options...
Ermans Posted March 24, 2016 Author Share Posted March 24, 2016 Container#crafters is a list of ICrafting objects, it may contain implementations of ICrafting other than EntityPlayerMP . It's not safe to cast to EntityPlayerMP without checking. Every player with the GUI open will have their own Container on the client and server, so Container#crafters will usually contain 0 players on the client and 1 player on the server. Your TileEntity shouldn't interact with your Container directly, it certainly shouldn't be storing an instance of it. Ok, so is better if inside Container#detectAndSendChanges I get the message from the tile (if it is changed) and send it to crafter (checking if is a player) ? Quote Link to comment Share on other sites More sharing options...
Choonster Posted March 24, 2016 Share Posted March 24, 2016 Container#crafters is a list of ICrafting objects, it may contain implementations of ICrafting other than EntityPlayerMP . It's not safe to cast to EntityPlayerMP without checking. Every player with the GUI open will have their own Container on the client and server, so Container#crafters will usually contain 0 players on the client and 1 player on the server. Your TileEntity shouldn't interact with your Container directly, it certainly shouldn't be storing an instance of it. Ok, so is better if inside Container#detectAndSendChanges I get the message from the tile (if it is changed) and send it to crafter (checking if is a player) ? Yes, that should work. Quote Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future. Link to comment Share on other sites More sharing options...
Recommended Posts
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.