Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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?

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.

  • 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.

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.

  • Author

Im not calling the handler, all im doing, is this :

MainRegistry.network.sendToServer(new SlotChangeMessage(tile));

Where do i call the handler?

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.

  • Author

It is registered in the pre-init method.

Is there a way to send the tileentity, istead of getting it by coordinates?

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.

  • Author

if(tile.getStackInSlot(0) == new ItemStack(Items.diamond)){
tile.setInventorySlotContents(0, new ItemStack(ModItems.crystalVivium));
}

it is

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.

  • Author

It was the condition, without it, it works!

It seems, that getting the itemstack, returns "null".

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.