Jump to content

GUI/Container slots [1.15.2]


modders2

Recommended Posts

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

 

Link to comment
Share on other sites

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

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.