Jump to content

Scrollable container data from Client to Server


Xerus

Recommended Posts

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;
	}

}

}

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.