From 3ba1453ec6becd209e181621ce6efa5bdfabb459 Mon Sep 17 00:00:00 2001 From: Serenibyss <10861407+serenibyss@users.noreply.github.com> Date: Sun, 24 Sep 2023 18:50:09 -0500 Subject: [PATCH] Allow recipe properties to individually hide default tooltips (#2094) --- .../java/gregtech/api/recipes/Recipe.java | 4 ++++ .../EmptyRecipePropertyStorage.java | 5 +++++ .../IRecipePropertyStorage.java | 2 ++ .../recipeproperties/PrimitiveProperty.java | 10 +++++++++ .../recipeproperties/RecipeProperty.java | 21 +++++++++++++++++++ .../RecipePropertyStorage.java | 5 +++++ .../jei/recipe/GTRecipeWrapper.java | 16 ++++++++++---- 7 files changed, 59 insertions(+), 4 deletions(-) diff --git a/src/main/java/gregtech/api/recipes/Recipe.java b/src/main/java/gregtech/api/recipes/Recipe.java index 248035e0bf3..1c6d9a31cef 100644 --- a/src/main/java/gregtech/api/recipes/Recipe.java +++ b/src/main/java/gregtech/api/recipes/Recipe.java @@ -587,6 +587,10 @@ public Set getPropertyKeys() { return recipePropertyStorage.getRecipePropertyKeys(); } + public Set> getPropertyTypes() { + return recipePropertyStorage.getPropertyTypes(); + } + public boolean hasProperty(RecipeProperty property) { return recipePropertyStorage.hasRecipeProperty(property); } diff --git a/src/main/java/gregtech/api/recipes/recipeproperties/EmptyRecipePropertyStorage.java b/src/main/java/gregtech/api/recipes/recipeproperties/EmptyRecipePropertyStorage.java index fb1aad7f52d..2310d82d6ad 100644 --- a/src/main/java/gregtech/api/recipes/recipeproperties/EmptyRecipePropertyStorage.java +++ b/src/main/java/gregtech/api/recipes/recipeproperties/EmptyRecipePropertyStorage.java @@ -57,6 +57,11 @@ public Set getRecipePropertyKeys() { return Collections.emptySet(); } + @Override + public Set> getPropertyTypes() { + return Collections.emptySet(); + } + @Override public Object getRawRecipePropertyValue(String key) { return null; diff --git a/src/main/java/gregtech/api/recipes/recipeproperties/IRecipePropertyStorage.java b/src/main/java/gregtech/api/recipes/recipeproperties/IRecipePropertyStorage.java index 5d4c93f4414..bdcbdce5576 100644 --- a/src/main/java/gregtech/api/recipes/recipeproperties/IRecipePropertyStorage.java +++ b/src/main/java/gregtech/api/recipes/recipeproperties/IRecipePropertyStorage.java @@ -50,6 +50,8 @@ public interface IRecipePropertyStorage { Set getRecipePropertyKeys(); + Set> getPropertyTypes(); + /** * Provides un-casted value for one specific {@link RecipeProperty} searched by key * diff --git a/src/main/java/gregtech/api/recipes/recipeproperties/PrimitiveProperty.java b/src/main/java/gregtech/api/recipes/recipeproperties/PrimitiveProperty.java index cc655a573c9..13f689e9401 100644 --- a/src/main/java/gregtech/api/recipes/recipeproperties/PrimitiveProperty.java +++ b/src/main/java/gregtech/api/recipes/recipeproperties/PrimitiveProperty.java @@ -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; + } } diff --git a/src/main/java/gregtech/api/recipes/recipeproperties/RecipeProperty.java b/src/main/java/gregtech/api/recipes/recipeproperties/RecipeProperty.java index 01d5eb32080..a04120bc509 100644 --- a/src/main/java/gregtech/api/recipes/recipeproperties/RecipeProperty.java +++ b/src/main/java/gregtech/api/recipes/recipeproperties/RecipeProperty.java @@ -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; diff --git a/src/main/java/gregtech/api/recipes/recipeproperties/RecipePropertyStorage.java b/src/main/java/gregtech/api/recipes/recipeproperties/RecipePropertyStorage.java index 92a138ef2a6..2645053bd93 100644 --- a/src/main/java/gregtech/api/recipes/recipeproperties/RecipePropertyStorage.java +++ b/src/main/java/gregtech/api/recipes/recipeproperties/RecipePropertyStorage.java @@ -108,6 +108,11 @@ public Set getRecipePropertyKeys() { return keys; } + @Override + public Set> getPropertyTypes() { + return recipeProperties.keySet(); + } + @Override public Object getRawRecipePropertyValue(String key) { RecipeProperty recipeProperty = getRecipePropertyValue(key); diff --git a/src/main/java/gregtech/integration/jei/recipe/GTRecipeWrapper.java b/src/main/java/gregtech/integration/jei/recipe/GTRecipeWrapper.java index 7dd05ff55cf..9fd0c617e04 100644 --- a/src/main/java/gregtech/integration/jei/recipe/GTRecipeWrapper.java +++ b/src/main/java/gregtech/integration/jei/recipe/GTRecipeWrapper.java @@ -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; @@ -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, Object> propertyEntry : recipe.getPropertyValues()) { if (!propertyEntry.getKey().isHidden()) { RecipeProperty property = propertyEntry.getKey();