Posted April 18, 20205 yr I was wondering how to remove an item from a slot in my GUI. I currently have 2 slots, and I want to, when the user clicks a button in the GUI, to remove it from the slot and then place a different item into the second slot. I have the button setup like this currently in the Screen class: @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { super.drawGuiContainerForegroundLayer(mouseX, mouseY); this.font.drawString(this.title.getFormattedText(), 51.0f, 6.0f, 4210752); this.font.drawString(this.playerInventory.getDisplayName().getFormattedText(), 8.0f, 112.0f, 4210752); this.addButton(new ImageButton(this.guiLeft + 77, this.guiTop + 24, 21, 20, 0, 208, 21, BACKGROUND_TEXTURE, (e) -> { System.out.println("Hello"); })); } And the PlayerInventory, along with the two slots are initialised inside of the Container class constructor here: this.addSlot(new Slot(tileEntity, 0, 16, 26)); this.addSlot(new Slot(tileEntity, 1, 52, 26));
April 19, 20205 yr Howdy This tutorial project has two working examples of containers with GUI that you might perhaps find useful https://github.com/TheGreyGhost/MinecraftByExample (mbe30, mbe31) Add the button to your ContainerScreen, and as dieSieben says, send a packet to the server when your button is clicked (if you don't know how, see mbe60 for clues) and forward it to your server-side container code to actually move the items. -TGG
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.