Jump to content

[SOLVED] Packet Sending Crash!


deerangle

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.