Posted February 16, 201510 yr comment_144063 Hello, I ran into a strange packet issue: When I send a packet to update the server for an ItemStack.TagCompount changes, it seems can't upadate nothing, even if i use the ItemStack or TagCompound object: Packet: public class PacketPlayerStats implements IMessage { ItemStack drill; NBTTagCompound stackCompound; public PacketPlayerStats() { } public PacketPlayerStats(ItemStack item, NBTTagCompound compound) { this.drill = item; this.stackCompound = compound; } @Override public void fromBytes(ByteBuf buf) { this.drill = ByteBufUtils.readItemStack(buf); this.stackCompound = ByteBufUtils.readTag(buf); } @Override public void toBytes(ByteBuf buf) { ByteBufUtils.writeItemStack(buf, this.drill); ByteBufUtils.writeTag(buf, this.stackCompound); } public static class Handler implements IMessageHandler<PacketPlayerStats, IMessage> { @Override public IMessage onMessage(PacketPlayerStats message, MessageContext ctx) { EntityPlayer player = NetUtils.getPlayerFromContext(ctx); message.drill.stackTagCompound.setInteger("scan", (int)message.value); OR message.stackCompound.setInteger("scan", (int)message.value); return null; } } } Function: @Override public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) { if (world.isRemote) { if (Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL)) { if(!itemStack.hasTagCompound()) itemStack.setTagCompound(new NBTTagCompound()); int scanMode = itemStack.stackTagCompound.getInteger("scan"); if (scanMode == 0) { scanMode = 1; } else if (scanMode == 1) { scanMode = 2; } else if (scanMode == 2) { scanMode = 3; } else if (scanMode == 3) { scanMode = 0; } itemStack.stackTagCompound.setInteger("scan", scanMode); PacketDispatcher.sendToServer(new PacketPlayerStats(itemStack, itemStack.stackTagCompound)); } } }
February 17, 201510 yr comment_144088 Hello, I ran into a strange packet issue: When I send a packet to update the server for an ItemStack.TagCompount changes, it seems can't upadate nothing, even if i use the ItemStack or TagCompound object: Packet: public class PacketPlayerStats implements IMessage { ItemStack drill; NBTTagCompound stackCompound; public PacketPlayerStats() { } public PacketPlayerStats(ItemStack item, NBTTagCompound compound) { this.drill = item; this.stackCompound = compound; } @Override public void fromBytes(ByteBuf buf) { this.drill = ByteBufUtils.readItemStack(buf); this.stackCompound = ByteBufUtils.readTag(buf); } @Override public void toBytes(ByteBuf buf) { ByteBufUtils.writeItemStack(buf, this.drill); ByteBufUtils.writeTag(buf, this.stackCompound); } public static class Handler implements IMessageHandler<PacketPlayerStats, IMessage> { @Override public IMessage onMessage(PacketPlayerStats message, MessageContext ctx) { EntityPlayer player = NetUtils.getPlayerFromContext(ctx); message.drill.stackTagCompound.setInteger("scan", (int)message.value); OR message.stackCompound.setInteger("scan", (int)message.value); return null; } } } Function: @Override public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) { if (world.isRemote) { if (Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL)) { if(!itemStack.hasTagCompound()) itemStack.setTagCompound(new NBTTagCompound()); int scanMode = itemStack.stackTagCompound.getInteger("scan"); if (scanMode == 0) { scanMode = 1; } else if (scanMode == 1) { scanMode = 2; } else if (scanMode == 2) { scanMode = 3; } else if (scanMode == 3) { scanMode = 0; } itemStack.stackTagCompound.setInteger("scan", scanMode); PacketDispatcher.sendToServer(new PacketPlayerStats(itemStack, itemStack.stackTagCompound)); } } } You aren't doing anything in the onMessage method... Since the message.drill is just a part of 'message', not the real ItemStack instance player is holding, nothing will happen. You should get the drill item form the Player. & there is no need to send the 'drill' ItemStack. I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.
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.