-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Properly implementing fluid tooltips #1581
base: master
Are you sure you want to change the base?
Conversation
I don't think you should be breaking something in api like this? Why not:
|
You are also not doing the same validation when registering a list:
The old method checks for an empty tooltip while you are checking for an empty list of tooltips. Why not just make the new method do:
I also think the original validation for an empty tooltip is wrong.
|
…uggested changes.
Thanks for the suggestions, fixed those area's. I didn't really think about how I was destroying backwards compatibility. |
One more suggestion, I think the return value for the new method should be implemented something like:
i.e. if any registration works it should return true. |
I don't know why it's there either, but shouldn't I be avoiding unnecessary mutability? I'm just carrying on the return type from before. @DStrand1 can possibly let us know what he was thinking. |
mutablility of local variables/parameters is fine mutability is an issue when it is shared state across threads. |
There was no significant motivation for providing return values for registration, other than that I did not want to throw an exception like other registries do when bad parameters are passed, so I wanted some form of a return code for the user of the API to have if needed. If I had a mistake in returning the wrong value, then it should be fixed. True should be returned on a successful registry, otherwise false. Additionally, I am not sure why we are using Java's |
Since we are doing a more flexible system for adding tooltips, it may be wise to have a registry freeze to prevent the tooltip registry from being modified further past a certain point in the Forge loading cycle. If you need help implementing this, I can do it |
It's swings and roundabouts. Iterable.forEach() can be optimised by the implementation in ways for(x : Iterable) cannot. In the above example using a for() would probably be the better choice since we know the implementation |
Should we freeze the registry, and if so, should it be a Quick edit: There also |
What issue does freezing the registry solve? Is there something like block or color registration where you will "miss the bus" if you register too late? Or the other use of registry freezing is to write the registry keys into the save file. So that forge can warn if they are missing in a future load of the save. |
I don't feel like there is any reason for us to freeze this as there would not be "anything missing" if some one adds tooltip later. |
@@ -145,12 +146,12 @@ public static void init() { | |||
int temperature = fluidMaterial.getFluidTemperature(); | |||
Fluid fluid = registerFluid(fluidMaterial, FluidType.NORMAL, temperature); | |||
fluidMaterial.setMaterialFluid(fluid); | |||
FluidTooltipUtil.registerTooltip(fluid, fluidMaterial.chemicalFormula); | |||
FluidTooltipUtil.registerTooltip(fluid, ChatFormatting.GRAY + fluidMaterial.chemicalFormula); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use TextFormatting
as ChatFormatting
only exists on the Client, and since we are now setting this from a shared class, this will cause a NoClassDefFoundError
on dedicated servers
if (fluid == null) | ||
return null; | ||
|
||
return tooltips.get(fluid).get(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be .get(0)
? From how we are registering it in registerTooltip(Fluid, String)
, it does not appear to be skipping the 0 index
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am too bit concerned why we are using sometimes 0, sometimes 1 when working with tooltips.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it is because when applying the tooltip to an ItemStack, the name of the Item is in index 0 in the list. For fluid tooltips, since I had to do it a bit more roundabout, index 0 of the registry will be put at index 1 of an ItemStack containing this fluid. Otherwise, when given to a FluidStack in JEI, it will just simply add to the end of the tooltip list rather than insert at an index.
@@ -154,33 +152,33 @@ public static void addMaterialFormulaHandler(ItemTooltipEvent event) { | |||
|
|||
// Handles Item tooltips | |||
if (!(itemStack.getItem() instanceof ItemBlock)) { | |||
String chemicalFormula = null; | |||
List<String> chemicalFormula = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should change this to be 2 different methods of handling it, since our fluid tooltip is not just a chemical formula anymore, but a general fluid tooltip application
What:
This PR allows for people to implement their own tooltips, with more than one line.
How solved:
This is solved by allowing for the user to pass a list through the argument, and storing them as a list.
Additional Info:
GTCE formula tooltips should still be put at index of one and show up in machine slots, and tank tooltips.