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 made a scrollable container via handleMouseInput(), but the problem is, that the Server container doesnt know that I have scrolled, sending the wrong inventoryItemstacks to the client Container, creating Ghost Stacks. Now I tried to make it via a SimpleNetworkWrapper and followed Diesiebens tutorial but the Server always receives an EmptyByteBuf...

 

Gui:

	private int currentScroll;
@Override
public void handleMouseInput() throws IOException {
        super.handleMouseInput();
        int i = Mouse.getEventDWheel();
        //int m = Mouse.getEventButton();
        if(i!=0&&this.needsScrollBars())
            scroll(i);
}

private void scroll(int wheel){
        wheel=wheel>0?1:-1;
        currentScroll=util.cap(currentScroll-wheel,0,terows()-5);
        container().scrollTo(currentScroll);
	main.network.sendToServer(new Message(currentScroll));
}

 

Container:

    int scrolled=0;
public void scrollTo(int scroll) {
	scrolled=scroll;
        for (int y=0;y<5;++y) {
            for (int x=0;x<9;++x) {
                this.addSlotToContainer(new Slot(te,x+(y+scroll)*9,8+x*18,18+y*18),x+y*9);
            }
        }
}

private void addSlotToContainer(Slot slot,int pos){
	slot.slotNumber=pos;
        this.inventorySlots.set(pos,slot);
        this.inventoryItemStacks.set(pos,(ItemStack)null);
}

 

Message:

public class Message implements IMessage {

private int scroll;

public Message(){
}

public Message(int scroll){
	this.scroll=scroll;
}

@Override
public void fromBytes(ByteBuf buf) {
	if(!(buf instanceof EmptyByteBuf))
		scroll=buf.getInt(0);
	//scroll=Integer.getInteger(ByteBufUtils.readUTF8String(buf));
}

@Override
public void toBytes(ByteBuf buf) {
	buf.setInt(0,scroll);
	//ByteBufUtils.writeUTF8String(buf,Integer.toString(scroll));
}

public static class Handler implements IMessageHandler<Message, IMessage>{
	@Override
	public IMessage onMessage(final Message message, MessageContext ctx) {
		IThreadListener main=(WorldServer)ctx.getServerHandler().playerEntity.worldObj;
		final Container c=ctx.getServerHandler().playerEntity.openContainer;
		if(c!=null && c instanceof BulkContainer)
		main.addScheduledTask(new Runnable(){
			public void run() {
				//((BulkContainer)c).scrollTo(message.scroll);
			}
		});
		return null;
	}

}

}

Why are you using those ByteBuf functions? Have you tried

this.scroll = buf.readInt()

in fromBytes and

buf.writeInt(this.scroll)

in toBytes?  That's all you need, ie:

Packet example

 

 

[edit] Forgot to mention, if you have multiple variables you need to read them and write them in the exact same order.

  • Author

1. Read more careful pls. the ByteBuf functions were commented out.

2. WHY does it work if i replace setInt and getInt with writeInt and readInt?

Anyway, thanks!

I think you need to read more carefully, I didn't say ByteBufUtils, I said ByteBuf.  And likely because the functions you were using don't do what you thought they did, or were being used incorrectly.

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.