Skip to content

Commit

Permalink
add network size enum to fix overlap; fix NPE; merged from upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
Lothrazar committed Sep 22, 2024
2 parents 509db97 + d4bbcfd commit 877b101
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 28 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ minecraft {
property 'forge.logging.console.level', 'debug'
properties 'mixin.env.disableRefMap': 'true'

args '--username=ADev'
args '--username=AnotherDev'

mods {
storagenetwork {
Expand Down
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 @@ -40,11 +39,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 @@ -128,7 +125,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 @@ -172,14 +168,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 @@ -44,7 +44,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 @@ -53,12 +53,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 @@ -310,7 +325,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 @@ -380,4 +395,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
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* <p>
* Used by Containers displaying network inventory as well as most other packets that perform small actions
*/
@SuppressWarnings("resource")
public class RefreshFilterClientMessage {

private int size;
Expand Down
5 changes: 3 additions & 2 deletions update.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
"1.19.4": {
"1.9.0":"Ported to 1.19.4. Previous changelog: 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.9.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.9.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 877b101

Please sign in to comment.