Skip to content

Commit

Permalink
Merge branch '1.21' into 1.20.5
Browse files Browse the repository at this point in the history
  • Loading branch information
emilyploszaj committed Nov 1, 2024
2 parents 1414d0d + 5e4fc1b commit 9023c59
Show file tree
Hide file tree
Showing 23 changed files with 1,037 additions and 67 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
### Tweaks
* Added "Hidden" option for status effect display location #517
* Tweak a small few recipe IDs to be synthetic when they previously weren't
* Updated config UI on modern versions to be more similar to vanilla changes
* Tweaked "default stack" bind to also toggle during resolution

### Fixes
* Properly implement JEI fixes in 1.20.1 #743
* Added additional dev mode nags for synthetic IDs #730
* Added further safety around recipe baking to prevent self mutation from affecting EMI significantly #776
* Further update JEI integration with null backgrounds #755
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ protected void addBrewingRecipesAgnos(EmiRegistry registry) {
String oid = EmiUtil.subId(recipe.to().value());
Consumer<RegistryEntry<Potion>> potionRecipeGen = entry -> {
if (brewingRegistry.isBrewable(entry)) {
Identifier id = EmiPort.id("emi", "brewing/item/"
Identifier id = EmiPort.id("emi", "/brewing/item/"
+ EmiUtil.subId(entry.getKey().get().getValue()) + "/" + gid + "/" + iid + "/" + oid);
registry.addRecipe(new EmiBrewingRecipe(
EmiStack.of(EmiPort.setPotion(new ItemStack(recipe.from().value()), entry.value())), EmiIngredient.of(recipeIngredient),
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ minecraft_version=1.20.6
enabled_platforms=fabric,neoforge

archives_base_name=emi
mod_version=1.1.16
mod_version=1.1.17
maven_group=dev.emi

architectury_version=4.9.83
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ protected void addBrewingRecipesAgnos(EmiRegistry registry) {
Consumer<RegistryEntry<Potion>> potionRecipeGen = entry -> {
Potion potion = entry.value();
if (brewingRegistry.isBrewable(entry)) {
Identifier id = EmiPort.id("emi", "brewing/item/"
Identifier id = EmiPort.id("emi", "/brewing/item/"
+ EmiUtil.subId(entry.getKey().get().getValue()) + "/" + gid + "/" + iid + "/" + oid);
registry.addRecipe(new EmiBrewingRecipe(
EmiStack.of(EmiPort.setPotion(new ItemStack(recipe.from().value()), potion)), EmiIngredient.of(recipe.ingredient()),
Expand All @@ -215,7 +215,7 @@ protected void addBrewingRecipesAgnos(EmiRegistry registry) {
EmiStack input = EmiStack.of(is);
EmiIngredient ingredient = EmiIngredient.of(recipe.getIngredient());
EmiStack output = EmiStack.of(recipe.getOutput(is, recipe.getIngredient().getMatchingStacks()[0]));
Identifier id = EmiPort.id("emi", "brewing/neoforge/"
Identifier id = EmiPort.id("emi", "/brewing/neoforge/"
+ EmiUtil.subId(input.getId()) + "/"
+ EmiUtil.subId(ingredient.getEmiStacks().get(0).getId()) + "/"
+ EmiUtil.subId(output.getId()));
Expand Down
4 changes: 4 additions & 0 deletions xplat/src/main/java/dev/emi/emi/EmiPort.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,8 @@ public static Identifier id(String id) {
public static Identifier id(String namespace, String path) {
return new Identifier(namespace, path);
}

public static void applyModelViewMatrix() {
RenderSystem.applyModelViewMatrix();
}
}
6 changes: 5 additions & 1 deletion xplat/src/main/java/dev/emi/emi/api/widget/SlotWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,11 @@ private boolean slotInteraction(Function<EmiBind, Boolean> function) {
EmiRecipe recipe = getRecipe();
if (canResolve()) {
if (function.apply(EmiConfig.defaultStack)) {
BoM.addRecipe(RecipeScreen.resolve, recipe);
if (BoM.isDefaultRecipe(RecipeScreen.resolve, recipe)) {
BoM.removeRecipe(RecipeScreen.resolve, recipe);
} else {
BoM.addRecipe(RecipeScreen.resolve, recipe);
}
EmiHistory.pop();
return true;
} else if (function.apply(EmiConfig.viewRecipes)) {
Expand Down
6 changes: 5 additions & 1 deletion xplat/src/main/java/dev/emi/emi/jemi/JemiRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import dev.emi.emi.runtime.EmiDrawContext;
import dev.emi.emi.screen.EmiScreenManager;
import mezz.jei.api.gui.IRecipeLayoutDrawable;
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.api.recipe.RecipeIngredientRole;
import mezz.jei.api.recipe.category.IRecipeCategory;
import mezz.jei.library.focus.FocusGroup;
Expand Down Expand Up @@ -161,7 +162,10 @@ public void render(DrawContext draw, int mouseX, int mouseY, float delta) {
EmiDrawContext context = EmiDrawContext.wrap(draw);
context.push();
context.matrices().translate(x, y, 0);
category.getBackground().draw(context.raw());
IDrawable background = category.getBackground();
if (background != null) {
background.draw(context.raw());
}
category.draw(recipe, recipeLayoutDrawable.getRecipeSlotsView(), context.raw(), mouseX, mouseY);
context.resetColor();
context.pop();
Expand Down
30 changes: 27 additions & 3 deletions xplat/src/main/java/dev/emi/emi/registry/EmiRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public Manager(List<EmiRecipeCategory> categories, Map<EmiRecipeCategory, List<E
this.recipes = List.copyOf(recipes);

Object2IntMap<Identifier> duplicateIds = new Object2IntOpenHashMap<>();
Set<Identifier> incorrectIds = new ObjectArraySet<>();
for (EmiRecipe recipe : recipes) {
Identifier id = recipe.getId();
EmiRecipeCategory category = recipe.getCategory();
Expand All @@ -178,13 +179,20 @@ public Manager(List<EmiRecipeCategory> categories, Map<EmiRecipeCategory, List<E
} else {
byId.put(id, recipe);
}

if (!id.getPath().startsWith("/") && !recipeIds.containsValue(id)) {
incorrectIds.add(id);
}
}
}

if (EmiConfig.devMode) {
for (Identifier id : duplicateIds.keySet()) {
EmiReloadLog.warn(duplicateIds.getInt(id) + " recipes loaded with the same id: " + id);
}
for (Identifier id : incorrectIds) {
EmiReloadLog.warn("Recipe " + id + " not present in recipe manager. Consider prefixing its path with '/' if it is synthetic.");
}
}

Map<EmiStack, Set<EmiRecipe>> byInput = new Object2ObjectOpenCustomHashMap<>(new EmiStackList.ComparisonHashStrategy());
Expand Down Expand Up @@ -215,13 +223,28 @@ public Manager(List<EmiRecipeCategory> categories, Map<EmiRecipeCategory, List<E
}
}
for (EmiStack key : byInput.keySet()) {
this.byInput.put(key, byInput.get(key).stream().toList());
Set<EmiRecipe> r = byInput.getOrDefault(key, null);
if (r != null) {
this.byInput.put(key, r.stream().toList());
} else {
EmiReloadLog.warn("Stack illegally self-mutated during recipe bake, causing recipe loss: " + key);
}
}
for (EmiStack key : byOutput.keySet()) {
this.byOutput.put(key, byOutput.get(key).stream().toList());
Set<EmiRecipe> r = byOutput.getOrDefault(key, null);
if (r != null) {
this.byOutput.put(key, r.stream().toList());
} else {
EmiReloadLog.warn("Stack illegally self-mutated during recipe bake, causing recipe loss: " + key);
}
}
for (EmiRecipeCategory category : workstations.keySet()) {
workstations.put(category, workstations.get(category).stream().distinct().toList());
List<EmiIngredient> w = workstations.getOrDefault(category, null);
if (w != null) {
workstations.put(category, w.stream().distinct().toList());
} else {
EmiReloadLog.warn("Recipe category illegally self-mutated during recipe bake, causing recipe loss: " + category);
}
}
for (Map.Entry<EmiRecipeCategory, List<EmiRecipe>> entry : byCategory.entrySet()) {
for (EmiIngredient ingredient : workstations.getOrDefault(entry.getKey(), List.of())) {
Expand All @@ -233,6 +256,7 @@ public Manager(List<EmiRecipeCategory> categories, Map<EmiRecipeCategory, List<E

if (EmiConfig.devMode) {
EmiDev.duplicateRecipeIds = duplicateIds.keySet();
EmiDev.incorrectRecipeIds = incorrectIds;
}
}

Expand Down
19 changes: 19 additions & 0 deletions xplat/src/main/java/dev/emi/emi/runtime/EmiProfiler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package dev.emi.emi.runtime;

import net.minecraft.client.MinecraftClient;

public class EmiProfiler {
private static final MinecraftClient CLIENT = MinecraftClient.getInstance();

public static void push(String name) {
CLIENT.getProfiler().push(name);
}

public static void pop() {
CLIENT.getProfiler().pop();
}

public static void swap(String name) {
CLIENT.getProfiler().swap(name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private static void saveScreenshotInner(String path, int width, int height, Runn
view.translate(-1.0f, 1.0f, 0.0f);
view.scale(2f / width, -2f / height, -1f / 1000f);
view.translate(0.0f, 0.0f, 10.0f);
RenderSystem.applyModelViewMatrix();
EmiPort.applyModelViewMatrix();

Matrix4f backupProj = RenderSystem.getProjectionMatrix();
RenderSystem.setProjectionMatrix(new Matrix4f().identity(), VertexSorter.BY_Z);
Expand All @@ -80,7 +80,7 @@ private static void saveScreenshotInner(String path, int width, int height, Runn

RenderSystem.setProjectionMatrix(backupProj, VertexSorter.BY_Z);
view.popMatrix();
RenderSystem.applyModelViewMatrix();
EmiPort.applyModelViewMatrix();

framebuffer.endWrite();
client.getFramebuffer().beginWrite(true);
Expand Down
1 change: 1 addition & 0 deletions xplat/src/main/java/dev/emi/emi/runtime/dev/EmiDev.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@

public class EmiDev {
public static Set<Identifier> duplicateRecipeIds = Set.of();
public static Set<Identifier> incorrectRecipeIds = Set.of();
}
4 changes: 2 additions & 2 deletions xplat/src/main/java/dev/emi/emi/screen/BoMScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public void render(DrawContext raw, int mouseX, int mouseY, float delta) {
view.translate(width / 2, height / 2, 0);
view.scale(scale, scale, 1);
view.translate((float)offX, (float)offY, 0);
RenderSystem.applyModelViewMatrix();
EmiPort.applyModelViewMatrix();
if (BoM.tree != null) {
batcher.begin(0, 0, 0);
int cy = nodeHeight * NODE_VERTICAL_SPACING * 2;
Expand Down Expand Up @@ -254,7 +254,7 @@ public void render(DrawContext raw, int mouseX, int mouseY, float delta) {
}

view.popMatrix();
RenderSystem.applyModelViewMatrix();
EmiPort.applyModelViewMatrix();

if (help.contains(mouseX, mouseY)) {
context.setColor(0.5f, 0.6f, 1f, 1f);
Expand Down
8 changes: 1 addition & 7 deletions xplat/src/main/java/dev/emi/emi/screen/ConfigScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -366,19 +366,13 @@ public void updateChanges() {
public void render(DrawContext raw, int mouseX, int mouseY, float delta) {
EmiDrawContext context = EmiDrawContext.wrap(raw);
list.setScrollAmount(list.getScrollAmount());
this.renderDarkening(context.raw());
list.render(context.raw(), mouseX, mouseY, delta);
super.render(context.raw(), mouseX, mouseY, delta);
list.render(context.raw(), mouseX, mouseY, delta);
if (list.getHoveredEntry() != null) {
EmiRenderHelper.drawTooltip(this, context, list.getHoveredEntry().getTooltip(mouseX, mouseY), mouseX, mouseY, Math.min(width / 2 - 16, maxWidth));
}
}

@Override
public void renderBackground(DrawContext context, int mouseX, int mouseY, float delta) {
// Prevent double background draw
}

@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (activeBind != null) {
Expand Down
27 changes: 14 additions & 13 deletions xplat/src/main/java/dev/emi/emi/screen/EmiScreenManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import dev.emi.emi.runtime.EmiHidden;
import dev.emi.emi.runtime.EmiHistory;
import dev.emi.emi.runtime.EmiLog;
import dev.emi.emi.runtime.EmiProfiler;
import dev.emi.emi.runtime.EmiReloadLog;
import dev.emi.emi.runtime.EmiReloadManager;
import dev.emi.emi.runtime.EmiSidebars;
Expand Down Expand Up @@ -576,15 +577,15 @@ public static void drawBackground(EmiDrawContext context, int mouseX, int mouseY
recalculate();
EmiScreenBase base = EmiScreenBase.getCurrent();
if (base != null) {
client.getProfiler().push("sidebar");
EmiProfiler.push("sidebar");
for (SidebarPanel panel : panels) {
panel.drawBackground(context, mouseX, mouseY, delta);
}
}
}

public static void render(EmiDrawContext context, int mouseX, int mouseY, float delta) {
client.getProfiler().push("emi");
EmiProfiler.push("emi");
updateMouse(mouseX, mouseY);
recalculate();
EmiScreenBase base = EmiScreenBase.getCurrent();
Expand Down Expand Up @@ -612,7 +613,7 @@ public static void render(EmiDrawContext context, int mouseX, int mouseY, float
}
}
}
client.getProfiler().pop();
EmiProfiler.pop();
lastHoveredCraftable = null;
return;
} else if (EmiRecipes.activeWorker != null) {
Expand All @@ -621,20 +622,20 @@ public static void render(EmiDrawContext context, int mouseX, int mouseY, float
renderDevMode(context, mouseX, mouseY, delta, base);
}
renderWidgets(context, mouseX, mouseY, delta, base);
client.getProfiler().push("sidebars");
EmiProfiler.push("sidebars");
for (SidebarPanel panel : panels) {
panel.render(context, mouseX, mouseY, delta);
}

renderLastHoveredCraftable(context, mouseX, mouseY, delta, base);

client.getProfiler().pop();
EmiProfiler.pop();

renderExclusionAreas(context, mouseX, mouseY, delta, base);

client.getProfiler().swap("slots");
EmiProfiler.swap("slots");
renderSlotOverlays(context, mouseX, mouseY, delta, base);
client.getProfiler().pop();
EmiProfiler.pop();

RenderSystem.disableDepthTest();
}
Expand Down Expand Up @@ -665,14 +666,14 @@ private static void renderLastHoveredCraftable(EmiDrawContext context, int mouse
Matrix4fStack view = RenderSystem.getModelViewStack();
view.pushMatrix();
view.translate(0, 0, 200);
RenderSystem.applyModelViewMatrix();
EmiPort.applyModelViewMatrix();
int lhx = space.getRawX(lastHoveredCraftableOffset);
int lhy = space.getRawY(lastHoveredCraftableOffset);
context.fill(lhx, lhy, 18, 18, 0x44AA00FF);
lastHoveredCraftable.getStack().render(context.raw(), lhx + 1, lhy + 1, delta,
EmiIngredient.RENDER_ICON);
view.popMatrix();
RenderSystem.applyModelViewMatrix();
EmiPort.applyModelViewMatrix();
}
}
}
Expand Down Expand Up @@ -729,7 +730,7 @@ private static void renderCurrentTooltip(EmiDrawContext context, int mouseX, int
}
}
if (cursor.isEmpty() && draggedStack.isEmpty()) {
client.getProfiler().swap("hover");
EmiProfiler.swap("hover");
EmiIngredient hov = EmiStack.EMPTY;
SidebarType sidebar = SidebarType.NONE;
if (getHoveredStack(mouseX, mouseY, false) instanceof SidebarEmiStackInteraction sesi) {
Expand All @@ -753,15 +754,15 @@ private static void renderCurrentTooltip(EmiDrawContext context, int mouseX, int
} else {
EmiRenderHelper.drawTooltip(base.screen(), context, list, mouseX, mouseY);
}
client.getProfiler().pop();
EmiProfiler.pop();
}
lastStackTooltipRendered = null;
}

private static void renderDevMode(EmiDrawContext context, int mouseX, int mouseY, float delta, EmiScreenBase base) {
if (EmiConfig.devMode) {
Screen screen = base.screen();
client.getProfiler().swap("dev");
EmiProfiler.swap("dev");
int color = 0xFFFFFF;
Text title = EmiPort.literal("EMI Dev Mode");
int off = -16;
Expand Down Expand Up @@ -1435,7 +1436,7 @@ public void render(EmiDrawContext context, int mouseX, int mouseY, float delta)
}
}
if (isVisible()) {
client.getProfiler().swap(side.getName());
EmiProfiler.swap(side.getName());
context.push();
context.matrices().translate(0, 0, 100);
pageLeft.render(context.raw(), mouseX, mouseY, delta);
Expand Down
4 changes: 2 additions & 2 deletions xplat/src/main/java/dev/emi/emi/screen/RecipeScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public void render(DrawContext raw, int mouseX, int mouseY, float delta) {
int my = mouseY - group.y();
context.push();
context.matrices().translate(group.x(), group.y(), 0);
RenderSystem.applyModelViewMatrix();
EmiPort.applyModelViewMatrix();
try {
for (Widget widget : group.widgets) {
widget.render(context.raw(), mx, my, delta);
Expand All @@ -244,7 +244,7 @@ public void render(DrawContext raw, int mouseX, int mouseY, float delta) {
}
}
context.pop();
RenderSystem.applyModelViewMatrix();
EmiPort.applyModelViewMatrix();
}
EmiScreenManager.drawBackground(context, mouseX, mouseY, delta);
EmiScreenManager.render(context, mouseX, mouseY, delta);
Expand Down
5 changes: 5 additions & 0 deletions xplat/src/main/java/dev/emi/emi/screen/WidgetGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ public void decorateDevMode() {
tooltip.addAll(EmiTooltip.splitTranslate("emi.dev.synthetic_id"));
}
errors.add(new RecipeError(RecipeError.Severity.ERROR, tooltip));
} else if (EmiDev.incorrectRecipeIds.contains(id)) {
List<TooltipComponent> tooltip = Lists.newArrayList();
tooltip.addAll(EmiTooltip.splitTranslate("emi.dev.synthetic_nag_explanation", id));
tooltip.addAll(EmiTooltip.splitTranslate("emi.dev.synthetic_id"));
errors.add(new RecipeError(RecipeError.Severity.ERROR, tooltip));
}

if (recipe.getInputs() == null || recipe.getOutputs() == null || recipe.getCatalysts() == null) {
Expand Down
Loading

0 comments on commit 9023c59

Please sign in to comment.