From dbfbcdfd44574535ac2fc06dbfd1e0d7fe069841 Mon Sep 17 00:00:00 2001 From: slprime Date: Thu, 30 Oct 2025 08:49:03 +0200 Subject: [PATCH 1/2] Fix favorite state refresh --- .../nei/recipe/GuiFavoriteButton.java | 7 ++++++- .../nei/recipe/GuiRecipeButton.java | 4 ++++ .../nei/recipe/NEIRecipeWidget.java | 20 ++++++++++++++----- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/main/java/codechicken/nei/recipe/GuiFavoriteButton.java b/src/main/java/codechicken/nei/recipe/GuiFavoriteButton.java index 557243d2..5806a973 100644 --- a/src/main/java/codechicken/nei/recipe/GuiFavoriteButton.java +++ b/src/main/java/codechicken/nei/recipe/GuiFavoriteButton.java @@ -72,7 +72,7 @@ public class GuiFavoriteButton extends GuiRecipeButton { } public boolean isFavorite() { - return favorite; + return this.favorite; } public void toggleFavorite() { @@ -86,6 +86,11 @@ public class GuiFavoriteButton extends GuiRecipeButton { .setFavorite(this.favoriteResult.getItemStack(), this.favorite ? this.recipe.getRecipeId() : null); } + @Override + public void update() { + this.favorite = this.favorite && FavoriteRecipes.getFavorite(this.recipe.getRecipeId()) != null; + } + @Override protected void drawContent(Minecraft minecraft, int y, int x, boolean mouseOver) { final DrawableResource icon = isFavorite() ? ICON_STATE_ON : ICON_STATE_OFF; diff --git a/src/main/java/codechicken/nei/recipe/GuiRecipeButton.java b/src/main/java/codechicken/nei/recipe/GuiRecipeButton.java index fc13147e..0dbc478a 100644 --- a/src/main/java/codechicken/nei/recipe/GuiRecipeButton.java +++ b/src/main/java/codechicken/nei/recipe/GuiRecipeButton.java @@ -61,6 +61,10 @@ public abstract class GuiRecipeButton extends GuiNEIButton { public abstract void drawItemOverlay(); + public void update() { + + } + public boolean mouseScrolled(int scroll) { return false; } diff --git a/src/main/java/codechicken/nei/recipe/NEIRecipeWidget.java b/src/main/java/codechicken/nei/recipe/NEIRecipeWidget.java index 5199b84c..d722fe5a 100644 --- a/src/main/java/codechicken/nei/recipe/NEIRecipeWidget.java +++ b/src/main/java/codechicken/nei/recipe/NEIRecipeWidget.java @@ -34,7 +34,8 @@ import codechicken.nei.recipe.GuiRecipeButton.UpdateRecipeButtonsEvent; public class NEIRecipeWidget extends Widget { protected final WeakHashMap> permutations = new WeakHashMap<>(); - protected boolean needUpdate = true; + protected boolean btnUpdate = true; + protected boolean ingrUpdate = true; protected int cycleticks = 0; protected int lastcycle = 0; @@ -64,10 +65,12 @@ public class NEIRecipeWidget extends Widget { this.h += this.handlerInfo.getYShift(); } - if (!this.needUpdate && !NEIClientUtils.shiftKey() && (this.cycleticks++) / 20 != this.lastcycle) { + if (!this.ingrUpdate && !NEIClientUtils.shiftKey() && (this.cycleticks++) / 20 != this.lastcycle) { this.lastcycle = this.cycleticks / 20; - this.needUpdate = true; + this.ingrUpdate = true; } + + this.btnUpdate = true; } public List getRecipeButtons() { @@ -163,11 +166,18 @@ public class NEIRecipeWidget extends Widget { public void draw(int mouseX, int mouseY) { final int yShift = this.handlerInfo.getYShift(); - if (this.needUpdate) { - this.needUpdate = false; + if (this.ingrUpdate) { + this.ingrUpdate = false; updatePermutations(); } + if (this.btnUpdate) { + this.btnUpdate = false; + for (GuiRecipeButton button : getRecipeButtons()) { + button.update(); + } + } + GL11.glPushAttrib(GL11.GL_ENABLE_BIT | GL11.GL_COLOR_BUFFER_BIT | GL11.GL_LIGHTING_BIT); GL11.glTranslatef(this.x, this.y + yShift, 0); From e8ee08da26b98d94d6c3255b0ed31b7350b51acb Mon Sep 17 00:00:00 2001 From: slprime Date: Thu, 30 Oct 2025 19:26:49 +0200 Subject: [PATCH 2/2] optimize --- .../nei/recipe/NEIRecipeWidget.java | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/main/java/codechicken/nei/recipe/NEIRecipeWidget.java b/src/main/java/codechicken/nei/recipe/NEIRecipeWidget.java index d722fe5a..224a6b54 100644 --- a/src/main/java/codechicken/nei/recipe/NEIRecipeWidget.java +++ b/src/main/java/codechicken/nei/recipe/NEIRecipeWidget.java @@ -34,10 +34,9 @@ import codechicken.nei.recipe.GuiRecipeButton.UpdateRecipeButtonsEvent; public class NEIRecipeWidget extends Widget { protected final WeakHashMap> permutations = new WeakHashMap<>(); - protected boolean btnUpdate = true; - protected boolean ingrUpdate = true; + protected boolean update = true; protected int cycleticks = 0; - protected int lastcycle = 0; + protected int lastcycle = -1; protected final RecipeHandlerRef handlerRef; protected final HandlerInfo handlerInfo; @@ -65,12 +64,7 @@ public class NEIRecipeWidget extends Widget { this.h += this.handlerInfo.getYShift(); } - if (!this.ingrUpdate && !NEIClientUtils.shiftKey() && (this.cycleticks++) / 20 != this.lastcycle) { - this.lastcycle = this.cycleticks / 20; - this.ingrUpdate = true; - } - - this.btnUpdate = true; + this.update = true; } public List getRecipeButtons() { @@ -166,13 +160,14 @@ public class NEIRecipeWidget extends Widget { public void draw(int mouseX, int mouseY) { final int yShift = this.handlerInfo.getYShift(); - if (this.ingrUpdate) { - this.ingrUpdate = false; - updatePermutations(); - } + if (this.update) { + this.update = false; + + if (!NEIClientUtils.shiftKey() && (this.cycleticks++) / 20 != this.lastcycle || this.lastcycle == -1) { + this.lastcycle = this.cycleticks / 20; + updatePermutations(); + } - if (this.btnUpdate) { - this.btnUpdate = false; for (GuiRecipeButton button : getRecipeButtons()) { button.update(); }