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

Hi! Im trying to send information (Clicking a button to change the value of a integer in the tileEntity) from the GUI to the TileEntity. I know I have to do some packets, and there's where the problem is.

I have a IMessage and an IMessageHandler, but when I try pressing the button I get "A fatal error has occured, this connection is terminated".

 

Here's the code for the IMessage and the IMessageHandler.

public class PacketDrill implements IMessage{

private int x;
private int y;
private int z;
private int mode;

public PacketDrill(TileEntityDrillModifier te){
	x = te.xCoord;
	y = te.yCoord;
	z = te.zCoord;
	mode = te.getMode();
}

@Override
public void fromBytes(ByteBuf buf) {
	x = buf.readInt();
	y = buf.readInt();
	z = buf.readInt();
	mode = buf.readInt();
}

@Override
public void toBytes(ByteBuf buf) {
	buf.writeInt(x);
	buf.writeInt(y);
	buf.writeInt(z);		
	buf.writeInt(mode);
}

public static class Handler implements IMessageHandler<PacketDrill, IMessage>{

	@Override
	public IMessage onMessage(PacketDrill message, MessageContext ctx) {
		TileEntity tile = ctx.getServerHandler().playerEntity.worldObj.getTileEntity(message.x, message.y, message.z);
		if(tile instanceof TileEntityDrillModifier){
			TileEntityDrillModifier modifier =  (TileEntityDrillModifier)tile;
			modifier.setMode(message.mode);
			ctx.getServerHandler().playerEntity.worldObj.markBlockForUpdate(message.x, message.y, message.z);
		}
		return null;
	}
}
}

 

After that I register it in the preInit:

Miscellany.network.registerMessage(PacketDrill.Handler.class, PacketDrill.class, 0, Side.SERVER);

 

And finally here's the code of me using it in the GUI:

@Override
protected void actionPerformed(GuiButton button) {
	super.actionPerformed(button);
	switch(button.id){
	case 0:
		if(tile.getMode()==0){
			tile.setMode(1);
		}else{
			tile.setMode(0); 
		}
		Miscellany.network.sendToServer(new PacketDrill(this.tile));
	}
}

 

What am I doing wrong? First time trying to do packets in GUI so this may be a small error, thanks!

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.