Skip to content

Commit

Permalink
Allow recipe properties to individually hide default tooltips (#2094)
Browse files Browse the repository at this point in the history
  • Loading branch information
serenibyss authored Sep 24, 2023
1 parent da171a7 commit 3ba1453
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/main/java/gregtech/api/recipes/Recipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,10 @@ public Set<String> getPropertyKeys() {
return recipePropertyStorage.getRecipePropertyKeys();
}

public Set<RecipeProperty<?>> getPropertyTypes() {
return recipePropertyStorage.getPropertyTypes();
}

public boolean hasProperty(RecipeProperty<?> property) {
return recipePropertyStorage.hasRecipeProperty(property);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public Set<String> getRecipePropertyKeys() {
return Collections.emptySet();
}

@Override
public Set<RecipeProperty<?>> getPropertyTypes() {
return Collections.emptySet();
}

@Override
public Object getRawRecipePropertyValue(String key) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public interface IRecipePropertyStorage {

Set<String> getRecipePropertyKeys();

Set<RecipeProperty<?>> getPropertyTypes();

/**
* Provides un-casted value for one specific {@link RecipeProperty} searched by key
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,14 @@ public static PrimitiveProperty getInstance() {
@Override
public void drawInfo(Minecraft minecraft, int x, int y, int color, Object value) {
}

@Override
public boolean hideTotalEU() {
return true;
}

@Override
public boolean hideEUt() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,27 @@ public boolean isHidden() {
return false;
}

/**
* Whether to hide the Total EU tooltip for the recipe in JEI.
*/
public boolean hideTotalEU() {
return false;
}

/**
* Whether to hide the EU/t tooltip for the recipe in JEI.
*/
public boolean hideEUt() {
return false;
}

/**
* Whether to hide the Duration tooltip for the recipe in JEI.
*/
public boolean hideDuration() {
return false;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ public Set<String> getRecipePropertyKeys() {
return keys;
}

@Override
public Set<RecipeProperty<?>> getPropertyTypes() {
return recipeProperties.keySet();
}

@Override
public Object getRawRecipePropertyValue(String key) {
RecipeProperty<?> recipeProperty = getRecipePropertyValue(key);
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/gregtech/integration/jei/recipe/GTRecipeWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import gregtech.api.recipes.ingredients.GTRecipeInput;
import gregtech.api.recipes.machines.IResearchRecipeMap;
import gregtech.api.recipes.machines.IScannerRecipeMap;
import gregtech.api.recipes.recipeproperties.PrimitiveProperty;
import gregtech.api.recipes.recipeproperties.RecipeProperty;
import gregtech.api.util.AssemblyLineManager;
import gregtech.api.util.ClipboardUtil;
Expand Down Expand Up @@ -152,11 +151,20 @@ public void addFluidTooltip(int slotIndex, boolean input, Object ingredient, Lis
public void drawInfo(@Nonnull Minecraft minecraft, int recipeWidth, int recipeHeight, int mouseX, int mouseY) {
super.drawInfo(minecraft, recipeWidth, recipeHeight, mouseX, mouseY);
int yPosition = recipeHeight - recipeMap.getPropertyListHeight(recipe);
if (!recipe.hasProperty(PrimitiveProperty.getInstance())) {

// Default entries
var properties = recipe.getPropertyTypes();
if (properties.isEmpty() || properties.stream().noneMatch(RecipeProperty::hideTotalEU)) {
minecraft.fontRenderer.drawString(I18n.format("gregtech.recipe.total", Math.abs((long) recipe.getEUt()) * recipe.getDuration()), 0, yPosition, 0x111111);
} else yPosition -= LINE_HEIGHT;
if (properties.isEmpty() || properties.stream().noneMatch(RecipeProperty::hideEUt)) {
minecraft.fontRenderer.drawString(I18n.format(recipe.getEUt() >= 0 ? "gregtech.recipe.eu" : "gregtech.recipe.eu_inverted", Math.abs(recipe.getEUt()), GTValues.VN[GTUtility.getTierByVoltage(recipe.getEUt())]), 0, yPosition += LINE_HEIGHT, 0x111111);
} else yPosition -= LINE_HEIGHT * 2;
minecraft.fontRenderer.drawString(I18n.format("gregtech.recipe.duration", TextFormattingUtil.formatNumbers(recipe.getDuration() / 20d)), 0, yPosition += LINE_HEIGHT, 0x111111);
} else yPosition -= LINE_HEIGHT;
if (properties.isEmpty() || properties.stream().noneMatch(RecipeProperty::hideDuration)) {
minecraft.fontRenderer.drawString(I18n.format("gregtech.recipe.duration", TextFormattingUtil.formatNumbers(recipe.getDuration() / 20d)), 0, yPosition += LINE_HEIGHT, 0x111111);
} else yPosition -= LINE_HEIGHT;

// Property custom entries
for (Map.Entry<RecipeProperty<?>, Object> propertyEntry : recipe.getPropertyValues()) {
if (!propertyEntry.getKey().isHidden()) {
RecipeProperty<?> property = propertyEntry.getKey();
Expand Down

0 comments on commit 3ba1453

Please sign in to comment.