From 06720e361d53e7df5cc107cec1aa88e4f4d6ee8b Mon Sep 17 00:00:00 2001 From: MCTian-mi <35869948+MCTian-mi@users.noreply.github.com> Date: Sun, 27 Oct 2024 21:45:47 +0800 Subject: [PATCH 1/2] implementing tooltip display for BiomeProperty --- .../api/recipes/properties/BiomeProperty.java | 51 ++++++++++++++----- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/src/main/java/supersymmetry/api/recipes/properties/BiomeProperty.java b/src/main/java/supersymmetry/api/recipes/properties/BiomeProperty.java index 88a45815c..8455b3968 100644 --- a/src/main/java/supersymmetry/api/recipes/properties/BiomeProperty.java +++ b/src/main/java/supersymmetry/api/recipes/properties/BiomeProperty.java @@ -1,8 +1,12 @@ package supersymmetry.api.recipes.properties; +import gregtech.api.gui.resources.TextureArea; import gregtech.api.recipes.recipeproperties.RecipeProperty; +import gregtech.api.util.Position; +import gregtech.api.util.Size; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.resources.I18n; import net.minecraft.world.biome.Biome; import net.minecraftforge.fml.relauncher.Side; @@ -14,6 +18,9 @@ public class BiomeProperty extends RecipeProperty { public static final String KEY = "biome"; + private static final Position POSITION = new Position(80, 43); + private static final Size SIZE = new Size(16, 16); + private static final TextureArea ICON = TextureArea.fullImage("textures/gui/widget/information.png"); private static BiomeProperty INSTANCE; @@ -27,32 +34,50 @@ public static BiomeProperty getInstance() { return INSTANCE; } - private static String getBiomesForRecipe(List value) { + private static String getBiomesForRecipe(BiomePropertyList biomePropertyList, boolean limited) { + boolean isWhiteList = biomePropertyList.whiteListBiomes.size() > 0; + List list = isWhiteList ? biomePropertyList.whiteListBiomes : biomePropertyList.blackListBiomes; + StringBuilder builder = new StringBuilder(); - for (int i = 0; i < value.size(); i++) { - builder.append(value.get(i).biomeName); - if (i != value.size() - 1) + for (int i = 0; i < list.size(); i++) { + builder.append(list.get(i).biomeName); + if (i != list.size() - 1) builder.append(", "); } - String str = builder.toString(); + String str = I18n.format(isWhiteList ? "susy.recipe.biomes" : "susy.recipe.biomes_blocked", builder.toString()); - if (str.length() >= 26) { - str = str.substring(0, 23) + ".."; + if (limited && str.length() >= 35) { + str = str.substring(0, 32) + ".."; } + return str; } + @Override + @SideOnly(Side.CLIENT) + public void getTooltipStrings(List tooltip, int mouseX, int mouseY, Object value) { + super.getTooltipStrings(tooltip, mouseX, mouseY, value); + + BiomePropertyList list = castValue(value); + + if (mouseX < POSITION.getX() || mouseX > POSITION.getX() + SIZE.getWidth() || + mouseY < POSITION.getY() || mouseY > POSITION.getY() + SIZE.getHeight()) + return; + + tooltip.add(getBiomesForRecipe(list, false)); + } + @Override @SideOnly(Side.CLIENT) public void drawInfo(Minecraft minecraft, int x, int y, int color, Object value) { BiomePropertyList list = castValue(value); + minecraft.fontRenderer.drawString(getBiomesForRecipe(list, true), x, y, color); - if (list.whiteListBiomes.size() > 0) - minecraft.fontRenderer.drawString(I18n.format("susy.recipe.biomes", - getBiomesForRecipe(castValue(value).whiteListBiomes)), x, y, color); - if (list.blackListBiomes.size() > 0) - minecraft.fontRenderer.drawString(I18n.format("susy.recipe.biomes_blocked", - getBiomesForRecipe(castValue(value).blackListBiomes)), x, y, color); + GlStateManager.enableLighting(); + GlStateManager.enableLight(1); + ICON.draw(POSITION.getX(), POSITION.getY(), SIZE.getWidth(), SIZE.getHeight()); + GlStateManager.disableLight(1); + GlStateManager.disableLighting(); } public static class BiomePropertyList { From 4e5144798747f351eebca45ebc603aec48c4cca4 Mon Sep 17 00:00:00 2001 From: bruberu <80226372+bruberu@users.noreply.github.com> Date: Wed, 30 Oct 2024 21:05:53 -0500 Subject: [PATCH 2/2] fix: slightly-too-high info button --- .../supersymmetry/api/recipes/properties/BiomeProperty.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/supersymmetry/api/recipes/properties/BiomeProperty.java b/src/main/java/supersymmetry/api/recipes/properties/BiomeProperty.java index 8455b3968..0b3ce3a0c 100644 --- a/src/main/java/supersymmetry/api/recipes/properties/BiomeProperty.java +++ b/src/main/java/supersymmetry/api/recipes/properties/BiomeProperty.java @@ -18,7 +18,7 @@ public class BiomeProperty extends RecipeProperty { public static final String KEY = "biome"; - private static final Position POSITION = new Position(80, 43); + private static final Position POSITION = new Position(80, 45); private static final Size SIZE = new Size(16, 16); private static final TextureArea ICON = TextureArea.fullImage("textures/gui/widget/information.png");