Posted September 1, 20169 yr 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; } } }
September 1, 20169 yr 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.
September 1, 20169 yr 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!
September 1, 20169 yr 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.