Skip to content

Commit

Permalink
More QOL (GTNewHorizons#510)
Browse files Browse the repository at this point in the history
* ItemZoom, hotkeys & more tooltips

* fix tooltips

* fix hover crash to unnamed item

* fix bookmark group with groupIds bigger than 127

---------

Co-authored-by: slprime <[email protected]>
Co-authored-by: Martin Robertz <[email protected]>
  • Loading branch information
3 people authored Aug 17, 2024
1 parent f0a554b commit 72ad8aa
Show file tree
Hide file tree
Showing 43 changed files with 2,895 additions and 998 deletions.
125 changes: 125 additions & 0 deletions src/main/java/codechicken/nei/AutoFocusWidget.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package codechicken.nei;

import static codechicken.lib.gui.GuiDraw.getMousePosition;

import java.awt.Point;
import java.util.ArrayList;
import java.util.List;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.settings.GameSettings;

import org.lwjgl.input.Keyboard;

import codechicken.nei.guihook.GuiContainerManager;
import codechicken.nei.guihook.IContainerInputHandler;

public class AutoFocusWidget implements IContainerInputHandler {

/**
* Implement this interface on a GuiContainer to enable the autofocus search in NEI (if the autofocus option is
* enabled) without needing to add the classname to the config file .
*/
public interface INEIAutoFocusSearchEnable {
}

public static AutoFocusWidget instance = new AutoFocusWidget();

public static List<String> enableAutoFocusPrefixes = new ArrayList<>();

protected boolean autofocus = false;
protected Point mouse;

public AutoFocusWidget() {
GuiContainerManager.addInputHandler(this);
}

public void load(GuiContainer gui) {
this.autofocus = LayoutManager.searchField.isVisible() && NEIClientConfig.searchWidgetAutofocus() != 0
&& isAllowedGuiAutoSearchFocus(gui);
this.mouse = getMousePosition();
}

@Override
public boolean keyTyped(GuiContainer gui, char keyChar, int keyCode) {

if (this.autofocus) {
this.autofocus = false;

if (!this.mouse.equals(getMousePosition())) {
return false;
}

if (NEIClientConfig.searchWidgetAutofocus() == 2
&& GameSettings.isKeyDown(Minecraft.getMinecraft().gameSettings.keyBindInventory)) {
return false;
}

if (keyCode == Keyboard.KEY_RETURN || keyCode == Keyboard.KEY_NUMPADENTER
|| keyCode == Keyboard.KEY_ESCAPE) {
return false;
}

LayoutManager.searchField.setFocus(true);
LayoutManager.searchField.handleKeyPress(keyCode, keyChar);
return true;
}

return false;
}

@Override
public boolean lastKeyTyped(GuiContainer gui, char keyChar, int keyID) {
return false;
}

@Override
public boolean mouseClicked(GuiContainer gui, int mousex, int mousey, int button) {
this.autofocus = false;
return false;
}

@Override
public boolean mouseScrolled(GuiContainer gui, int mousex, int mousey, int scrolled) {
this.autofocus = false;
return false;
}

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

@Override
public void onMouseClicked(GuiContainer gui, int mousex, int mousey, int button) {
this.autofocus = false;
}

@Override
public void onMouseDragged(GuiContainer gui, int mousex, int mousey, int button, long heldTime) {
this.autofocus = false;
}

@Override
public void onMouseScrolled(GuiContainer gui, int mousex, int mousey, int scrolled) {
this.autofocus = false;
}

@Override
public void onMouseUp(GuiContainer gui, int mousex, int mousey, int button) {
this.autofocus = false;
}

protected boolean isAllowedGuiAutoSearchFocus(GuiContainer gui) {
if (gui instanceof INEIAutoFocusSearchEnable) {
return true;
}
String guiClassName = gui.getClass().getName();
for (String prefix : enableAutoFocusPrefixes) {
if (guiClassName.startsWith(prefix)) {
return true;
}
}
return false;
}

}
18 changes: 11 additions & 7 deletions src/main/java/codechicken/nei/BookmarkCraftingChain.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class BookmarkCraftingChain {

public HashMap<ItemStack, ItemStack> inputs = new HashMap<>();
public HashMap<ItemStack, ItemStack> outputs = new HashMap<>();
public HashMap<ItemStack, ItemStack> remainder = new HashMap<>();
public HashMap<ItemStack, ItemStack> intermediate = new HashMap<>();

protected static class CraftingChainItem {
Expand Down Expand Up @@ -206,6 +207,7 @@ public void refresh(List<ItemStack> items, List<ItemStackMetadata> metadata) {

this.inputs.clear();
this.outputs.clear();
this.remainder.clear();
this.intermediate.clear();
this.calculatedItems.clear();
this.multiplier.clear();
Expand Down Expand Up @@ -245,18 +247,20 @@ public void refresh(List<ItemStack> items, List<ItemStackMetadata> metadata) {
}

} else { // output
long iCount = calculateCount(request, request.inputs.get(item.stackIndex))
- iShift.getOrDefault(item.stackIndex, 0L);
long iCalcCount = calculateCount(request, request.inputs.get(item.stackIndex));
long iCount = iCalcCount - iShift.getOrDefault(item.stackIndex, 0L);
this.multiplier.put(item.stack, item.factor > 0 ? (int) (count / item.factor) : 0);

if (iCount < count) {
this.outputs.put(item.stack, item.getItemStack(count - iCount));
iShift.put(item.stackIndex, iShift.getOrDefault(item.stackIndex, 0L) + iCount);
} else if (iCount >= count) {
if (iCount >= count) {
this.intermediate.put(item.stack, item.getItemStack(0));
iShift.put(item.stackIndex, iShift.getOrDefault(item.stackIndex, 0L) + count);
} else if (iCalcCount > 0) {
this.remainder.put(item.stack, item.getItemStack(count - iCount));
iShift.put(item.stackIndex, iShift.getOrDefault(item.stackIndex, 0L) + iCount);
} else {
this.outputs.put(item.stack, item.getItemStack(count - iCount));
iShift.put(item.stackIndex, iShift.getOrDefault(item.stackIndex, 0L) + iCount);
}

}

}
Expand Down
Loading

0 comments on commit 72ad8aa

Please sign in to comment.