Skip to content

Commit

Permalink
add network size enum to fix overlap; fix NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
Lothrazar committed Sep 22, 2024
1 parent b066fdf commit 19fc7b3
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -38,11 +37,9 @@ public class ScreenNetworkInventory extends AbstractContainerScreen<ContainerNet
public ScreenNetworkInventory(ContainerNetworkInventory container, Inventory inv, Component name) {
super(container, inv, name);
tile = container.tile;
network = new NetworkWidget(this);
network.setLines(8);
network = new NetworkWidget(this, NetworkScreenSize.LARGE);
imageWidth = WIDTH;
imageHeight = HEIGHT;
network.fieldHeight = 180;
}

@Override
Expand Down Expand Up @@ -126,7 +123,6 @@ public BlockPos getPos() {

@Override
public void renderBg(PoseStack ms, float partialTicks, int mouseX, int mouseY) {
// minecraft.getTextureManager().bind(texture);
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderTexture(0, texture);
int xCenter = (width - imageWidth) / 2;
Expand Down Expand Up @@ -170,14 +166,6 @@ public boolean mouseScrolled(double x, double y, double mouseButton) {
public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) {
super.mouseClicked(mouseX, mouseY, mouseButton);
network.mouseClicked(mouseX, mouseY, mouseButton);
//recipe clear thingy
int rectX = 63;
int rectY = 110;
if (isHovering(rectX, rectY, 7, 7, mouseX, mouseY)) {
PacketRegistry.INSTANCE.sendToServer(new ClearRecipeMessage());
PacketRegistry.INSTANCE.sendToServer(new RequestMessage(0, ItemStack.EMPTY, false, false));
return true;
}
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -38,7 +39,7 @@ public class ScreenNetworkTable extends AbstractContainerScreen<ContainerNetwork
public ScreenNetworkTable(ContainerNetworkCraftingTable container, Inventory inv, Component name) {
super(container, inv, name);
tile = container.getTileRequest();
network = new NetworkWidget(this);
network = new NetworkWidget(this, NetworkScreenSize.NORMAL);
imageWidth = WIDTH;
imageHeight = HEIGHT;
}
Expand Down
31 changes: 29 additions & 2 deletions src/main/java/com/lothrazar/storagenetwork/gui/NetworkWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class NetworkWidget {
public ButtonRequest sortBtn;
public ButtonRequest jeiBtn;
public ButtonRequest focusBtn;
public int fieldHeight = 90;
private int fieldHeight = 90;
private List<ItemSlotNetwork> slots;
private final IGuiNetwork gui;
private long lastClick;
Expand All @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -36,12 +37,10 @@ public class ScreenNetworkCraftingRemote extends AbstractContainerScreen<Contain
public ScreenNetworkCraftingRemote(ContainerNetworkCraftingRemote screenContainer, Inventory inv, Component titleIn) {
super(screenContainer, inv, titleIn);
//since the rightclick action forces only MAIN_HAND openings, is ok
this.remote = screenContainer.getRemote();// inv.player.getItemInHand(InteractionHand.MAIN_HAND);
network = new NetworkWidget(this);
network.setLines(4);
this.remote = screenContainer.getRemote();
network = new NetworkWidget(this, NetworkScreenSize.NORMAL);
this.imageWidth = WIDTH;
this.imageHeight = HEIGHT;
network.fieldHeight = 90;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.SettingsSyncMessage;
import com.lothrazar.storagenetwork.registry.PacketRegistry;
Expand Down Expand Up @@ -33,12 +34,10 @@ public class ScreenNetworkRemote extends AbstractContainerScreen<ContainerNetwor
public ScreenNetworkRemote(ContainerNetworkRemote screenContainer, Inventory inv, Component titleIn) {
super(screenContainer, inv, titleIn);
//since the rightclick action forces only MAIN_HAND openings, is ok
this.remote = screenContainer.getRemote();//inv.player.getItemInHand(InteractionHand.MAIN_HAND);
network = new NetworkWidget(this);
network.setLines(8);
this.remote = screenContainer.getRemote();
network = new NetworkWidget(this, NetworkScreenSize.LARGE);
this.imageWidth = WIDTH;
this.imageHeight = HEIGHT;
network.fieldHeight = 180;
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion update.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

"1.7.0":"Added version warning, Does not work with any JEI versions in the 10.X series, only with 9.7.X (for example 9.7.1.255 or 9.7.2.281). Community Pull Request Contributions: Merge pull request #492 from IIpragmaII/trunk/1.18 @IIpragmaII @VasurTrekkson Improved performance for export node. fix priority german translation @lightlike . Fixed recipes not showing when pressing the JEI recipe key @Demerso. Create uk_ua.json @SKZGx . "

,"1.7.1":"The Storage Request Table 'storagenetwork:request' block no longer saves the contents of its crafting-grid; instead items are returned to the player on close, exactly matching vanilla crafting table behavior (this was changed to prevent potential exploits. If any items are left behind in the grid during world upgrade they will be returned and not lost. No changes were made to the remotes or to other blocks) "
,"1.7.1":"The Storage Request Table 'storagenetwork:request' block no longer saves the contents of its crafting-grid; instead items are returned to the player on close, exactly matching vanilla crafting table behavior (this was changed to prevent potential exploits. If any items are left behind in the grid during world upgrade they will be returned and not lost. No changes were made to the remotes or to other blocks). Fix the bug when using small window sizes where the top row of player inventory items getting inserted instead of picked up when using the remote when jei is installed. Fixed a null pointer exception"

}
}

0 comments on commit 19fc7b3

Please sign in to comment.