Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

SpectralGerbil

Members
  • Posts

    8
  • Joined

  • Last visited

SpectralGerbil's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. Just took a look at them, seems perfect! Thanks for the quick response and the help! Problem solved.
  2. Hiya. I have quite a Java-y question for you today that I'm hoping I can recieve some help with although I still feel it is related enough to Minecraft Forge to warrant posting here. I do apologise for the unclear title. I'm somewhat experienced in Java; no expert, but I have a lot of time with it under my belt. I know a lot about it but still also have a lot to learn. Essentially, I'm writing a new gameplay mechanic/system, and as part of this I pass an ItemStack to a custom function. I then need to return different values, based on what ItemStack it is. The immediate thought on how to do this is with multiple if branches. However, I worry this may have a performance impact. Since the function may well be called every single tick, or at least several times a second, I don't want to force the program to run through 100 if branches each tick, which I imagine would cause slowdown. An example of what I would do is below. This is pseudocode, so ignore any errors. It's just to give an idea of the concept of what the code should do. if (itemType == Items.LEATHER_HELMET) { defense += 4 agility += 4 } if (itemType == Items.IRON_HELMET) { defense += 7 } if (itemType == Items.GOLD_HELMET) { defense += 3 wisdom += 6 } Unlike the above example however, I would likely have this iterating over anywhere from 50-200 items. Is there a more efficient mechanism within Java (or Minecraft Forge) that would achieve the same result, without requiring so many iterations over if statements?
  3. Oh! Simple enough. Thanks, things are working now! I've just got a few bits of tidying up to do with my code, to make everything work perfectly, but I've removed the tooltips I wanted. Massive props for the help!
  4. It does! Thank you! I've figured out what I'm supposed to do now with the components. I just have one more question on how to finish up. After running all my checks, how can I modify the resulting tooltip to apply my changes? I can't see an event.setTooltip method or anything of that nature. I have the finished, edited tooltip that I need, but how do I apply it over the one the event gives me?
  5. Sorry, but I'm a little confused on which component you're referring to as the parent. Do you mean the one a level above the attribute I want to remove, or are you saying I should remove the entire tooltip processed in the event? Is there a particular method to going about doing that? Also, how would I view the full translation structure? I'm not familiar with doing so.
  6. Hello again. Things seem to be working great so far now, thanks to your help; I've been able to dig into the arguments and found the "generic.armor" attribute tooltips. However, how do I remove them from the TranslatableComponent arguments? There isn't a method to edit the arguments. Alternatively, if I need to redefine my own TranslatableComponent to replace the old one, how can I do so properly, passing the right amount of arguments and such?
  7. The issue I'm experiencing there is that when I attempt to cast most TextComponents to a TranslatableComponent, the game crashes saying it cannot. I fixed this by running an instanceof check, but that is only returning a few translation keys, none of which are what I need. Most look like this: item.modifiers.chest attribute.modifier.plus.0 attribute.modifier.plus.0 item.modifiers.mainhand attribute.modifier.plus.0 attribute.modifier.take.0 When I tested using regular components, I saw names of every single item which verified that was working, however in this instance I am only seeing the strings listed above and no item ids, block ids, or "attribute.name.generic.armor" as I need. I feel I may be doing something completely wrong. I'll post an excerpt of my code below from inside my ItemTooltipEvent listener (apologies for the messy variable names during testing) List<Component> tooltip = event.getToolTip(); int size = tooltip.size(); int i = 0; while (i < size) { Component ttcomp = tooltip.get(i); if (ttcomp instanceof TranslatableComponent) { TranslatableComponent trancomp = (TranslatableComponent) ttcomp; String ttkey = trancomp.getKey(); if (ttkey.contains("attribute.name.generic.armor")) { event.getToolTip().remove(i); size -= 1; i -= 1; } } i += 1; } Just to outline, the purpose of the code is to search / iterate incoming tooltips for the "attribute.name.generic.armor" key and then remove those lines from the tooltip.
  8. Hello, I'll keep it short and sweet. I'm removing armor tooltips from armor for a custom defense system that's nearly finished. I am using ItemTooltipEvent to obtain each tooltip and check if it contains the +X Armor tooltip, and then remove that tooltip. It works however I would like to make it work across languages. (Searching for the phrase "Armor" will not work in other languages). After some research I've found I need to obtain the translation keys for parts of these tooltips, and I can then iterate them and remove tooltips that contain the translation key "attribute.name.generic.armor". However I'm digging through 1.17 documentation and cannot find a way to obtain translation keys from the tooltips. I believe I could convert the Components retrieved from the tooltips into TranslatableComponents, but cannot find a method that does this. Could someone with the proper knowledge tell me how I can achieve this? Edit: For some context, yes I plan on updating to 1.18.1 soon but would like to figure this out first.
×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.