Skip to content

Refactor JEI description, add support for fluids#382

Open
Wizzerinus wants to merge 3 commits intoCleanroomMC:masterfrom
TeamDimensional:fix/jei-description
Open

Refactor JEI description, add support for fluids#382
Wizzerinus wants to merge 3 commits intoCleanroomMC:masterfrom
TeamDimensional:fix/jei-description

Conversation

@Wizzerinus
Copy link
Copy Markdown
Contributor

Allows using fluid(...) in mods.jei.description, which also fixes a startup crash when the code does that

This 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

VanillaTypes.ITEM,
entry.getRight().toArray(new String[0]));
for (DescriptionEntry<?> entry : this.getScriptedRecipes()) {
System.out.println("adding entry: " + entry);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

println

for (Pair<List<IIngredient>, List<String>> entry : this.getBackupRecipes()) {
if (entry.getKey()
for (DescriptionEntry<?> entry : this.getBackupRecipes()) {
System.out.println("removing entry: " + entry);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

println

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 am coding ❤️

@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) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe do Object[] target + get the IIngredientRegistry#getIngredientType later on + check that everything has the same ingredient type. wouldnt use IIngredient or FluidStack anymore

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, we could do that I guess, that would be much better in terms of future flexibility too

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this changed to array? Lists are much nicer in groovy.

}

private boolean compareObjects(Object inEntry, Object inRegistry) {
if (inEntry instanceof ItemStack ieStack) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would suggest ensuring everything is the same IIngredientRegistry#getIngredientType + registering via that (casting as needed. shouldnt need an instanceof then

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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> {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

think this needs public

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of right now it's only used within the class, any reason why?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

part of the signature, Description extends VirtualizedRegistry<Description.DescriptionEntry<?>>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This too

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List > array

}

@MethodDescription(type = MethodDescription.Type.ADDITION)
public void add(Object[] target, List<String> description) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List > array

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List > array

}

@MethodDescription(type = MethodDescription.Type.ADDITION)
public void add(FluidStack[] target, List<String> description) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List > array

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants