mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-22 21:19:51 +00:00
Create Favorites Widget; More hotkeys; More Tooltips; (#617)
Co-authored-by: slprime <[email protected]> Co-authored-by: Maya <[email protected]>
This commit is contained in:
63 files changed
+8441
-3975
No files matched your search
@@ -0,0 +1,50 @@
|
||||
package codechicken.nei.recipe;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import codechicken.nei.FavoriteRecipes;
|
||||
import codechicken.nei.ItemsTooltipLineHandler;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
|
||||
public class AcceptsFollowingTooltipLineHandler extends ItemsTooltipLineHandler {
|
||||
|
||||
protected static final int DEFAULT_MAX_ROWS = 5;
|
||||
|
||||
public Object tooltipGUID;
|
||||
|
||||
public AcceptsFollowingTooltipLineHandler(Object tooltipGUID, List<ItemStack> items, ItemStack activeStack,
|
||||
int maxRows) {
|
||||
super(NEIClientUtils.translate("recipe.accepts"), items, false, maxRows);
|
||||
this.tooltipGUID = tooltipGUID;
|
||||
setActiveStack(activeStack);
|
||||
}
|
||||
|
||||
public static AcceptsFollowingTooltipLineHandler of(Object tooltipGUID, List<ItemStack> items,
|
||||
ItemStack activeStack) {
|
||||
return of(tooltipGUID, items, activeStack, DEFAULT_MAX_ROWS);
|
||||
}
|
||||
|
||||
public static AcceptsFollowingTooltipLineHandler of(Object tooltipGUID, List<ItemStack> items,
|
||||
ItemStack activeStack, int maxRows) {
|
||||
|
||||
if (items.size() > 1) {
|
||||
items.sort(Comparator.comparing(FavoriteRecipes::contains).reversed());
|
||||
return new AcceptsFollowingTooltipLineHandler(tooltipGUID, items, activeStack, maxRows);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawItem(int x, int y, ItemStack drawStack, String stackSize) {
|
||||
super.drawItem(x, y, drawStack, stackSize);
|
||||
|
||||
if (FavoriteRecipes.contains(drawStack)) {
|
||||
NEIClientUtils.drawNEIOverlayText("F", x, y);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
package codechicken.nei.recipe;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import codechicken.nei.ItemStackAmount;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.RestartableTask;
|
||||
import codechicken.nei.bookmark.BookmarkItem;
|
||||
import codechicken.nei.recipe.Recipe.RecipeId;
|
||||
import codechicken.nei.recipe.chain.RecipeChainIterator;
|
||||
import codechicken.nei.recipe.chain.RecipeChainMath;
|
||||
|
||||
public class AutoCraftingManager {
|
||||
|
||||
private static RecipeChainMath math;
|
||||
|
||||
private static final RestartableTask task = new RestartableTask("NEI Bookmark AutoCraft Processing") {
|
||||
|
||||
private static final ItemStack ROOT_ITEM = new ItemStack(Blocks.fire);
|
||||
private static final RecipeId ROOT_RECIPE_ID = RecipeId
|
||||
.of(ROOT_ITEM, "recipe-autocrafting", Collections.emptyList());
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
final GuiContainer guiContainer = NEIClientUtils.getGuiContainer();
|
||||
final InventoryPlayer playerInventory = guiContainer.mc.thePlayer.inventory;
|
||||
final ItemStackAmount inventory = ItemStackAmount.of(Arrays.asList(playerInventory.mainInventory));
|
||||
final RecipeChainMath math = createMasterRoot(AutoCraftingManager.math);
|
||||
final List<BookmarkItem> initialItems = prepareInitialItems(math, inventory);
|
||||
boolean processed = false;
|
||||
boolean changed = false;
|
||||
|
||||
do {
|
||||
changed = false;
|
||||
|
||||
RecipeChainIterator iterator = new RecipeChainIterator(math, initialItems);
|
||||
iterator.updateInventory(playerInventory.mainInventory);
|
||||
|
||||
while (iterator.hasNext() && !interrupted(guiContainer)) {
|
||||
final Map<RecipeId, Long> recipes = iterator.next();
|
||||
boolean craft = false;
|
||||
|
||||
for (Map.Entry<RecipeId, Long> entry : recipes.entrySet()) {
|
||||
final RecipeHandlerRef handler = RecipeHandlerRef.of(entry.getKey());
|
||||
|
||||
if (handler != null && handler.canCraft(guiContainer)) {
|
||||
long multiplier = entry.getValue();
|
||||
|
||||
while (multiplier > 0 && !interrupted(guiContainer)
|
||||
&& handler.craft(guiContainer, (int) Math.min(64, multiplier))) {
|
||||
multiplier -= 64;
|
||||
}
|
||||
|
||||
craft = multiplier != entry.getValue();
|
||||
}
|
||||
|
||||
if (interrupted(guiContainer)) break;
|
||||
}
|
||||
|
||||
if (craft) {
|
||||
changed = true;
|
||||
processed = true;
|
||||
iterator.updateInventory(playerInventory.mainInventory);
|
||||
}
|
||||
}
|
||||
|
||||
} while (changed && !interrupted(guiContainer));
|
||||
|
||||
if (processed && !changed && !interrupted(guiContainer)) {
|
||||
NEIClientUtils.playClickSound();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearTasks() {
|
||||
super.clearTasks();
|
||||
AutoCraftingManager.math = null;
|
||||
}
|
||||
|
||||
private boolean interrupted(GuiContainer guiContainer) {
|
||||
return interrupted() || guiContainer != NEIClientUtils.getGuiContainer();
|
||||
}
|
||||
|
||||
private RecipeChainMath createMasterRoot(RecipeChainMath math) {
|
||||
final List<BookmarkItem> rootIngredients = new ArrayList<>();
|
||||
|
||||
for (BookmarkItem item : math.recipeResults) {
|
||||
if (math.outputRecipes.containsKey(item.recipeId)) {
|
||||
long amount = item.factor * math.outputRecipes.get(item.recipeId);
|
||||
rootIngredients.add(
|
||||
BookmarkItem.of(
|
||||
-1,
|
||||
item.getItemStack(amount),
|
||||
item.getStackSize(amount),
|
||||
ROOT_RECIPE_ID,
|
||||
true,
|
||||
BookmarkItem.generatePermutations(item.itemStack, null)));
|
||||
}
|
||||
}
|
||||
|
||||
math.outputRecipes.clear();
|
||||
math.outputRecipes.put(ROOT_RECIPE_ID, 1L);
|
||||
math.recipeResults.add(BookmarkItem.of(-1, ROOT_ITEM, 1, ROOT_RECIPE_ID, false));
|
||||
math.recipeIngredients.addAll(rootIngredients);
|
||||
|
||||
return math;
|
||||
}
|
||||
|
||||
private List<BookmarkItem> prepareInitialItems(RecipeChainMath math, ItemStackAmount inventory) {
|
||||
final List<BookmarkItem> initialItems = new ArrayList<>();
|
||||
|
||||
for (BookmarkItem item : math.initialItems) {
|
||||
final long invStackSize = inventory.getOrDefault(item.itemStack, 0L);
|
||||
final long amount = Math.max(0, item.amount - invStackSize * item.fluidCellAmount);
|
||||
if (amount > 0) {
|
||||
initialItems.add(item.copyWithAmount(amount));
|
||||
}
|
||||
}
|
||||
|
||||
return initialItems;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
private AutoCraftingManager() {}
|
||||
|
||||
public static void runProcessing(RecipeChainMath math) {
|
||||
task.stop();
|
||||
AutoCraftingManager.math = math;
|
||||
|
||||
if (AutoCraftingManager.math != null) {
|
||||
task.restart();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean processing() {
|
||||
return AutoCraftingManager.math != null && !task.interrupted();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import com.google.gson.JsonPrimitive;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.util.NBTJson;
|
||||
|
||||
@Deprecated
|
||||
public class BookmarkRecipeId {
|
||||
|
||||
public String handlerName = null;
|
||||
|
||||
@@ -7,15 +7,20 @@ import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.entity.EntityClientPlayerMP;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.inventory.SlotCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import codechicken.lib.inventory.InventoryUtils;
|
||||
import codechicken.nei.FastTransferManager;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.NEIServerUtils;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.api.IOverlayHandler;
|
||||
import codechicken.nei.util.NBTHelper;
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
|
||||
public class DefaultOverlayHandler implements IOverlayHandler {
|
||||
@@ -70,44 +75,90 @@ public class DefaultOverlayHandler implements IOverlayHandler {
|
||||
public int offsety;
|
||||
|
||||
@Override
|
||||
public void overlayRecipe(GuiContainer gui, IRecipeHandler recipe, int recipeIndex, boolean shift) {
|
||||
List<PositionedStack> ingredients = recipe.getIngredientStacks(recipeIndex);
|
||||
List<DistributedIngred> ingredStacks = getPermutationIngredients(ingredients);
|
||||
public void overlayRecipe(GuiContainer gui, IRecipeHandler handler, int recipeIndex, boolean maxTransfer) {
|
||||
transferRecipe(gui, handler, recipeIndex, maxTransfer ? Integer.MAX_VALUE : 1);
|
||||
}
|
||||
|
||||
if (!clearIngredients(gui, ingredients)) return;
|
||||
@Override
|
||||
public int transferRecipe(GuiContainer gui, IRecipeHandler handler, int recipeIndex, int multiplier) {
|
||||
final List<PositionedStack> ingredients = handler.getIngredientStacks(recipeIndex);
|
||||
final List<DistributedIngred> ingredStacks = getPermutationIngredients(ingredients);
|
||||
|
||||
if (!clearIngredients(gui)) return 0;
|
||||
|
||||
findInventoryQuantities(gui, ingredStacks);
|
||||
|
||||
List<IngredientDistribution> assignedIngredients = assignIngredients(ingredients, ingredStacks);
|
||||
if (assignedIngredients == null) return;
|
||||
final List<IngredientDistribution> assignedIngredients = assignIngredients(ingredients, ingredStacks);
|
||||
if (assignedIngredients == null) return 0;
|
||||
|
||||
assignIngredSlots(gui, ingredients, assignedIngredients);
|
||||
int quantity = calculateRecipeQuantity(assignedIngredients);
|
||||
multiplier = Math.min(multiplier == 0 ? 64 : multiplier, calculateRecipeQuantity(assignedIngredients));
|
||||
|
||||
if (quantity != 0) moveIngredients(gui, assignedIngredients, quantity);
|
||||
if (multiplier != 0) {
|
||||
moveIngredients(gui, assignedIngredients, (int) multiplier);
|
||||
}
|
||||
|
||||
return multiplier;
|
||||
}
|
||||
|
||||
private boolean clearIngredients(GuiContainer gui, List<PositionedStack> ingreds) {
|
||||
for (PositionedStack pstack : ingreds) {
|
||||
for (Slot slot : gui.inventorySlots.inventorySlots) {
|
||||
if (slot.xDisplayPosition == pstack.relx + offsetx && slot.yDisplayPosition == pstack.rely + offsety) {
|
||||
if (!slot.getHasStack()) continue;
|
||||
@Override
|
||||
public boolean canFillCraftingGrid(GuiContainer firstGui, IRecipeHandler handler, int recipeIndex) {
|
||||
return presenceOverlay(firstGui, handler, recipeIndex).stream().allMatch(state -> state.isPresent());
|
||||
}
|
||||
|
||||
FastTransferManager.clickSlot(gui, slot.slotNumber, 0, 1);
|
||||
if (slot.getHasStack()) return false;
|
||||
@Override
|
||||
public boolean canCraft(GuiContainer firstGui, IRecipeHandler handler, int recipeIndex) {
|
||||
return canFillCraftingGrid(firstGui, handler, recipeIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean craft(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex, int multiplier) {
|
||||
final EntityClientPlayerMP thePlayer = NEIClientUtils.mc().thePlayer;
|
||||
boolean craft = false;
|
||||
|
||||
while (multiplier > 0) {
|
||||
final int transfer = transferRecipe(firstGui, recipe, recipeIndex, multiplier);
|
||||
|
||||
if (transfer <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
multiplier -= transfer;
|
||||
|
||||
for (Slot slot : firstGui.inventorySlots.inventorySlots) {
|
||||
if (slot.getHasStack() && slot instanceof SlotCrafting && slot.canTakeStack(thePlayer)) {
|
||||
FastTransferManager.clickSlot(firstGui, slot.slotNumber, 0, 1);
|
||||
craft = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return craft;
|
||||
}
|
||||
|
||||
private boolean clearIngredients(GuiContainer gui) {
|
||||
final EntityClientPlayerMP thePlayer = NEIClientUtils.mc().thePlayer;
|
||||
|
||||
for (Slot slot : gui.inventorySlots.inventorySlots) {
|
||||
if (slot.getHasStack() && !canMoveFrom(slot, gui)
|
||||
&& !(slot instanceof SlotCrafting)
|
||||
&& slot.canTakeStack(thePlayer)) {
|
||||
FastTransferManager.clickSlot(gui, slot.slotNumber, 0, 1);
|
||||
if (slot.getHasStack()) return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void moveIngredients(GuiContainer gui, List<IngredientDistribution> assignedIngredients, int quantity) {
|
||||
private void moveIngredients(GuiContainer gui, List<IngredientDistribution> assignedIngredients, int multiplier) {
|
||||
for (IngredientDistribution distrib : assignedIngredients) {
|
||||
if (distrib.slots.length == 0) continue;
|
||||
|
||||
ItemStack pstack = distrib.permutation;
|
||||
int transferCap = quantity * pstack.stackSize;
|
||||
int transferCap = multiplier * pstack.stackSize;
|
||||
int transferred = 0;
|
||||
|
||||
int destSlotIndex = 0;
|
||||
@@ -119,7 +170,7 @@ public class DefaultOverlayHandler implements IOverlayHandler {
|
||||
if (!slot.getHasStack() || !canMoveFrom(slot, gui)) continue;
|
||||
|
||||
ItemStack stack = slot.getStack();
|
||||
if (!canStack(stack, pstack)) continue;
|
||||
if (!canStack(pstack, stack)) continue;
|
||||
|
||||
int amount = Math.min(transferCap - transferred, stack.stackSize);
|
||||
FastTransferManager.clickSlot(gui, slot.slotNumber);
|
||||
@@ -145,6 +196,7 @@ public class DefaultOverlayHandler implements IOverlayHandler {
|
||||
|
||||
private int calculateRecipeQuantity(List<IngredientDistribution> assignedIngredients) {
|
||||
int quantity = Integer.MAX_VALUE;
|
||||
|
||||
for (IngredientDistribution distrib : assignedIngredients) {
|
||||
DistributedIngred istack = distrib.distrib;
|
||||
if (istack.numSlots == 0) return 0;
|
||||
@@ -160,6 +212,7 @@ public class DefaultOverlayHandler implements IOverlayHandler {
|
||||
}
|
||||
quantity = Math.min(quantity, newQuantity);
|
||||
}
|
||||
|
||||
if (quantity == Integer.MAX_VALUE) {
|
||||
// Only possible if all ingredients were non-stackable
|
||||
quantity = 1;
|
||||
@@ -292,14 +345,14 @@ public class DefaultOverlayHandler implements IOverlayHandler {
|
||||
}
|
||||
|
||||
public DistributedIngred findIngred(List<DistributedIngred> ingredStacks, ItemStack pstack) {
|
||||
for (DistributedIngred istack : ingredStacks) if (canStack(pstack, istack.stack)) return istack;
|
||||
for (DistributedIngred istack : ingredStacks) if (canStack(istack.stack, pstack)) return istack;
|
||||
return null;
|
||||
}
|
||||
|
||||
protected boolean canStack(ItemStack stack1, ItemStack stack2) {
|
||||
if (stack1 == null || stack2 == null) return true;
|
||||
if (stack1.getItem() == stack2.getItem() && stack1.getItemDamage() == stack2.getItemDamage()) {
|
||||
if (ItemStack.areItemStackTagsEqual(stack2, stack1)) return true;
|
||||
if (NEIServerUtils.areStacksSameTypeCrafting(stack2, stack1)) {
|
||||
if (NBTHelper.matchTag(stack1.getTagCompound(), stack2.getTagCompound())) return true;
|
||||
|
||||
// GT Items don't have any NBT set for the recipe, so if either of the stacks has a NULL nbt, and the other
|
||||
// doesn't, pretend they stack
|
||||
|
||||
@@ -6,7 +6,6 @@ import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.IFluidContainerItem;
|
||||
|
||||
import codechicken.nei.ItemPanel.ItemPanelSlot;
|
||||
import codechicken.nei.ItemPanels;
|
||||
import codechicken.nei.api.INEIGuiAdapter;
|
||||
|
||||
@@ -19,18 +18,18 @@ public class FillFluidContainerHandler extends INEIGuiAdapter {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (draggedStack.getItem() instanceof IFluidContainerItem || FluidContainerRegistry.isContainer(draggedStack)) {
|
||||
ItemPanelSlot mouseOverSlot = ItemPanels.itemPanel.getSlotMouseOver(mouseX, mouseY);
|
||||
if (StackInfo.isFluidContainer(draggedStack)) {
|
||||
ItemStack overItemStack = ItemPanels.itemPanel.getStackMouseOver(mouseX, mouseY);
|
||||
|
||||
if (mouseOverSlot == null) {
|
||||
mouseOverSlot = ItemPanels.bookmarkPanel.getSlotMouseOver(mouseX, mouseY);
|
||||
if (overItemStack == null) {
|
||||
overItemStack = ItemPanels.bookmarkPanel.getStackMouseOver(mouseX, mouseY);
|
||||
}
|
||||
|
||||
if (mouseOverSlot != null) {
|
||||
FluidStack fluidStack = StackInfo.getFluid(mouseOverSlot.item);
|
||||
if (overItemStack != null) {
|
||||
final FluidStack fluidStack = StackInfo.getFluid(overItemStack);
|
||||
|
||||
if (fluidStack != null) {
|
||||
ItemStack container = fillContainer(draggedStack, fluidStack);
|
||||
final ItemStack container = fillContainer(draggedStack, fluidStack);
|
||||
|
||||
if (container != null) {
|
||||
container.stackSize = draggedStack.stackSize;
|
||||
@@ -43,7 +42,7 @@ public class FillFluidContainerHandler extends INEIGuiAdapter {
|
||||
}
|
||||
|
||||
if (button == 1 && StackInfo.getFluid(container != null ? container : draggedStack) != null) {
|
||||
ItemPanels.bookmarkPanel.addOrRemoveItem((container != null ? container : draggedStack).copy());
|
||||
ItemPanels.bookmarkPanel.addItem(container != null ? container : draggedStack);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import java.awt.Point;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.UnaryOperator;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -14,11 +13,12 @@ import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import codechicken.lib.gui.GuiDraw;
|
||||
import codechicken.nei.ItemPanel.ItemPanelSlot;
|
||||
import codechicken.nei.FavoriteRecipes;
|
||||
import codechicken.nei.ItemPanels;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.bookmark.BookmarksGridSlot;
|
||||
import codechicken.nei.recipe.Recipe.RecipeId;
|
||||
import codechicken.nei.recipe.stackinfo.GTFluidStackStringifyHandler;
|
||||
|
||||
public class GuiCraftingRecipe extends GuiRecipe<ICraftingHandler> {
|
||||
@@ -33,7 +33,7 @@ public class GuiCraftingRecipe extends GuiRecipe<ICraftingHandler> {
|
||||
|
||||
public static GuiRecipe<?> createRecipeGui(String outputId, boolean open, Object... results) {
|
||||
final Minecraft mc = NEIClientUtils.mc();
|
||||
final BookmarkRecipeId recipeId;
|
||||
final RecipeId recipeId;
|
||||
|
||||
if ("item".equals(outputId)) {
|
||||
for (int i = 0; i < results.length; i++) {
|
||||
@@ -41,7 +41,7 @@ public class GuiCraftingRecipe extends GuiRecipe<ICraftingHandler> {
|
||||
}
|
||||
recipeId = getRecipeId(mc.currentScreen, (ItemStack) results[0]);
|
||||
} else if ("recipeId".equals(outputId)) {
|
||||
recipeId = (BookmarkRecipeId) results[1];
|
||||
recipeId = (RecipeId) results[1];
|
||||
} else {
|
||||
recipeId = getCurrentRecipeId(mc.currentScreen);
|
||||
}
|
||||
@@ -62,28 +62,6 @@ public class GuiCraftingRecipe extends GuiRecipe<ICraftingHandler> {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean overlayRecipe(ItemStack stack, BookmarkRecipeId recipeId, final Boolean shift) {
|
||||
|
||||
if (stack == null || recipeId == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final ArrayList<ICraftingHandler> handlers = getCraftingHandlers("recipeId", stack, recipeId);
|
||||
|
||||
if (!handlers.isEmpty()) {
|
||||
final GuiCraftingRecipe gui = new GuiCraftingRecipe(handlers, true);
|
||||
final int recipe = gui.openTargetRecipe(recipeId);
|
||||
|
||||
if (recipe != -1) {
|
||||
gui.overlayRecipe(recipe, shift);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ArrayList<ICraftingHandler> getCraftingHandlers(String outputId, Object... results) {
|
||||
ArrayList<ICraftingHandler> craftinghandlers = GuiCraftingRecipe.craftinghandlers;
|
||||
ArrayList<ICraftingHandler> serialCraftingHandlers = GuiCraftingRecipe.serialCraftingHandlers;
|
||||
@@ -91,9 +69,9 @@ public class GuiCraftingRecipe extends GuiRecipe<ICraftingHandler> {
|
||||
|
||||
if ("recipeId".equals(outputId)) {
|
||||
ItemStack stack = (ItemStack) results[0];
|
||||
BookmarkRecipeId recipeId = (BookmarkRecipeId) results[1];
|
||||
craftinghandlers = filterByHandlerName(craftinghandlers, recipeId.handlerName);
|
||||
serialCraftingHandlers = filterByHandlerName(serialCraftingHandlers, recipeId.handlerName);
|
||||
RecipeId recipeId = (RecipeId) results[1];
|
||||
craftinghandlers = filterByHandlerName(craftinghandlers, recipeId.getHandleName());
|
||||
serialCraftingHandlers = filterByHandlerName(serialCraftingHandlers, recipeId.getHandleName());
|
||||
recipeHandlerFunction = h -> h.getRecipeHandler("item", stack);
|
||||
} else {
|
||||
recipeHandlerFunction = h -> h.getRecipeHandler(outputId, results);
|
||||
@@ -127,25 +105,29 @@ public class GuiCraftingRecipe extends GuiRecipe<ICraftingHandler> {
|
||||
return stack;
|
||||
}
|
||||
|
||||
protected static BookmarkRecipeId getRecipeId(GuiScreen gui, ItemStack stackover) {
|
||||
public static RecipeId getRecipeId(GuiScreen gui, ItemStack stackover) {
|
||||
|
||||
if (gui instanceof GuiRecipe) {
|
||||
final List<PositionedStack> ingredients = ((GuiRecipe<?>) gui).getFocusedRecipeIngredients();
|
||||
final String handlerName = ((GuiRecipe<?>) gui).getHandlerName();
|
||||
if (gui instanceof GuiRecipe guiRecipe) {
|
||||
final Recipe focusedRecipe = guiRecipe.getFocusedRecipe();
|
||||
|
||||
if (ingredients != null && !ingredients.isEmpty()) {
|
||||
return new BookmarkRecipeId(handlerName, ingredients);
|
||||
if (focusedRecipe != null) {
|
||||
return focusedRecipe.getRecipeId();
|
||||
}
|
||||
}
|
||||
|
||||
final Point mouseover = GuiDraw.getMousePosition();
|
||||
ItemPanelSlot panelSlot = ItemPanels.bookmarkPanel.getSlotMouseOver(mouseover.x, mouseover.y);
|
||||
final BookmarksGridSlot panelSlot = ItemPanels.bookmarkPanel.getSlotMouseOver(mouseover.x, mouseover.y);
|
||||
RecipeId recipeId = null;
|
||||
|
||||
if (panelSlot != null) {
|
||||
return ItemPanels.bookmarkPanel.getBookmarkRecipeId(panelSlot.slotIndex);
|
||||
if (panelSlot != null && !panelSlot.isIngredient()) {
|
||||
recipeId = panelSlot.getRecipeId();
|
||||
}
|
||||
|
||||
return ItemPanels.bookmarkPanel.getBookmarkRecipeId(stackover);
|
||||
if (recipeId == null) {
|
||||
recipeId = FavoriteRecipes.getFavorite(stackover);
|
||||
}
|
||||
|
||||
return recipeId;
|
||||
}
|
||||
|
||||
private GuiCraftingRecipe(ArrayList<ICraftingHandler> handlers, boolean limitToOneRecipe) {
|
||||
|
||||
@@ -0,0 +1,249 @@
|
||||
package codechicken.nei.recipe;
|
||||
|
||||
import static codechicken.nei.NEIClientUtils.translate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import codechicken.lib.gui.GuiDraw;
|
||||
import codechicken.nei.BookmarkPanel.BookmarkViewMode;
|
||||
import codechicken.nei.FavoriteRecipes;
|
||||
import codechicken.nei.Image;
|
||||
import codechicken.nei.ItemPanels;
|
||||
import codechicken.nei.ItemStackSet;
|
||||
import codechicken.nei.LayoutManager;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.drawable.DrawableBuilder;
|
||||
import codechicken.nei.drawable.DrawableResource;
|
||||
import codechicken.nei.recipe.Recipe.RecipeId;
|
||||
import codechicken.nei.recipe.Recipe.RecipeIngredient;
|
||||
import codechicken.nei.util.NEIMouseUtils;
|
||||
|
||||
public class GuiFavoriteButton extends GuiRecipeButton {
|
||||
|
||||
private static final int BUTTON_ID_START = 14;
|
||||
|
||||
protected static final DrawableResource ICON_STATE_OFF = new DrawableBuilder(
|
||||
"nei:textures/nei_sprites.png",
|
||||
10,
|
||||
76,
|
||||
9,
|
||||
10).build();
|
||||
protected static final DrawableResource ICON_STATE_ON = new DrawableBuilder(
|
||||
"nei:textures/nei_sprites.png",
|
||||
19,
|
||||
76,
|
||||
9,
|
||||
10).build();
|
||||
|
||||
protected final Recipe recipe;
|
||||
protected boolean favorite = false;
|
||||
protected RecipeIngredient favoriteResult = null;
|
||||
protected RecipeIngredient selectedResult = null;
|
||||
|
||||
public GuiFavoriteButton(RecipeHandlerRef handlerRef, int x, int y) {
|
||||
super(handlerRef, x, y, BUTTON_ID_START + handlerRef.recipeIndex, "❤");
|
||||
this.recipe = Recipe.of(this.handlerRef);
|
||||
|
||||
ItemStack stack = FavoriteRecipes.getFavorite(this.recipe.getRecipeId());
|
||||
this.favorite = stack != null;
|
||||
|
||||
if (stack == null) {
|
||||
stack = this.recipe.getResult();
|
||||
}
|
||||
|
||||
for (RecipeIngredient result : this.recipe.getResults()) {
|
||||
if (StackInfo.equalItemAndNBT(result.getItemStack(), stack, true)) {
|
||||
this.favoriteResult = result;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this.visible = this.favoriteResult != null;
|
||||
}
|
||||
|
||||
public boolean isFavorite() {
|
||||
return favorite;
|
||||
}
|
||||
|
||||
public void toggleFavorite() {
|
||||
this.favorite = !this.favorite;
|
||||
|
||||
if (this.selectedResult != null) {
|
||||
this.favoriteResult = this.selectedResult;
|
||||
}
|
||||
|
||||
FavoriteRecipes
|
||||
.setFavorite(this.favoriteResult.getItemStack(), this.favorite ? 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;
|
||||
final int iconX = this.xPosition + (this.width - icon.width - 1) / 2;
|
||||
final int iconY = this.yPosition + (this.height - icon.height) / 2;
|
||||
|
||||
GL11.glColor4f(1, 1, 1, this.enabled ? 1 : 0.5f);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
icon.draw(iconX, iconY);
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
|
||||
if (!mouseOver) {
|
||||
this.selectedResult = null;
|
||||
} else if (this.selectedResult == null) {
|
||||
this.selectedResult = this.favoriteResult;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(int mouseX, int mouseY) {
|
||||
toggleFavorite();
|
||||
}
|
||||
|
||||
public Recipe getRecipe() {
|
||||
return Recipe.of(this.handlerRef);
|
||||
}
|
||||
|
||||
public void lastKeyTyped(GuiRecipe<?> gui, char keyChar, int keyID) {
|
||||
|
||||
if (NEIClientConfig.isKeyHashDown("gui.bookmark") && NEIClientUtils.shiftKey()) {
|
||||
ItemPanels.bookmarkPanel.addGroup(getRecipesTree(getRecipe()), BookmarkViewMode.TODO_LIST, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> handleHotkeys(GuiContainer gui, int mousex, int mousey, Map<String, String> hotkeys) {
|
||||
hotkeys.put(
|
||||
NEIClientConfig.getKeyName("gui.bookmark", NEIClientUtils.SHIFT_HASH),
|
||||
translate("recipe.favorite.bookmark_recipe"));
|
||||
|
||||
if (this.recipe.getResults().size() > 1) {
|
||||
hotkeys.put(
|
||||
NEIMouseUtils.getKeyName(NEIMouseUtils.MOUSE_BTN_NONE + NEIMouseUtils.MOUSE_SCROLL),
|
||||
translate("recipe.favorite.change_result_index"));
|
||||
}
|
||||
|
||||
return hotkeys;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> handleTooltip(GuiRecipe<?> gui, List<String> currenttip) {
|
||||
currenttip.add(translate("recipe.favorite"));
|
||||
|
||||
return currenttip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawItemOverlay() {
|
||||
if (this.selectedResult == null) return;
|
||||
|
||||
NEIClientUtils.gl2DRenderContext(
|
||||
() -> GuiDraw.drawRect(this.selectedResult.relx, this.selectedResult.rely, 16, 16, 0x66333333));
|
||||
|
||||
final Image icon = isFavorite() ? ICON_STATE_ON : ICON_STATE_OFF;
|
||||
final int iconX = this.selectedResult.relx + (16 - icon.width) / 2;
|
||||
final int iconY = this.selectedResult.rely + (18 - icon.height) / 2;
|
||||
|
||||
LayoutManager.drawIcon(iconX, iconY, icon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseScrolled(GuiRecipe<?> gui, int scroll) {
|
||||
if (this.selectedResult == null) return true;
|
||||
|
||||
final List<RecipeIngredient> results = new ArrayList<>(this.recipe.getResults());
|
||||
if (results.size() <= 1) return true;
|
||||
|
||||
final Set<String> uniqueResults = new HashSet<>();
|
||||
results.removeIf(ingr -> !uniqueResults.add(StackInfo.getItemStackGUID(ingr.getItemStack())));
|
||||
final int nextIndex = (results.size() - scroll + results.indexOf(this.selectedResult)) % results.size();
|
||||
|
||||
this.selectedResult = results.get(nextIndex);
|
||||
this.favorite = StackInfo.equalItemAndNBT(
|
||||
results.get(nextIndex).getItemStack(),
|
||||
FavoriteRecipes.getFavorite(this.recipe.getRecipeId()),
|
||||
true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private List<Recipe> getRecipesTree(Recipe mainRecipe) {
|
||||
int depth = NEIClientConfig.getIntSetting("inventory.favorites.depth");
|
||||
final ItemStackSet items = new ItemStackSet();
|
||||
final List<Recipe> result = new ArrayList<>();
|
||||
List<Recipe> loop = new ArrayList<>();
|
||||
loop.add(mainRecipe);
|
||||
result.add(mainRecipe);
|
||||
|
||||
while (!loop.isEmpty() && depth-- >= 0) {
|
||||
List<Recipe> localLoop = new ArrayList<>();
|
||||
|
||||
for (Recipe localRecipe : loop) {
|
||||
for (RecipeIngredient ingr : localRecipe.getIngredients()) {
|
||||
List<ItemStack> permutations = ingr.getPermutations();
|
||||
ItemStack stack = permutations.stream().filter(items::contains).findFirst().orElse(null);
|
||||
|
||||
if (stack == null) {
|
||||
stack = ingr.getItemStack();
|
||||
RecipeId recipeId = FavoriteRecipes.getFavorite(stack);
|
||||
|
||||
if (recipeId == null) {
|
||||
for (ItemStack permStack : permutations) {
|
||||
if ((recipeId = FavoriteRecipes.getFavorite(permStack)) != null) {
|
||||
stack = permStack;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Recipe recipe = Recipe.of(recipeId);
|
||||
|
||||
if (recipe == null) {
|
||||
stack = null;
|
||||
} else {
|
||||
items.add(stack);
|
||||
|
||||
if (depth >= 0) {
|
||||
result.add(recipe);
|
||||
localLoop.add(recipe);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (stack != null) {
|
||||
ingr.setActiveIndex(getIngrActiveIndex(permutations, stack));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
loop = localLoop;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private int getIngrActiveIndex(List<ItemStack> permutations, ItemStack stack) {
|
||||
|
||||
for (int i = 0; i < permutations.size(); i++) {
|
||||
if (StackInfo.equalItemAndNBT(stack, permutations.get(i), true)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,66 +1,31 @@
|
||||
package codechicken.nei.recipe;
|
||||
|
||||
import static codechicken.nei.NEIClientUtils.translate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraftforge.client.event.GuiScreenEvent;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import codechicken.lib.gui.GuiDraw;
|
||||
import codechicken.lib.vec.Rectangle4i;
|
||||
import codechicken.nei.BookmarkPanel.BookmarkRecipe;
|
||||
import codechicken.nei.GuiNEIButton;
|
||||
import codechicken.nei.ItemPanels;
|
||||
import codechicken.nei.ItemsTooltipLineHandler;
|
||||
import codechicken.nei.LayoutManager;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.api.IOverlayHandler;
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import codechicken.nei.bookmark.BookmarkGrid;
|
||||
import codechicken.nei.drawable.DrawableBuilder;
|
||||
import codechicken.nei.drawable.DrawableResource;
|
||||
import codechicken.nei.util.NEIMouseUtils;
|
||||
|
||||
public class GuiOverlayButton extends GuiNEIButton {
|
||||
|
||||
public static class UpdateOverlayButtonsEvent extends GuiScreenEvent {
|
||||
|
||||
public List<GuiOverlayButton> buttonList;
|
||||
|
||||
public UpdateOverlayButtonsEvent(GuiRecipe<?> gui, List<GuiOverlayButton> buttonList) {
|
||||
super(gui);
|
||||
this.buttonList = new ArrayList<>(buttonList);
|
||||
}
|
||||
|
||||
@Cancelable
|
||||
public static class Pre extends UpdateOverlayButtonsEvent {
|
||||
|
||||
public int xOffset;
|
||||
public int yOffset;
|
||||
public int height;
|
||||
public HandlerInfo handlerInfo;
|
||||
|
||||
public Pre(GuiRecipe<?> gui, int xOffset, int yOffset, int height, HandlerInfo handlerInfo) {
|
||||
super(gui, new ArrayList<>());
|
||||
this.xOffset = xOffset;
|
||||
this.yOffset = yOffset;
|
||||
this.height = height;
|
||||
this.handlerInfo = handlerInfo;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Post extends UpdateOverlayButtonsEvent {
|
||||
|
||||
public Post(GuiRecipe<?> gui, List<GuiOverlayButton> buttonList) {
|
||||
super(gui, buttonList);
|
||||
}
|
||||
}
|
||||
}
|
||||
public class GuiOverlayButton extends GuiRecipeButton {
|
||||
|
||||
public enum ItemOverlayFormat {
|
||||
|
||||
@@ -99,44 +64,59 @@ public class GuiOverlayButton extends GuiNEIButton {
|
||||
}
|
||||
}
|
||||
|
||||
private static final int OVERLAY_BUTTON_ID_START = 4;
|
||||
protected static final DrawableResource ICON_FILL = new DrawableBuilder(
|
||||
"nei:textures/nei_sprites.png",
|
||||
28,
|
||||
76,
|
||||
9,
|
||||
10).build();
|
||||
protected static final DrawableResource ICON_FILL_ERROR = new DrawableBuilder(
|
||||
"nei:textures/nei_sprites.png",
|
||||
37,
|
||||
76,
|
||||
9,
|
||||
10).build();
|
||||
protected static final DrawableResource ICON_OVERLAY = new DrawableBuilder(
|
||||
"nei:textures/nei_sprites.png",
|
||||
46,
|
||||
76,
|
||||
9,
|
||||
10).build();
|
||||
protected static final int BUTTON_ID_SHIFT = 4;
|
||||
|
||||
public final GuiContainer firstGui;
|
||||
public final IRecipeHandler handler;
|
||||
public final int recipeIndex;
|
||||
|
||||
protected ItemsTooltipLineHandler missedMaterialsTooltipLineHandler;
|
||||
|
||||
protected final IOverlayHandler overlayHandler;
|
||||
protected final List<ItemOverlayState> itemPresenceCache = new ArrayList<>();
|
||||
protected ItemsTooltipLineHandler missedMaterialsTooltipLineHandler;
|
||||
protected boolean requireShiftForOverlayRecipe = true;
|
||||
protected boolean useOverlayRenderer = false;
|
||||
protected boolean canUseOverlayRenderer = false;
|
||||
protected boolean canFillCraftingGrid = false;
|
||||
protected boolean hasOverlay = false;
|
||||
|
||||
public GuiOverlayButton(GuiContainer firstGui, IRecipeHandler handler, int recipeIndex, int x, int y, int width,
|
||||
int height) {
|
||||
super(OVERLAY_BUTTON_ID_START + recipeIndex, x, y, width, height, "+");
|
||||
public GuiOverlayButton(GuiContainer firstGui, RecipeHandlerRef handlerRef, int x, int y) {
|
||||
super(handlerRef, x, y, handlerRef.recipeIndex + BUTTON_ID_SHIFT, "+");
|
||||
this.firstGui = firstGui != null && firstGui.inventorySlots != null ? firstGui : null;
|
||||
this.handler = handler;
|
||||
this.recipeIndex = recipeIndex;
|
||||
this.hasOverlay = this.firstGui != null
|
||||
&& handler.hasOverlay(this.firstGui, this.firstGui.inventorySlots, recipeIndex);
|
||||
this.useOverlayRenderer = this.hasOverlay && handler.getOverlayRenderer(firstGui, recipeIndex) != null;
|
||||
this.overlayHandler = this.hasOverlay ? handler.getOverlayHandler(firstGui, recipeIndex) : null;
|
||||
|
||||
this.canUseOverlayRenderer = this.firstGui != null && handlerRef.getRecipeOverlayRenderer(firstGui) != null;
|
||||
this.canFillCraftingGrid = this.firstGui != null && handlerRef.getOverlayHandler(firstGui) != null;
|
||||
this.hasOverlay = this.canUseOverlayRenderer || this.canFillCraftingGrid;
|
||||
|
||||
setRequireShiftForOverlayRecipe(NEIClientConfig.requireShiftForOverlayRecipe());
|
||||
ingredientsOverlay();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> handleTooltip(GuiRecipe<?> gui, List<String> currenttip) {
|
||||
currenttip.add(translate("recipe.overlay"));
|
||||
currenttip.add(NEIClientUtils.translate("recipe.overlay"));
|
||||
|
||||
if (!this.enabled && this.requireShiftForOverlayRecipe && this.overlayHandler == null) {
|
||||
if (!this.enabled && this.requireShiftForOverlayRecipe && this.canFillCraftingGrid) {
|
||||
currenttip.set(currenttip.size() - 1, currenttip.get(currenttip.size() - 1) + GuiDraw.TOOLTIP_LINESPACE);
|
||||
currenttip.add(EnumChatFormatting.RED + translate("recipe.overlay.mismatch") + EnumChatFormatting.RESET);
|
||||
currenttip.add(
|
||||
EnumChatFormatting.RED + NEIClientUtils.translate("recipe.overlay.mismatch")
|
||||
+ EnumChatFormatting.RESET);
|
||||
} else if (this.missedMaterialsTooltipLineHandler != null) {
|
||||
|
||||
if ((!this.requireShiftForOverlayRecipe || NEIClientUtils.shiftKey()) && this.overlayHandler != null) {
|
||||
if ((!this.requireShiftForOverlayRecipe || NEIClientUtils.shiftKey()) && this.canFillCraftingGrid) {
|
||||
this.missedMaterialsTooltipLineHandler.setLabelColor(EnumChatFormatting.RED);
|
||||
} else {
|
||||
this.missedMaterialsTooltipLineHandler.setLabelColor(EnumChatFormatting.GRAY);
|
||||
@@ -148,31 +128,32 @@ public class GuiOverlayButton extends GuiNEIButton {
|
||||
return currenttip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> handleHotkeys(GuiContainer gui, int mousex, int mousey, Map<String, String> hotkeys) {
|
||||
|
||||
if (this.requireShiftForOverlayRecipe && this.useOverlayRenderer) {
|
||||
hotkeys.put(translate("recipe.overlay.fillCraftingGrid.key"), translate("recipe.overlay.fillCraftingGrid"));
|
||||
if (requireShiftForOverlayRecipe()) {
|
||||
|
||||
if (useOverlayRenderer()) {
|
||||
hotkeys.put(
|
||||
NEIMouseUtils.getKeyName(NEIMouseUtils.MOUSE_BTN_LMB),
|
||||
NEIClientUtils.translate("recipe.overlay.overlayRecipe"));
|
||||
}
|
||||
|
||||
if (canFillCraftingGrid()) {
|
||||
hotkeys.put(
|
||||
NEIClientUtils.getKeyName(NEIClientUtils.SHIFT_HASH, NEIMouseUtils.MOUSE_BTN_LMB),
|
||||
NEIClientUtils.translate("recipe.overlay.fillCraftingGrid"));
|
||||
}
|
||||
|
||||
} else if (canFillCraftingGrid()) {
|
||||
hotkeys.put(
|
||||
NEIMouseUtils.getKeyName(NEIMouseUtils.MOUSE_BTN_LMB),
|
||||
NEIClientUtils.translate("recipe.overlay.fillCraftingGrid"));
|
||||
}
|
||||
|
||||
String keyName = NEIClientConfig.getKeyName("gui.bookmark");
|
||||
if (keyName != null) {
|
||||
hotkeys.put(keyName, translate("recipe.overlay.bookmark"));
|
||||
}
|
||||
|
||||
keyName = NEIClientConfig.getKeyName("gui.bookmark_recipe");
|
||||
if (keyName != null) {
|
||||
hotkeys.put(keyName, translate("recipe.overlay.bookmarkRecipe"));
|
||||
}
|
||||
|
||||
keyName = NEIClientConfig.getKeyName("gui.bookmark_count");
|
||||
if (keyName != null) {
|
||||
hotkeys.put(keyName, translate("recipe.overlay.bookmarkAmount"));
|
||||
}
|
||||
|
||||
keyName = NEIClientConfig.getKeyName("gui.bookmark_recipe_count");
|
||||
if (keyName != null) {
|
||||
hotkeys.put(keyName, translate("recipe.overlay.bookmarkRecipeAndAmount"));
|
||||
}
|
||||
hotkeys.put(
|
||||
NEIClientConfig.getKeyName("gui.bookmark", NEIClientUtils.SHIFT_HASH),
|
||||
NEIClientUtils.translate("recipe.overlay.bookmarkRecipe"));
|
||||
|
||||
return hotkeys;
|
||||
}
|
||||
@@ -185,37 +166,59 @@ public class GuiOverlayButton extends GuiNEIButton {
|
||||
}
|
||||
}
|
||||
|
||||
public void drawItemPresenceOverlay() {
|
||||
final int presenceOverlay = NEIClientConfig.itemPresenceOverlay();
|
||||
final boolean highlightPresentItem = NEIClientConfig.isSlotHighlightPresent();
|
||||
final ItemOverlayFormat format = ItemOverlayFormat.from(presenceOverlay);
|
||||
@Override
|
||||
protected void drawContent(Minecraft minecraft, int y, int x, boolean mouseOver) {
|
||||
DrawableResource icon = ICON_OVERLAY;
|
||||
|
||||
for (ItemOverlayState overlay : ingredientsOverlay()) {
|
||||
if (highlightPresentItem || !overlay.isPresent()) {
|
||||
overlay.draw(format);
|
||||
if (this.hasOverlay && (!this.requireShiftForOverlayRecipe || NEIClientUtils.shiftKey())) {
|
||||
icon = canFillCraftingGrid() ? ICON_FILL : ICON_FILL_ERROR;
|
||||
}
|
||||
|
||||
final int iconX = this.xPosition + (this.width - icon.width - 1) / 2;
|
||||
final int iconY = this.yPosition + (this.height - icon.height) / 2;
|
||||
|
||||
GL11.glColor4f(1, 1, 1, this.enabled ? 1 : 0.5f);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
icon.draw(iconX, iconY);
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawItemOverlay() {
|
||||
final int presenceOverlay = NEIClientConfig.itemPresenceOverlay();
|
||||
|
||||
if (presenceOverlay > 0) {
|
||||
final boolean highlightPresentItem = NEIClientConfig.isSlotHighlightPresent();
|
||||
final ItemOverlayFormat format = ItemOverlayFormat.from(presenceOverlay);
|
||||
|
||||
for (ItemOverlayState overlay : ingredientsOverlay()) {
|
||||
if (highlightPresentItem || !overlay.isPresent()) {
|
||||
overlay.draw(format);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected List<ItemOverlayState> ingredientsOverlay() {
|
||||
List<PositionedStack> ingredients = this.handler.getIngredientStacks(recipeIndex);
|
||||
List<PositionedStack> ingredients = this.handlerRef.handler.getIngredientStacks(this.handlerRef.recipeIndex);
|
||||
|
||||
if (this.itemPresenceCache.size() != ingredients.size()) {
|
||||
this.itemPresenceCache.clear();
|
||||
|
||||
if (this.overlayHandler != null) {
|
||||
this.itemPresenceCache
|
||||
.addAll(this.overlayHandler.presenceOverlay(this.firstGui, this.handler, this.recipeIndex));
|
||||
if (this.canFillCraftingGrid) {
|
||||
this.itemPresenceCache.addAll(this.handlerRef.getPresenceOverlay(this.firstGui));
|
||||
} else if (this.firstGui != null) {
|
||||
this.itemPresenceCache.addAll(presenceOverlay(ingredients));
|
||||
}
|
||||
|
||||
List<ItemStack> items = this.itemPresenceCache.stream().filter(state -> !state.isPresent())
|
||||
.map(state -> state.getSlot().item).collect(Collectors.toCollection(ArrayList::new));
|
||||
.map(state -> state.getSlot().item).collect(Collectors.toList());
|
||||
|
||||
if (!items.isEmpty()) {
|
||||
this.missedMaterialsTooltipLineHandler = new ItemsTooltipLineHandler(
|
||||
translate("recipe.overlay.missing"),
|
||||
NEIClientUtils.translate("recipe.overlay.missing"),
|
||||
items,
|
||||
true,
|
||||
Integer.MAX_VALUE);
|
||||
@@ -229,25 +232,33 @@ public class GuiOverlayButton extends GuiNEIButton {
|
||||
|
||||
public void setRequireShiftForOverlayRecipe(boolean require) {
|
||||
this.requireShiftForOverlayRecipe = require;
|
||||
this.enabled = this.hasOverlay && (this.requireShiftForOverlayRecipe || this.overlayHandler != null);
|
||||
this.enabled = this.hasOverlay && (this.requireShiftForOverlayRecipe || this.canFillCraftingGrid);
|
||||
}
|
||||
|
||||
public void setUseOverlayRenderer(boolean use) {
|
||||
this.useOverlayRenderer = use;
|
||||
public void setCanUseOverlayRenderer(boolean use) {
|
||||
this.canUseOverlayRenderer = use;
|
||||
}
|
||||
|
||||
public boolean useOverlayRenderer() {
|
||||
return this.useOverlayRenderer;
|
||||
return this.canUseOverlayRenderer;
|
||||
}
|
||||
|
||||
public boolean requireShiftForOverlayRecipe() {
|
||||
return this.requireShiftForOverlayRecipe;
|
||||
}
|
||||
|
||||
public boolean canFillCraftingGrid() {
|
||||
return this.missedMaterialsTooltipLineHandler == null;
|
||||
return this.missedMaterialsTooltipLineHandler == null || this.handlerRef.canFillCraftingGrid(this.firstGui);
|
||||
}
|
||||
|
||||
public boolean hasOverlay() {
|
||||
return this.hasOverlay;
|
||||
}
|
||||
|
||||
public Recipe getRecipe() {
|
||||
return Recipe.of(this.handlerRef);
|
||||
}
|
||||
|
||||
private List<ItemOverlayState> presenceOverlay(List<PositionedStack> ingredients) {
|
||||
final List<ItemOverlayState> itemPresenceSlots = new ArrayList<>();
|
||||
final List<ItemStack> invStacks = this.firstGui.inventorySlots.inventorySlots.stream()
|
||||
@@ -276,82 +287,30 @@ public class GuiOverlayButton extends GuiNEIButton {
|
||||
public void overlayRecipe(boolean shift) {
|
||||
if (!this.hasOverlay) return;
|
||||
|
||||
if (!this.useOverlayRenderer || !this.requireShiftForOverlayRecipe || shift) {
|
||||
if (this.overlayHandler != null) {
|
||||
this.overlayHandler.overlayRecipe(
|
||||
this.firstGui,
|
||||
this.handler,
|
||||
this.recipeIndex,
|
||||
!this.requireShiftForOverlayRecipe || shift);
|
||||
if (!this.requireShiftForOverlayRecipe || shift) {
|
||||
if (canFillCraftingGrid()) {
|
||||
this.handlerRef.fillCraftingGrid(this.firstGui, 0);
|
||||
}
|
||||
} else {
|
||||
LayoutManager.overlayRenderer = this.handler.getOverlayRenderer(this.firstGui, this.recipeIndex);
|
||||
} else if (useOverlayRenderer()) {
|
||||
this.handlerRef.useOverlayRenderer(this.firstGui);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lastKeyTyped(GuiRecipe<?> gui, char keyChar, int keyID) {
|
||||
|
||||
if (NEIClientConfig.isKeyHashDown("gui.bookmark")) {
|
||||
saveRecipeInBookmark(false, false);
|
||||
} else if (NEIClientConfig.isKeyHashDown("gui.bookmark_recipe")) {
|
||||
saveRecipeInBookmark(true, false);
|
||||
} else if (NEIClientConfig.isKeyHashDown("gui.bookmark_count")) {
|
||||
saveRecipeInBookmark(false, true);
|
||||
} else if (NEIClientConfig.isKeyHashDown("gui.bookmark_recipe_count")) {
|
||||
saveRecipeInBookmark(true, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void saveRecipeInBookmark(boolean saveIngredients, boolean saveStackSize) {
|
||||
final HandlerInfo handlerInfo = GuiRecipeTab.getHandlerInfo(this.handler);
|
||||
final List<PositionedStack> ingredients = this.handler.getIngredientStacks(this.recipeIndex);
|
||||
final BookmarkRecipeId recipeId = new BookmarkRecipeId(handlerInfo.getHandlerName(), ingredients);
|
||||
|
||||
if (!ItemPanels.bookmarkPanel.removeBookmarkRecipeId(recipeId)) {
|
||||
BookmarkRecipe recipe = new BookmarkRecipe();
|
||||
recipe.handlerName = recipeId.handlerName;
|
||||
recipe.recipeId = recipeId;
|
||||
|
||||
if (saveIngredients) {
|
||||
for (PositionedStack stack : ingredients) {
|
||||
recipe.ingredients.add(stack.item);
|
||||
}
|
||||
}
|
||||
|
||||
PositionedStack result = this.handler.getResultStack(this.recipeIndex);
|
||||
|
||||
if (result != null) {
|
||||
recipe.result.add(result.item);
|
||||
} else {
|
||||
for (PositionedStack stack : this.handler.getOtherStacks(this.recipeIndex)) {
|
||||
recipe.result.add(stack.item);
|
||||
}
|
||||
}
|
||||
|
||||
ItemPanels.bookmarkPanel.addRecipe(recipe, saveStackSize);
|
||||
if (NEIClientConfig.isKeyHashDown("gui.bookmark") && NEIClientUtils.shiftKey()) {
|
||||
saveRecipeInBookmark();
|
||||
}
|
||||
}
|
||||
|
||||
public int getResultStackSize(ItemStack stackover) {
|
||||
final List<PositionedStack> stacks = this.handler.getOtherStacks(this.recipeIndex);
|
||||
int stackSize = stackover.stackSize;
|
||||
public void saveRecipeInBookmark() {
|
||||
final Recipe recipe = getRecipe();
|
||||
|
||||
for (PositionedStack pStack : stacks) {
|
||||
if (StackInfo.equalItemAndNBT(pStack.item, stackover, true)) {
|
||||
stackSize += pStack.item.stackSize;
|
||||
}
|
||||
if (!ItemPanels.bookmarkPanel.removeRecipe(recipe.getRecipeId(), BookmarkGrid.DEFAULT_GROUP_ID)) {
|
||||
ItemPanels.bookmarkPanel.addRecipe(recipe, BookmarkGrid.DEFAULT_GROUP_ID);
|
||||
}
|
||||
|
||||
return stackSize;
|
||||
}
|
||||
|
||||
public Rectangle4i bounds() {
|
||||
return new Rectangle4i(this.xPosition, this.yPosition, this.width, this.height);
|
||||
}
|
||||
|
||||
public boolean contains(int mx, int my) {
|
||||
return bounds().contains(mx, my);
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,6 @@ import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
@@ -28,8 +27,6 @@ import org.lwjgl.opengl.GL11;
|
||||
import codechicken.lib.gui.GuiDraw;
|
||||
import codechicken.nei.Button;
|
||||
import codechicken.nei.GuiNEIButton;
|
||||
import codechicken.nei.ItemsTooltipLineHandler;
|
||||
import codechicken.nei.LayoutManager;
|
||||
import codechicken.nei.NEICPH;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
@@ -40,10 +37,8 @@ import codechicken.nei.SearchField;
|
||||
import codechicken.nei.VisiblityData;
|
||||
import codechicken.nei.api.IGuiContainerOverlay;
|
||||
import codechicken.nei.api.INEIGuiHandler;
|
||||
import codechicken.nei.api.IOverlayHandler;
|
||||
import codechicken.nei.api.IRecipeFilter;
|
||||
import codechicken.nei.api.IRecipeFilter.IRecipeFilterProvider;
|
||||
import codechicken.nei.api.IRecipeOverlayRenderer;
|
||||
import codechicken.nei.api.ItemFilter;
|
||||
import codechicken.nei.api.TaggedInventoryArea;
|
||||
import codechicken.nei.drawable.DrawableBuilder;
|
||||
@@ -52,7 +47,9 @@ import codechicken.nei.guihook.GuiContainerManager;
|
||||
import codechicken.nei.guihook.IContainerTooltipHandler;
|
||||
import codechicken.nei.guihook.IGuiClientSide;
|
||||
import codechicken.nei.guihook.IGuiHandleMouseWheel;
|
||||
import codechicken.nei.recipe.GuiOverlayButton.UpdateOverlayButtonsEvent;
|
||||
import codechicken.nei.recipe.GuiRecipeButton.UpdateRecipeButtonsEvent;
|
||||
import codechicken.nei.recipe.Recipe.RecipeId;
|
||||
import codechicken.nei.util.NEIMouseUtils;
|
||||
|
||||
public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer implements IGuiContainerOverlay,
|
||||
IGuiClientSide, IGuiHandleMouseWheel, IContainerTooltipHandler, INEIGuiHandler {
|
||||
@@ -67,14 +64,14 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
private static final int BG_BOTTOM_Y = BG_MIDDLE_Y + BG_MIDDLE_HEIGHT;
|
||||
|
||||
// Button sizes
|
||||
private static final int borderPadding = 6;
|
||||
private static final int buttonWidth = 13;
|
||||
private static final int buttonHeight = 12;
|
||||
private static final int BORDER_PADDING = 6;
|
||||
private static final int BUTTON_WIDTH = 13;
|
||||
private static final int BUTTON_HEIGHT = 12;
|
||||
|
||||
public static final List<IRecipeFilterProvider> recipeFilterers = new LinkedList<>();
|
||||
|
||||
protected boolean limitToOneRecipe = false;
|
||||
protected PermutationTooltipLineHandler permutationTooltipLineHandler;
|
||||
protected AcceptsFollowingTooltipLineHandler acceptsFollowingTooltipLineHandler;
|
||||
|
||||
// Background image
|
||||
final DrawableResource bgTop = new DrawableBuilder("nei:textures/gui/recipebg.png", 0, BG_TOP_Y, 176, BG_TOP_HEIGHT)
|
||||
@@ -96,7 +93,7 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
public int page;
|
||||
public int recipetype;
|
||||
|
||||
public BookmarkRecipeId recipeId;
|
||||
private RecipeId recipeId;
|
||||
public ContainerRecipe slotcontainer;
|
||||
public GuiContainer firstGui;
|
||||
public GuiScreen firstGuiGeneral;
|
||||
@@ -106,8 +103,13 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
private GuiButton nexttype;
|
||||
private GuiButton prevtype;
|
||||
|
||||
// some mods reflect this property
|
||||
@Deprecated
|
||||
private GuiOverlayButton[] overlayButtons = new GuiOverlayButton[0];
|
||||
|
||||
private final List<GuiRecipeButton> recipeButtons = new ArrayList<>();
|
||||
private String recipePageCacheKey = "";
|
||||
|
||||
private final Rectangle area = new Rectangle();
|
||||
private final GuiRecipeTabs recipeTabs;
|
||||
private final GuiRecipeCatalyst guiRecipeCatalyst;
|
||||
@@ -116,41 +118,6 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
|
||||
private int yShift = 0;
|
||||
|
||||
protected static class PermutationTooltipLineHandler extends ItemsTooltipLineHandler {
|
||||
|
||||
protected PositionedStack pStack = null;
|
||||
|
||||
public PermutationTooltipLineHandler(PositionedStack pStack, List<ItemStack> items) {
|
||||
super(NEIClientUtils.translate("recipe.accepts"), items, false, 5);
|
||||
this.pStack = pStack;
|
||||
}
|
||||
|
||||
public static PermutationTooltipLineHandler getInstance(PositionedStack pStack) {
|
||||
final List<ItemStack> items = pStack.getFilteredPermutations();
|
||||
|
||||
if (items.size() > 1) {
|
||||
return new PermutationTooltipLineHandler(pStack, items);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawItem(int x, int y, ItemStack drawStack, String stackSize) {
|
||||
|
||||
if (StackInfo.equalItemAndNBT(drawStack, this.pStack.item, true)) {
|
||||
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
GuiDraw.drawRect(x - 1, y - 1, 18, 18, 0x66555555);
|
||||
GL11.glPopAttrib();
|
||||
}
|
||||
|
||||
super.drawItem(x, y, drawStack, stackSize);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class ItemRecipeFilter implements IRecipeFilter {
|
||||
|
||||
public ItemFilter filter;
|
||||
@@ -248,7 +215,7 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
guiRecipe.changePage(0);
|
||||
} else {
|
||||
final IRecipeFilter filter = new ItemRecipeFilter(GuiRecipe.searchField.getFilter());
|
||||
List<Integer> filtered = searchHandler.getSearchResult(filter);
|
||||
final List<Integer> filtered = searchHandler.getSearchResult(filter);
|
||||
|
||||
if (filtered == null) {
|
||||
stop();
|
||||
@@ -323,9 +290,9 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
this.firstGui = (GuiContainer) prevgui;
|
||||
}
|
||||
|
||||
if (prevgui instanceof IGuiContainerOverlay) {
|
||||
this.firstGui = ((IGuiContainerOverlay) prevgui).getFirstScreen();
|
||||
this.firstGuiGeneral = ((IGuiContainerOverlay) prevgui).getFirstScreenGeneral();
|
||||
if (prevgui instanceof IGuiContainerOverlay gui) {
|
||||
this.firstGui = gui.getFirstScreen();
|
||||
this.firstGuiGeneral = gui.getFirstScreenGeneral();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -435,23 +402,21 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
|
||||
if (handler == null) {
|
||||
setRecipePage(recipetype);
|
||||
} else {
|
||||
updateOverlayButtons();
|
||||
}
|
||||
|
||||
checkYShift();
|
||||
|
||||
final int rightButtonX = guiLeft + xSize - borderPadding - buttonWidth;
|
||||
final int leftButtonX = guiLeft + borderPadding;
|
||||
final int rightButtonX = guiLeft + xSize - BORDER_PADDING - BUTTON_WIDTH;
|
||||
final int leftButtonX = guiLeft + BORDER_PADDING;
|
||||
|
||||
nexttype = new GuiNEIButton(0, leftButtonX, guiTop + 3, buttonWidth, buttonHeight, "<") {
|
||||
nexttype = new GuiNEIButton(0, leftButtonX, guiTop + 3, BUTTON_WIDTH, BUTTON_HEIGHT, "<") {
|
||||
|
||||
@Override
|
||||
public void mouseReleased(int mouseX, int mouseY) {
|
||||
prevType();
|
||||
}
|
||||
};
|
||||
prevtype = new GuiNEIButton(1, rightButtonX, guiTop + 3, buttonWidth, buttonHeight, ">") {
|
||||
prevtype = new GuiNEIButton(1, rightButtonX, guiTop + 3, BUTTON_WIDTH, BUTTON_HEIGHT, ">") {
|
||||
|
||||
@Override
|
||||
public void mouseReleased(int mouseX, int mouseY) {
|
||||
@@ -459,14 +424,14 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
}
|
||||
};
|
||||
|
||||
nextpage = new GuiNEIButton(2, leftButtonX, guiTop + 17, buttonWidth, buttonHeight, "<") {
|
||||
nextpage = new GuiNEIButton(2, leftButtonX, guiTop + 17, BUTTON_WIDTH, BUTTON_HEIGHT, "<") {
|
||||
|
||||
@Override
|
||||
public void mouseReleased(int mouseX, int mouseY) {
|
||||
prevPage();
|
||||
}
|
||||
};
|
||||
prevpage = new GuiNEIButton(3, rightButtonX, guiTop + 17, buttonWidth, buttonHeight, ">") {
|
||||
prevpage = new GuiNEIButton(3, rightButtonX, guiTop + 17, BUTTON_WIDTH, BUTTON_HEIGHT, ">") {
|
||||
|
||||
@Override
|
||||
public void mouseReleased(int mouseX, int mouseY) {
|
||||
@@ -477,7 +442,8 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
toggleSearch.icon = new DrawableBuilder("nei:textures/nei_sprites.png", 0, 76, 10, 10).build();
|
||||
|
||||
this.buttonList.addAll(Arrays.asList(nexttype, prevtype, nextpage, prevpage));
|
||||
this.overlayButtons = new GuiOverlayButton[0];
|
||||
this.recipeButtons.clear();
|
||||
this.recipePageCacheKey = "";
|
||||
|
||||
if (currenthandlers.size() == 1) {
|
||||
nexttype.visible = false;
|
||||
@@ -488,22 +454,32 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
refreshPage();
|
||||
}
|
||||
|
||||
private void updateOverlayButtons() {
|
||||
private void updateRecipePage() {
|
||||
final List<Integer> indices = getRecipeIndices();
|
||||
final String cacheKey = indices.isEmpty() ? ""
|
||||
: handlerInfo.getHandlerName() + ":" + indices.get(0) + ":" + indices.get(indices.size() - 1);
|
||||
|
||||
if (isDirtyOverlayButtons(indices)) {
|
||||
this.buttonList.removeIf(Arrays.asList(this.overlayButtons)::contains);
|
||||
if (!cacheKey.equals(this.recipePageCacheKey)) {
|
||||
this.recipePageCacheKey = cacheKey;
|
||||
|
||||
final int xOffset = (limitToOneRecipe ? 0 : guiLeft) + xSize - borderPadding;
|
||||
final int yOffset = (limitToOneRecipe ? -buttonHeight : guiTop - 18) + getRecipePosition(0).y;
|
||||
for (int refIndex = 0; refIndex < indices.size(); refIndex++) {
|
||||
final int recipeIndex = indices.get(refIndex);
|
||||
for (PositionedStack pStack : handler.original.getIngredientStacks(recipeIndex)) {
|
||||
pStack.setPermutationToRender(pStack.getFilteredPermutations().get(0));
|
||||
}
|
||||
}
|
||||
|
||||
final int xOffset = (limitToOneRecipe ? 0 : guiLeft) + xSize - BORDER_PADDING;
|
||||
final int yOffset = (limitToOneRecipe ? -BUTTON_HEIGHT : guiTop - 18) + getRefIndexPosition(0).y;
|
||||
final int height = handlerInfo.getHeight() - yShift;
|
||||
final UpdateOverlayButtonsEvent.Pre preEvent = new UpdateOverlayButtonsEvent.Pre(
|
||||
final boolean showFavorites = NEIClientConfig.favoritesEnabled();
|
||||
final UpdateRecipeButtonsEvent.Pre preEvent = new UpdateRecipeButtonsEvent.Pre(
|
||||
this,
|
||||
xOffset,
|
||||
yOffset,
|
||||
height,
|
||||
handlerInfo);
|
||||
List<GuiOverlayButton> buttons = new ArrayList<>();
|
||||
List<GuiRecipeButton> buttons = new ArrayList<>();
|
||||
|
||||
if (MinecraftForge.EVENT_BUS.post(preEvent)) {
|
||||
buttons = preEvent.buttonList;
|
||||
@@ -517,42 +493,46 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
continue;
|
||||
}
|
||||
|
||||
buttons.add(
|
||||
new GuiOverlayButton(
|
||||
firstGui,
|
||||
handler.original,
|
||||
recipeIndex,
|
||||
xOffset - buttonWidth,
|
||||
yOffset + height * (refIndex + 1),
|
||||
buttonWidth,
|
||||
buttonHeight));
|
||||
GuiRecipeButton button = new GuiOverlayButton(
|
||||
firstGui,
|
||||
RecipeHandlerRef.of(handler.original, recipeIndex),
|
||||
xOffset - GuiRecipeButton.BUTTON_WIDTH,
|
||||
yOffset + height * (refIndex + 1));
|
||||
|
||||
buttons.add(button);
|
||||
|
||||
if (showFavorites) {
|
||||
buttons.add(
|
||||
new GuiFavoriteButton(
|
||||
RecipeHandlerRef.of(handler.original, recipeIndex),
|
||||
button.xPosition,
|
||||
button.yPosition - button.height - 1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (this.equals(this.mc.currentScreen)) {
|
||||
UpdateOverlayButtonsEvent.Post postEvent = new UpdateOverlayButtonsEvent.Post(this, buttons);
|
||||
UpdateRecipeButtonsEvent.Post postEvent = new UpdateRecipeButtonsEvent.Post(this, buttons);
|
||||
MinecraftForge.EVENT_BUS.post(postEvent);
|
||||
buttons = postEvent.buttonList;
|
||||
}
|
||||
}
|
||||
|
||||
this.overlayButtons = buttons.toArray(new GuiOverlayButton[buttons.size()]);
|
||||
if (!showFavorites) {
|
||||
buttons.removeIf(GuiFavoriteButton.class::isInstance);
|
||||
}
|
||||
|
||||
/** compatibility with old format */
|
||||
this.overlayButtons = buttons.stream().filter(GuiOverlayButton.class::isInstance)
|
||||
.toArray(GuiOverlayButton[]::new);
|
||||
|
||||
this.buttonList.removeIf(this.recipeButtons::contains);
|
||||
this.recipeButtons.clear();
|
||||
|
||||
this.recipeButtons.addAll(buttons);
|
||||
this.buttonList.addAll(buttons);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isDirtyOverlayButtons(List<Integer> indices) {
|
||||
|
||||
if (this.overlayButtons.length == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (GuiOverlayButton button : this.overlayButtons) {
|
||||
if (button.handler != handler.original || !indices.contains(button.recipeIndex)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static IRecipeFilter getRecipeListFilter() {
|
||||
@@ -604,11 +584,18 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
checkYShift();
|
||||
}
|
||||
|
||||
public List<GuiButton> getOverlayButtons() {
|
||||
return Collections.unmodifiableList(Arrays.asList(this.overlayButtons));
|
||||
public List<GuiRecipeButton> getRecipeButtons() {
|
||||
return Collections.unmodifiableList(this.recipeButtons);
|
||||
}
|
||||
|
||||
public int openTargetRecipe(BookmarkRecipeId recipeId) {
|
||||
public List<GuiButton> getOverlayButtons() {
|
||||
return Collections.unmodifiableList(
|
||||
Arrays.asList(
|
||||
this.recipeButtons.stream().filter(GuiOverlayButton.class::isInstance)
|
||||
.toArray(GuiButton[]::new)));
|
||||
}
|
||||
|
||||
public int openTargetRecipe(RecipeId recipeId) {
|
||||
int refIndex = -1;
|
||||
int recipetype = 0;
|
||||
|
||||
@@ -619,13 +606,13 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
H localHandler = currenthandlers.get(j);
|
||||
HandlerInfo localHandlerInfo = GuiRecipeTab.getHandlerInfo(localHandler);
|
||||
|
||||
if (localHandlerInfo.getHandlerName().equals(this.recipeId.handlerName)) {
|
||||
if (localHandlerInfo.getHandlerName().equals(this.recipeId.getHandleName())) {
|
||||
recipetype = j;
|
||||
|
||||
if (!this.recipeId.ingredients.isEmpty()) {
|
||||
if (!this.recipeId.getIngredients().isEmpty()) {
|
||||
refIndex = SearchRecipeHandler.findFirst(
|
||||
localHandler,
|
||||
(recipeIndex) -> this.recipeId
|
||||
recipeIndex -> this.recipeId
|
||||
.equalsIngredients(localHandler.getIngredientStacks(recipeIndex)));
|
||||
}
|
||||
|
||||
@@ -639,49 +626,21 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
return refIndex;
|
||||
}
|
||||
|
||||
public List<PositionedStack> getFocusedRecipeIngredients() {
|
||||
List<Integer> indices = getRecipeIndices();
|
||||
public Recipe getFocusedRecipe() {
|
||||
final List<Integer> indices = getRecipeIndices();
|
||||
|
||||
for (int refIndex = 0; refIndex < indices.size(); refIndex++) {
|
||||
final int recipeIndex = indices.get(refIndex);
|
||||
if (recipeInFocus(refIndex, recipeIndex)) {
|
||||
return handler.original.getIngredientStacks(recipeIndex);
|
||||
return Recipe.of(handler.original, recipeIndex);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public int prepareFocusedRecipeResultStackSize(ItemStack stackover) {
|
||||
List<Integer> indices = getRecipeIndices();
|
||||
|
||||
for (int refIndex = 0; refIndex < indices.size(); refIndex++) {
|
||||
final int recipeIndex = indices.get(refIndex);
|
||||
if (recipeInFocus(refIndex, recipeIndex)) {
|
||||
final PositionedStack result = handler.original.getResultStack(recipeIndex);
|
||||
int stackSize = 0;
|
||||
|
||||
if (result != null && StackInfo.equalItemAndNBT(result.item, stackover, true)) {
|
||||
stackSize += result.item.stackSize;
|
||||
}
|
||||
|
||||
final List<PositionedStack> stacks = handler.original.getOtherStacks(recipeIndex);
|
||||
for (PositionedStack pStack : stacks) {
|
||||
if (StackInfo.equalItemAndNBT(pStack.item, stackover, true)) {
|
||||
stackSize += pStack.item.stackSize;
|
||||
}
|
||||
}
|
||||
|
||||
return stackSize;
|
||||
}
|
||||
}
|
||||
|
||||
return stackover.stackSize;
|
||||
}
|
||||
|
||||
protected boolean recipeInFocus(int refIndex, int recipeIndex) {
|
||||
final PositionedStack result = handler.original.getResultStack(recipeIndex);
|
||||
|
||||
if (result != null && isMouseOver(result, refIndex)) {
|
||||
return true;
|
||||
}
|
||||
@@ -696,6 +655,15 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isMouseOver(PositionedStack stack, int refIndex) {
|
||||
Point p = getRefIndexPosition(refIndex);
|
||||
Point mousepos = GuiDraw.getMousePosition();
|
||||
Slot stackSlot = slotcontainer.getSlotWithStack(stack, p.x, p.y);
|
||||
Slot mouseoverSlot = getSlotAtPosition(mousepos.x, mousepos.y);
|
||||
|
||||
return stackSlot == mouseoverSlot;
|
||||
}
|
||||
|
||||
public String getHandlerName() {
|
||||
return handlerInfo.getHandlerName();
|
||||
}
|
||||
@@ -708,7 +676,7 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
final int recipesPerPage = getRecipesPerPage();
|
||||
final int minIndex = page * recipesPerPage;
|
||||
final int maxIndex = Math.min(this.numRecipes(), (page + 1) * recipesPerPage);
|
||||
final ArrayList<Integer> range = new ArrayList<>();
|
||||
final List<Integer> range = new ArrayList<>();
|
||||
|
||||
for (int index = minIndex; index < maxIndex; index++) {
|
||||
range.add(handler.ref(index));
|
||||
@@ -752,7 +720,7 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
|
||||
Point mouse = GuiDraw.getMousePosition();
|
||||
|
||||
for (GuiOverlayButton button : this.overlayButtons) {
|
||||
for (GuiRecipeButton button : this.recipeButtons) {
|
||||
if (button.contains(mouse.x, mouse.y)) {
|
||||
button.lastKeyTyped(this, c, i);
|
||||
}
|
||||
@@ -814,9 +782,19 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
// handler-specific scroll behavior.
|
||||
if (recipeTabs.mouseScrolled(scroll)) return;
|
||||
|
||||
for (int recipeIndex : getRecipeIndices()) {
|
||||
if (handler.original.mouseScrolled(this, scroll, recipeIndex)) {
|
||||
return;
|
||||
try (CompatibilityHacks compatibilityHacks = new CompatibilityHacks()) {
|
||||
Point mouse = GuiDraw.getMousePosition();
|
||||
|
||||
for (GuiRecipeButton button : this.recipeButtons) {
|
||||
if (button.contains(mouse.x, mouse.y) && button.mouseScrolled(this, scroll)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (int recipeIndex : getRecipeIndices()) {
|
||||
if (handler.original.mouseScrolled(this, scroll, recipeIndex)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -845,8 +823,17 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
super.updateScreen();
|
||||
onUpdate();
|
||||
}
|
||||
|
||||
public void onUpdate() {
|
||||
handler.original.onUpdate();
|
||||
refreshPage();
|
||||
|
||||
if (limitToOneRecipe) {
|
||||
refreshSlots();
|
||||
} else {
|
||||
refreshPage();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -857,7 +844,7 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
currenttip = handler.original.handleTooltip(this, currenttip, recipeIndex);
|
||||
}
|
||||
|
||||
for (GuiOverlayButton button : this.overlayButtons) {
|
||||
for (GuiRecipeButton button : this.recipeButtons) {
|
||||
if (button.contains(mousex, mousey)) {
|
||||
currenttip = button.handleTooltip(this, currenttip);
|
||||
}
|
||||
@@ -892,36 +879,36 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
}
|
||||
}
|
||||
|
||||
if (NEIClientConfig.showCycledIngredientsTooltip()) {
|
||||
PositionedStack focused = null;
|
||||
if (NEIClientConfig.showCycledIngredientsTooltip() && itemstack != null) {
|
||||
PositionedStack hovered = null;
|
||||
|
||||
for (int refIndex = 0; refIndex < indices.size(); refIndex++) {
|
||||
for (int refIndex = 0; refIndex < indices.size() && hovered == null; refIndex++) {
|
||||
final int recipeIndex = indices.get(refIndex);
|
||||
final List<PositionedStack> stacks = handler.original.getIngredientStacks(recipeIndex);
|
||||
|
||||
if (itemstack != null && focused == null) {
|
||||
final List<PositionedStack> stacks = handler.original.getIngredientStacks(recipeIndex);
|
||||
|
||||
for (PositionedStack pStack : stacks) {
|
||||
if (isMouseOver(pStack, refIndex)) {
|
||||
focused = pStack;
|
||||
break;
|
||||
}
|
||||
for (PositionedStack pStack : stacks) {
|
||||
if (isMouseOver(pStack, refIndex)) {
|
||||
hovered = pStack;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (focused == null || focused.items.length <= 1) {
|
||||
this.permutationTooltipLineHandler = null;
|
||||
} else if (this.permutationTooltipLineHandler == null
|
||||
|| this.permutationTooltipLineHandler.pStack != focused) {
|
||||
this.permutationTooltipLineHandler = PermutationTooltipLineHandler.getInstance(focused);
|
||||
if (hovered == null || hovered.items.length <= 1) {
|
||||
this.acceptsFollowingTooltipLineHandler = null;
|
||||
} else if (this.acceptsFollowingTooltipLineHandler == null
|
||||
|| this.acceptsFollowingTooltipLineHandler.tooltipGUID != hovered) {
|
||||
this.acceptsFollowingTooltipLineHandler = AcceptsFollowingTooltipLineHandler
|
||||
.of(hovered, hovered.getFilteredPermutations(), hovered.item);
|
||||
}
|
||||
} else if (this.permutationTooltipLineHandler != null) {
|
||||
this.permutationTooltipLineHandler = null;
|
||||
} else if (this.acceptsFollowingTooltipLineHandler != null) {
|
||||
this.acceptsFollowingTooltipLineHandler = null;
|
||||
}
|
||||
|
||||
if (this.permutationTooltipLineHandler != null) {
|
||||
currenttip.add(GuiDraw.TOOLTIP_HANDLER + GuiDraw.getTipLineId(this.permutationTooltipLineHandler));
|
||||
if (this.acceptsFollowingTooltipLineHandler != null) {
|
||||
this.acceptsFollowingTooltipLineHandler
|
||||
.setActiveStack(((PositionedStack) this.acceptsFollowingTooltipLineHandler.tooltipGUID).item);
|
||||
currenttip.add(GuiDraw.TOOLTIP_HANDLER + GuiDraw.getTipLineId(this.acceptsFollowingTooltipLineHandler));
|
||||
}
|
||||
|
||||
return currenttip;
|
||||
@@ -931,13 +918,21 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
public Map<String, String> handleHotkeys(GuiContainer gui, int mousex, int mousey, Map<String, String> hotkeys) {
|
||||
|
||||
try (CompatibilityHacks compatibilityHacks = new CompatibilityHacks()) {
|
||||
for (GuiOverlayButton button : this.overlayButtons) {
|
||||
for (GuiRecipeButton button : this.recipeButtons) {
|
||||
if (button.contains(mousex, mousey)) {
|
||||
hotkeys = button.handleHotkeys(gui, mousex, mousey, hotkeys);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.acceptsFollowingTooltipLineHandler != null) {
|
||||
hotkeys.put(
|
||||
NEIClientUtils.getKeyName(
|
||||
NEIClientUtils.SHIFT_HASH,
|
||||
NEIMouseUtils.MOUSE_BTN_NONE + NEIMouseUtils.MOUSE_SCROLL),
|
||||
NEIClientUtils.translate("recipe.accepts.scroll"));
|
||||
}
|
||||
|
||||
return hotkeys;
|
||||
}
|
||||
|
||||
@@ -962,26 +957,6 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
setRecipePage(--recipetype);
|
||||
}
|
||||
|
||||
protected void overlayRecipe(int recipeIndex, boolean shift) {
|
||||
|
||||
if (handler == null || !handler.original.hasOverlay(firstGui, firstGui.inventorySlots, recipeIndex)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final boolean requireShiftForOverlayRecipe = NEIClientConfig.requireShiftForOverlayRecipe();
|
||||
final IOverlayHandler overlayHandler = handler.original.getOverlayHandler(firstGui, recipeIndex);
|
||||
final IRecipeOverlayRenderer renderer = handler.original.getOverlayRenderer(firstGui, recipeIndex);
|
||||
|
||||
if (renderer == null || !requireShiftForOverlayRecipe || shift) {
|
||||
if (overlayHandler != null) {
|
||||
overlayHandler
|
||||
.overlayRecipe(firstGui, handler.original, recipeIndex, !requireShiftForOverlayRecipe || shift);
|
||||
}
|
||||
} else {
|
||||
LayoutManager.overlayRenderer = renderer;
|
||||
}
|
||||
}
|
||||
|
||||
protected void changePage(int shift) {
|
||||
final int recipesPerPage = getRecipesPerPage();
|
||||
final int numRecipes = this.numRecipes();
|
||||
@@ -997,7 +972,6 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
|
||||
public void refreshPage() {
|
||||
changePage(0);
|
||||
refreshSlots();
|
||||
final int recipesPerPage = getRecipesPerPage();
|
||||
final boolean multiplepages = this.numRecipes() > recipesPerPage;
|
||||
final int numRecipes = Math.min(this.numRecipes() - (page * recipesPerPage), recipesPerPage);
|
||||
@@ -1011,18 +985,19 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
if (!limitToOneRecipe) {
|
||||
RecipeCatalysts.updatePosition(ySize - BG_TOP_HEIGHT - (GuiRecipeCatalyst.fullBorder * 2));
|
||||
toggleSearch.w = toggleSearch.h = 12;
|
||||
toggleSearch.x = borderPadding + buttonWidth;
|
||||
toggleSearch.x = BORDER_PADDING + BUTTON_WIDTH;
|
||||
toggleSearch.y = 17;
|
||||
|
||||
searchField.y = 16;
|
||||
searchField.x = borderPadding + buttonWidth + toggleSearch.w - 1;
|
||||
searchField.w = xSize - (borderPadding + buttonWidth) * 2 + 1 - toggleSearch.w - 45;
|
||||
searchField.x = BORDER_PADDING + BUTTON_WIDTH + toggleSearch.w - 1;
|
||||
searchField.w = xSize - (BORDER_PADDING + BUTTON_WIDTH) * 2 + 1 - toggleSearch.w - 45;
|
||||
searchField.h = 14;
|
||||
}
|
||||
|
||||
nextpage.enabled = prevpage.enabled = multiplepages;
|
||||
|
||||
updateOverlayButtons();
|
||||
updateRecipePage();
|
||||
refreshSlots();
|
||||
recipeTabs.refreshPage();
|
||||
}
|
||||
|
||||
@@ -1032,7 +1007,7 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
|
||||
for (int refIndex = 0; refIndex < indices.size(); refIndex++) {
|
||||
int recipeIndex = indices.get(refIndex);
|
||||
Point p = getRecipePosition(refIndex);
|
||||
Point p = getRefIndexPosition(refIndex);
|
||||
// Legacy recipe handlers only expect a single paging widget at the top of the recipe screen, in contrast,
|
||||
// GTNH NEI moves the recipe paging widget from the bottom to the top, which means said legacy handlers will
|
||||
// position item slots 16px too high in the screen.
|
||||
@@ -1042,18 +1017,21 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
|
||||
TemplateRecipeHandler.disableCycledIngredients = false;
|
||||
|
||||
List<PositionedStack> stacks = handler.original.getIngredientStacks(recipeIndex);
|
||||
for (PositionedStack stack : stacks) slotcontainer.addSlot(stack, p.x, p.y);
|
||||
for (PositionedStack stack : handler.original.getIngredientStacks(recipeIndex)) {
|
||||
slotcontainer.addSlot(stack, p.x, p.y);
|
||||
}
|
||||
|
||||
stacks = handler.original.getOtherStacks(recipeIndex);
|
||||
for (PositionedStack stack : stacks) slotcontainer.addSlot(stack, p.x, p.y);
|
||||
for (PositionedStack stack : handler.original.getOtherStacks(recipeIndex)) {
|
||||
slotcontainer.addSlot(stack, p.x, p.y);
|
||||
}
|
||||
|
||||
PositionedStack result = handler.original.getResultStack(recipeIndex);
|
||||
if (result != null) slotcontainer.addSlot(result, p.x, p.y);
|
||||
if (result != null) {
|
||||
slotcontainer.addSlot(result, p.x, p.y);
|
||||
}
|
||||
|
||||
if (!limitToOneRecipe) {
|
||||
List<PositionedStack> catalysts = RecipeCatalysts.getRecipeCatalysts(handler.original);
|
||||
for (PositionedStack catalyst : catalysts) {
|
||||
for (PositionedStack catalyst : RecipeCatalysts.getRecipeCatalysts(handler.original)) {
|
||||
int xOffset = -GuiRecipeCatalyst.ingredientSize + 1;
|
||||
int yOffset = BG_TOP_Y + GuiRecipeCatalyst.fullBorder;
|
||||
slotcontainer.addSlot(catalyst, xOffset, yOffset);
|
||||
@@ -1108,21 +1086,12 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
handler.original.drawForeground(recipeIndex);
|
||||
|
||||
if (limitToOneRecipe) {
|
||||
GuiOverlayButton overlayButton = Arrays.asList(this.overlayButtons).stream()
|
||||
.filter(b -> b.recipeIndex == recipeIndex).findAny().orElse(null);
|
||||
GuiOverlayButton overlayButton = (GuiOverlayButton) this.recipeButtons.stream()
|
||||
.filter(b -> b instanceof GuiOverlayButton && b.handlerRef.recipeIndex == recipeIndex)
|
||||
.findAny().orElse(null);
|
||||
|
||||
if (overlayButton != null && overlayButton.enabled) {
|
||||
final String overlayKeyName = NEIClientConfig.getKeyName("gui.overlay_use");
|
||||
|
||||
if (overlayKeyName != null) {
|
||||
fontRendererObj.drawStringWithShadow(
|
||||
EnumChatFormatting.ITALIC + overlayKeyName,
|
||||
xSize - borderPadding - fontRendererObj.getStringWidth(overlayKeyName) - 10,
|
||||
handlerInfo.getHeight() - fontRendererObj.FONT_HEIGHT,
|
||||
0xffffff);
|
||||
}
|
||||
|
||||
overlayButton.drawItemPresenceOverlay();
|
||||
overlayButton.drawItemOverlay();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1134,11 +1103,14 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(5, ySkip + yShift, 0);
|
||||
|
||||
if (!limitToOneRecipe && NEIClientConfig.itemPresenceOverlay() > 0) {
|
||||
for (GuiOverlayButton button : this.overlayButtons) {
|
||||
if (!limitToOneRecipe) {
|
||||
for (GuiRecipeButton button : this.recipeButtons) {
|
||||
if (button.contains(mouseX, mouseY)) {
|
||||
GL11.glTranslatef(0, handlerInfo.getHeight() * indices.indexOf(button.recipeIndex), 0);
|
||||
button.drawItemPresenceOverlay();
|
||||
GL11.glTranslatef(
|
||||
0,
|
||||
handlerInfo.getHeight() * indices.indexOf(button.handlerRef.recipeIndex),
|
||||
0);
|
||||
button.drawItemOverlay();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1158,16 +1130,16 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
|
||||
if (NEIClientConfig.areJEIStyleTabsVisible() && !limitToOneRecipe) {
|
||||
drawRect(
|
||||
guiLeft + borderPadding + buttonWidth - 1,
|
||||
guiLeft + BORDER_PADDING + BUTTON_WIDTH - 1,
|
||||
nexttype.yPosition,
|
||||
guiLeft + xSize - borderPadding - buttonWidth,
|
||||
nexttype.yPosition + buttonHeight,
|
||||
guiLeft + xSize - BORDER_PADDING - BUTTON_WIDTH,
|
||||
nexttype.yPosition + BUTTON_HEIGHT,
|
||||
0x30000000);
|
||||
drawRect(
|
||||
guiLeft + borderPadding + buttonWidth - 1,
|
||||
guiLeft + BORDER_PADDING + BUTTON_WIDTH - 1,
|
||||
nextpage.yPosition,
|
||||
guiLeft + xSize - borderPadding - buttonWidth,
|
||||
nextpage.yPosition + buttonHeight,
|
||||
guiLeft + xSize - BORDER_PADDING - BUTTON_WIDTH,
|
||||
nextpage.yPosition + BUTTON_HEIGHT,
|
||||
0x30000000);
|
||||
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
@@ -1240,15 +1212,6 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
return firstGuiGeneral;
|
||||
}
|
||||
|
||||
public boolean isMouseOver(PositionedStack stack, int refIndex) {
|
||||
Point p = getRecipePosition(refIndex);
|
||||
Point mousepos = GuiDraw.getMousePosition();
|
||||
Slot stackSlot = slotcontainer.getSlotWithStack(stack, p.x, p.y);
|
||||
Slot mouseoverSlot = getSlotAtPosition(mousepos.x, mousepos.y);
|
||||
|
||||
return stackSlot == mouseoverSlot;
|
||||
}
|
||||
|
||||
private int getRecipesPerPage() {
|
||||
return limitToOneRecipe ? 1 : getRecipesPerPage(handlerInfo);
|
||||
}
|
||||
@@ -1257,7 +1220,7 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
if (handlerInfo != null) {
|
||||
return Math.max(
|
||||
Math.min(
|
||||
((ySize - (buttonHeight * 3)) / handlerInfo.getHeight()),
|
||||
((ySize - (BUTTON_HEIGHT * 3)) / handlerInfo.getHeight()),
|
||||
handlerInfo.getMaxRecipesPerPage()),
|
||||
1);
|
||||
} else if (handler != null) {
|
||||
@@ -1266,10 +1229,14 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
return 1;
|
||||
}
|
||||
|
||||
public Point getRecipePosition(int refIndex) {
|
||||
// Legacy recipe handlers using the height hack might use getRecipePosition in combination with guiTop/height to
|
||||
// position certain elements like tooltips. Since guiTop is moved down by 16px during height hacking, we need to
|
||||
// reduce the vertical shift here to 16px instead of 32px.
|
||||
public Point getRecipePosition(int recipe) {
|
||||
return getRefIndexPosition(getRecipeIndices().indexOf(recipe));
|
||||
}
|
||||
|
||||
protected Point getRefIndexPosition(int refIndex) {
|
||||
// Legacy recipe handlers using the height hack might use getRefIndexPosition in combination with guiTop/height
|
||||
// to position certain elements like tooltips. Since guiTop is moved down by 16px during height hacking, we need
|
||||
// to reduce the vertical shift here to 16px instead of 32px.
|
||||
return new Point(
|
||||
5,
|
||||
(isHeightHackApplied ? 16 : 32) - (limitToOneRecipe ? 25 : 0)
|
||||
@@ -1311,16 +1278,14 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
return area.intersects(x, y, w, h);
|
||||
}
|
||||
|
||||
protected static BookmarkRecipeId getCurrentRecipeId(GuiScreen gui) {
|
||||
protected static RecipeId getCurrentRecipeId(GuiScreen gui) {
|
||||
|
||||
if (gui instanceof GuiRecipe && ((GuiRecipe<?>) gui).handler.numRecipes() > 0) {
|
||||
final GuiRecipe<?> gRecipe = (GuiRecipe<?>) gui;
|
||||
if ((gui instanceof GuiRecipe<?>gRecipe) && gRecipe.handler.numRecipes() > 0) {
|
||||
final List<Integer> indices = gRecipe.getRecipeIndices();
|
||||
final int curRecipe = indices.isEmpty() ? 0 : indices.get(0);
|
||||
final Recipe recipe = Recipe.of(gRecipe.handler.original, curRecipe);
|
||||
|
||||
return new BookmarkRecipeId(
|
||||
gRecipe.handlerInfo.getHandlerName(),
|
||||
gRecipe.handler.original.getIngredientStacks(curRecipe));
|
||||
return recipe != null ? recipe.getRecipeId() : null;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package codechicken.nei.recipe;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraftforge.client.event.GuiScreenEvent;
|
||||
|
||||
import codechicken.lib.vec.Rectangle4i;
|
||||
import codechicken.nei.GuiNEIButton;
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
|
||||
public abstract class GuiRecipeButton extends GuiNEIButton {
|
||||
|
||||
public static class UpdateRecipeButtonsEvent extends GuiScreenEvent {
|
||||
|
||||
public List<GuiRecipeButton> buttonList;
|
||||
|
||||
public UpdateRecipeButtonsEvent(GuiRecipe<?> gui, List<GuiRecipeButton> buttonList) {
|
||||
super(gui);
|
||||
this.buttonList = new ArrayList<>(buttonList);
|
||||
}
|
||||
|
||||
@Cancelable
|
||||
public static class Pre extends UpdateRecipeButtonsEvent {
|
||||
|
||||
public int xOffset;
|
||||
public int yOffset;
|
||||
public int height;
|
||||
public HandlerInfo handlerInfo;
|
||||
|
||||
public Pre(GuiRecipe<?> gui, int xOffset, int yOffset, int height, HandlerInfo handlerInfo) {
|
||||
super(gui, new ArrayList<>());
|
||||
this.xOffset = xOffset;
|
||||
this.yOffset = yOffset;
|
||||
this.height = height;
|
||||
this.handlerInfo = handlerInfo;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Post extends UpdateRecipeButtonsEvent {
|
||||
|
||||
public Post(GuiRecipe<?> gui, List<GuiRecipeButton> buttonList) {
|
||||
super(gui, buttonList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final int BUTTON_WIDTH = 12;
|
||||
public static final int BUTTON_HEIGHT = 12;
|
||||
|
||||
public final RecipeHandlerRef handlerRef;
|
||||
|
||||
protected GuiRecipeButton(RecipeHandlerRef point, int x, int y, int buttonId, String label) {
|
||||
super(buttonId, x, y, BUTTON_WIDTH, BUTTON_HEIGHT, label);
|
||||
this.handlerRef = point;
|
||||
}
|
||||
|
||||
abstract List<String> handleTooltip(GuiRecipe<?> gui, List<String> currenttip);
|
||||
|
||||
abstract Map<String, String> handleHotkeys(GuiContainer gui, int mousex, int mousey, Map<String, String> hotkeys);
|
||||
|
||||
abstract void lastKeyTyped(GuiRecipe<?> gui, char keyChar, int keyID);
|
||||
|
||||
abstract void drawItemOverlay();
|
||||
|
||||
public boolean mouseScrolled(GuiRecipe<?> gui, int scroll) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Rectangle4i bounds() {
|
||||
return new Rectangle4i(this.xPosition, this.yPosition, this.width, this.height);
|
||||
}
|
||||
|
||||
public boolean contains(int mx, int my) {
|
||||
return bounds().contains(mx, my);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import net.minecraft.item.ItemStack;
|
||||
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.recipe.Recipe.RecipeId;
|
||||
import codechicken.nei.recipe.stackinfo.GTFluidStackStringifyHandler;
|
||||
|
||||
public class GuiUsageRecipe extends GuiRecipe<IUsageHandler> {
|
||||
@@ -30,7 +31,7 @@ public class GuiUsageRecipe extends GuiRecipe<IUsageHandler> {
|
||||
|
||||
if (!handlers.isEmpty()) {
|
||||
final Minecraft mc = NEIClientUtils.mc();
|
||||
final BookmarkRecipeId recipeId = getCurrentRecipeId(mc.currentScreen);
|
||||
final RecipeId recipeId = getCurrentRecipeId(mc.currentScreen);
|
||||
final GuiUsageRecipe gui = new GuiUsageRecipe(handlers);
|
||||
|
||||
mc.displayGuiScreen(gui);
|
||||
|
||||
@@ -0,0 +1,456 @@
|
||||
package codechicken.nei.recipe;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
|
||||
import codechicken.nei.NEIServerUtils;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.api.ItemInfo;
|
||||
import codechicken.nei.util.NBTJson;
|
||||
|
||||
public class Recipe {
|
||||
|
||||
public static class RecipeId {
|
||||
|
||||
private static final String KEY_HANDLER_NAME = "handlerName";
|
||||
private static final String KEY_INGREDIENTS = "ingredients";
|
||||
private static final String KEY_RESULT = "result";
|
||||
|
||||
private final String handlerName;
|
||||
private final List<ItemStack> ingredients;
|
||||
private final ItemStack result;
|
||||
|
||||
protected RecipeId(ItemStack result, String handlerName, List<ItemStack> ingredients) {
|
||||
this.result = result != null ? StackInfo.withAmount(result, 0) : null;
|
||||
this.handlerName = handlerName;
|
||||
this.ingredients = ingredients;
|
||||
}
|
||||
|
||||
public static RecipeId of(Object result, String handlerName, Iterable<?> ingredients) {
|
||||
return new RecipeId(extractItem(result), handlerName, extractItems(ingredients));
|
||||
}
|
||||
|
||||
public static RecipeId of(JsonObject json) {
|
||||
String handlerName = null;
|
||||
List<ItemStack> ingredients = new ArrayList<>();
|
||||
ItemStack result = null;
|
||||
|
||||
if (json.get(KEY_HANDLER_NAME) != null) {
|
||||
handlerName = json.get(KEY_HANDLER_NAME).getAsString();
|
||||
}
|
||||
|
||||
if (json.get(KEY_INGREDIENTS) != null) {
|
||||
ingredients = convertJsonArrayToItems(json.getAsJsonArray(KEY_INGREDIENTS));
|
||||
}
|
||||
|
||||
if (json.get(KEY_RESULT) != null) {
|
||||
result = StackInfo.loadFromNBT((NBTTagCompound) NBTJson.toNbt(json.getAsJsonObject(KEY_RESULT)));
|
||||
}
|
||||
|
||||
return new RecipeId(result, handlerName, ingredients);
|
||||
}
|
||||
|
||||
public String getHandleName() {
|
||||
return this.handlerName;
|
||||
}
|
||||
|
||||
public ItemStack getResult() {
|
||||
return this.result;
|
||||
}
|
||||
|
||||
public List<ItemStack> getIngredients() {
|
||||
return new ArrayList<>(this.ingredients);
|
||||
}
|
||||
|
||||
protected static List<ItemStack> extractItems(Iterable<?> items) {
|
||||
final List<ItemStack> list = new ArrayList<>();
|
||||
|
||||
for (Object item : items) {
|
||||
ItemStack stack = extractItem(item);
|
||||
|
||||
if (stack != null) {
|
||||
list.add(stack.copy());
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
protected static ItemStack extractItem(Object item) {
|
||||
|
||||
if (item instanceof PositionedStack positionedStack) {
|
||||
item = StackInfo.getItemStackWithMinimumDamage(positionedStack.items);
|
||||
}
|
||||
|
||||
if (item instanceof RecipeIngredient ingr) {
|
||||
item = StackInfo.getItemStackWithMinimumDamage(ingr.getPermutations().toArray(new ItemStack[0]));
|
||||
}
|
||||
|
||||
if (item instanceof NBTTagCompound nbTag) {
|
||||
return StackInfo.loadFromNBT(nbTag);
|
||||
}
|
||||
|
||||
if (item instanceof ItemStack stack) {
|
||||
return stack;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean equalsIngredients(List<PositionedStack> stacks) {
|
||||
|
||||
if (ingredients.size() != stacks.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int index = 0; index < stacks.size(); index++) {
|
||||
if (!stacks.get(index).containsWithNBT(ingredients.get(index))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public JsonObject toJsonObject() {
|
||||
final JsonObject json = new JsonObject();
|
||||
|
||||
if (this.handlerName != null && !"".equals(this.handlerName)) {
|
||||
json.add(KEY_HANDLER_NAME, new JsonPrimitive(this.handlerName));
|
||||
json.add(KEY_INGREDIENTS, convertItemsToJsonArray(this.ingredients));
|
||||
|
||||
if (this.result != null) { // old format without result
|
||||
json.add(KEY_RESULT, NBTJson.toJsonObject(StackInfo.itemStackToNBT(this.result)));
|
||||
}
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
protected JsonArray convertItemsToJsonArray(List<ItemStack> items) {
|
||||
final JsonArray arr = new JsonArray();
|
||||
|
||||
for (ItemStack nbTag : items) {
|
||||
arr.add(NBTJson.toJsonObject(StackInfo.itemStackToNBT(nbTag)));
|
||||
}
|
||||
|
||||
return arr;
|
||||
}
|
||||
|
||||
protected static List<ItemStack> convertJsonArrayToItems(JsonArray arr) {
|
||||
final List<ItemStack> items = new ArrayList<>();
|
||||
|
||||
for (JsonElement elem : arr) {
|
||||
final ItemStack nbt = StackInfo.loadFromNBT((NBTTagCompound) NBTJson.toNbt(elem));
|
||||
|
||||
if (nbt == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
items.add(nbt);
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(this.handlerName, this.ingredients.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object anObject) {
|
||||
if (this == anObject) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (anObject instanceof RecipeId anRecipeId) {
|
||||
|
||||
if (!this.handlerName.equals(anRecipeId.handlerName)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.ingredients.size() != anRecipeId.ingredients.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.result != null && anRecipeId.result != null
|
||||
&& !StackInfo.equalItemAndNBT(this.result, anRecipeId.result, true)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int idx = 0; idx < this.ingredients.size(); idx++) {
|
||||
if (!StackInfo.equalItemAndNBT(this.ingredients.get(idx), anRecipeId.ingredients.get(idx), true)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public RecipeId copy() {
|
||||
return new RecipeId(this.result, this.handlerName, this.ingredients);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class RecipeIngredient {
|
||||
|
||||
protected final ItemStack[] items;
|
||||
protected int activeIndex = 0;
|
||||
protected int amount = 0;
|
||||
|
||||
protected int relx;
|
||||
protected int rely;
|
||||
|
||||
public RecipeIngredient(int relx, int rely, List<ItemStack> items, int activeIndex) {
|
||||
this.items = items.stream().map(ItemStack::copy).toArray(size -> new ItemStack[size]);
|
||||
this.amount = StackInfo.getAmount(this.items[activeIndex]);
|
||||
this.activeIndex = activeIndex;
|
||||
this.relx = relx;
|
||||
this.rely = rely;
|
||||
}
|
||||
|
||||
public static RecipeIngredient of(PositionedStack positionedStack) {
|
||||
final List<ItemStack> stacks = Arrays.asList(positionedStack.items).stream()
|
||||
.filter(item -> !ItemInfo.isHidden(item)).collect(Collectors.toList());
|
||||
int activeIndex = 0;
|
||||
|
||||
if (stacks.isEmpty()) {
|
||||
stacks.addAll(Arrays.asList(positionedStack.items));
|
||||
}
|
||||
|
||||
for (int i = 0; i < stacks.size(); i++) {
|
||||
if (NEIServerUtils.areStacksSameTypeCraftingWithNBT(positionedStack.item, stacks.get(i))) {
|
||||
activeIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return of(positionedStack.relx, positionedStack.rely, stacks, activeIndex);
|
||||
}
|
||||
|
||||
public static RecipeIngredient of(int relx, int rely, List<ItemStack> stacks, int activeIndex) {
|
||||
return new RecipeIngredient(relx, rely, stacks, activeIndex);
|
||||
}
|
||||
|
||||
public int getAmount() {
|
||||
return this.amount;
|
||||
}
|
||||
|
||||
public ItemStack getItemStack() {
|
||||
return this.items[this.activeIndex];
|
||||
}
|
||||
|
||||
public void setActiveIndex(int activeIndex) {
|
||||
this.activeIndex = Math.max(0, Math.min(activeIndex, this.items.length - 1));
|
||||
}
|
||||
|
||||
public boolean contains(ItemStack stackA) {
|
||||
return getPermutations().stream().anyMatch(stackB -> StackInfo.equalItemAndNBT(stackA, stackB, true));
|
||||
}
|
||||
|
||||
public List<ItemStack> getPermutations() {
|
||||
return Arrays.asList(this.items);
|
||||
}
|
||||
|
||||
public RecipeIngredient setAmount(int amount) {
|
||||
|
||||
for (int index = 0; index < this.items.length; index++) {
|
||||
this.items[index] = StackInfo.withAmount(this.items[index], amount);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public RecipeIngredient copy() {
|
||||
return new RecipeIngredient(
|
||||
this.relx,
|
||||
this.rely,
|
||||
getPermutations().stream().map(ItemStack::copy).collect(Collectors.toList()),
|
||||
this.activeIndex);
|
||||
}
|
||||
}
|
||||
|
||||
private final String handlerName;
|
||||
private final RecipeIngredient[] results;
|
||||
private final RecipeIngredient[] ingredients;
|
||||
private RecipeId recipeId = null;
|
||||
|
||||
private Recipe(String handlerName, List<RecipeIngredient> ingredients, List<RecipeIngredient> results) {
|
||||
this.handlerName = handlerName;
|
||||
this.ingredients = ingredients.toArray(new RecipeIngredient[ingredients.size()]);
|
||||
this.results = results.toArray(new RecipeIngredient[results.size()]);
|
||||
}
|
||||
|
||||
public static Recipe of(IRecipeHandler handler, int recipeIndex) {
|
||||
final String handlerName = GuiRecipeTab.getHandlerInfo(handler).getHandlerName();
|
||||
final List<RecipeIngredient> ingredients = new ArrayList<>();
|
||||
final List<RecipeIngredient> results = new ArrayList<>();
|
||||
|
||||
for (PositionedStack positionedStack : handler.getIngredientStacks(recipeIndex)) {
|
||||
ingredients.add(RecipeIngredient.of(positionedStack));
|
||||
}
|
||||
|
||||
if (handler.getResultStack(recipeIndex) != null) {
|
||||
results.add(RecipeIngredient.of(handler.getResultStack(recipeIndex)));
|
||||
} else {
|
||||
for (PositionedStack positionedStack : handler.getOtherStacks(recipeIndex)) {
|
||||
results.add(RecipeIngredient.of(positionedStack));
|
||||
}
|
||||
}
|
||||
|
||||
return new Recipe(handlerName, ingredients, results);
|
||||
}
|
||||
|
||||
public static Recipe of(List<?> results, String handlerName, List<?> ingredients) {
|
||||
return new Recipe(handlerName, extractItems(ingredients), extractItems(results));
|
||||
}
|
||||
|
||||
public static Recipe of(RecipeHandlerRef handlerRef) {
|
||||
return Recipe.of(handlerRef.handler, handlerRef.recipeIndex);
|
||||
}
|
||||
|
||||
public static Recipe of(RecipeId recipeId) {
|
||||
if (recipeId == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final RecipeHandlerRef handlerRef = RecipeHandlerRef.of(recipeId);
|
||||
|
||||
if (handlerRef != null) {
|
||||
return Recipe.of(handlerRef);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static List<RecipeIngredient> extractItems(List<?> items) {
|
||||
final List<RecipeIngredient> list = new ArrayList<>();
|
||||
|
||||
for (Object item : items) {
|
||||
RecipeIngredient ingr = extractItem(item);
|
||||
|
||||
if (ingr != null) {
|
||||
list.add(ingr);
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
protected static RecipeIngredient extractItem(Object item) {
|
||||
|
||||
if (item instanceof PositionedStack positionedStack) {
|
||||
return RecipeIngredient.of(positionedStack);
|
||||
}
|
||||
|
||||
if (item instanceof NBTTagCompound nbTag) {
|
||||
item = StackInfo.loadFromNBT(nbTag);
|
||||
}
|
||||
|
||||
if (item instanceof ItemStack stack) {
|
||||
return RecipeIngredient.of(0, 0, Arrays.asList(stack), 0);
|
||||
}
|
||||
|
||||
if (item instanceof RecipeIngredient ingr) {
|
||||
return ingr.copy();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getHandlerName() {
|
||||
return this.handlerName;
|
||||
}
|
||||
|
||||
public List<RecipeIngredient> getResults() {
|
||||
return Arrays.asList(this.results);
|
||||
}
|
||||
|
||||
public List<RecipeIngredient> getIngredients() {
|
||||
return Arrays.asList(this.ingredients);
|
||||
}
|
||||
|
||||
public ItemStack getResult() {
|
||||
return getResult(null);
|
||||
}
|
||||
|
||||
public ItemStack getResult(ItemStack stack) {
|
||||
|
||||
if (this.results.length == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (stack == null && this.results.length > 1) {
|
||||
for (RecipeIngredient ingr : this.results) {
|
||||
if (!FluidContainerRegistry.isContainer(ingr.getItemStack())
|
||||
|| StackInfo.getFluid(ingr.getItemStack()) != null) {
|
||||
stack = ingr.getItemStack();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (stack == null) {
|
||||
stack = this.results[0].getItemStack();
|
||||
}
|
||||
|
||||
int stackSize = 0;
|
||||
|
||||
for (RecipeIngredient result : this.results) {
|
||||
if (result.contains(stack)) {
|
||||
stackSize += result.getAmount();
|
||||
}
|
||||
}
|
||||
|
||||
return StackInfo.withAmount(stack, stackSize);
|
||||
}
|
||||
|
||||
public RecipeId getRecipeId() {
|
||||
|
||||
if (this.recipeId == null) {
|
||||
this.recipeId = RecipeId.of(getResult(), this.handlerName, getIngredients());
|
||||
}
|
||||
|
||||
return this.recipeId;
|
||||
}
|
||||
|
||||
public void setCustomRecipeId(RecipeId recipeId) {
|
||||
this.recipeId = recipeId;
|
||||
}
|
||||
|
||||
public Recipe copy() {
|
||||
final List<RecipeIngredient> ingredients = new ArrayList<>();
|
||||
final List<RecipeIngredient> results = new ArrayList<>();
|
||||
|
||||
for (RecipeIngredient ingr : this.ingredients) {
|
||||
ingredients.add(ingr.copy());
|
||||
}
|
||||
|
||||
for (RecipeIngredient res : this.results) {
|
||||
results.add(res.copy());
|
||||
}
|
||||
|
||||
Recipe recipe = new Recipe(this.handlerName, ingredients, results);
|
||||
recipe.recipeId = this.recipeId;
|
||||
|
||||
return recipe;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
package codechicken.nei.recipe;
|
||||
|
||||
import java.util.Collections;
|
||||
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;
|
||||
import codechicken.nei.recipe.GuiOverlayButton.ItemOverlayState;
|
||||
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;
|
||||
|
||||
private RecipeHandlerRef(IRecipeHandler handler, int recipeIndex) {
|
||||
this.handler = handler;
|
||||
this.recipeIndex = recipeIndex;
|
||||
}
|
||||
|
||||
public static RecipeHandlerRef of(IRecipeHandler handler, int recipeIndex) {
|
||||
return new RecipeHandlerRef(handler, recipeIndex);
|
||||
}
|
||||
|
||||
public static RecipeHandlerRef of(RecipeId recipeId) {
|
||||
|
||||
if (recipeId.getResult() != null && !recipeId.getIngredients().isEmpty()) {
|
||||
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)));
|
||||
|
||||
if (refIndex >= 0) {
|
||||
return new RecipeHandlerRef(handler, refIndex);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private GuiContainer prepareGui(GuiContainer firstGui) {
|
||||
|
||||
if (firstGui instanceof GuiRecipe gui) {
|
||||
firstGui = gui.firstGui;
|
||||
}
|
||||
|
||||
return firstGui != null && firstGui.inventorySlots != null ? firstGui : null;
|
||||
}
|
||||
|
||||
public IOverlayHandler getOverlayHandler(GuiContainer gui) {
|
||||
final GuiContainer firstGui = prepareGui(gui);
|
||||
|
||||
if (firstGui != null && this.handler.hasOverlay(firstGui, firstGui.inventorySlots, this.recipeIndex)) {
|
||||
return this.handler.getOverlayHandler(firstGui, this.recipeIndex);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean canFillCraftingGrid(GuiContainer gui) {
|
||||
final IOverlayHandler overlayHandler = getOverlayHandler(gui);
|
||||
|
||||
if (overlayHandler != null) {
|
||||
return overlayHandler.canFillCraftingGrid(prepareGui(gui), this.handler, this.recipeIndex);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean canCraft(GuiContainer gui) {
|
||||
final IOverlayHandler overlayHandler = getOverlayHandler(gui);
|
||||
|
||||
if (overlayHandler != null && allowedTransferAlghoritm(gui)) {
|
||||
return overlayHandler.canCraft(prepareGui(gui), this.handler, this.recipeIndex);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<ItemOverlayState> getPresenceOverlay(GuiContainer gui) {
|
||||
final IOverlayHandler overlayHandler = getOverlayHandler(gui);
|
||||
|
||||
if (overlayHandler != null) {
|
||||
return overlayHandler.presenceOverlay(prepareGui(gui), this.handler, this.recipeIndex);
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public void fillCraftingGrid(GuiContainer gui, int multiplier) {
|
||||
final IOverlayHandler overlayHandler = getOverlayHandler(gui);
|
||||
|
||||
if (overlayHandler != null) {
|
||||
final GuiContainer firstGui = prepareGui(gui);
|
||||
|
||||
if (!firstGui.equals(firstGui.mc.currentScreen)) {
|
||||
firstGui.mc.displayGuiScreen(firstGui);
|
||||
}
|
||||
|
||||
if (!allowedTransferAlghoritm(gui)) {
|
||||
overlayHandler.overlayRecipe(firstGui, this.handler, this.recipeIndex, multiplier != 1);
|
||||
} else {
|
||||
overlayHandler.transferRecipe(firstGui, this.handler, this.recipeIndex, multiplier);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean craft(GuiContainer gui, int multiplier) {
|
||||
final GuiContainer firstGui = prepareGui(gui);
|
||||
final IOverlayHandler overlayHandler = getOverlayHandler(firstGui);
|
||||
|
||||
if (overlayHandler != null && overlayHandler.canCraft(firstGui, this.handler, this.recipeIndex)) {
|
||||
|
||||
if (!firstGui.equals(firstGui.mc.currentScreen)) {
|
||||
firstGui.mc.displayGuiScreen(firstGui);
|
||||
}
|
||||
|
||||
return overlayHandler.craft(firstGui, this.handler, this.recipeIndex, multiplier);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean allowedTransferAlghoritm(GuiContainer gui) {
|
||||
final IOverlayHandler overlayHandler = getOverlayHandler(gui);
|
||||
|
||||
if (overlayHandler != null) {
|
||||
try {
|
||||
return !overlayHandler.getClass()
|
||||
.getDeclaredMethod(
|
||||
"transferRecipe",
|
||||
GuiContainer.class,
|
||||
IRecipeHandler.class,
|
||||
int.class,
|
||||
int.class)
|
||||
.isDefault();
|
||||
} catch (NoSuchMethodException e) {}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public IRecipeOverlayRenderer getRecipeOverlayRenderer(GuiContainer gui) {
|
||||
final GuiContainer firstGui = prepareGui(gui);
|
||||
|
||||
if (firstGui != null && this.handler.hasOverlay(firstGui, firstGui.inventorySlots, this.recipeIndex)) {
|
||||
return this.handler.getOverlayRenderer(firstGui, this.recipeIndex);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean canUseOverlayRenderer(GuiContainer gui) {
|
||||
return getRecipeOverlayRenderer(gui) != null;
|
||||
}
|
||||
|
||||
public void useOverlayRenderer(GuiContainer gui) {
|
||||
final IRecipeOverlayRenderer renderer = getRecipeOverlayRenderer(gui);
|
||||
|
||||
if (renderer != null) {
|
||||
final GuiContainer firstGui = prepareGui(gui);
|
||||
|
||||
if (!firstGui.equals(firstGui.mc.currentScreen)) {
|
||||
firstGui.mc.displayGuiScreen(firstGui);
|
||||
}
|
||||
|
||||
LayoutManager.overlayRenderer = renderer;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,28 @@
|
||||
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.lib.vec.Rectangle4i;
|
||||
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);
|
||||
@@ -26,7 +37,8 @@ public class RecipeItemInputHandler implements IContainerInputHandler, IContaine
|
||||
@Override
|
||||
public boolean mouseClicked(GuiContainer gui, int mousex, int mousey, int button) {
|
||||
if (!(gui instanceof GuiRecipe) || ItemPanels.itemPanel.contains(mousex, mousey)
|
||||
|| ItemPanels.bookmarkPanel.contains(mousex, mousey))
|
||||
|| ItemPanels.bookmarkPanel.contains(mousex, mousey)
|
||||
|| ItemPanels.itemPanel.historyPanel.contains(mousex, mousey))
|
||||
return false;
|
||||
|
||||
return ShortcutInputHandler.handleMouseClick(GuiContainerManager.getStackMouseOver(gui));
|
||||
@@ -46,6 +58,63 @@ 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.showRecipeTooltipInPanel() ? FavoriteRecipes.getFavorite(itemstack) : null;
|
||||
}
|
||||
|
||||
if (gui instanceof GuiRecipe<?>guiRecipe
|
||||
&& new Rectangle4i(gui.guiLeft, gui.guiTop, gui.xSize, gui.ySize).contains(mousex, mousey)
|
||||
&& NEIClientConfig.showRecipeTooltipInGui()
|
||||
&& guiRecipe.getFocusedRecipe() == null) {
|
||||
return FavoriteRecipes.getFavorite(itemstack);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeyTyped(GuiContainer gui, char keyChar, int keyID) {}
|
||||
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
package codechicken.nei.recipe;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
import codechicken.lib.gui.GuiDraw.ITooltipLineHandler;
|
||||
import codechicken.nei.guihook.GuiContainerManager;
|
||||
import codechicken.nei.recipe.Recipe.RecipeId;
|
||||
|
||||
public class RecipeTooltipLineHandler implements ITooltipLineHandler {
|
||||
|
||||
protected long lastUpdate = System.currentTimeMillis();
|
||||
protected GuiRecipe<?> gui = null;
|
||||
protected RecipeId recipeId = null;
|
||||
protected boolean createdGui = false;
|
||||
|
||||
public RecipeTooltipLineHandler(RecipeId recipeId) {
|
||||
this.recipeId = recipeId;
|
||||
}
|
||||
|
||||
public ItemStack getItemStack() {
|
||||
return this.recipeId.getResult();
|
||||
}
|
||||
|
||||
public RecipeId getRecipeId() {
|
||||
return this.recipeId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getSize() {
|
||||
|
||||
if (this.gui == null && !this.createdGui) {
|
||||
this.gui = GuiCraftingRecipe.createRecipeGui("recipeId", false, this.recipeId.getResult(), this.recipeId);
|
||||
this.createdGui = true;
|
||||
|
||||
if (this.gui != null) {
|
||||
this.gui.initGui();
|
||||
this.gui.guiTop = 0;
|
||||
this.gui.guiLeft = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.gui != null) {
|
||||
return this.gui.getWidgetSize();
|
||||
}
|
||||
|
||||
return new Dimension(0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(int x, int y) {
|
||||
if (this.gui == null) return;
|
||||
|
||||
if ((System.currentTimeMillis() - lastUpdate) > 50) {
|
||||
lastUpdate = System.currentTimeMillis();
|
||||
this.gui.onUpdate();
|
||||
}
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glScaled(1, 1, 3);
|
||||
GL11.glTranslatef(x, y, 0);
|
||||
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
|
||||
this.gui.drawGuiContainerBackgroundLayer(0.0f, -100, -100);
|
||||
|
||||
GL11.glPopAttrib();
|
||||
|
||||
if (this.gui.slotcontainer != null) {
|
||||
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
List<Slot> slots = this.gui.slotcontainer.inventorySlots;
|
||||
|
||||
for (Slot slot : slots) {
|
||||
if (slot != null && slot.getStack() != null) {
|
||||
GuiContainerManager.drawItem(slot.xDisplayPosition, slot.yDisplayPosition, slot.getStack());
|
||||
}
|
||||
}
|
||||
|
||||
GL11.glPopAttrib();
|
||||
}
|
||||
|
||||
this.gui.drawGuiContainerForegroundLayer(-100, -100);
|
||||
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
}
|
||||
@@ -90,7 +90,7 @@ public class StackInfo {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (useNBT) {
|
||||
if (useNBT && stackA != stackB) {
|
||||
NBTTagCompound tagCompoundA = itemStackToNBT(stackA, false);
|
||||
NBTTagCompound tagCompoundB = itemStackToNBT(stackB, false);
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import com.google.common.base.Stopwatch;
|
||||
|
||||
import codechicken.lib.gui.GuiDraw;
|
||||
import codechicken.lib.vec.Rectangle4i;
|
||||
import codechicken.nei.FavoriteRecipes;
|
||||
import codechicken.nei.ItemList;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
@@ -193,7 +194,7 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
|
||||
for (PositionedStack pStack : stacks) {
|
||||
if (pStack.items.length <= 1) continue;
|
||||
final List<ItemStack> items = pStack.getFilteredPermutations();
|
||||
final List<ItemStack> items = pStack.getFilteredPermutations(FavoriteRecipes::contains);
|
||||
pStack.setPermutationToRender(items.get((int) (cycle % items.size())));
|
||||
}
|
||||
}
|
||||
@@ -204,7 +205,7 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
: Math.abs(new Random(cycle + offset).nextInt());
|
||||
|
||||
if (stack.items.length <= 1) return;
|
||||
final List<ItemStack> items = stack.getFilteredPermutations();
|
||||
final List<ItemStack> items = stack.getFilteredPermutations(FavoriteRecipes::contains);
|
||||
stack.setPermutationToRender(items.get((int) (cycle % items.size())));
|
||||
}
|
||||
|
||||
@@ -706,15 +707,7 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
|
||||
if (overStack != null && overStack.items.length > 1) {
|
||||
final List<ItemStack> items = overStack.getFilteredPermutations();
|
||||
int stackIndex = 0;
|
||||
|
||||
for (int index = 0; index < items.size(); index++) {
|
||||
if (NEIServerUtils.areStacksSameTypeCraftingWithNBT(items.get(index), overStack.item)) {
|
||||
stackIndex = index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
final int stackIndex = getPermutationIndex(overStack.item, items);
|
||||
final ItemStack stack = items.get((items.size() - scroll + stackIndex) % items.size());
|
||||
|
||||
if (NEIClientConfig.useJEIStyledCycledIngredients()) {
|
||||
@@ -733,6 +726,17 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH
|
||||
return false;
|
||||
}
|
||||
|
||||
private int getPermutationIndex(ItemStack stack, List<ItemStack> items) {
|
||||
|
||||
for (int index = 0; index < items.size(); index++) {
|
||||
if (NEIServerUtils.areStacksSameTypeCraftingWithNBT(items.get(index), stack)) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
private PositionedStack getIngredientMouseOver(int mousex, int mousey, int recipe) {
|
||||
|
||||
for (PositionedStack pStack : getIngredientStacks(recipe)) {
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
package codechicken.nei.recipe.chain;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import codechicken.nei.ItemStackAmount;
|
||||
import codechicken.nei.bookmark.BookmarkItem;
|
||||
import codechicken.nei.recipe.Recipe.RecipeId;
|
||||
import codechicken.nei.recipe.StackInfo;
|
||||
|
||||
public class RecipeChainIterator implements Iterator<Map<RecipeId, Long>> {
|
||||
|
||||
public final ItemStackAmount inventory = new ItemStackAmount();
|
||||
private final Set<RecipeId> precessedRecipes = new HashSet<>();
|
||||
private RecipeChainMath math;
|
||||
private Set<RecipeId> topRecipes;
|
||||
private Set<RecipeId> processedRecipes;
|
||||
private List<BookmarkItem> initialItems;
|
||||
|
||||
public RecipeChainIterator(RecipeChainMath math, List<BookmarkItem> initialItems) {
|
||||
this.math = math;
|
||||
this.topRecipes = this.math.outputRecipes.keySet();
|
||||
this.initialItems = new ArrayList<>(initialItems);
|
||||
this.processedRecipes = new HashSet<>(this.topRecipes);
|
||||
}
|
||||
|
||||
public void updateInventory(ItemStack[] mainInventory) {
|
||||
updateInventory(ItemStackAmount.of(Arrays.asList(mainInventory)));
|
||||
}
|
||||
|
||||
public void updateInventory(ItemStackAmount mainInventory) {
|
||||
this.inventory.clear();
|
||||
this.inventory.putAll(mainInventory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<RecipeId, Long> next() {
|
||||
refreshInitialItems(this.math, this.initialItems);
|
||||
this.math.refresh();
|
||||
|
||||
final Set<RecipeId> skipRecipes = new HashSet<>();
|
||||
final Map<RecipeId, Long> rootRecipes = new HashMap<>();
|
||||
final HashMap<BookmarkItem, BookmarkItem> preferredItems = new HashMap<>(this.math.preferredItems);
|
||||
preferredItems.values()
|
||||
.removeIf(item -> item == null || item.amount == 0 || this.precessedRecipes.contains(item.recipeId));
|
||||
preferredItems.keySet().removeIf(item -> item.amount == 0);
|
||||
|
||||
for (Map.Entry<BookmarkItem, BookmarkItem> entry : preferredItems.entrySet()) {
|
||||
final BookmarkItem keyItem = entry.getKey();
|
||||
if (this.topRecipes.contains(keyItem.recipeId) && !skipRecipes.contains(keyItem.recipeId)) {
|
||||
final BookmarkItem item = entry.getValue();
|
||||
|
||||
if (preferredItems.entrySet().stream().anyMatch(
|
||||
pref -> !this.processedRecipes.contains(pref.getKey().recipeId)
|
||||
&& item.equals(pref.getValue()))) {
|
||||
skipRecipes.add(item.recipeId);
|
||||
} else {
|
||||
rootRecipes.put(
|
||||
item.recipeId,
|
||||
Math.max(rootRecipes.getOrDefault(item.recipeId, 0L), item.getMultiplier()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (RecipeId recipeId : skipRecipes) {
|
||||
rootRecipes.remove(recipeId);
|
||||
}
|
||||
|
||||
this.processedRecipes.addAll(rootRecipes.keySet());
|
||||
rootRecipes.values().removeIf(amount -> amount == 0);
|
||||
this.topRecipes = rootRecipes.keySet();
|
||||
this.precessedRecipes.addAll(this.topRecipes);
|
||||
|
||||
return rootRecipes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return !this.topRecipes.isEmpty();
|
||||
}
|
||||
|
||||
private void refreshInitialItems(RecipeChainMath math, List<BookmarkItem> initialItems) {
|
||||
math.initialItems.clear();
|
||||
math.initialItems.addAll(initialItems);
|
||||
|
||||
for (ItemStack stack : this.inventory.values()) {
|
||||
final long invStackSize = this.inventory.getOrDefault(stack, 0L);
|
||||
|
||||
if (invStackSize > 0) {
|
||||
math.initialItems.add(BookmarkItem.of(-1, StackInfo.withAmount(stack, invStackSize)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,296 @@
|
||||
package codechicken.nei.recipe.chain;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import codechicken.nei.ItemStackAmount;
|
||||
import codechicken.nei.bookmark.BookmarkItem;
|
||||
import codechicken.nei.recipe.Recipe;
|
||||
import codechicken.nei.recipe.Recipe.RecipeId;
|
||||
import codechicken.nei.recipe.Recipe.RecipeIngredient;
|
||||
import codechicken.nei.recipe.StackInfo;
|
||||
|
||||
public class RecipeChainMath {
|
||||
|
||||
public final Map<RecipeId, Long> outputRecipes = new HashMap<>();
|
||||
|
||||
public final List<BookmarkItem> initialItems = new ArrayList<>();
|
||||
public final List<BookmarkItem> recipeIngredients = new ArrayList<>();
|
||||
public final List<BookmarkItem> recipeResults = new ArrayList<>();
|
||||
|
||||
public final Map<BookmarkItem, BookmarkItem> preferredItems = new HashMap<>();
|
||||
public final Map<BookmarkItem, Long> requiredAmount = new HashMap<>();
|
||||
|
||||
private RecipeChainMath(List<BookmarkItem> recipeItems, Set<RecipeId> collapsedRecipes) {
|
||||
final Map<RecipeId, Integer> recipeState = new HashMap<>();
|
||||
final Map<RecipeId, Long> multipliers = new HashMap<>();
|
||||
|
||||
for (BookmarkItem item : recipeItems) {
|
||||
if (item.recipeId != null) {
|
||||
recipeState
|
||||
.put(item.recipeId, recipeState.getOrDefault(item.recipeId, 0) | (item.isIngredient ? 1 : 2));
|
||||
}
|
||||
}
|
||||
|
||||
for (BookmarkItem item : recipeItems) {
|
||||
if (recipeState.getOrDefault(item.recipeId, 0) != 3) {
|
||||
this.initialItems.add(item.copy());
|
||||
} else if (item.isIngredient) {
|
||||
this.recipeIngredients.add(item.copyWithAmount(0));
|
||||
} else {
|
||||
this.recipeResults.add(item.copyWithAmount(0));
|
||||
multipliers.put(
|
||||
item.recipeId,
|
||||
Math.max(multipliers.getOrDefault(item.recipeId, 0L), item.getMultiplier()));
|
||||
}
|
||||
}
|
||||
|
||||
for (Map.Entry<RecipeId, Long> entry : multipliers.entrySet()) {
|
||||
if (entry.getValue() > 1 || collapsedRecipes.contains(entry.getKey())) {
|
||||
collectPreferredItems(entry.getKey(), this.preferredItems, new HashSet<>());
|
||||
this.outputRecipes.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
while (true) {
|
||||
Map<BookmarkItem, BookmarkItem> maxReference = Collections.emptyMap();
|
||||
RecipeId maxRecipeId = null;
|
||||
long maxMultiplier = 0;
|
||||
int maxDepth = 0;
|
||||
|
||||
for (Map.Entry<RecipeId, Long> entry : multipliers.entrySet()) {
|
||||
final RecipeId recipeId = entry.getKey();
|
||||
if (!this.outputRecipes.containsKey(recipeId) && this.preferredItems.values().stream()
|
||||
.noneMatch(resItem -> resItem.recipeId.equals(recipeId))) {
|
||||
final Map<BookmarkItem, BookmarkItem> references = new HashMap<>(this.preferredItems);
|
||||
final int depth = collectPreferredItems(recipeId, references, new HashSet<>());
|
||||
|
||||
if (maxDepth < depth || maxDepth == depth && entry.getValue() > maxMultiplier) {
|
||||
maxMultiplier = entry.getValue();
|
||||
maxReference = references;
|
||||
maxRecipeId = recipeId;
|
||||
maxDepth = depth;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (maxReference.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
|
||||
this.preferredItems.putAll(maxReference);
|
||||
this.outputRecipes.put(maxRecipeId, multipliers.get(maxRecipeId));
|
||||
}
|
||||
|
||||
for (Map.Entry<RecipeId, Long> entry : multipliers.entrySet()) {
|
||||
if (!this.outputRecipes.containsKey(entry.getKey()) && this.preferredItems.values().stream()
|
||||
.noneMatch(resItem -> resItem.recipeId.equals(entry.getKey()))) {
|
||||
this.outputRecipes.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
for (Map.Entry<RecipeId, Long> entry : this.outputRecipes.entrySet()) {
|
||||
if (entry.getValue() == 0 && this.preferredItems.values().stream()
|
||||
.noneMatch(prefItem -> prefItem.recipeId.equals(entry.getKey()))) {
|
||||
entry.setValue(1L);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int collectPreferredItems(RecipeId recipeId, Map<BookmarkItem, BookmarkItem> preferredItems,
|
||||
Set<RecipeId> visited) {
|
||||
int maxDepth = 0;
|
||||
visited.add(recipeId);
|
||||
|
||||
for (BookmarkItem ingrItem : this.recipeIngredients) {
|
||||
if (ingrItem.factor > 0 && recipeId.equals(ingrItem.recipeId) && !preferredItems.containsKey(ingrItem)) {
|
||||
BookmarkItem prefItem = null;
|
||||
|
||||
for (BookmarkItem item : this.recipeResults) {
|
||||
if (item.factor > (prefItem == null ? 0 : prefItem.factor) && item.containsItems(ingrItem)
|
||||
&& !visited.contains(item.recipeId)) {
|
||||
prefItem = item;
|
||||
}
|
||||
}
|
||||
|
||||
if (prefItem != null) {
|
||||
preferredItems.put(ingrItem, prefItem);
|
||||
maxDepth = Math
|
||||
.max(maxDepth, collectPreferredItems(prefItem.recipeId, preferredItems, visited) + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
visited.remove(recipeId);
|
||||
return maxDepth;
|
||||
}
|
||||
|
||||
public static RecipeChainMath of(List<BookmarkItem> chainItems, Set<RecipeId> collapsedRecipes) {
|
||||
return new RecipeChainMath(chainItems, collapsedRecipes);
|
||||
}
|
||||
|
||||
public static RecipeChainMath of(Recipe recipe, long multiplier) {
|
||||
final List<BookmarkItem> chainItems = new ArrayList<>();
|
||||
final RecipeId recipeId = recipe.getRecipeId();
|
||||
final ItemStack result = recipe.getResult();
|
||||
|
||||
chainItems.add(BookmarkItem.of(-1, result, StackInfo.getAmount(result), recipeId, false));
|
||||
|
||||
for (RecipeIngredient ingr : recipe.getIngredients()) {
|
||||
chainItems.add(
|
||||
BookmarkItem.of(
|
||||
-1,
|
||||
ingr.getItemStack(),
|
||||
ingr.getAmount(),
|
||||
recipeId,
|
||||
true,
|
||||
BookmarkItem.generatePermutations(ingr.getItemStack(), recipe)));
|
||||
}
|
||||
|
||||
for (BookmarkItem item : chainItems) {
|
||||
item.amount *= multiplier;
|
||||
}
|
||||
|
||||
return new RecipeChainMath(chainItems, Collections.emptySet());
|
||||
}
|
||||
|
||||
public ItemStackAmount getMissedItems() {
|
||||
final ItemStackAmount missedItems = new ItemStackAmount();
|
||||
|
||||
for (BookmarkItem item : this.recipeResults) {
|
||||
long amount = item.amount - this.requiredAmount.getOrDefault(item, 0L);
|
||||
if (amount > 0) {
|
||||
missedItems.add(item.getItemStack(amount));
|
||||
}
|
||||
}
|
||||
|
||||
for (BookmarkItem item : this.recipeIngredients) {
|
||||
long amount = this.requiredAmount.containsKey(this.preferredItems.get(item)) ? 0
|
||||
: this.requiredAmount.getOrDefault(item, item.amount);
|
||||
if (amount > 0) {
|
||||
missedItems.add(item.getItemStack(amount));
|
||||
}
|
||||
}
|
||||
|
||||
for (BookmarkItem item : this.initialItems) {
|
||||
if (this.requiredAmount.getOrDefault(item, -1L) == 0) {
|
||||
missedItems.add(item.getItemStack());
|
||||
}
|
||||
}
|
||||
|
||||
return missedItems;
|
||||
}
|
||||
|
||||
private void resetCalculation() {
|
||||
|
||||
for (BookmarkItem item : this.recipeIngredients) {
|
||||
item.amount = 0;
|
||||
}
|
||||
|
||||
for (BookmarkItem item : this.recipeResults) {
|
||||
item.amount = 0;
|
||||
}
|
||||
|
||||
this.preferredItems.clear();
|
||||
this.requiredAmount.clear();
|
||||
|
||||
for (RecipeId recipeId : this.outputRecipes.keySet()) {
|
||||
collectPreferredItems(recipeId, this.preferredItems, new HashSet<>());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public RecipeChainMath refresh() {
|
||||
resetCalculation();
|
||||
|
||||
for (BookmarkItem prefItem : this.recipeResults) {
|
||||
if (prefItem.factor > 0 && this.outputRecipes.containsKey(prefItem.recipeId)) {
|
||||
final long prefAmount = prefItem.factor * this.outputRecipes.get(prefItem.recipeId);
|
||||
|
||||
this.preferredItems.put(prefItem, prefItem);
|
||||
calculateSuitableRecipe(prefItem, prepareAmount(prefItem, prefAmount), new ArrayList<>());
|
||||
this.preferredItems.remove(prefItem);
|
||||
}
|
||||
}
|
||||
|
||||
for (BookmarkItem prefItem : this.recipeResults) {
|
||||
if (prefItem.factor > 0 && this.outputRecipes.containsKey(prefItem.recipeId)
|
||||
&& this.requiredAmount.containsKey(prefItem)) {
|
||||
final long prefAmount = prefItem.factor * this.outputRecipes.get(prefItem.recipeId);
|
||||
this.requiredAmount.put(prefItem, this.requiredAmount.get(prefItem) - prefAmount);
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
private void prepareIngredients(RecipeId recipeId, long stepShift, List<RecipeId> visited) {
|
||||
for (BookmarkItem item : this.recipeIngredients) {
|
||||
if (item.factor > 0 && recipeId.equals(item.recipeId)) {
|
||||
calculateSuitableRecipe(item, prepareAmount(item, item.factor * stepShift), visited);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void calculateSuitableRecipe(BookmarkItem ingrItem, long ingrAmount, List<RecipeId> visited) {
|
||||
final BookmarkItem prefItem = this.preferredItems.get(ingrItem);
|
||||
|
||||
if (prefItem == null) {
|
||||
this.requiredAmount.put(ingrItem, this.requiredAmount.getOrDefault(ingrItem, 0L) + ingrAmount);
|
||||
} else if (visited.contains(prefItem.recipeId)) {
|
||||
this.requiredAmount.put(prefItem, this.requiredAmount.getOrDefault(prefItem, 0L) + ingrAmount);
|
||||
} else {
|
||||
this.requiredAmount.put(prefItem, this.requiredAmount.getOrDefault(prefItem, 0L) + ingrAmount);
|
||||
final long shift = (long) Math
|
||||
.ceil((this.requiredAmount.get(prefItem) - prefItem.amount) / (double) prefItem.factor);
|
||||
|
||||
if (shift > 0) {
|
||||
addShift(prefItem.recipeId, shift);
|
||||
|
||||
visited.add(prefItem.recipeId);
|
||||
prepareIngredients(prefItem.recipeId, shift, visited);
|
||||
visited.remove(prefItem.recipeId);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private long prepareAmount(BookmarkItem ingrItem, long ingrAmount) {
|
||||
if (ingrAmount == 0) return 0;
|
||||
|
||||
for (BookmarkItem item : this.initialItems) {
|
||||
if (item.containsItems(ingrItem)) {
|
||||
long initAmount = Math.min(ingrAmount, item.amount - this.requiredAmount.getOrDefault(item, 0L));
|
||||
if (initAmount > 0) {
|
||||
this.requiredAmount.put(item, this.requiredAmount.getOrDefault(item, 0L) + initAmount);
|
||||
ingrAmount -= initAmount;
|
||||
if (ingrAmount == 0) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ingrAmount;
|
||||
}
|
||||
|
||||
private void addShift(RecipeId recipeId, long shift) {
|
||||
for (BookmarkItem item : this.recipeIngredients) {
|
||||
if (recipeId.equals(item.recipeId)) {
|
||||
item.amount += item.factor * shift;
|
||||
}
|
||||
}
|
||||
|
||||
for (BookmarkItem item : this.recipeResults) {
|
||||
if (recipeId.equals(item.recipeId)) {
|
||||
item.amount += item.factor * shift;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
package codechicken.nei.recipe.chain;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
|
||||
import codechicken.lib.gui.GuiDraw;
|
||||
import codechicken.lib.gui.GuiDraw.ITooltipLineHandler;
|
||||
import codechicken.nei.ItemSorter;
|
||||
import codechicken.nei.ItemStackAmount;
|
||||
import codechicken.nei.ItemsTooltipLineHandler;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.NEIClientUtils;
|
||||
import codechicken.nei.bookmark.BookmarkItem;
|
||||
import codechicken.nei.recipe.StackInfo;
|
||||
|
||||
public class RecipeChainTooltipLineHandler implements ITooltipLineHandler {
|
||||
|
||||
public final int groupId;
|
||||
public final boolean crafting;
|
||||
protected final RecipeChainMath math;
|
||||
protected final List<BookmarkItem> initialItems;
|
||||
|
||||
protected ItemsTooltipLineHandler available;
|
||||
protected ItemsTooltipLineHandler inputs;
|
||||
protected ItemsTooltipLineHandler outputs;
|
||||
protected ItemsTooltipLineHandler remainder;
|
||||
protected boolean lastShiftKey = false;
|
||||
|
||||
protected Dimension size = new Dimension();
|
||||
|
||||
public RecipeChainTooltipLineHandler(int groupId, boolean crafting, RecipeChainMath math) {
|
||||
this.groupId = groupId;
|
||||
this.crafting = crafting;
|
||||
this.math = math;
|
||||
this.initialItems = new ArrayList<>(this.math.initialItems);
|
||||
}
|
||||
|
||||
private void onUpdate() {
|
||||
final List<ItemStack> available = new ArrayList<>();
|
||||
final List<ItemStack> inputs = new ArrayList<>();
|
||||
final List<ItemStack> outputs = new ArrayList<>();
|
||||
final List<ItemStack> remainder = new ArrayList<>();
|
||||
final ItemStackAmount inventory = new ItemStackAmount();
|
||||
|
||||
if (lastShiftKey) {
|
||||
inventory.addAll(Arrays.asList(NEIClientUtils.mc().thePlayer.inventory.mainInventory));
|
||||
}
|
||||
|
||||
if (!this.math.outputRecipes.isEmpty()) {
|
||||
this.math.initialItems.clear();
|
||||
|
||||
if (lastShiftKey) {
|
||||
for (ItemStack stack : inventory.values()) {
|
||||
final long invStackSize = inventory.get(stack);
|
||||
|
||||
if (invStackSize > 0) {
|
||||
this.math.initialItems.add(BookmarkItem.of(-1, stack.copy()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.math.initialItems.addAll(initialItems);
|
||||
}
|
||||
|
||||
this.math.refresh();
|
||||
|
||||
for (BookmarkItem item : math.initialItems) {
|
||||
final long amount = math.requiredAmount.getOrDefault(item, 0L);
|
||||
|
||||
if (amount > 0) {
|
||||
if (lastShiftKey) {
|
||||
available.add(item.getItemStack(amount));
|
||||
} else {
|
||||
inputs.add(item.getItemStack(amount));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (BookmarkItem item : math.recipeIngredients) {
|
||||
final long amount = math.requiredAmount.containsKey(math.preferredItems.get(item)) ? 0
|
||||
: math.requiredAmount.getOrDefault(item, item.amount);
|
||||
|
||||
if (amount > 0) {
|
||||
inputs.add(item.getItemStack(amount));
|
||||
}
|
||||
}
|
||||
|
||||
for (BookmarkItem item : math.recipeResults) {
|
||||
final long amount = item.amount - math.requiredAmount.getOrDefault(item, 0L);
|
||||
|
||||
if (amount > 0) {
|
||||
if (math.outputRecipes.containsKey(item.recipeId)) {
|
||||
outputs.add(item.getItemStack(amount));
|
||||
} else if (lastShiftKey) {
|
||||
remainder.add(item.getItemStack(amount));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else if (lastShiftKey) {
|
||||
|
||||
for (BookmarkItem item : this.math.initialItems) {
|
||||
if (inventory.contains(item.itemStack)) {
|
||||
final long invAmount = inventory.get(item.itemStack) * item.fluidCellAmount;
|
||||
|
||||
if ((item.amount - invAmount) > 0) {
|
||||
inputs.add(item.getItemStack(item.amount - invAmount));
|
||||
}
|
||||
|
||||
if (Math.min(item.amount, invAmount) > 0) {
|
||||
available.add(item.getItemStack(Math.min(item.amount, invAmount)));
|
||||
}
|
||||
|
||||
} else {
|
||||
inputs.add(item.getItemStack());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
inputs.sort(
|
||||
Comparator.comparing((ItemStack stack) -> StackInfo.getFluid(stack) != null)
|
||||
.thenComparing(ItemSorter.instance));
|
||||
outputs.sort(
|
||||
Comparator.comparing((ItemStack stack) -> StackInfo.getFluid(stack) != null)
|
||||
.thenComparing(ItemSorter.instance));
|
||||
remainder.sort(
|
||||
Comparator.comparing((ItemStack stack) -> StackInfo.getFluid(stack) != null)
|
||||
.thenComparing(ItemSorter.instance));
|
||||
|
||||
this.inputs = new ItemsTooltipLineHandler(
|
||||
lastShiftKey ? NEIClientUtils.translate("bookmark.crafting_chain.missing")
|
||||
: NEIClientUtils.translate("bookmark.crafting_chain.input"),
|
||||
inputs,
|
||||
true,
|
||||
Integer.MAX_VALUE);
|
||||
|
||||
this.available = new ItemsTooltipLineHandler(
|
||||
NEIClientUtils.translate("bookmark.crafting_chain.available"),
|
||||
available,
|
||||
true,
|
||||
Integer.MAX_VALUE);
|
||||
|
||||
this.outputs = new ItemsTooltipLineHandler(
|
||||
NEIClientUtils.translate("bookmark.crafting_chain.output"),
|
||||
outputs,
|
||||
true,
|
||||
Integer.MAX_VALUE);
|
||||
|
||||
this.remainder = new ItemsTooltipLineHandler(
|
||||
NEIClientUtils.translate("bookmark.crafting_chain.remainder"),
|
||||
remainder,
|
||||
true,
|
||||
Integer.MAX_VALUE);
|
||||
|
||||
if (lastShiftKey) {
|
||||
this.inputs.setLabelColor(EnumChatFormatting.RED);
|
||||
this.available.setLabelColor(EnumChatFormatting.GREEN);
|
||||
}
|
||||
|
||||
if (!this.inputs.isEmpty() || !this.outputs.isEmpty()
|
||||
|| !this.remainder.isEmpty()
|
||||
|| !this.available.isEmpty()) {
|
||||
|
||||
if (!this.math.outputRecipes.isEmpty()) {
|
||||
this.size.height = 2 + GuiDraw.fontRenderer.FONT_HEIGHT;
|
||||
}
|
||||
|
||||
this.size.width = Math.max(
|
||||
this.inputs.getSize().width,
|
||||
Math.max(
|
||||
this.outputs.getSize().width,
|
||||
Math.max(this.remainder.getSize().width, this.available.getSize().width)));
|
||||
|
||||
this.size.height += this.inputs.getSize().height + this.outputs.getSize().height
|
||||
+ this.remainder.getSize().height
|
||||
+ this.available.getSize().height;
|
||||
} else {
|
||||
this.size.height = this.size.width = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getSize() {
|
||||
if (this.lastShiftKey != (this.lastShiftKey = NEIClientUtils.shiftKey()) || this.outputs == null) {
|
||||
onUpdate();
|
||||
}
|
||||
return this.size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(int x, int y) {
|
||||
if (this.size.height == 0) return;
|
||||
|
||||
if (!this.math.outputRecipes.isEmpty()) {
|
||||
GuiDraw.fontRenderer.drawStringWithShadow(
|
||||
EnumChatFormatting.AQUA + NEIClientUtils.translate("bookmark.crafting_chain"),
|
||||
x,
|
||||
y + 2,
|
||||
0xee555555);
|
||||
|
||||
y += 2 + GuiDraw.fontRenderer.FONT_HEIGHT;
|
||||
}
|
||||
|
||||
if (NEIClientConfig.recipeChainDir() == 0) {
|
||||
|
||||
if (!this.inputs.isEmpty()) {
|
||||
this.inputs.draw(x, y);
|
||||
y += this.inputs.getSize().height;
|
||||
}
|
||||
|
||||
if (!this.available.isEmpty()) {
|
||||
this.available.draw(x, y);
|
||||
y += this.available.getSize().height;
|
||||
}
|
||||
|
||||
if (!this.outputs.isEmpty()) {
|
||||
this.outputs.draw(x, y);
|
||||
y += this.outputs.getSize().height;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if (!this.outputs.isEmpty()) {
|
||||
this.outputs.draw(x, y);
|
||||
y += this.outputs.getSize().height;
|
||||
}
|
||||
|
||||
if (!this.inputs.isEmpty()) {
|
||||
this.inputs.draw(x, y);
|
||||
y += this.inputs.getSize().height;
|
||||
}
|
||||
|
||||
if (!this.available.isEmpty()) {
|
||||
this.available.draw(x, y);
|
||||
y += this.available.getSize().height;
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.remainder.isEmpty()) {
|
||||
this.remainder.draw(x, y);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user