diff --git a/xplat/src/main/java/dev/emi/emi/EmiRenderHelper.java b/xplat/src/main/java/dev/emi/emi/EmiRenderHelper.java index 1ab711bb..4f6c3f6b 100644 --- a/xplat/src/main/java/dev/emi/emi/EmiRenderHelper.java +++ b/xplat/src/main/java/dev/emi/emi/EmiRenderHelper.java @@ -39,6 +39,7 @@ import net.minecraft.client.texture.Sprite; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.fluid.Fluid; +import net.minecraft.item.ItemConvertible; import net.minecraft.text.MutableText; import net.minecraft.text.OrderedText; import net.minecraft.text.Style; @@ -224,30 +225,33 @@ public static Text getAmountText(EmiIngredient stack) { return getAmountText(stack, stack.getAmount()); } - public static Text getAmountText(EmiIngredient stack, long amount) { - if (stack.isEmpty() || amount == 0) { - return EMPTY_TEXT; - } - if (stack.getEmiStacks().get(0).getKey() instanceof Fluid) { - return getFluidAmount(amount); - } - return EmiPort.literal(TEXT_FORMAT.format(amount)); + public static Text getAmountText(EmiIngredient stack, double amount) { + return getAmountText(stack, (double) amount, false); } - public static Text getAmountText(EmiIngredient stack, double amount) { + public static Text getAmountText(EmiIngredient stack, double amount, boolean inStackFormat) { if (stack.isEmpty() || amount == 0) { return EMPTY_TEXT; } - if (stack.getEmiStacks().get(0).getKey() instanceof Fluid) { + + Object resource = stack.getEmiStacks().get(0).getKey(); + if (resource instanceof ItemConvertible item && inStackFormat) { + int stackSize = item.asItem().getMaxCount(); + long stackCount = (long) amount / stackSize; + double remainder = amount % stackSize; + MutableText text = EmiPort.literal(TEXT_FORMAT.format(stackCount) + "▤"); + if (remainder > 0) { + text = EmiPort.append(text, EmiPort.literal(" +" + TEXT_FORMAT.format(remainder))); + } + return text; + } + + if (resource instanceof Fluid) { return EmiConfig.fluidUnit.translate(amount); } return EmiPort.literal(TEXT_FORMAT.format(amount)); } - public static Text getFluidAmount(long amount) { - return EmiConfig.fluidUnit.translate(amount); - } - public static int getAmountOverflow(Text amount) { int width = CLIENT.textRenderer.getWidth(amount); if (width > 14) { diff --git a/xplat/src/main/java/dev/emi/emi/screen/BoMScreen.java b/xplat/src/main/java/dev/emi/emi/screen/BoMScreen.java index 3893e6d6..bbc572f9 100644 --- a/xplat/src/main/java/dev/emi/emi/screen/BoMScreen.java +++ b/xplat/src/main/java/dev/emi/emi/screen/BoMScreen.java @@ -77,6 +77,7 @@ public class BoMScreen extends Screen { private int nodeHeight = 0; private int lastMouseX, lastMouseY; private double scrollAcc = 0; + private boolean altDown = false; public BoMScreen(HandledScreen old) { super(EmiPort.translatable("screen.emi.recipe_tree")); @@ -265,6 +266,7 @@ public void render(DrawContext raw, int mouseX, int mouseY, float delta) { List list = Lists.newArrayList(); list.addAll(EmiTooltip.splitTranslate("tooltip.emi.bom.batch_size", BoM.tree.batches)); list.add(EmiTooltipComponents.of(EmiPort.translatable("tooltip.emi.bom.batch_size.ideal", EmiBind.LEFT_CLICK.getBindText()))); + list.add(EmiTooltipComponents.of(EmiPort.translatable("tooltip.emi.bom.amount_format"))); EmiRenderHelper.drawTooltip(this, context, list, mouseX, mouseY); } else if (BoM.tree != null && mode.contains(mx, my)) { String key = BoM.craftingMode ? "tooltip.emi.bom.mode.craft" : "tooltip.emi.bom.mode.view"; @@ -360,6 +362,16 @@ public float getScale() { return (float) desired / scale; } + @Override + public boolean keyReleased(int keyCode, int scanCode, int modifiers) { + if (EmiInput.isAltDown() != altDown) { + altDown = EmiInput.isAltDown(); + recalculateTree(); + } + + return super.keyReleased(keyCode, scanCode, modifiers); + } + @Override public boolean keyPressed(int keyCode, int scanCode, int modifiers) { if (keyCode == GLFW.GLFW_KEY_ESCAPE) { @@ -396,6 +408,12 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) { BoM.tree = null; init(); } + + if (EmiInput.isAltDown() != altDown) { + altDown = EmiInput.isAltDown(); + recalculateTree(); + } + return super.keyPressed(keyCode, scanCode, modifiers); } @@ -569,15 +587,15 @@ public Text getAmountText() { long adjusted = cost.getEffectiveAmount(); Text totalText; if (cost instanceof ChanceMaterialCost cmc) { - totalText = EmiPort.append(EmiPort.literal("≈"), EmiRenderHelper.getAmountText(cost.ingredient, adjusted)) + totalText = EmiPort.append(EmiPort.literal("≈"), EmiRenderHelper.getAmountText(cost.ingredient, adjusted, altDown)) .formatted(Formatting.GOLD); } else { - totalText = EmiRenderHelper.getAmountText(cost.ingredient, adjusted); + totalText = EmiRenderHelper.getAmountText(cost.ingredient, adjusted, altDown); } if (!remainder && BoM.craftingMode) { long amount = alreadyDone; if (amount < adjusted) { - Text amountText = amount == 0 ? EmiPort.literal("0") : (EmiRenderHelper.getAmountText(cost.ingredient, amount)); + Text amountText = amount == 0 ? EmiPort.literal("0") : (EmiRenderHelper.getAmountText(cost.ingredient, amount, altDown)); MutableText text = EmiPort.append(EmiPort.literal("", Formatting.RED), amountText); text = EmiPort.append(text, EmiPort.literal("/")); text = EmiPort.append(text, totalText); @@ -751,10 +769,10 @@ public Text getAmountText() { long a = Math.round(amount * chance.chance()); a = Math.max(a, node.amount); return EmiPort.append(EmiPort.literal("≈"), - EmiRenderHelper.getAmountText(node.ingredient, a)) + EmiRenderHelper.getAmountText(node.ingredient, a, altDown)) .formatted(Formatting.GOLD); } else { - return EmiRenderHelper.getAmountText(node.ingredient, amount); + return EmiRenderHelper.getAmountText(node.ingredient, amount, altDown); } } diff --git a/xplat/src/main/resources/assets/emi/lang/en_us.json b/xplat/src/main/resources/assets/emi/lang/en_us.json index 83526217..e622346e 100644 --- a/xplat/src/main/resources/assets/emi/lang/en_us.json +++ b/xplat/src/main/resources/assets/emi/lang/en_us.json @@ -259,6 +259,7 @@ "tooltip.emi.bom.batch_size": "Batch size: %s\nScroll to adjust\nHold §6[shift]§r to adjust by 16", "tooltip.emi.bom.batch_size.ideal": "Press %s to get minimal leftovers", + "tooltip.emi.bom.amount_format": "Hold §6[Alt]§r to view amounts in bulk form", "tooltip.emi.bom.mode.view": "§6Viewing§r recipe tree", "tooltip.emi.bom.mode.craft": "§6Crafting§r recipe tree\nProgress will be shown in recipe tree\n§bSynthetic favorites§r added to sidebar", "tooltip.emi.bom.help": "The recipe tree shows the process and base cost of a recipe\nThe display can be panned and zoomed\n\nLeft click a node to choose a recipe to assign to it\nHold §6[shift]§r to automatically pick based on your inventory\n\nRight click a recipe node to fold it temporarily\nHold §6[shift]§r to clear the recipe\n\nThe initial tree state is controlled by default recipes\nA button next to recipes can set default recipe preferences\n\nThe toggle by total cost can be used to help craft a recipe tree\nWhile crafting, materials that need to be collected will be displayed\n§bSynthetic favorites§r will be added to the favorites sidebar that\nwill show incomplete steps and can be used to craft",