Skip to content

Commit

Permalink
Add RecipeItemInputHandler#lastKeyTyped(ItemStack)
Browse files Browse the repository at this point in the history
  • Loading branch information
slprime committed Aug 21, 2022
1 parent 0293706 commit 99acc6b
Showing 1 changed file with 35 additions and 24 deletions.
59 changes: 35 additions & 24 deletions src/main/java/codechicken/nei/recipe/RecipeItemInputHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import codechicken.nei.ItemPanels;
import codechicken.nei.LayoutManager;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.NEIClientUtils;
import codechicken.nei.PositionedStack;
import codechicken.nei.guihook.GuiContainerManager;
import codechicken.nei.guihook.IContainerInputHandler;
Expand All @@ -12,27 +13,24 @@

public class RecipeItemInputHandler implements IContainerInputHandler {

@Override
public boolean lastKeyTyped(GuiContainer gui, char keyChar, int keyCode) {
public static boolean lastKeyTyped(ItemStack stackover) {

if (NEIClientConfig.isKeyHashDown("gui.overlay_hide")) {
return hideOverlayRecipe();
}

ItemStack stackover = GuiContainerManager.getStackMouseOver(gui);

if (stackover == null) {
return false;
}

stackover = stackover.copy();

if (NEIClientConfig.isKeyHashDown("gui.overlay")) {
return openOverlayRecipe(gui, stackover, false);
return openOverlayRecipe(stackover, false);
}

if (NEIClientConfig.isKeyHashDown("gui.overlay_use")) {
return openOverlayRecipe(gui, stackover, true);
return openOverlayRecipe(stackover, true);
}

if (NEIClientConfig.isKeyHashDown("gui.recipe")) {
Expand All @@ -44,44 +42,40 @@ public boolean lastKeyTyped(GuiContainer gui, char keyChar, int keyCode) {
}

if (NEIClientConfig.isKeyHashDown("gui.bookmark")) {
return saveRecipeInBookmark(gui, stackover, false, false);
return saveRecipeInBookmark(stackover, false, false);
}

if (NEIClientConfig.isKeyHashDown("gui.bookmark_recipe")) {
return saveRecipeInBookmark(gui, stackover, true, false);
return saveRecipeInBookmark(stackover, true, false);
}

if (NEIClientConfig.isKeyHashDown("gui.bookmark_count")) {
return saveRecipeInBookmark(gui, stackover, false, true);
return saveRecipeInBookmark(stackover, false, true);
}

if (NEIClientConfig.isKeyHashDown("gui.bookmark_recipe_count")) {
return saveRecipeInBookmark(gui, stackover, true, true);
return saveRecipeInBookmark(stackover, true, true);
}

return false;
}

@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)) return false;

ItemStack stackover = GuiContainerManager.getStackMouseOver(gui);
public static boolean mouseClicked(ItemStack stackover, int button) {

if (stackover != null) {
stackover = stackover.copy();

if (button == 0) {
return GuiCraftingRecipe.openRecipeGui("item", stackover.copy());
return GuiCraftingRecipe.openRecipeGui("item", stackover);
} else if (button == 1) {
return GuiUsageRecipe.openRecipeGui("item", stackover.copy());
return GuiUsageRecipe.openRecipeGui("item", stackover);
}
}

return false;
}

private boolean hideOverlayRecipe() {
private static boolean hideOverlayRecipe() {

if (LayoutManager.overlayRenderer != null) {
LayoutManager.overlayRenderer = null;
Expand All @@ -91,19 +85,20 @@ private boolean hideOverlayRecipe() {
return false;
}

private boolean openOverlayRecipe(GuiContainer gui, ItemStack stack, boolean shift) {
private static boolean openOverlayRecipe(ItemStack stack, boolean shift) {
final GuiContainer gui = NEIClientUtils.getGuiContainer();

if (gui instanceof GuiRecipe) {
if (gui == null || gui instanceof GuiRecipe) {
return false;
}

return GuiCraftingRecipe.openRecipeGui("item", true, shift, stack);
}

private boolean saveRecipeInBookmark(
GuiContainer gui, ItemStack stack, boolean saveIngredients, boolean saveStackSize) {
private static boolean saveRecipeInBookmark(ItemStack stack, boolean saveIngredients, boolean saveStackSize) {

if (stack != null) {
final GuiContainer gui = NEIClientUtils.getGuiContainer();
List<PositionedStack> ingredients = null;
String handlerName = "";

Expand All @@ -119,6 +114,22 @@ private boolean saveRecipeInBookmark(
return false;
}

@Override
public boolean lastKeyTyped(GuiContainer gui, char keyChar, int keyCode) {
return lastKeyTyped(GuiContainerManager.getStackMouseOver(gui));
}

@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)) return false;

ItemStack stackover = GuiContainerManager.getStackMouseOver(gui);

return mouseClicked(stackover, button);
}

@Override
public void onKeyTyped(GuiContainer gui, char keyChar, int keyID) {}

Expand Down

0 comments on commit 99acc6b

Please sign in to comment.