2014-04-29 10:54:20 +10:00
|
|
|
package codechicken.nei.recipe;
|
|
|
|
|
|
2019-12-24 13:37:41 -08:00
|
|
|
import codechicken.nei.ItemPanels;
|
2022-05-16 23:57:00 +08:00
|
|
|
import codechicken.nei.LayoutManager;
|
2014-04-29 10:54:20 +10:00
|
|
|
import codechicken.nei.NEIClientConfig;
|
|
|
|
|
import codechicken.nei.NEIClientUtils;
|
2022-05-16 23:57:00 +08:00
|
|
|
import codechicken.nei.PositionedStack;
|
2014-04-29 10:54:20 +10:00
|
|
|
import codechicken.nei.guihook.GuiContainerManager;
|
|
|
|
|
import codechicken.nei.guihook.IContainerInputHandler;
|
2022-06-24 12:32:13 +01:00
|
|
|
import java.util.List;
|
2014-04-29 10:54:20 +10:00
|
|
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
|
2022-05-16 23:57:00 +08:00
|
|
|
public class RecipeItemInputHandler implements IContainerInputHandler {
|
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) {
|
2014-04-29 10:54:20 +10:00
|
|
|
ItemStack stackover = GuiContainerManager.getStackMouseOver(gui);
|
2022-05-16 23:57:00 +08:00
|
|
|
if (stackover == null) return false;
|
2021-09-30 22:17:14 -06:00
|
|
|
|
2022-05-16 23:57:00 +08:00
|
|
|
if (keyCode == NEIClientConfig.getKeyBinding("gui.recipe"))
|
2014-04-29 10:54:20 +10:00
|
|
|
return GuiCraftingRecipe.openRecipeGui("item", stackover.copy());
|
2019-12-24 13:37:41 -08:00
|
|
|
|
2022-05-16 23:57:00 +08:00
|
|
|
if (keyCode == NEIClientConfig.getKeyBinding("gui.usage"))
|
2021-09-30 22:17:14 -06:00
|
|
|
return GuiUsageRecipe.openRecipeGui("item", stackover.copy());
|
|
|
|
|
|
2022-01-02 23:30:54 +02:00
|
|
|
if (keyCode == NEIClientConfig.getKeyBinding("gui.bookmark")) {
|
2019-12-24 13:37:41 -08:00
|
|
|
NEIClientConfig.logger.debug("Adding or removing {} from bookmarks", stackover.getDisplayName());
|
2022-01-02 23:30:54 +02:00
|
|
|
List<PositionedStack> ingredients = null;
|
|
|
|
|
String handlerName = "";
|
2021-11-22 05:31:02 +02:00
|
|
|
|
2022-01-02 23:30:54 +02:00
|
|
|
if (gui instanceof GuiRecipe && NEIClientConfig.saveCurrentRecipeInBookmarksEnabled()) {
|
2022-06-29 14:18:48 -04:00
|
|
|
ingredients = ((GuiRecipe<?>) gui).getFocusedRecipeIngredients();
|
|
|
|
|
handlerName = ((GuiRecipe<?>) gui).getHandlerName();
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
2021-11-22 05:31:02 +02:00
|
|
|
|
2022-01-02 23:30:54 +02:00
|
|
|
ItemPanels.bookmarkPanel.addOrRemoveItem(stackover.copy(), handlerName, ingredients);
|
2019-12-24 13:37:41 -08:00
|
|
|
}
|
|
|
|
|
|
2022-05-16 23:57:00 +08:00
|
|
|
if (keyCode == NEIClientConfig.getKeyBinding("gui.overlay")) {
|
|
|
|
|
if (NEIClientUtils.controlKey()) {
|
|
|
|
|
LayoutManager.overlayRenderer = null;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (!NEIClientConfig.saveCurrentRecipeInBookmarksEnabled()) return false;
|
|
|
|
|
final BookmarkRecipeId mouseOverRecipeId = ItemPanels.bookmarkPanel.getBookmarkMouseOverRecipeId();
|
2022-06-24 12:32:13 +01:00
|
|
|
if (mouseOverRecipeId == null
|
|
|
|
|
|| mouseOverRecipeId.ingredients == null
|
|
|
|
|
|| mouseOverRecipeId.ingredients.isEmpty()) return false;
|
2022-05-16 23:57:00 +08:00
|
|
|
return GuiCraftingRecipe.openRecipeGui("item", true, stackover.copy());
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2022-05-16 23:57:00 +08:00
|
|
|
public boolean mouseClicked(GuiContainer gui, int mousex, int mousey, int button) {
|
2014-04-29 10:54:20 +10:00
|
|
|
ItemStack stackover = GuiContainerManager.getStackMouseOver(gui);
|
2020-02-02 09:50:22 -08:00
|
|
|
|
2022-05-16 23:57:00 +08:00
|
|
|
if (stackover == null) return false;
|
2020-02-02 09:50:22 -08:00
|
|
|
|
2022-05-16 23:57:00 +08:00
|
|
|
if (!(gui instanceof GuiRecipe)) return false;
|
2020-02-02 10:44:48 -08:00
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
// disabled open recipe gui if hold shift (player have move recipe)
|
|
|
|
|
if (button == 0
|
|
|
|
|
&& ItemPanels.bookmarkPanel.getStackMouseOver(mousex, mousey) != null
|
|
|
|
|
&& NEIClientUtils.shiftKey()) {
|
2021-11-22 05:31:02 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-16 23:57:00 +08:00
|
|
|
if (button == 0) return GuiCraftingRecipe.openRecipeGui("item", stackover.copy());
|
2014-04-29 10:54:20 +10:00
|
|
|
|
2022-05-16 23:57:00 +08:00
|
|
|
if (button == 1) return GuiUsageRecipe.openRecipeGui("item", stackover.copy());
|
2021-11-22 05:31:02 +02:00
|
|
|
|
2014-04-29 10:54:20 +10:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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
|
|
|
}
|