Skip to content
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
19 changes: 8 additions & 11 deletions xplat/src/main/java/dev/emi/emi/api/EmiApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ public static HandledScreen<?> getHandledScreen() {
Screen s = client.currentScreen;
if (s instanceof HandledScreen<?> hs) {
return hs;
} else if (s instanceof RecipeScreen rs) {
return rs.old;
} else if (s instanceof BoMScreen bs) {
return bs.old;
} else if (s instanceof RecipeScreen rs && rs.old instanceof HandledScreen<?> hs) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's what I mean in my previous comment, both RecipeScreen and BoMScreen can now have an old screen that is not a HandledScreen, such as a quest UI, and then no recipes would show up as craftable. Maybe this behavior should default to the player's inventory when nothing else is valid, since that is always accessible. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like this?

Index: xplat/src/main/java/dev/emi/emi/api/EmiApi.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/xplat/src/main/java/dev/emi/emi/api/EmiApi.java b/xplat/src/main/java/dev/emi/emi/api/EmiApi.java
--- a/xplat/src/main/java/dev/emi/emi/api/EmiApi.java	(revision 12e249c067862fd4233bfb86ca8c92865f52fc8e)
+++ b/xplat/src/main/java/dev/emi/emi/api/EmiApi.java	(date 1771852166073)
@@ -111,6 +111,8 @@
 			return hs;
 		} else if (s instanceof BoMScreen bs && bs.old instanceof HandledScreen<?> hs) {
 			return hs;
+		} else if (client.player != null) {
+			return new InventoryScreen(client.player);
 		}
 		return null;
 	}

return hs;
} else if (s instanceof BoMScreen bs && bs.old instanceof HandledScreen<?> hs) {
return hs;
}
return null;
}
Expand Down Expand Up @@ -243,20 +243,17 @@ private static void setPages(Map<EmiRecipeCategory, List<EmiRecipe>> recipes, Em
.collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue()));
if (!recipes.isEmpty()) {
EmiSidebars.lookup(stack);
if (getHandledScreen() == null) {
client.setScreen(new InventoryScreen(client.player));
}
if (client.currentScreen instanceof HandledScreen<?> hs) {
push();
client.setScreen(new RecipeScreen(hs, recipes));
} else if (client.currentScreen instanceof BoMScreen bs) {
if (client.currentScreen instanceof BoMScreen bs) {
push();
client.setScreen(new RecipeScreen(bs.old, recipes));
} else if (client.currentScreen instanceof RecipeScreen rs) {
push();
RecipeScreen n = new RecipeScreen(rs.old, recipes);
client.setScreen(n);
n.focusCategory(rs.getFocusedCategory());
} else {
push();
client.setScreen(new RecipeScreen(client.currentScreen, recipes));
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions xplat/src/main/java/dev/emi/emi/registry/EmiRecipeFiller.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ public static <T extends ScreenHandler> List<EmiRecipeHandler<T>> getAllHandlers

@SuppressWarnings("unchecked")
public static <T extends ScreenHandler> @Nullable EmiRecipeHandler<T> getFirstValidHandler(EmiRecipe recipe, HandledScreen<T> screen) {
if (screen == null) {
return null;
}
EmiRecipeHandler<T> ret = null;
for (EmiRecipeHandler<T> handler : getAllHandlers(screen)) {
if (handler.supportsRecipe(recipe)) {
Expand Down
5 changes: 2 additions & 3 deletions xplat/src/main/java/dev/emi/emi/screen/BoMScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
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;
Expand All @@ -74,13 +73,13 @@ public class BoMScreen extends Screen {
private List<Cost> costs = Lists.newArrayList();
private EmiPlayerInventory playerInv;
private boolean hasRemainders = false;;
public HandledScreen<?> old;
public Screen old;
private int nodeWidth = 0;
private int nodeHeight = 0;
private int lastMouseX, lastMouseY;
private double scrollAcc = 0;

public BoMScreen(HandledScreen<?> old) {
public BoMScreen(Screen old) {
super(EmiPort.translatable("screen.emi.recipe_tree"));
this.old = old;
}
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 @@ -47,7 +47,7 @@ public class RecipeScreen extends Screen {
private static final Identifier TEXTURE = EmiPort.id("emi", "textures/gui/background.png");
public static @Nullable EmiIngredient resolve = null;
private Map<EmiRecipeCategory, List<EmiRecipe>> recipes;
public HandledScreen<?> old;
public Screen old;
private List<RecipeTab> tabs = Lists.newArrayList();
private int tabPageSize = 6;
private int tabPage = 0, tab = 0, page = 0;
Expand All @@ -63,7 +63,7 @@ public class RecipeScreen extends Screen {
int x = (this.width - backgroundWidth) / 2;
int y = (this.height - backgroundHeight) / 2;

public RecipeScreen(HandledScreen<?> old, Map<EmiRecipeCategory, List<EmiRecipe>> recipes) {
public RecipeScreen(Screen old, Map<EmiRecipeCategory, List<EmiRecipe>> recipes) {
super(EmiPort.translatable("screen.emi.recipe"));
this.old = old;
arrows = List.of(
Expand Down