Jump to content

1.5 GUI and Item information


Vogner
 Share

Recommended Posts

Basically, I'm working toward a weapon that levels, complete with a perks screen like a single talent tree from WoW, and I want to open its GUI with the inventory button.

 

I've been trying to trigger a GUI with a keybinding rather than right clicking an item or block, and I've hit a bit of a wall. I've got the code working to the extent that when I hit the inventory button, code triggers. But I don't have a world or player reference, although I guess I could grab the FMLClientHandler references. Anyway, there's too much to consider beyond that, I'm not sure where to go from here. Is there an obvious solution I'm unaware of?

 

Question 2: This idea will obviously require a bunch of NBT stuff. I'm probably just going to extrapolate from the code in ItemFireworks/FireworksCharge, which already keeps track of a bunch of NBT flags, which is perfect for a perks system . Since there are no dedicated methods for adding miscellaneous tags, I'll probably lump it in with one of the other methods that take a ItemStack object as a parameter. Is there an easier solution than this, or something I've missed?

 

Thanks in advance.

Link to comment
Share on other sites

The keybinding is quite easy. After you have the GUI working (test it via the onBlockActivated() method) you literally just use the FMLClientHandler.getClient().openGui(new GuiToOpen); (its something like that) and it opens the GUI*.

 

* I have yet to figure out how to CLOSE the GUI using the bound button :/

 

I know that I saw a tutorial on the minecraft forums that was to do with item stack nbt tag compounds... I cannot find it at the time being though.

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Link to comment
Share on other sites

Okay so I've got the item writing and reading values from NBT, but naturally I've hit a few more walls:

 

