Posted February 15, 201510 yr Hi again, I need to send via packet more data values at same time like this: PacketDispatcher.sendToServer(new PacketClientStats(1, 2, 3.5F, itemStack)); And I noticed that only the first param is correctly sended instead other params have wrong values: PacketClientStats class: public class PacketClientStats implements IMessage, IMessageHandler<PacketClientStats, IMessage> { int stats = 0; int food = 0; float heart = 0; static ItemStack drill; public PacketClientStats() { } public PacketClientStats(int stats, int food, float heart, ItemStack drill) { this.stats = stats; this.food = food; this.heart = heart; this.drill = drill; } public IMessage onMessage(PacketClientStats message, MessageContext ctx) { System.out.println("stats = " + message.stats); System.out.println("food = " + message.food); System.out.println("heart = " + message.heart); System.out.println("drill = " + message.drill.getDisplayName()); return null; } public void fromBytes(ByteBuf buf) { this.stats = buf.getInt(0); this.food = buf.getInt(0); this.heart = buf.getFloat(0); } public void toBytes(ByteBuf buf) { buf.writeInt(this.stats); buf.writeInt(this.food); buf.writeFloat(this.heart); } } And the "itemStack" param works properly only if it's declared with "static" option ...
February 15, 201510 yr Author Don't declare it static. It "doesn't work" because you don't send the "drill" parameter. And your fromBytes method is broken, use read***, not get***. Also do not implement IMessage and IMessageHandler on the same class. And you should use @Override where appropriate. How can I send a "ItemStack" object if it's possible?
February 15, 201510 yr Author Take a look at FML's ByteBufUtils class. Thanks works. Instaed is it possible to send a "IInventory" object?
February 15, 201510 yr Author Short answer: No. Longer answer: It depends. What kind of inventory is it? Why do you think you need to send it? What is your goal, why do you send this packet in the first place? Well, I realized that I don't need to send a packet to the server because the function "updateTick" of my block container (chest) affects both sides... correct me if I'm wrong thank you again ...
February 15, 201510 yr Author In your Block updateTick actually only happens on the server. then I right when I say "I don't need to send a packet to the server" .. and this is all i need to keep updated my inventory .. right?
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.