8000 add ability to view tree amounts in stack form by Vap0r1ze · Pull Request #928 · emilyploszaj/emi · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

add ability to view tree amounts in stack form #928

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 1.20
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions xplat/src/main/java/dev/emi/emi/EmiRenderHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
28 changes: 23 additions & 5 deletions xplat/src/main/java/dev/emi/emi/screen/BoMScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down Expand Up @@ -265,6 +266,7 @@ public void render(DrawContext raw, int mouseX, int mouseY, float delta) {
List<TooltipComponent> 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";
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}

Expand Down
1 change: 1 addition & 0 deletions xplat/src/main/resources/assets/emi/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
0