The NBTTagCompound is always null, despite the fact that the item is both damageable and not stackable, so I have to manually give it an NBTTagCompound object with ItemStack.setNBTTagCompound (or whatever it's called precisely)

 

Perhaps related to the aforementioned is the fact that there are only one set of values for all items, so they all share and affect the same sets of values. Basically, they're all using the same NBT object and I'm not sure  how to stop this from happening. Any ideas, guys?

 

Third, my GUI now works. I decided to give it its own dedicated key, instead of using the inventory button, because there just isn't enough screen space for both GUIs. However, the GUI's background image is tiling. Any thoughts on that one?

Link to comment
Share on other sites

Okay so I've got the item writing and reading values from NBT, but naturally I've hit a few more walls:

 

The NBTTagCompound is always null, despite the fact that the item is both damageable and not stackable, so I have to manually give it an NBTTagCompound object with ItemStack.setNBTTagCompound (or whatever it's called precisely)

 

Perhaps related to the aforementioned is the fact that there are only one set of values for all items, so they all share and affect the same sets of values. Basically, they're all using the same NBT object and I'm not sure  how to stop this from happening. Any ideas, guys?

 

Third, my GUI now works. I decided to give it its own dedicated key, instead of using the inventory button, because there just isn't enough screen space for both GUIs. However, the GUI's background image is tiling. Any thoughts on that one?

 

1. It's null if it has no enchantment or already defined data.

2. Do you create an entirely new instance of the NBTTagCompound for each item? Seems like not, because of the behavior.

3. Can we see a screenshot? or at least a bit more explanation, what do you mean by tiling, how exactly?

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

Okay so I've got the item writing and reading values from NBT, but naturally I've hit a few more walls:

 

The NBTTagCompound is always null, despite the fact that the item is both damageable and not stackable, so I have to manually give it an NBTTagCompound object with ItemStack.setNBTTagCompound (or whatever it's called precisely)

 

Perhaps related to the aforementioned is the fact that there are only one set of values for all items, so they all share and affect the same sets of values. Basically, they're all using the same NBT object and I'm not sure  how to stop this from happening. Any ideas, guys?

 

Third, my GUI now works. I decided to give it its own dedicated key, instead of using the inventory button, because there just isn't enough screen space for both GUIs. However, the GUI's background image is tiling. Any thoughts on that one?

 

1. It's null if it has no enchantment or already defined data.

2. Do you create an entirely new instance of the NBTTagCompound for each item? Seems like not, because of the behavior.

3. Can we see a screenshot? or at least a bit more explanation, what do you mean by tiling, how exactly?

 

Unfortunately, I don't have internet on the computer with my project on it. But this is an example of a tiled image:

 

width=102 height=102https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcSiPtcQZ10wUrygGkoBp4T1Gk9defn9K9EXI5ASHv6B_fKJ2m1fRA[/img]

 

The grass, sand and water images are laid next to each other, over and over again. This is happening to my GUI for some reason, although it is being displayed at the correct scale, so you can only see the tiling on the edges of the screen. Imagine the inventory gui, and then another next to it, and another beneath it, etc. This is only happening to the background layer. I'm using the exact same DrawBackgroundLayer code as every other GUI, with my own image substituted in.

 

Also, I solved the NBT problem. I resorted to event handlers yet again. <3 event handlers. While I didn't know that the NBTTagCompound will likely be null if the item isn't enchanted, the problem wasn't the NBT thing at all. I neglected that items are static, and I had the xp integer saving, initializing and incrementing in the item's class, and so they were all reading the same value. I moved the entire exp system to an EntityAttack event, effectively solving the problem. So voila, I now have a mod with weapons that tier without having to craft each tier separately, as well as one that encourages hunting over constructing mob farms. Also, I made spiders tameable and mountable. That's unrelated, but it rocks.

Link to comment
Share on other sites

I see, do you properly set the xSize and ySize variables in your gui? They must match the size of the drawn background or you'll see this "tiling"if the variables are set too small.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

I see, do you properly set the xSize and ySize variables in your gui? They must match the size of the drawn background or you'll see this "tiling"if the variables are set too small.

 

Well there's no gap or overlap between the tiles, so I'm not sure that's the issue. I'll keep comparing my code to vanilla code and see if I snafu'd something somewhere.

 

In terms of progress, however, I've arrived at the point that when opened, a cleanly formatted GUI is displayed that lists every relevant piece of equipment in the player's inventory (including equipped items) as a button. Basically, you'll click on the gear you want to enhance, go to a second, item-specific GUI and expend some experience to purchase abilities or perks that you've unlocked. It should be really fun when I'm done.

 

That issue aside, I haven't been able to trigger any of this with a keybinding, because there's no way that I know of to get a player reference that isn't null, and therefor I can't access its inventory, either... Quite a few mods have done it, though, so there's got to be a way.

Link to comment
Share on other sites

That issue aside, I haven't been able to trigger any of this with a keybinding, because there's no way that I know of to get a player reference that isn't null, and therefor I can't access its inventory, either... Quite a few mods have done it, though, so there's got to be a way.

 

That is not really that hard. All you need to do is make a new EntityPlayer variable like so:

EntityPlayer player = Minecraft.getMinecraft().thePlayer;

 

That will give you an instance of the player. BUT!!!! This is the CLIENT SIDE player, so if you are wanting stuff done server side, you will have a slight issue. Though I am sure that you could then create a packet that sends the required information to the server and casts the EntityPlayer (player) variable to a EntityPlayerMP (that being done in the packet).

 

I just released, GUI's are ONLY client side, so you will be fine with that reference I made. Also you WILL need a packet handler and such when working with GUI's, you have to pass information done and such to the server. But I am sure you would already know this.

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Link to comment
Share on other sites

I actually tried something like that using the FMLClientHandler.getClient().getPlayer() (or whatever its called), and the resultant player reference was null. My sanity checks were even client side/server side sensitive. I haven't yet tried that specific line of code, though - I'll try it and report back when I can.

 

Since yesterday I've moved from buttons listing all level-able gear as text to custom buttons displaying the item's Icon, including any animation. I've also managed some GUIInventory-style tooltips that describe which specific item you're about to affect. There are still plenty of visual bugs, but I'm very happy with it, since it's my first.

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
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.

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I created an SOUL_JAR Item that has been registered for each mob like - mod:soul_jar_minecraft_cow etc.. but it all has different registry names, i have a model file name soul_jar.json and i want to know how to bind each of those items to this class (When mod iterates through all of vanilla mobs and registering items for them).   I didn't found any info about it because all of info is outdated, and forge docs is complicated asf (i wish there would be more examples) i also used AI but it showing me only outdated info, but theres some code where i registering my item and trying to bind it to model ->   public static void register(IEventBus eventBus){ ITEMS.register(eventBus); Set<ResourceLocation> entityKeyList = ForgeRegistries.ENTITY_TYPES.getKeys(); for (ResourceLocation k : entityKeyList) { EntityType<?> entityType = ForgeRegistries.ENTITY_TYPES.getValue(k); if (!entityType.getCategory().equals(MobCategory.MISC)) { RegistryObject<Item> SOUL_JAR = ITEMS.register("soul_jar" + '_' + k.toString().replace(':', '_').replace('.', '_'), () -> new JarItem(new Item.Properties().rarity(Rarity.RARE).tab(ModTabs.MAGICAL_OBSESSION_JARS), entityType)); if (Thread.currentThread().getThreadGroup() == SidedThreadGroups.CLIENT) { ItemModelShaper itemModelShaper = Minecraft.getInstance().getItemRenderer().getItemModelShaper(); itemModelShaper.register(SOUL_JAR.get().asItem(), new ModelResourceLocation("item.soul_jar", "inventory")); } } } } I also have more questions like how to iterate through all other mods mobs also, or render mob inside of a jar in inventory, but i will try to figure it out.
    • I looked into OctoEconomyAPI and saw that it was a JAR api for fabric. This means you have a fabric mod in your mods folder. I downloaded your mod folder and wasted 2 solid hours creating a Python script to try to find the faulty mod, and eventually just gave up. I suggest you create two installations with half or the mods in each, find which one doesn't launch, cut that one in half, and repeat until you find the fabric mod. Investigué OctoEconomyAPI y vi que era una API JAR para fabric. Esto significa que tienes un mod de Fabric en tu carpeta de mods. Descargué su carpeta de mods y desperdicié 2 horas completas creando un script de Python para tratar de encontrar el mod defectuoso, y finalmente me di por vencido. Le sugiero que cree dos instalaciones con la mitad o las modificaciones en cada una, encuentre cuál no se inicia, córtela por la mitad y repita hasta que encuentre la modificación Fabric.   (The Python script I made is here): (El script de Python que hice está aquí):  
    • I've got it to work now. Instead of using the texture manager I used the Render System:   RenderSystem.setShaderTexture(0, new ResourceLocation("mcaquests", "textures/item/questbook.png"));  
    • Hello ive been having the same issue over Curse Forge's auto modding or when i use manual modding. The error seems to be within either Oculus or Rubidium. Im using 1.19 with the latest 1.19 forge + 1.19 compatible Oculus and Rubidium. Just in case the versions i am using; Oculus - oculus-1.4.3a Rubidium - rubidium-0.6.3 Note: I tried removing the two and add Optifine and it opens without a problem. I didnt use all 3 together to get this error im talking tho, i know they are not compatible with optifine dont worry. Logs Debug The actual error code im getting on start-up is ''1'' and nothing else on the pop up box. I have tried finding the jar files on the internet and insert them on my own but that didnt go too far.
  • Topics

×
×
  • Create New...

Important Information

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