mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-26 06:43:05 +00:00
Fix #1229 Squeezer Recipes in JEI do not show chance %
This commit is contained in:
1 parent
a5d57c4788
commit
7aa840282f
3 files changed
+22
-38
No files matched your search
@@ -16,18 +16,6 @@ public class ForestryTooltipCallback implements ITooltipCallback<ItemStack> {
|
||||
|
||||
private final ArrayListMultimap<Integer, String> tooltips = ArrayListMultimap.create();
|
||||
|
||||
public void addToTooltip(int index, List<String> tooltip) {
|
||||
tooltips.get(index).addAll(tooltip);
|
||||
}
|
||||
|
||||
public void addToTooltip(int index, String tooltip) {
|
||||
tooltips.get(index).add(tooltip);
|
||||
}
|
||||
|
||||
public List<String> getTooltip(int index) {
|
||||
return tooltips.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTooltip(int index, boolean input, ItemStack ingredient, List<String> tooltip) {
|
||||
List<String> tip = tooltips.get(index);
|
||||
@@ -36,20 +24,18 @@ public class ForestryTooltipCallback implements ITooltipCallback<ItemStack> {
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
+10
-11
@@ -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<ItemStack, Float> outputs, GuiItemStackGroup guiItemStacks) {
|
||||
private static void setResults(ForestryTooltipCallback tooltip, Map<ItemStack, Float> outputs, IGuiItemStackGroup guiItemStacks) {
|
||||
Set<Entry<ItemStack, Float>> entrySet = outputs.entrySet();
|
||||
if (entrySet.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
PriorityQueue<Entry<ItemStack, Float>> sortByChance = new PriorityQueue<>(entrySet.size(), highestChanceComparator);
|
||||
Queue<Entry<ItemStack, Float>> 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++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
|
||||
Reference in new issue
Block a user