Compare commits

..
Author SHA1 Message Date
Martin Robertz 68fcc34d18 update 2025-03-29 11:09:29 +01:00
slprime 3ff3bb5c11 recipe tooltip refactoring 2025-03-28 23:19:57 +02:00
slprime 903271b279 remove ingredients sorting 2025-03-27 10:59:46 +02:00
9 changed files with 90 additions and 112 deletions

No files matched your search

+1 -1
View File
@@ -2,7 +2,7 @@
dependencies {
api('com.github.GTNewHorizons:CodeChickenCore:1.4.1:dev')
implementation('com.github.GTNewHorizons:GTNHLib:0.6.16:dev')
implementation('com.github.GTNewHorizons:GTNHLib:0.6.17:dev')
shadowImplementation('org.apache.commons:commons-csv:1.10.0')
@@ -40,7 +40,6 @@ import codechicken.nei.recipe.BookmarkRecipeId;
import codechicken.nei.recipe.Recipe;
import codechicken.nei.recipe.Recipe.RecipeId;
import codechicken.nei.recipe.Recipe.RecipeIngredient;
import codechicken.nei.recipe.RecipeTooltipLineHandler;
import codechicken.nei.recipe.StackInfo;
import codechicken.nei.recipe.chain.RecipeChainMath;
import codechicken.nei.recipe.chain.RecipeChainTooltipLineHandler;
@@ -91,7 +90,6 @@ public class BookmarkPanel extends PanelWidget<BookmarkGrid> {
public SortableGroup sortableGroup;
public GroupingItem groupingItem;
protected RecipeTooltipLineHandler recipeTooltipLineHandler;
protected AcceptsFollowingTooltipLineHandler acceptsFollowingTooltipLineHandler;
protected RecipeChainTooltipLineHandler recipeChainTooltipLineHandler;
@@ -881,33 +879,6 @@ public class BookmarkPanel extends PanelWidget<BookmarkGrid> {
if (slot != null) {
if (!slot.isIngredient() && NEIClientConfig.getRecipeTooltipsMode() != 0) {
RecipeId recipeId = null;
if (slot.getRecipeId() != null) {
final int tooltipMode = NEIClientConfig.getRecipeTooltipsMode();
final BookmarkViewMode viewMode = slot.getGroup().viewMode;
if (tooltipMode == 3 || viewMode == BookmarkViewMode.DEFAULT && tooltipMode == 1
|| viewMode == BookmarkViewMode.TODO_LIST && tooltipMode == 2) {
recipeId = slot.getRecipeId();
}
}
if (recipeId == null) {
this.recipeTooltipLineHandler = null;
} else if (this.recipeTooltipLineHandler == null
|| !this.recipeTooltipLineHandler.getRecipeId().equals(recipeId)) {
this.recipeTooltipLineHandler = new RecipeTooltipLineHandler(recipeId);
}
if (this.recipeTooltipLineHandler != null) {
currenttip.add(GuiDraw.TOOLTIP_HANDLER + GuiDraw.getTipLineId(this.recipeTooltipLineHandler));
}
} else {
this.acceptsFollowingTooltipLineHandler = null;
}
if (slot.isIngredient() && slot.getRecipeId() != null && slot.getBookmarkItem().permutations.size() > 1) {
RecipeId recipeId = slot.getRecipeId();
@@ -931,7 +902,6 @@ public class BookmarkPanel extends PanelWidget<BookmarkGrid> {
}
} else {
this.recipeTooltipLineHandler = null;
this.acceptsFollowingTooltipLineHandler = null;
}
@@ -15,13 +15,10 @@ import codechicken.nei.guihook.IContainerTooltipHandler;
import codechicken.nei.recipe.GuiCraftingRecipe;
import codechicken.nei.recipe.GuiRecipe;
import codechicken.nei.recipe.GuiUsageRecipe;
import codechicken.nei.recipe.Recipe.RecipeId;
import codechicken.nei.recipe.RecipeTooltipLineHandler;
import codechicken.nei.recipe.StackInfo;
public class ItemHistoryPanel extends Widget implements IContainerTooltipHandler {
protected RecipeTooltipLineHandler recipeTooltipLineHandler = null;
protected int mouseDownItemIndex = -1;
protected ItemsGrid<ItemsGridSlot, MouseContext> grid = new ItemsGrid<>() {
@@ -217,27 +214,4 @@ public class ItemHistoryPanel extends Widget implements IContainerTooltipHandler
this.mouseDownItemIndex = -1;
}
@Override
public List<String> handleItemTooltip(GuiContainer gui, ItemStack itemstack, int mousex, int mousey,
List<String> currenttip) {
if (itemstack != null && contains(mousex, mousey) && NEIClientConfig.getFavoriteRecipeTooltips()) {
final RecipeId recipeId = FavoriteRecipes.getFavorite(itemstack);
if (recipeId == null) {
recipeTooltipLineHandler = null;
} else if (recipeTooltipLineHandler == null || !recipeTooltipLineHandler.getRecipeId().equals(recipeId)) {
recipeTooltipLineHandler = new RecipeTooltipLineHandler(recipeId);
}
if (recipeTooltipLineHandler != null) {
currenttip.add(GuiDraw.TOOLTIP_HANDLER + GuiDraw.getTipLineId(recipeTooltipLineHandler));
}
} else {
recipeTooltipLineHandler = null;
}
return currenttip;
}
}
+1 -22
View File
@@ -9,8 +9,6 @@ import net.minecraft.item.ItemStack;
import codechicken.lib.gui.GuiDraw;
import codechicken.nei.ItemsPanelGrid.ItemsPanelGridSlot;
import codechicken.nei.recipe.Recipe.RecipeId;
import codechicken.nei.recipe.RecipeTooltipLineHandler;
import codechicken.nei.util.NEIMouseUtils;
public class ItemPanel extends PanelWidget<ItemsPanelGrid> {
@@ -33,7 +31,6 @@ public class ItemPanel extends PanelWidget<ItemsPanelGrid> {
return super.getStackMouseOver(mousex, mousey);
}
protected RecipeTooltipLineHandler recipeTooltipLineHandler = null;
public ItemHistoryPanel historyPanel = new ItemHistoryPanel();
public Button toggleGroups;
@@ -207,25 +204,7 @@ public class ItemPanel extends PanelWidget<ItemsPanelGrid> {
}
}
currenttip = super.handleItemTooltip(gui, itemstack, mousex, mousey, currenttip);
if (itemstack != null && contains(mousex, mousey) && NEIClientConfig.getFavoriteRecipeTooltips()) {
RecipeId recipeId = FavoriteRecipes.getFavorite(itemstack);
if (recipeId == null) {
recipeTooltipLineHandler = null;
} else if (recipeTooltipLineHandler == null || !recipeTooltipLineHandler.getRecipeId().equals(recipeId)) {
recipeTooltipLineHandler = new RecipeTooltipLineHandler(recipeId);
}
if (recipeTooltipLineHandler != null) {
currenttip.add(GuiDraw.TOOLTIP_HANDLER + GuiDraw.getTipLineId(recipeTooltipLineHandler));
}
} else {
recipeTooltipLineHandler = null;
}
return currenttip;
return super.handleItemTooltip(gui, itemstack, mousex, mousey, currenttip);
}
@Override
@@ -165,11 +165,17 @@ public abstract class ShortcutInputHandler {
RecipeChainMath math = null;
if (slot == null) {
math = RecipeChainMath.of(Recipe.of(recipeId), slot != null ? slot.getMultiplier() : 1);
final Recipe recipe = Recipe.of(recipeId);
if (recipe != null) {
math = RecipeChainMath.of(recipe, 1);
}
} else if (slot.getRecipeId() != null && !slot.isIngredient()) {
if (slot.getGroup().crafting == null) {
math = RecipeChainMath.of(Recipe.of(slot.getRecipeId()), slot != null ? slot.getMultiplier() : 1);
final Recipe recipe = Recipe.of(slot.getRecipeId());
if (recipe != null) {
math = RecipeChainMath.of(recipe, slot != null ? slot.getMultiplier() : 1);
}
} else {
math = ItemPanels.bookmarkPanel.getGrid()
.createRecipeChainMath(slot.getGroupId(), slot.getRecipeId());
@@ -386,8 +386,8 @@ public class GuiContainerManager {
public static void enableMatrixStackLogging() {
if (!contextEnabled) {
modelviewDepth = GL11.glGetInteger(GL11.GL_MODELVIEW_STACK_DEPTH);
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
modelviewDepth = GL11.glGetInteger(GL11.GL_MODELVIEW_STACK_DEPTH);
contextEnabled = true;
}
}
@@ -2,7 +2,6 @@ package codechicken.nei.recipe;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
@@ -16,7 +15,6 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import codechicken.nei.LRUCache;
import codechicken.nei.NEIServerUtils;
import codechicken.nei.PositionedStack;
import codechicken.nei.api.ItemInfo;
@@ -289,8 +287,6 @@ public class Recipe {
}
}
private static final LRUCache<RecipeId, Recipe> recipeCache = new LRUCache<>(200);
private final String handlerName;
private final RecipeIngredient[] results;
private final RecipeIngredient[] ingredients;
@@ -298,14 +294,6 @@ public class Recipe {
private Recipe(String handlerName, List<RecipeIngredient> ingredients, List<RecipeIngredient> results) {
this.handlerName = handlerName;
ingredients.sort(
Comparator.comparingInt((RecipeIngredient ingr) -> ingr.rely)
.thenComparingInt((RecipeIngredient ingr) -> ingr.relx));
results.sort(
Comparator.comparingInt((RecipeIngredient ingr) -> ingr.rely)
.thenComparingInt((RecipeIngredient ingr) -> ingr.relx));
this.ingredients = ingredients.toArray(new RecipeIngredient[ingredients.size()]);
this.results = results.toArray(new RecipeIngredient[results.size()]);
}
@@ -343,17 +331,13 @@ public class Recipe {
return null;
}
final Recipe recipe = recipeCache.computeIfAbsent(recipeId, ri -> {
final RecipeHandlerRef handlerRef = RecipeHandlerRef.of(recipeId);
final RecipeHandlerRef handlerRef = RecipeHandlerRef.of(recipeId);
if (handlerRef != null) {
return Recipe.of(handlerRef);
}
if (handlerRef != null) {
return Recipe.of(handlerRef);
}
return null;
});
return recipe != null ? recipe.copy() : null;
return null;
}
protected static List<RecipeIngredient> extractItems(List<?> items) {
@@ -5,6 +5,7 @@ import java.util.List;
import net.minecraft.client.gui.inventory.GuiContainer;
import codechicken.nei.LRUCache;
import codechicken.nei.LayoutManager;
import codechicken.nei.api.IOverlayHandler;
import codechicken.nei.api.IRecipeOverlayRenderer;
@@ -13,6 +14,7 @@ import codechicken.nei.recipe.Recipe.RecipeId;
public class RecipeHandlerRef {
private static final LRUCache<RecipeId, RecipeHandlerRef> recipeRefCache = new LRUCache<>(200);
public final IRecipeHandler handler;
public final int recipeIndex;
@@ -28,19 +30,22 @@ public class RecipeHandlerRef {
public static RecipeHandlerRef of(RecipeId recipeId) {
if (recipeId.getResult() != null && !recipeId.getIngredients().isEmpty()) {
final List<ICraftingHandler> handlers = GuiCraftingRecipe
.getCraftingHandlers("recipeId", recipeId.getResult(), recipeId);
return recipeRefCache.computeIfAbsent(recipeId, ri -> {
final List<ICraftingHandler> handlers = GuiCraftingRecipe
.getCraftingHandlers("recipeId", recipeId.getResult(), recipeId);
for (ICraftingHandler handler : handlers) {
int refIndex = SearchRecipeHandler.findFirst(
handler,
recipeIndex -> recipeId.equalsIngredients(handler.getIngredientStacks(recipeIndex)));
for (ICraftingHandler handler : handlers) {
int refIndex = SearchRecipeHandler.findFirst(
handler,
recipeIndex -> recipeId.equalsIngredients(handler.getIngredientStacks(recipeIndex)));
if (refIndex >= 0) {
return new RecipeHandlerRef(handler, refIndex);
if (refIndex >= 0) {
return new RecipeHandlerRef(handler, refIndex);
}
}
}
return null;
});
}
return null;
@@ -1,17 +1,27 @@
package codechicken.nei.recipe;
import java.util.List;
import java.util.Map;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.ItemStack;
import codechicken.lib.gui.GuiDraw;
import codechicken.nei.BookmarkPanel.BookmarkViewMode;
import codechicken.nei.FavoriteRecipes;
import codechicken.nei.ItemPanels;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.api.ShortcutInputHandler;
import codechicken.nei.bookmark.BookmarksGridSlot;
import codechicken.nei.guihook.GuiContainerManager;
import codechicken.nei.guihook.IContainerInputHandler;
import codechicken.nei.guihook.IContainerTooltipHandler;
import codechicken.nei.recipe.Recipe.RecipeId;
public class RecipeItemInputHandler implements IContainerInputHandler, IContainerTooltipHandler {
protected RecipeTooltipLineHandler recipeTooltipLineHandler = null;
public static void load() {
RecipeItemInputHandler recipeHandler = new RecipeItemInputHandler();
GuiContainerManager.addInputHandler(recipeHandler);
@@ -47,6 +57,56 @@ public class RecipeItemInputHandler implements IContainerInputHandler, IContaine
return hotkeys;
}
@Override
public List<String> handleItemTooltip(GuiContainer gui, ItemStack itemstack, int mousex, int mousey,
List<String> currenttip) {
if (itemstack != null) {
final RecipeId recipeId = getHoveredRecipeId(gui, itemstack, mousex, mousey);
if (recipeId == null) {
recipeTooltipLineHandler = null;
} else if (recipeTooltipLineHandler == null || !recipeTooltipLineHandler.getRecipeId().equals(recipeId)) {
recipeTooltipLineHandler = new RecipeTooltipLineHandler(recipeId);
}
if (recipeTooltipLineHandler != null) {
currenttip.add(GuiDraw.TOOLTIP_HANDLER + GuiDraw.getTipLineId(recipeTooltipLineHandler));
}
} else {
recipeTooltipLineHandler = null;
}
return currenttip;
}
private RecipeId getHoveredRecipeId(GuiContainer gui, ItemStack itemstack, int mousex, int mousey) {
if (ItemPanels.bookmarkPanel.contains(mousex, mousey)) {
final BookmarksGridSlot slot = ItemPanels.bookmarkPanel.getSlotMouseOver(mousex, mousey);
if (slot != null && slot.getRecipeId() != null
&& !slot.isIngredient()
&& NEIClientConfig.getRecipeTooltipsMode() != 0) {
final int tooltipMode = NEIClientConfig.getRecipeTooltipsMode();
final BookmarkViewMode viewMode = slot.getGroup().viewMode;
if (tooltipMode == 3 || viewMode == BookmarkViewMode.DEFAULT && tooltipMode == 1
|| viewMode == BookmarkViewMode.TODO_LIST && tooltipMode == 2) {
return slot.getRecipeId();
}
}
return null;
}
if (ItemPanels.itemPanel.contains(mousex, mousey)
|| ItemPanels.itemPanel.historyPanel.contains(mousex, mousey)) {
return NEIClientConfig.getFavoriteRecipeTooltips() ? FavoriteRecipes.getFavorite(itemstack) : null;
}
return null;
}
@Override
public void onKeyTyped(GuiContainer gui, char keyChar, int keyID) {}