Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions xplat/src/main/java/dev/emi/emi/config/EmiConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,10 @@ public class EmiConfig {
@Comment("Whether to display exclusion areas")
@ConfigValue("dev.highlight-exclusion-areas")
public static boolean highlightExclusionAreas = false;

@Comment("Whether to display Recipe Tree bounding boxes for culling")
@ConfigValue("dev.recipe-tree-bounding-boxes")
public static boolean recipeTreeBoundingBoxes = false;

// Persistent (currently empty)

Expand Down
66 changes: 61 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 @@ -7,8 +7,8 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.joml.Matrix4f;
import org.joml.Matrix4fStack;
import org.joml.Vector4d;
import org.lwjgl.glfw.GLFW;

import com.google.common.collect.Lists;
Expand All @@ -33,7 +33,6 @@
import dev.emi.emi.bom.FoldState;
import dev.emi.emi.bom.MaterialNode;
import dev.emi.emi.bom.ProgressState;
import dev.emi.emi.bom.TreeCost;
import dev.emi.emi.config.EmiConfig;
import dev.emi.emi.data.EmiRecipeCategoryProperties;
import dev.emi.emi.input.EmiBind;
Expand All @@ -51,8 +50,6 @@
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.gui.tooltip.TooltipComponent;
import net.minecraft.client.sound.PositionedSoundInstance;
import net.minecraft.client.util.InputUtil;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
Expand All @@ -79,6 +76,8 @@ public class BoMScreen extends Screen {
private int nodeHeight = 0;
private int lastMouseX, lastMouseY;
private double scrollAcc = 0;
private Screen screen = MinecraftClient.getInstance().currentScreen;
private boolean shouldFullRenderNodes = true;

public BoMScreen(HandledScreen<?> old) {
super(EmiPort.translatable("screen.emi.recipe_tree"));
Expand All @@ -96,6 +95,7 @@ public void init() {

public void recalculateTree() {
help = new Bounds(width - 18, height - 18, 16, 16);
shouldFullRenderNodes = true;
if (BoM.tree != null) {
TreeVolume volume = addNewNodes(BoM.tree.goal, BoM.tree.batches, 1, 0, ChanceState.DEFAULT);
nodes = volume.nodes;
Expand Down Expand Up @@ -212,6 +212,9 @@ public void render(DrawContext raw, int mouseX, int mouseY, float delta) {

int mx = (int) ((mouseX - width / 2) / scale - offX);
int my = (int) ((mouseY - height / 2) / scale - offY);

int scaledScreenW = (int) ((screen.width / 2) / scale);
int scaledScreenH = (int) ((screen.height / 2) / scale);

Matrix4fStack view = RenderSystem.getModelViewStack();
view.pushMatrix();
Expand All @@ -230,8 +233,25 @@ public void render(DrawContext raw, int mouseX, int mouseY, float delta) {
cost.render(context);
}
for (Node node : nodes) {
node.render(context, mx, my, delta);
if(shouldFullRenderNodes) {
node.render(context, mx, my, delta);
if(EmiConfig.recipeTreeBoundingBoxes) {
node.renderBoundingBox(context);
}
} else {
Vector4d bounds = node.getBoundingBox();
if( bounds.x + offX < scaledScreenW &&
bounds.x + bounds.w + offX > -scaledScreenW &&
bounds.y + offY < scaledScreenH &&
bounds.y + bounds.z + offY> -scaledScreenH) {
node.render(context, mx, my, delta);
if(EmiConfig.recipeTreeBoundingBoxes) {
node.renderBoundingBox(context);
}
}
}
}
shouldFullRenderNodes = false;
int color = -1;
if (batches.contains(mx, my)) {
color = 0xff8099ff;
Expand Down Expand Up @@ -731,6 +751,42 @@ public void render(EmiDrawContext context, int mouseX, int mouseY, float delta)
batcher.render(node.ingredient, context.raw(), x + xo - 8 + midOffset, y - 8, 0);
EmiRenderHelper.renderAmount(context, x + xo - 8 + midOffset, y - 8, getAmountText());
}

public void renderBoundingBox(EmiDrawContext context) {
Vector4d bounds = getBoundingBox();
context.push();

context.setColor(0.5f,0.5f,0.5f,0.2f);
drawLine(context, (int) bounds.x, (int) bounds.y, (int) this.x, (int) this.y);
if(parent != null) {
drawLine(context, ((parent.x - this.x)/2 + this.x) - 2, ((parent.y - this.y)/2 + this.y) - 2, ((parent.x - this.x)/2 + this.x) + 2, ((parent.y - this.y)/2 + this.y) + 2);
}

context.setColor(1, 0, 0);
drawLine(context, (int) bounds.x, (int) bounds.y, (int) (bounds.x+bounds.w), (int) bounds.y);
drawLine(context, (int) bounds.x, (int) bounds.y, (int) bounds.x, (int) (bounds.y + bounds.z));
drawLine(context, (int) (bounds.x+bounds.w), (int) bounds.y, (int) (bounds.x+bounds.w), (int) (bounds.y+bounds.z));
drawLine(context, (int) bounds.x, (int) (bounds.y+bounds.z), (int) (bounds.x+bounds.w), (int) (bounds.y+bounds.z));

context.pop();
}

public Vector4d getBoundingBox() {
Vector4d bounds = new Vector4d();

if(parent != null) {
bounds.w = this.width + 10 + (Math.abs(parent.x - this.x));
bounds.z = NODE_VERTICAL_SPACING + 10 + (Math.abs(parent.y - this.y));
bounds.x = ((parent.x - this.x)/2 + this.x) - bounds.w/2;
bounds.y = ((parent.y - this.y)/2 + this.y) - bounds.z/2;
return bounds;
}
bounds.w = this.width + 10;
bounds.z = NODE_VERTICAL_SPACING + 10;
bounds.x = x - bounds.w/2;
bounds.y = y - bounds.z/2;
return bounds;
}

public void setColor(EmiDrawContext context, MaterialNode node, boolean chanced, boolean hovered) {
context.setColor(1f, 1f, 1f, 1f);
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 @@ -179,6 +179,7 @@
"config.emi.dev.show_recipe_decorators": "Show Recipe Decorators",
"config.emi.dev.highlight_defaulted": "Highlight Defaulted",
"config.emi.dev.highlight_exclusion_areas": "Highlight Exclusion Areas",
"config.emi.dev.recipe-tree-bounding-boxes": "Recipe Tree Bounding Boxes",

"config.emi.presets.sidebars": "Sidebars",
"config.emi.presets.binds": "Binds",
Expand Down