From 7aa840282fb9898ef2399a3654dfc92714a1bbe9 Mon Sep 17 00:00:00 2001 From: mezz Date: Mon, 13 Jun 2016 21:32:19 -0700 Subject: [PATCH] Fix #1229 Squeezer Recipes in JEI do not show chance % --- .../recipes/jei/ForestryTooltipCallback.java | 34 ++++++------------- .../centrifuge/CentrifugeRecipeCategory.java | 21 ++++++------ .../jei/squeezer/SqueezerRecipeCategory.java | 5 ++- 3 files changed, 22 insertions(+), 38 deletions(-) diff --git a/src/main/java/forestry/core/recipes/jei/ForestryTooltipCallback.java b/src/main/java/forestry/core/recipes/jei/ForestryTooltipCallback.java index 0d5909ab7..78dce7f44 100644 --- a/src/main/java/forestry/core/recipes/jei/ForestryTooltipCallback.java +++ b/src/main/java/forestry/core/recipes/jei/ForestryTooltipCallback.java @@ -16,18 +16,6 @@ public class ForestryTooltipCallback implements ITooltipCallback { private final ArrayListMultimap tooltips = ArrayListMultimap.create(); - public void addToTooltip(int index, List tooltip) { - tooltips.get(index).addAll(tooltip); - } - - public void addToTooltip(int index, String tooltip) { - tooltips.get(index).add(tooltip); - } - - public List getTooltip(int index) { - return tooltips.get(index); - } - @Override public void onTooltip(int index, boolean input, ItemStack ingredient, List tooltip) { List tip = tooltips.get(index); @@ -36,20 +24,18 @@ public class ForestryTooltipCallback implements ITooltipCallback { } } - public void clearTooltip(){ - tooltips.clear(); - } - public void addChanceTooltip(int index, float chance) { - if (chance <= 0.0F) { - tooltips.get(index).add(TextFormatting.GRAY + String.format(Translator.translateToLocal("forestry.jei.chance"), Translator.translateToLocal("forestry.jei.chance.never"))); - } else if (chance < 0.01F) { - tooltips.get(index).add(TextFormatting.GRAY + String.format(Translator.translateToLocal("forestry.jei.chance"), Translator.translateToLocal("forestry.jei.chance.lessThan1"))); - } else if (chance != 1.0F) { - NumberFormat percentFormat = NumberFormat.getPercentInstance(); - percentFormat.setMaximumFractionDigits(2); - tooltips.get(index).add(TextFormatting.GRAY + String.format(Translator.translateToLocal("forestry.jei.chance"), String.valueOf(percentFormat.format(chance)))); + if (chance < 0) { + chance = 0; + } else if (chance > 1.0) { + chance = 1.0f; } + + NumberFormat percentFormat = NumberFormat.getPercentInstance(); + percentFormat.setMaximumFractionDigits(2); + String chanceString = String.valueOf(percentFormat.format(chance)); + + tooltips.get(index).add(TextFormatting.GRAY + Translator.translateToLocalFormatted("for.jei.chance", chanceString)); } } diff --git a/src/main/java/forestry/factory/recipes/jei/centrifuge/CentrifugeRecipeCategory.java b/src/main/java/forestry/factory/recipes/jei/centrifuge/CentrifugeRecipeCategory.java index 243ea6da7..a7ee02e8c 100644 --- a/src/main/java/forestry/factory/recipes/jei/centrifuge/CentrifugeRecipeCategory.java +++ b/src/main/java/forestry/factory/recipes/jei/centrifuge/CentrifugeRecipeCategory.java @@ -5,6 +5,7 @@ import java.util.Comparator; import java.util.Map; import java.util.Map.Entry; import java.util.PriorityQueue; +import java.util.Queue; import java.util.Set; import net.minecraft.client.Minecraft; @@ -22,7 +23,6 @@ import mezz.jei.api.gui.IDrawableStatic; import mezz.jei.api.gui.IGuiItemStackGroup; import mezz.jei.api.gui.IRecipeLayout; import mezz.jei.api.recipe.IRecipeWrapper; -import mezz.jei.gui.ingredients.GuiItemStackGroup; public class CentrifugeRecipeCategory extends ForestryRecipeCategory { @@ -41,8 +41,7 @@ public class CentrifugeRecipeCategory extends ForestryRecipeCategory { private final static ResourceLocation guiTexture = new ForestryResource("textures/gui/centrifugesocket.png"); @Nonnull private final IDrawableAnimated arrow; - private final ForestryTooltipCallback tooltip = new ForestryTooltipCallback(); - + public CentrifugeRecipeCategory(IGuiHelper guiHelper) { super(guiHelper.createDrawable(guiTexture, 25, 18, 126, 54), "tile.for.centrifuge.name"); @@ -68,17 +67,17 @@ public class CentrifugeRecipeCategory extends ForestryRecipeCategory { guiItemStacks.init(inputSlot, true, 4, 18); guiItemStacks.setFromRecipe(inputSlot, recipeWrapper.getInputs()); CentrifugeRecipeWrapper centrifugeWrapper = (CentrifugeRecipeWrapper) recipeWrapper; - tooltip.clearTooltip(); - setResults(centrifugeWrapper.getRecipe().getAllProducts(), (GuiItemStackGroup) guiItemStacks); + ForestryTooltipCallback tooltip = new ForestryTooltipCallback(); + setResults(tooltip, centrifugeWrapper.getRecipe().getAllProducts(), guiItemStacks); guiItemStacks.addTooltipCallback(tooltip); } - private void setResults(Map outputs, GuiItemStackGroup guiItemStacks) { + private static void setResults(ForestryTooltipCallback tooltip, Map outputs, IGuiItemStackGroup guiItemStacks) { Set> entrySet = outputs.entrySet(); if (entrySet.isEmpty()) { return; } - PriorityQueue> sortByChance = new PriorityQueue<>(entrySet.size(), highestChanceComparator); + Queue> sortByChance = new PriorityQueue<>(entrySet.size(), highestChanceComparator); sortByChance.addAll(entrySet); int i = 0; @@ -89,10 +88,10 @@ public class CentrifugeRecipeCategory extends ForestryRecipeCategory { } int x = 72 + OUTPUTS[i][0] * 18; int y = OUTPUTS[i][1] * 18; - int ID = outputSlot + i; - guiItemStacks.init(ID, false, x, y); - guiItemStacks.set(ID, stack.getKey()); - tooltip.addChanceTooltip(ID + 1, stack.getValue()); + int slotIndex = outputSlot + i; + guiItemStacks.init(slotIndex, false, x, y); + guiItemStacks.set(slotIndex, stack.getKey()); + tooltip.addChanceTooltip(slotIndex, stack.getValue()); i++; } } diff --git a/src/main/java/forestry/factory/recipes/jei/squeezer/SqueezerRecipeCategory.java b/src/main/java/forestry/factory/recipes/jei/squeezer/SqueezerRecipeCategory.java index 75c726888..a5d19528a 100644 --- a/src/main/java/forestry/factory/recipes/jei/squeezer/SqueezerRecipeCategory.java +++ b/src/main/java/forestry/factory/recipes/jei/squeezer/SqueezerRecipeCategory.java @@ -35,8 +35,7 @@ public class SqueezerRecipeCategory extends ForestryRecipeCategory { private final IDrawableAnimated arrow; @Nonnull private final IDrawable tankOverlay; - private final ForestryTooltipCallback tooltip = new ForestryTooltipCallback(); - + public SqueezerRecipeCategory(@Nonnull IGuiHelper guiHelper) { super(guiHelper.createDrawable(guiTexture, 9, 16, 158, 62), "tile.for.squeezer.name"); @@ -70,7 +69,7 @@ public class SqueezerRecipeCategory extends ForestryRecipeCategory { guiItemStacks.init(craftOutputSlot, false, 87, 43); guiItemStacks.set(craftOutputSlot, wrapper.getOutputs()); - tooltip.clearTooltip(); + ForestryTooltipCallback tooltip = new ForestryTooltipCallback(); tooltip.addChanceTooltip(craftOutputSlot, chance); setIngredients(guiItemStacks, wrapper.getInputs());