Compare commits

...
Author SHA1 Message Date
firenoo b64d104d7e README.md: Add some documentation for getting started on development (#283) 2022-08-27 17:19:09 +02:00
miozune 46d90b6923 Show handler order when hovering on tab and shift pressed (#281) 2022-08-26 22:14:08 +02:00
slprime e61120099a Fix DnD Real Item as Ghost (#279) 2022-08-23 21:15:37 +02:00
Yang Xizhi bcb6eb214f fix dead loop when click certain gui with real item (#278)
fix https://github.com/GTNewHorizons/GT-New-Horizons-Modpack/issues/11067
2022-08-23 06:41:34 +01:00
slprimeandVladislav Laetansky 9221434b2e Create ShortcutInputHandler api class (#277)
* Add RecipeItemInputHandler#lastKeyTyped(ItemStack)

* move shortcut to api

* Update src/main/java/codechicken/nei/api/ShortcutInputHandler.java

Co-authored-by: Vladislav Laetansky <[email protected]>

Co-authored-by: Vladislav Laetansky <[email protected]>
2022-08-21 16:33:52 +02:00
6 changed files with 135 additions and 101 deletions

No files matched your search

+7
View File
@@ -27,6 +27,13 @@ If you have issues with NEI outside of the GTNH modpack you may report them in t
* Remove TMI style
* Removed inventory Load/Save state
## Development
Before launching, you need to add
```
-Dfml.coreMods.load=codechicken.nei.asm.NEICorePlugin
```
as a command line argument to the VM.
## License
GTNH Modifications Copyright (c) 2019-2022 mitchej123 and the GTNH Team
@@ -87,9 +87,13 @@ public class NEIClientConfig {
public static final Function<IRecipeHandler, String> HANDLER_ID_FUNCTION =
handler -> Objects.firstNonNull(handler.getOverlayIdentifier(), handler.getHandlerId());
public static int getHandlerOrder(IRecipeHandler handler) {
return handlerOrdering.getOrDefault(HANDLER_ID_FUNCTION.apply(handler), 0);
}
// Comparator that compares handlers using the handlerOrdering map.
public static final Comparator<IRecipeHandler> HANDLER_COMPARATOR =
Comparator.comparingInt(handler -> handlerOrdering.getOrDefault(HANDLER_ID_FUNCTION.apply(handler), 0));
Comparator.comparingInt(NEIClientConfig::getHandlerOrder);
public static ItemStack[] creativeInv;
@@ -289,9 +289,6 @@ public abstract class PanelWidget extends Widget {
GuiInfo.readLock.lock();
for (INEIGuiHandler handler : GuiInfo.guiHandlers) {
if (handler.handleDragNDrop(gui, mouseX, mouseY, draggedStack, button)) {
NEIClientConfig.logger.info(handler);
handled = true;
break;
}
@@ -0,0 +1,119 @@
package codechicken.nei.api;
import codechicken.nei.ItemPanels;
import codechicken.nei.LayoutManager;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.NEIClientUtils;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.GuiCraftingRecipe;
import codechicken.nei.recipe.GuiRecipe;
import codechicken.nei.recipe.GuiUsageRecipe;
import java.util.List;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.ItemStack;
import org.lwjgl.input.Mouse;
public abstract class ShortcutInputHandler {
public static boolean handleKeyEvent(ItemStack stackover) {
if (NEIClientConfig.isKeyHashDown("gui.overlay_hide")) {
return hideOverlayRecipe();
}
if (stackover == null) {
return false;
}
stackover = stackover.copy();
if (NEIClientConfig.isKeyHashDown("gui.overlay")) {
return openOverlayRecipe(stackover, false);
}
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) {
if (stackover != null) {
final int button = Mouse.getEventButton();
stackover = stackover.copy();
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;
}
private static boolean openOverlayRecipe(ItemStack stack, boolean shift) {
final GuiContainer gui = NEIClientUtils.getGuiContainer();
if (gui == null || gui instanceof GuiRecipe) {
return false;
}
return GuiCraftingRecipe.openRecipeGui("item", true, shift, stack);
}
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();
}
ItemPanels.bookmarkPanel.addOrRemoveItem(stack, handlerName, ingredients, saveIngredients, saveStackSize);
return true;
}
return false;
}
}
@@ -140,6 +140,7 @@ public abstract class GuiRecipeTab extends Widget {
tooltip.add("");
tooltip.add("HandlerName: " + handlerName);
tooltip.add("HandlerID: " + handlerID);
tooltip.add("HandlerOrder: " + NEIClientConfig.getHandlerOrder(handler));
}
}
@@ -1,12 +1,9 @@
package codechicken.nei.recipe;
import codechicken.nei.ItemPanels;
import codechicken.nei.LayoutManager;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.PositionedStack;
import codechicken.nei.api.ShortcutInputHandler;
import codechicken.nei.guihook.GuiContainerManager;
import codechicken.nei.guihook.IContainerInputHandler;
import java.util.List;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.ItemStack;
@@ -14,52 +11,7 @@ public class RecipeItemInputHandler implements IContainerInputHandler {
@Override
public boolean lastKeyTyped(GuiContainer gui, char keyChar, int keyCode) {
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);
}
if (NEIClientConfig.isKeyHashDown("gui.overlay_use")) {
return openOverlayRecipe(gui, 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(gui, stackover, false, false);
}
if (NEIClientConfig.isKeyHashDown("gui.bookmark_recipe")) {
return saveRecipeInBookmark(gui, stackover, true, false);
}
if (NEIClientConfig.isKeyHashDown("gui.bookmark_count")) {
return saveRecipeInBookmark(gui, stackover, false, true);
}
if (NEIClientConfig.isKeyHashDown("gui.bookmark_recipe_count")) {
return saveRecipeInBookmark(gui, stackover, true, true);
}
return false;
return ShortcutInputHandler.handleKeyEvent(GuiContainerManager.getStackMouseOver(gui));
}
@Override
@@ -70,53 +22,7 @@ public class RecipeItemInputHandler implements IContainerInputHandler {
ItemStack stackover = GuiContainerManager.getStackMouseOver(gui);
if (stackover != null) {
if (button == 0) {
return GuiCraftingRecipe.openRecipeGui("item", stackover.copy());
} else if (button == 1) {
return GuiUsageRecipe.openRecipeGui("item", stackover.copy());
}
}
return false;
}
private boolean hideOverlayRecipe() {
if (LayoutManager.overlayRenderer != null) {
LayoutManager.overlayRenderer = null;
return true;
}
return false;
}
private boolean openOverlayRecipe(GuiContainer gui, ItemStack stack, boolean shift) {
if (gui instanceof GuiRecipe) {
return false;
}
return GuiCraftingRecipe.openRecipeGui("item", true, shift, stack);
}
private boolean saveRecipeInBookmark(
GuiContainer gui, ItemStack stack, boolean saveIngredients, boolean saveStackSize) {
if (stack != null) {
List<PositionedStack> ingredients = null;
String handlerName = "";
if (gui instanceof GuiRecipe) {
ingredients = ((GuiRecipe<?>) gui).getFocusedRecipeIngredients();
handlerName = ((GuiRecipe<?>) gui).getHandlerName();
}
ItemPanels.bookmarkPanel.addOrRemoveItem(stack, handlerName, ingredients, saveIngredients, saveStackSize);
return true;
}
return false;
return ShortcutInputHandler.handleMouseClick(stackover);
}
@Override