From 19fc7b3c6f2e08ff763c6401711b24e62a788def Mon Sep 17 00:00:00 2001 From: lothrazar Date: Sun, 22 Sep 2024 08:02:32 -0700 Subject: [PATCH] add network size enum to fix overlap; fix NPE --- .../inventory/ScreenNetworkInventory.java | 16 ++-------- .../block/request/ScreenNetworkTable.java | 3 +- .../storagenetwork/gui/NetworkWidget.java | 31 +++++++++++++++++-- .../remote/ScreenNetworkCraftingRemote.java | 7 ++--- .../item/remote/ScreenNetworkRemote.java | 7 ++--- update.json | 2 +- 6 files changed, 40 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/lothrazar/storagenetwork/block/inventory/ScreenNetworkInventory.java b/src/main/java/com/lothrazar/storagenetwork/block/inventory/ScreenNetworkInventory.java index ce69b735..6da599fd 100644 --- a/src/main/java/com/lothrazar/storagenetwork/block/inventory/ScreenNetworkInventory.java +++ b/src/main/java/com/lothrazar/storagenetwork/block/inventory/ScreenNetworkInventory.java @@ -5,9 +5,8 @@ import com.lothrazar.storagenetwork.api.EnumSortType; import com.lothrazar.storagenetwork.api.IGuiNetwork; import com.lothrazar.storagenetwork.gui.NetworkWidget; +import com.lothrazar.storagenetwork.gui.NetworkWidget.NetworkScreenSize; import com.lothrazar.storagenetwork.jei.JeiHooks; -import com.lothrazar.storagenetwork.network.ClearRecipeMessage; -import com.lothrazar.storagenetwork.network.RequestMessage; import com.lothrazar.storagenetwork.network.SettingsSyncMessage; import com.lothrazar.storagenetwork.registry.PacketRegistry; import com.mojang.blaze3d.platform.InputConstants; @@ -38,11 +37,9 @@ public class ScreenNetworkInventory extends AbstractContainerScreen slots; private final IGuiNetwork gui; private long lastClick; @@ -49,12 +49,27 @@ public class NetworkWidget { private int lines = 4; private final int columns = 9; + @Deprecated public NetworkWidget(IGuiNetwork gui) { + this(gui, NetworkScreenSize.NORMAL); + } + + public NetworkWidget(IGuiNetwork gui, NetworkScreenSize size) { this.gui = gui; stacks = Lists.newArrayList(); slots = Lists.newArrayList(); PacketRegistry.INSTANCE.sendToServer(new RequestMessage()); lastClick = System.currentTimeMillis(); + switch (size) { + case LARGE: + setLines(8); + setFieldHeight(180 - 8); // offset is important + break; + case NORMAL: + setLines(4); + setFieldHeight(90); + break; + } } public void applySearchTextToSlots() { @@ -306,7 +321,7 @@ else if (!stackCarriedByMouse.isEmpty() && inField((int) mouseX, (int) mouseY) & private boolean inField(int mouseX, int mouseY) { return mouseX > (gui.getGuiLeft() + 7) && mouseX < (gui.getGuiLeft() + ScreenNetworkTable.WIDTH - 7) - && mouseY > (gui.getGuiTopFixJei() + 7) && mouseY < (gui.getGuiTopFixJei() + fieldHeight); + && mouseY > (gui.getGuiTopFixJei() + 7) && mouseY < (gui.getGuiTopFixJei() + getFieldHeight()); } public void initButtons() { @@ -376,4 +391,16 @@ public void render() { jeiBtn.setTextureId(gui.isJeiSearchSynced() ? TextureEnum.JEI_GREEN : TextureEnum.JEI_RED); } } + + public int getFieldHeight() { + return fieldHeight; + } + + public void setFieldHeight(int fieldHeight) { + this.fieldHeight = fieldHeight; + } + + public enum NetworkScreenSize { + NORMAL, LARGE; + } } diff --git a/src/main/java/com/lothrazar/storagenetwork/item/remote/ScreenNetworkCraftingRemote.java b/src/main/java/com/lothrazar/storagenetwork/item/remote/ScreenNetworkCraftingRemote.java index 61eb9245..6de7be1d 100644 --- a/src/main/java/com/lothrazar/storagenetwork/item/remote/ScreenNetworkCraftingRemote.java +++ b/src/main/java/com/lothrazar/storagenetwork/item/remote/ScreenNetworkCraftingRemote.java @@ -5,6 +5,7 @@ import com.lothrazar.storagenetwork.api.EnumSortType; import com.lothrazar.storagenetwork.api.IGuiNetwork; import com.lothrazar.storagenetwork.gui.NetworkWidget; +import com.lothrazar.storagenetwork.gui.NetworkWidget.NetworkScreenSize; import com.lothrazar.storagenetwork.jei.JeiHooks; import com.lothrazar.storagenetwork.network.ClearRecipeMessage; import com.lothrazar.storagenetwork.network.RequestMessage; @@ -36,12 +37,10 @@ public class ScreenNetworkCraftingRemote extends AbstractContainerScreen