2022-08-21 17:33:52 +03:00
|
|
|
package codechicken.nei.api;
|
|
|
|
|
|
2024-02-04 14:09:24 +02:00
|
|
|
import static codechicken.lib.gui.GuiDraw.getMousePosition;
|
|
|
|
|
|
|
|
|
|
import java.awt.Point;
|
2024-02-21 18:12:28 +02:00
|
|
|
import java.awt.Toolkit;
|
|
|
|
|
import java.awt.datatransfer.StringSelection;
|
2023-09-25 00:35:24 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
2024-02-21 18:12:28 +02:00
|
|
|
import net.minecraftforge.oredict.OreDictionary;
|
2023-09-25 00:35:24 +02:00
|
|
|
|
|
|
|
|
import org.lwjgl.input.Mouse;
|
|
|
|
|
|
2024-02-04 14:09:24 +02:00
|
|
|
import codechicken.nei.ItemPanel.ItemPanelSlot;
|
2022-08-21 17:33:52 +03:00
|
|
|
import codechicken.nei.ItemPanels;
|
|
|
|
|
import codechicken.nei.LayoutManager;
|
|
|
|
|
import codechicken.nei.NEIClientConfig;
|
|
|
|
|
import codechicken.nei.NEIClientUtils;
|
|
|
|
|
import codechicken.nei.PositionedStack;
|
2024-02-04 14:09:24 +02:00
|
|
|
import codechicken.nei.recipe.BookmarkRecipeId;
|
2022-08-21 17:33:52 +03:00
|
|
|
import codechicken.nei.recipe.GuiCraftingRecipe;
|
|
|
|
|
import codechicken.nei.recipe.GuiRecipe;
|
|
|
|
|
import codechicken.nei.recipe.GuiUsageRecipe;
|
|
|
|
|
|
|
|
|
|
public abstract class ShortcutInputHandler {
|
|
|
|
|
|
|
|
|
|
public static boolean handleKeyEvent(ItemStack stackover) {
|
|
|
|
|
|
2023-07-16 09:00:35 +01:00
|
|
|
if (!NEIClientConfig.isLoaded()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-21 17:33:52 +03:00
|
|
|
if (NEIClientConfig.isKeyHashDown("gui.overlay_hide")) {
|
|
|
|
|
return hideOverlayRecipe();
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-04 14:09:24 +02:00
|
|
|
if (NEIClientConfig.isKeyHashDown("gui.bookmark_pull_items")) {
|
|
|
|
|
return ItemPanels.bookmarkPanel.pullBookmarkItems(ItemPanels.bookmarkPanel.getHoveredGroupId(true), false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (NEIClientConfig.isKeyHashDown("gui.bookmark_pull_items_ingredients")) {
|
|
|
|
|
return ItemPanels.bookmarkPanel.pullBookmarkItems(ItemPanels.bookmarkPanel.getHoveredGroupId(true), true);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-17 23:24:27 +03:00
|
|
|
if (stackover == null && NEIClientConfig.isKeyHashDown("gui.remove_recipe")) {
|
2024-02-04 14:09:24 +02:00
|
|
|
final int groupId = ItemPanels.bookmarkPanel.getHoveredGroupId(true);
|
|
|
|
|
|
|
|
|
|
if (groupId != -1) {
|
|
|
|
|
ItemPanels.bookmarkPanel.removeGroup(groupId);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-21 17:33:52 +03:00
|
|
|
if (stackover == null) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stackover = stackover.copy();
|
|
|
|
|
|
|
|
|
|
if (NEIClientConfig.isKeyHashDown("gui.overlay")) {
|
|
|
|
|
return openOverlayRecipe(stackover, false);
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-21 18:12:28 +02:00
|
|
|
if (NEIClientConfig.isKeyHashDown("gui.copy_name")) {
|
|
|
|
|
return copyItemStackName(stackover);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (NEIClientConfig.isKeyHashDown("gui.copy_oredict")) {
|
|
|
|
|
return copyItemStackOreDictionary(stackover);
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-21 17:33:52 +03:00
|
|
|
if (NEIClientConfig.isKeyHashDown("gui.overlay_use")) {
|
|
|
|
|
return openOverlayRecipe(stackover, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (NEIClientConfig.isKeyHashDown("gui.recipe")) {
|
|
|
|
|
return GuiCraftingRecipe.openRecipeGui("item", stackover);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (NEIClientConfig.isKeyHashDown("gui.usage")) {
|
|
|
|
|
return GuiUsageRecipe.openRecipeGui("item", stackover);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (NEIClientConfig.isKeyHashDown("gui.bookmark")) {
|
|
|
|
|
return saveRecipeInBookmark(stackover, false, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (NEIClientConfig.isKeyHashDown("gui.bookmark_recipe")) {
|
|
|
|
|
return saveRecipeInBookmark(stackover, true, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (NEIClientConfig.isKeyHashDown("gui.bookmark_count")) {
|
|
|
|
|
return saveRecipeInBookmark(stackover, false, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (NEIClientConfig.isKeyHashDown("gui.bookmark_recipe_count")) {
|
|
|
|
|
return saveRecipeInBookmark(stackover, true, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean handleMouseClick(ItemStack stackover) {
|
|
|
|
|
|
2023-07-16 09:00:35 +01:00
|
|
|
if (!NEIClientConfig.isLoaded()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-21 17:33:52 +03:00
|
|
|
if (stackover != null) {
|
|
|
|
|
final int button = Mouse.getEventButton();
|
|
|
|
|
|
|
|
|
|
if (button == 0) {
|
|
|
|
|
return GuiCraftingRecipe.openRecipeGui("item", stackover);
|
|
|
|
|
} else if (button == 1) {
|
|
|
|
|
return GuiUsageRecipe.openRecipeGui("item", stackover);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static boolean hideOverlayRecipe() {
|
|
|
|
|
|
|
|
|
|
if (LayoutManager.overlayRenderer != null) {
|
|
|
|
|
LayoutManager.overlayRenderer = null;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-21 18:12:28 +02:00
|
|
|
private static boolean copyItemStackName(ItemStack stackover) {
|
|
|
|
|
Toolkit.getDefaultToolkit().getSystemClipboard()
|
|
|
|
|
.setContents(new StringSelection(stackover.getDisplayName()), null);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static boolean copyItemStackOreDictionary(ItemStack stackover) {
|
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
for (int id : OreDictionary.getOreIDs(stackover)) {
|
|
|
|
|
String oreDictionaryName = OreDictionary.getOreName(id);
|
|
|
|
|
if (!"Unknown".equals(oreDictionaryName)) {
|
|
|
|
|
builder.append(oreDictionaryName).append(",");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (builder.length() > 0) {
|
|
|
|
|
builder.deleteCharAt(builder.length() - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(builder.toString()), null);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-04 14:09:24 +02:00
|
|
|
private static boolean openOverlayRecipe(ItemStack stackover, boolean shift) {
|
2022-08-21 17:33:52 +03:00
|
|
|
final GuiContainer gui = NEIClientUtils.getGuiContainer();
|
|
|
|
|
|
|
|
|
|
if (gui == null || gui instanceof GuiRecipe) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-04 14:09:24 +02:00
|
|
|
final Point mouseover = getMousePosition();
|
|
|
|
|
ItemPanelSlot panelSlot = ItemPanels.bookmarkPanel.getSlotMouseOver(mouseover.x, mouseover.y);
|
|
|
|
|
BookmarkRecipeId recipeId = null;
|
|
|
|
|
|
|
|
|
|
if (panelSlot != null) {
|
|
|
|
|
recipeId = ItemPanels.bookmarkPanel.getBookmarkRecipeId(panelSlot.slotIndex);
|
|
|
|
|
} else {
|
|
|
|
|
recipeId = ItemPanels.bookmarkPanel.getBookmarkRecipeId(stackover);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (recipeId != null) {
|
|
|
|
|
return GuiCraftingRecipe.overlayRecipe(stackover, recipeId, shift);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
2022-08-21 17:33:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static boolean saveRecipeInBookmark(ItemStack stack, boolean saveIngredients, boolean saveStackSize) {
|
|
|
|
|
|
|
|
|
|
if (stack != null) {
|
|
|
|
|
final GuiContainer gui = NEIClientUtils.getGuiContainer();
|
|
|
|
|
List<PositionedStack> ingredients = null;
|
|
|
|
|
String handlerName = "";
|
|
|
|
|
|
|
|
|
|
if (gui instanceof GuiRecipe) {
|
|
|
|
|
ingredients = ((GuiRecipe<?>) gui).getFocusedRecipeIngredients();
|
|
|
|
|
handlerName = ((GuiRecipe<?>) gui).getHandlerName();
|
2022-10-13 21:49:43 +03:00
|
|
|
stack.stackSize = ((GuiRecipe<?>) gui).prepareFocusedRecipeResultStackSize(stack);
|
2022-08-21 17:33:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ItemPanels.bookmarkPanel.addOrRemoveItem(stack, handlerName, ingredients, saveIngredients, saveStackSize);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2024-02-04 14:09:24 +02:00
|
|
|
|
2022-08-21 17:33:52 +03:00
|
|
|
}
|