Refactor JEI description, add support for fluids#382
Refactor JEI description, add support for fluids#382Wizzerinus wants to merge 3 commits intoCleanroomMC:masterfrom
Conversation
| VanillaTypes.ITEM, | ||
| entry.getRight().toArray(new String[0])); | ||
| for (DescriptionEntry<?> entry : this.getScriptedRecipes()) { | ||
| System.out.println("adding entry: " + entry); |
| for (Pair<List<IIngredient>, List<String>> entry : this.getBackupRecipes()) { | ||
| if (entry.getKey() | ||
| for (DescriptionEntry<?> entry : this.getBackupRecipes()) { | ||
| System.out.println("removing entry: " + entry); |
| @MethodDescription(type = MethodDescription.Type.ADDITION) | ||
| public void add(List<IIngredient> target, List<String> description) { | ||
| addScripted(Pair.of(target, description)); | ||
| public void add(IIngredient[] target, String... description) { |
There was a problem hiding this comment.
maybe do Object[] target + get the IIngredientRegistry#getIngredientType later on + check that everything has the same ingredient type. wouldnt use IIngredient or FluidStack anymore
There was a problem hiding this comment.
Hmm, we could do that I guess, that would be much better in terms of future flexibility too
There was a problem hiding this comment.
Why is this changed to array? Lists are much nicer in groovy.
| } | ||
|
|
||
| private boolean compareObjects(Object inEntry, Object inRegistry) { | ||
| if (inEntry instanceof ItemStack ieStack) { |
There was a problem hiding this comment.
since this happens only in applyRemovals, we can compare using IIngredientHelper#getUniqueId - perhaps IngredientUtil#equal? although i think that might be intended for internal logic.
There was a problem hiding this comment.
The problem is sometimes you need to remove description from an item with a specific NBT, which checking only the ID doesn't. I wanted to keep the old logic in regards to this. Though I don't really like how this turned out, yeah
There was a problem hiding this comment.
See my comment on applyAdditions
| entry.getRight().toArray(new String[0])); | ||
| for (DescriptionEntry<?> entry : this.getScriptedRecipes()) { | ||
| System.out.println("adding entry: " + entry); | ||
| if (entry.representative instanceof ItemStack) { |
There was a problem hiding this comment.
would suggest ensuring everything is the same IIngredientRegistry#getIngredientType + registering via that (casting as needed. shouldnt need an instanceof then
There was a problem hiding this comment.
This is not possible due to a Java quirk, that I have already outlined in the Discord channel. The JEI API exposes an overloaded function like this:
<T> void addIngredientInfo(T ingredient, IIngredientType<T> ingredientType, String... descriptionKeys);
<T> void addIngredientInfo(List<T> ingredients, IIngredientType<T> ingredientType, String... descriptionKeys);
If T := Object is substituted (or T being an existential type, which eventually reduces to Object), then these two methods are ambiguous, so T must be a concrete type, hence this is necessary.
| public class Description extends VirtualizedRegistry<Pair<List<IIngredient>, List<String>>> { | ||
| public class Description extends VirtualizedRegistry<Description.DescriptionEntry<?>> { | ||
|
|
||
| static class DescriptionEntry<T> { |
There was a problem hiding this comment.
think this needs public
There was a problem hiding this comment.
As of right now it's only used within the class, any reason why?
There was a problem hiding this comment.
part of the signature, Description extends VirtualizedRegistry<Description.DescriptionEntry<?>>
There was a problem hiding this comment.
is this for consistency reasons? it works fine as is, but if its for consistency idm fixing
| @MethodDescription(type = MethodDescription.Type.ADDITION) | ||
| public void add(List<IIngredient> target, List<String> description) { | ||
| addScripted(Pair.of(target, description)); | ||
| public void add(IIngredient[] target, String... description) { |
There was a problem hiding this comment.
Why is this changed to array? Lists are much nicer in groovy.
| @MethodDescription(type = MethodDescription.Type.ADDITION) | ||
| public void add(List<IIngredient> target, String... description) { | ||
| addScripted(Pair.of(target, Arrays.asList(description))); | ||
| public void add(IIngredient[] target, List<String> description) { |
There was a problem hiding this comment.
because then we cannot overload based on the input type, as all lists cast down to List<?> on the JVM, and we need to apply different code depending on FluidStack, an IIngredient that is not FluidStack, or another type (the latter is currently not supported in JEI so idk an example for that). We could disambiguate manually though. Idk, these group methods are very uncommon I believe (since for IIngredient you can just use an OrIngredient), so it's hard to tell whether the manual overloading will be worth in the long run.
| } | ||
|
|
||
| @MethodDescription(type = MethodDescription.Type.ADDITION) | ||
| public void add(Object[] target, String... description) { |
| } | ||
|
|
||
| @MethodDescription(type = MethodDescription.Type.ADDITION) | ||
| public void add(Object[] target, List<String> description) { |
There was a problem hiding this comment.
not possible due to type erasure
| // This overload set is the same as Object one. It exists because FluidStack implements IIngredient, but does not have any matching stacks, | ||
| // which causes a JEI startup crash when trying to add that description | ||
| @MethodDescription(type = MethodDescription.Type.ADDITION) | ||
| public void add(FluidStack[] target, String... description) { |
| } | ||
|
|
||
| @MethodDescription(type = MethodDescription.Type.ADDITION) | ||
| public void add(FluidStack[] target, List<String> description) { |
Allows using
fluid(...)inmods.jei.description, which also fixes a startup crash when the code does thatThis should support adding more types fairly easily
lmk if this is a bad approach, I was kinda very focused on keeping it a VirtualizedRegistry, and its probably not the cleanest way