2014-04-29 10:54:20 +10:00
|
|
|
package codechicken.nei.recipe;
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
import java.util.List;
|
2025-01-25 21:16:28 +02:00
|
|
|
import java.util.Map;
|
|
|
|
|
|
2023-09-25 00:35:24 +02:00
|
|
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
2025-04-24 18:48:40 +03:00
|
|
|
import net.minecraft.item.ItemStack;
|
2023-09-25 00:35:24 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
import codechicken.lib.gui.GuiDraw;
|
|
|
|
|
import codechicken.lib.vec.Rectangle4i;
|
|
|
|
|
import codechicken.nei.BookmarkPanel.BookmarkViewMode;
|
|
|
|
|
import codechicken.nei.FavoriteRecipes;
|
2019-12-24 13:37:41 -08:00
|
|
|
import codechicken.nei.ItemPanels;
|
2025-08-22 14:58:41 +03:00
|
|
|
import codechicken.nei.ItemsGrid.ItemsGridSlot;
|
2025-04-24 18:48:40 +03:00
|
|
|
import codechicken.nei.NEIClientConfig;
|
2022-08-21 17:33:52 +03:00
|
|
|
import codechicken.nei.api.ShortcutInputHandler;
|
2025-04-24 18:48:40 +03:00
|
|
|
import codechicken.nei.bookmark.BookmarksGridSlot;
|
2014-04-29 10:54:20 +10:00
|
|
|
import codechicken.nei.guihook.GuiContainerManager;
|
|
|
|
|
import codechicken.nei.guihook.IContainerInputHandler;
|
2025-01-25 21:16:28 +02:00
|
|
|
import codechicken.nei.guihook.IContainerTooltipHandler;
|
2025-04-24 18:48:40 +03:00
|
|
|
import codechicken.nei.recipe.Recipe.RecipeId;
|
2025-01-25 21:16:28 +02:00
|
|
|
|
|
|
|
|
public class RecipeItemInputHandler implements IContainerInputHandler, IContainerTooltipHandler {
|
2014-04-29 10:54:20 +10:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
protected RecipeTooltipLineHandler recipeTooltipLineHandler = null;
|
|
|
|
|
|
2025-01-25 21:16:28 +02:00
|
|
|
public static void load() {
|
|
|
|
|
RecipeItemInputHandler recipeHandler = new RecipeItemInputHandler();
|
|
|
|
|
GuiContainerManager.addInputHandler(recipeHandler);
|
|
|
|
|
GuiContainerManager.addTooltipHandler(recipeHandler);
|
|
|
|
|
}
|
2022-08-19 15:03:42 +03:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
@Override
|
2022-05-16 23:57:00 +08:00
|
|
|
public boolean lastKeyTyped(GuiContainer gui, char keyChar, int keyCode) {
|
2022-08-21 17:33:52 +03:00
|
|
|
return ShortcutInputHandler.handleKeyEvent(GuiContainerManager.getStackMouseOver(gui));
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2022-05-16 23:57:00 +08:00
|
|
|
public boolean mouseClicked(GuiContainer gui, int mousex, int mousey, int button) {
|
2025-10-12 19:39:21 +03:00
|
|
|
return false;
|
2025-01-25 21:16:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Map<String, String> handleHotkeys(GuiContainer gui, int mousex, int mousey, Map<String, String> hotkeys) {
|
|
|
|
|
|
2025-10-12 19:39:21 +03:00
|
|
|
if (gui instanceof GuiRecipe || ItemPanels.itemPanel.containsWithSubpanels(mousex, mousey)
|
|
|
|
|
|| ItemPanels.bookmarkPanel.contains(mousex, mousey)) {
|
2025-01-25 21:16:28 +02:00
|
|
|
hotkeys.putAll(
|
2025-10-12 19:39:21 +03:00
|
|
|
ShortcutInputHandler.handleHotkeys(mousex, mousey, GuiContainerManager.getStackMouseOver(gui)));
|
2025-01-25 21:16:28 +02:00
|
|
|
}
|
2020-02-02 09:50:22 -08:00
|
|
|
|
2025-01-25 21:16:28 +02:00
|
|
|
return hotkeys;
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
@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;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-22 14:58:41 +03:00
|
|
|
if (NEIClientConfig.showRecipeTooltipInPanel()) {
|
|
|
|
|
ItemsGridSlot panelSlot = ItemPanels.itemPanel.getSlotMouseOver(mousex, mousey);
|
|
|
|
|
|
|
|
|
|
if (panelSlot == null) {
|
|
|
|
|
panelSlot = ItemPanels.itemPanel.historyPanel.getSlotMouseOver(mousex, mousey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (panelSlot == null) {
|
|
|
|
|
panelSlot = ItemPanels.itemPanel.craftablesPanel.getSlotMouseOver(mousex, mousey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (panelSlot != null) {
|
|
|
|
|
return panelSlot.getRecipeId();
|
|
|
|
|
}
|
2025-04-24 18:48:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
@Override
|
2022-06-24 12:32:13 +01:00
|
|
|
public void onKeyTyped(GuiContainer gui, char keyChar, int keyID) {}
|
2014-04-29 10:54:20 +10:00
|
|
|
|
|
|
|
|
@Override
|
2022-06-24 12:32:13 +01:00
|
|
|
public void onMouseClicked(GuiContainer gui, int mousex, int mousey, int button) {}
|
2014-04-29 10:54:20 +10:00
|
|
|
|
|
|
|
|
@Override
|
2022-06-24 12:32:13 +01:00
|
|
|
public void onMouseUp(GuiContainer gui, int mousex, int mousey, int button) {}
|
2014-04-29 10:54:20 +10:00
|
|
|
|
|
|
|
|
@Override
|
2022-05-16 23:57:00 +08:00
|
|
|
public boolean keyTyped(GuiContainer gui, char keyChar, int keyID) {
|
2014-04-29 10:54:20 +10:00
|
|
|
return false;
|
|
|
|
|
}
|
2021-11-22 05:31:02 +02:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
@Override
|
2022-05-16 23:57:00 +08:00
|
|
|
public boolean mouseScrolled(GuiContainer gui, int mousex, int mousey, int scrolled) {
|
2014-04-29 10:54:20 +10:00
|
|
|
return false;
|
|
|
|
|
}
|
2021-11-22 05:31:02 +02:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
@Override
|
2022-06-24 12:32:13 +01:00
|
|
|
public void onMouseScrolled(GuiContainer gui, int mousex, int mousey, int scrolled) {}
|
2021-11-22 05:31:02 +02:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
@Override
|
2022-06-24 12:32:13 +01:00
|
|
|
public void onMouseDragged(GuiContainer gui, int mousex, int mousey, int button, long heldTime) {}
|
2014-04-29 10:54:20 +10:00
|
|
|
}
|