Skip to content

Commit

Permalink
implementing tooltip display for BiomeProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
MCTian-mi committed Oct 27, 2024
1 parent 1c42eba commit 06720e3
Showing 1 changed file with 38 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,6 +18,9 @@
public class BiomeProperty extends RecipeProperty<BiomeProperty.BiomePropertyList> {

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;

Expand All @@ -27,32 +34,50 @@ public static BiomeProperty getInstance() {
return INSTANCE;
}

private static String getBiomesForRecipe(List<Biome> value) {
private static String getBiomesForRecipe(BiomePropertyList biomePropertyList, boolean limited) {
boolean isWhiteList = biomePropertyList.whiteListBiomes.size() > 0;
List<Biome> 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<String> 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 {
Expand Down

0 comments on commit 06720e3

Please sign in to comment.