deerangle Posted February 6, 2016 Posted February 6, 2016 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? Quote
Choonster Posted February 6, 2016 Posted February 6, 2016 Your message can have multiple constructors, as long as one of them takes no arguments. 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.
deerangle Posted February 6, 2016 Author Posted February 6, 2016 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. Quote
Choonster Posted February 6, 2016 Posted February 6, 2016 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 ? 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.
deerangle Posted February 6, 2016 Author Posted February 6, 2016 Im not calling the handler, all im doing, is this : MainRegistry.network.sendToServer(new SlotChangeMessage(tile)); Where do i call the handler? Quote
Choonster Posted February 6, 2016 Posted February 6, 2016 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 ? 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.
deerangle Posted February 6, 2016 Author Posted February 6, 2016 It is registered in the pre-init method. Is there a way to send the tileentity, istead of getting it by coordinates? Quote
Choonster Posted February 6, 2016 Posted February 6, 2016 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 ? 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.
deerangle Posted February 6, 2016 Author Posted February 6, 2016 if(tile.getStackInSlot(0) == new ItemStack(Items.diamond)){ tile.setInventorySlotContents(0, new ItemStack(ModItems.crystalVivium)); } it is Quote
Choonster Posted February 6, 2016 Posted February 6, 2016 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. 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.
deerangle Posted February 6, 2016 Author Posted February 6, 2016 It was the condition, without it, it works! It seems, that getting the itemstack, returns "null". Quote
deerangle Posted February 6, 2016 Author Posted February 6, 2016 I got it, the ItemStack array sots, wasn't set to be public! Thank You SO much for helping Quote
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.