Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • GUI/Container slots [1.15.2]
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 1
modders2

GUI/Container slots [1.15.2]

By modders2, April 18, 2020 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

modders2    0

modders2

modders2    0

  • Tree Puncher
  • modders2
  • Members
  • 0
  • 26 posts
Posted April 18, 2020

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

 

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7695

diesieben07

diesieben07    7695

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7695
  • 56358 posts
Posted April 18, 2020

Buttons are client side. You will need to send a custom packet to the server, do the proper validations (check that the correct container is still open) and then modify the underlying inventory.

The fact that you are using your tileEntity variable as an inventory also suggests you are using IInventory, you should be using IItemHandler.

  • Quote

Share this post


Link to post
Share on other sites

TheGreyGhost    819

TheGreyGhost

TheGreyGhost    819

  • Reality Controller
  • TheGreyGhost
  • Members
  • 819
  • 3280 posts
Posted April 19, 2020

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

  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 1
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Eksity
      Another freaking "error in currently selected datapacks prevented world from loading"

      By Eksity · Posted 2 minutes ago

      fair enough.
    • diesieben07
      Another freaking "error in currently selected datapacks prevented world from loading"

      By diesieben07 · Posted 4 minutes ago

      Well, you can do a binary search: Take out half the mods every time to narrow down the mods you need to check by half every time.
    • Eksity
      Another freaking "error in currently selected datapacks prevented world from loading"

      By Eksity · Posted 7 minutes ago

      great. Is there anything I can do other than go mod-by-mod and test everything?
    • diesieben07
      Another freaking "error in currently selected datapacks prevented world from loading"

      By diesieben07 · Posted 8 minutes ago

      Well, it looks like some of the mods you have installed are breaking your world. I can't tell from the logs which one it is though.
    • Eksity
      Another freaking "error in currently selected datapacks prevented world from loading"

      By Eksity · Posted 10 minutes ago

      also if I save and quit and try to rejoin it doesn't work
  • Topics

    • Eksity
      14
      Another freaking "error in currently selected datapacks prevented world from loading"

      By Eksity
      Started 19 hours ago

    • Ariel David
      1
      Do i need minecraft installed

      By Ariel David
      Started 33 minutes ago

    • Skyriis
      12
      [1.16.5] Adding a Button to KeyBindings

      By Skyriis
      Started Wednesday at 11:07 PM

    • Deadlocked47
      1
      Can't get into forge discord

      By Deadlocked47
      Started 21 hours ago

    • IntentScarab
      6
      (SOLVED)[1.16.4] Block entity invalid

      By IntentScarab
      Started 1 hour ago

  • Who's Online (See full list)

    • LexManos
    • Eksity
    • diesieben07
    • Beethoven92
    • vemerion
    • gottsch
    • IntentScarab
    • Aviator737
    • KatiePandaEx
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • GUI/Container slots [1.15.2]
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community