Jump to content

Item Rendering in Gui


Kloonder

Recommended Posts

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

Link to comment
Share on other sites

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.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • How to fix file server-1.20.1-20230612.114412-srg.jar  
    • Just a few months ago I was creating my own plugin for Minecraft 1.20.2 spigot that did the same thing, but the skins were not saved, if you can understand this code that I made a long time ago it may help you.   //This is a class method private static String APIRequest(String value, String url, String toSearch) { try { URL api = new URL(url + value); HttpURLConnection connection = (HttpURLConnection) api.openConnection(); connection.setRequestMethod("GET"); int responseCode = connection.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_OK) { BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); StringBuilder response = new StringBuilder(); for (String responseChar; (responseChar = reader.readLine()) != null; ) response.append(responseChar); reader.close(); JSONObject responseObject = new JSONObject(response.toString()); if (!toSearch.equals("id")) return responseObject .getJSONArray("properties") .getJSONObject(0) .getString("value"); else return responseObject.getString("id"); } else { AntiGianka.ConsoleMessage(ChatColor.RED, String.format( "Could not get %s. Response code: %s", ((toSearch.equals("id")) ? "UUID" : "texture"), responseCode )); } } catch (MalformedURLException error) { AntiGianka.ConsoleMessage(ChatColor.RED, "An error occurred while trying to access the URL. Error: " + error); } catch (IOException error) { AntiGianka.ConsoleMessage(ChatColor.RED, "An error occurred while attempting to connect to the URL. Error: " + error); } return ""; } //other class method private void SkinGetter() { String uuid; String textureCoded; if ((uuid = APIRequest(args[0], "https://api.mojang.com/users/profiles/minecraft/", "id")).isEmpty() || (textureCoded = APIRequest(uuid, "https://sessionserver.mojang.com/session/minecraft/profile/", "value")).isEmpty() ) sender.sendMessage(ChatColor.RED + String.format( "An error has occurred while trying to obtain the %s player skin, please check if the name %s is spelled correctly or try again later.", args[0], args[0] ) ); else SkinSetter(textureCoded); } //other more private void SkinSetter(String textureCoded) { JSONObject profile = new JSONObject(new String(Base64.getDecoder().decode(textureCoded))); try { URL textureUrl = new URL(profile.getJSONObject("textures"). getJSONObject("SKIN"). getString("url")); if (sender instanceof Player && args.length == 1) { PlayerTextures playerTextures = ((Player) sender).getPlayerProfile().getTextures(); playerTextures.setSkin(textureUrl); ((Player) sender).getPlayerProfile().setTextures(playerTextures); if (((Player) sender).getPlayerProfile().getTextures().getSkin() != null) sender.sendMessage(((Player) sender).getPlayerProfile().getTextures().getSkin().toString()); else sender.sendMessage("Null"); sender.sendMessage("Skin changed successfully.a"); } else { } AntiGianka.ConsoleMessage(ChatColor.GREEN, "Skin command executed successfully."); } catch (MalformedURLException error) { sender.sendMessage(ChatColor.RED + String.format( "An error has occurred while trying to obtain the %s player skin, please check if the name %s is spelled correctly or try again later.", args[0], args[0] ) ); AntiGianka.ConsoleMessage(ChatColor.RED, "An error occurred while trying to access the URL. Error: " + error); } }  
    • Use /locate structure The chat should show all available structures as suggestion For the Ancient City it is /locate structure ancient_city
    • So does it work without this mod? Did you test it with other builds?
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.