Posted February 6, 20169 yr I have programmed my mod, so it will send a packet: public class SlotChangeMessage implements IMessage{ int x,y,z; public SlotChangeMessage(int x, int y, int z){ this.x = x; this.y = y; this.z = z; } @Override public void fromBytes(ByteBuf buf) { this.x = buf.readInt(); this.y = buf.readInt(); this.z = buf.readInt(); } @Override public void toBytes(ByteBuf buf) { buf.writeInt(x); buf.writeInt(y); buf.writeInt(z); } public static class Handler implements IMessageHandler<SlotChangeMessage, SlotChangeMessage>{ @Override public SlotChangeMessage onMessage(SlotChangeMessage message, MessageContext ctx) { World world = ctx.getServerHandler().playerEntity.worldObj; TileEntityTableLives tile = (TileEntityTableLives) world.getTileEntity(message.x, message.y, message.z); if(tile.getStackInSlot(0) == new ItemStack(Items.diamond)){ tile.setInventorySlotContents(0, new ItemStack(ModItems.crystalVivium)); } return null; } } } but it crashes! I have heared, that the constructor must be empty, but how do i then put the values into the packet?
February 6, 20169 yr Your message can have multiple constructors, as long as one of them takes no arguments. 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.
February 6, 20169 yr Author Thanks, Its not crashing anymore, but it still doesnt do anything, i added a println statement, to check if the values are sent properly, and its recieving the values.
February 6, 20169 yr Thanks, Its not crashing anymore, but it still doesnt do anything, i added a println statement, to check if the values are sent properly, and its recieving the values. Is your handler being called? Is the handler calling setInventorySlotContents ? 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.
February 6, 20169 yr Author Im not calling the handler, all im doing, is this : MainRegistry.network.sendToServer(new SlotChangeMessage(tile)); Where do i call the handler?
February 6, 20169 yr You don't call the handler yourself, FML should be calling it when the message is received on the server. Have you registered your message and handler using SimpleNetworkWrapper#registerMessage ? 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.
February 6, 20169 yr Author It is registered in the pre-init method. Is there a way to send the tileentity, istead of getting it by coordinates?
February 6, 20169 yr No, you need to send the coordinates so you can modify the TileEntity that already exists there. Is your handler being called? Is the handler calling setInventorySlotContents ? 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.
February 6, 20169 yr Author if(tile.getStackInSlot(0) == new ItemStack(Items.diamond)){ tile.setInventorySlotContents(0, new ItemStack(ModItems.crystalVivium)); } it is
February 6, 20169 yr I can see that you're calling setInventorySlotContents , but is the if condition actually met at the time the packet is received? Is the handler being called? Set a breakpoint in Handler#onMessage , run Minecraft in debug mode and step through the code. 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.
February 6, 20169 yr Author It was the condition, without it, it works! It seems, that getting the itemstack, returns "null".
February 6, 20169 yr Author I got it, the ItemStack array sots, wasn't set to be public! Thank You SO much for helping
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.