aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVixid <52578495+VixidDev@users.noreply.github.com>2023-04-04 19:18:07 +0100
committerGitHub <noreply@github.com>2023-04-04 20:18:07 +0200
commita278e49969e073be5abc7e46514b73b0d5073a11 (patch)
tree37c0a3b7ceb3eb3eb8e93e9c6c6c9ee031a5963f
parent32e7f4704fe2639314451e39c32741a1900907c0 (diff)
downloadNotEnoughUpdates-a278e49969e073be5abc7e46514b73b0d5073a11.tar.gz
NotEnoughUpdates-a278e49969e073be5abc7e46514b73b0d5073a11.tar.bz2
NotEnoughUpdates-a278e49969e073be5abc7e46514b73b0d5073a11.zip
Item Recipe and Usage keybinds in Storage Overlay (#654)
* Allow item recipe and usage keybinds in storage overlay * Add check for if search bar or rename field is focused
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscgui/StorageOverlay.java44
1 files changed, 29 insertions, 15 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/StorageOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/StorageOverlay.java
index 774b935d..d469065d 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/StorageOverlay.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/StorageOverlay.java
@@ -20,6 +20,8 @@
package io.github.moulberry.notenoughupdates.miscgui;
import com.google.common.collect.Lists;
+import com.google.gson.JsonObject;
+import io.github.moulberry.notenoughupdates.NEUManager;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.core.BackgroundBlur;
import io.github.moulberry.notenoughupdates.core.ChromaColour;
@@ -72,9 +74,6 @@ import java.util.Set;
public class StorageOverlay extends GuiElement {
public static final ResourceLocation[] STORAGE_PREVIEW_TEXTURES = new ResourceLocation[4];
- private static final int CHEST_TOP_OFFSET = 17;
- private static final int CHEST_SLOT_SIZE = 18;
- private static final int CHEST_BOTTOM_OFFSET = 215;
private static final ResourceLocation[] STORAGE_TEXTURES = new ResourceLocation[4];
private static final ResourceLocation STORAGE_ICONS_TEXTURE = new ResourceLocation(
"notenoughupdates:storage_gui/storage_icons.png");
@@ -85,6 +84,7 @@ public class StorageOverlay extends GuiElement {
private static final StorageOverlay INSTANCE = new StorageOverlay();
private static final String CHROMA_STR = "230:255:255:0:0";
private static final ResourceLocation RES_ITEM_GLINT = new ResourceLocation("textures/misc/enchanted_item_glint.png");
+ private static final NEUManager manager = NotEnoughUpdates.INSTANCE.manager;
static {
for (int i = 0; i < STORAGE_TEXTURES.length; i++) {
@@ -281,7 +281,7 @@ public class StorageOverlay extends GuiElement {
if (stack != null &&
(stack.getItem() == Item.getItemFromBlock(Blocks.stained_glass_pane) || stack.getItem() == Item.getItemFromBlock(
Blocks.glass_pane))) {
- String internalName = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stack);
+ String internalName = manager.createItemResolutionQuery().withItemStack(stack).resolveInternalName();
if (internalName != null) {
if (internalName.startsWith("STAINED_GLASS_PANE")) {
if (cache != null) cache[index] = stack.getItemDamage() + 1;
@@ -1044,7 +1044,7 @@ public class StorageOverlay extends GuiElement {
int itemY = storageY + 1 + 18 * (k / 9);
if (!searchBar.getText().isEmpty()) {
- if (stack == null || !NotEnoughUpdates.INSTANCE.manager.doesStackMatchSearch(stack, searchBar.getText())) {
+ if (stack == null || !manager.doesStackMatchSearch(stack, searchBar.getText())) {
GlStateManager.disableDepth();
Gui.drawRect(itemX, itemY, itemX + 16, itemY + 16, 0x80000000);
GlStateManager.enableDepth();
@@ -1298,7 +1298,7 @@ public class StorageOverlay extends GuiElement {
GlStateManager.popMatrix();
if (!searchBar.getText().isEmpty()) {
- if (playerItems[i] == null || !NotEnoughUpdates.INSTANCE.manager.doesStackMatchSearch(
+ if (playerItems[i] == null || !manager.doesStackMatchSearch(
playerItems[i],
searchBar.getText()
)) {
@@ -1332,7 +1332,7 @@ public class StorageOverlay extends GuiElement {
GlStateManager.popMatrix();
if (!searchBar.getText().isEmpty()) {
- if (playerItems[i + 9] == null || !NotEnoughUpdates.INSTANCE.manager.doesStackMatchSearch(
+ if (playerItems[i + 9] == null || !manager.doesStackMatchSearch(
playerItems[i + 9],
searchBar.getText()
)) {
@@ -2180,6 +2180,15 @@ public class StorageOverlay extends GuiElement {
@Override
public boolean keyboardInput() {
+ ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft());
+ int width = scaledResolution.getScaledWidth();
+ int height = scaledResolution.getScaledHeight();
+ int mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth;
+ int mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1;
+
+ if (!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) return true;
+ GuiContainer container = (GuiContainer) Minecraft.getMinecraft().currentScreen;
+
if (Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) {
clearSearch();
return false;
@@ -2190,18 +2199,23 @@ public class StorageOverlay extends GuiElement {
if (Keyboard.getEventKey() == Minecraft.getMinecraft().gameSettings.keyBindFullscreen.getKeyCode()) {
return false;
}
+
+ if (!searchBar.getFocus() && !renameStorageField.getFocus() &&
+ (Keyboard.getEventKey() == manager.keybindViewRecipe.getKeyCode() ||
+ Keyboard.getEventKey() == manager.keybindViewUsages.getKeyCode())) {
+ for (Slot slot : container.inventorySlots.inventorySlots) {
+ if (slot != null && ((AccessorGuiContainer) container).doIsMouseOverSlot(slot, mouseX, mouseY)) {
+ String internalName = manager.createItemResolutionQuery().withItemStack(slot.getStack()).resolveInternalName();
+ JsonObject item = manager.getItemInformation().get(internalName);
+ if (Keyboard.getEventKey() == manager.keybindViewRecipe.getKeyCode()) manager.showRecipe(item);
+ if (Keyboard.getEventKey() == manager.keybindViewUsages.getKeyCode()) manager.displayGuiItemUsages(internalName);
+ }
+ }
+ }
if (Keyboard.getEventKeyState()) {
if (NotEnoughUpdates.INSTANCE.config.slotLocking.enableSlotLocking &&
KeybindHelper.isKeyPressed(NotEnoughUpdates.INSTANCE.config.slotLocking.slotLockKey) && !searchBar.getFocus()) {
- if (!(Minecraft.getMinecraft().currentScreen instanceof GuiContainer)) return true;
- GuiContainer container = (GuiContainer) Minecraft.getMinecraft().currentScreen;
-
- ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft());
- int width = scaledResolution.getScaledWidth();
- int height = scaledResolution.getScaledHeight();
- int mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth;
- int mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1;
for (Slot slot : container.inventorySlots.inventorySlots) {
if (slot != null &&