Posted June 28, 201411 yr Hey how can I switch of Item Rendering in a gui when I press a button in a gui? Creator of Extra Shoes Watch out, I'm total jerk, and I'll troll anybody if it feels like its necessary. Pls report me then
June 28, 201411 yr Author I am unsure what you mean. Do you have a GuiContainer (displaying an inventory) and want to turn off the inventory? I want all Items,. they are in your inventory, are away, so there icons are away, not the items,so you can't see them anymore Creator of Extra Shoes Watch out, I'm total jerk, and I'll troll anybody if it feels like its necessary. Pls report me then
June 28, 201411 yr Are you trying to hide all item in your container? If so, the player's creative container does a cheaty way of hiding all items. It lifts them up by a couple thousand positions in the y coordinate. First of all, save the y positions of all the slots you want to 'hide' in an array, to keep the actual y position if you want to show the slots again. If you do not want to show them afterwards, you can skip this. [All of this code should be added to your guicontainer class] #1 private boolean _showOptions = false; //To control whether or not if you want to show or hide the slots. private int[] _slotPosY = new int[16]; //My container contains 16 slots, you can change this number to how many yours has. //In some load/initialization method eg. GuiScreen#initGui() /** Saving the containerslots' y pos in an array. */ public void saveYPos() { for(int i = 1; i < 16; i++) //I am skipping the first slot of my container, it's not part of the ones I want to move. _slotPosY[i] = _container.getSlot(i).yDisplayPosition; } You're talking about a button (on/off switch?), that's perfect to move the slots up. #2 @Override protected void actionPerformed(GuiButton guibutton) { if (guibutton instanceof GuiButtonOptions) { this._showOptions = !this._showOptions; for(int i = 1; i < 16; i++) //again skipping the first one. this._container.getSlot(i).yDisplayPosition = this._showOptions ? -2000 : this._slotPosY[i]; } } Whenever you click on a button, for me it's when I click on a button which is an instance of GuiButtonOptions, it's set's the showOptions state to not equals to showOptions. ( if you're using id's for your buttons, you can just change this line to check whether the button id is the button for hiding the slots) Then I am moving all the container's slots up by 2000 (- = negative guitop) whether the showOptions is true, else I am setting their y position back on their original position using the array. I have used it in my entity's container as well, works fine for me.
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.