Skip to content

Commit

Permalink
refactor expanded inventory texture to tileable per row records
Browse files Browse the repository at this point in the history
  • Loading branch information
Lothrazar committed Nov 18, 2024
1 parent cff95ea commit cd4051b
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,28 @@
import com.lothrazar.storagenetwork.block.AbstractNetworkScreen;
import com.lothrazar.storagenetwork.gui.NetworkScreenSize;
import com.lothrazar.storagenetwork.gui.NetworkWidget;
import com.lothrazar.storagenetwork.gui.TileableTexture;
import com.lothrazar.storagenetwork.util.SsnConsts;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Inventory;
import net.minecraftforge.fml.ModList;

public class ScreenNetworkInventoryExpanded extends AbstractNetworkScreen<ContainerNetworkInventoryExpanded> {//AbstractContainerScreen<ContainerNetworkInventoryExpanded> implements IGuiNetwork {
public class ScreenNetworkInventoryExpanded extends AbstractNetworkScreen<ContainerNetworkInventoryExpanded> {

protected int HEIGHT = 256;
public int WIDTH = 176;
//i know they could all be in the same png file and i pull out sprites from it, but split images is easier to work with
private TileableTexture head = new TileableTexture(new ResourceLocation(StorageNetworkMod.MODID, "textures/gui/expandable_head.png"), WIDTH, 10);
private TileableTexture row = new TileableTexture(new ResourceLocation(StorageNetworkMod.MODID, "textures/gui/expandable_row.png"), WIDTH, SsnConsts.SQ);
private TileableTexture crafting = new TileableTexture(new ResourceLocation(StorageNetworkMod.MODID, "textures/gui/expandable_crafting.png"), WIDTH, 58);
private TileableTexture player = new TileableTexture(new ResourceLocation(StorageNetworkMod.MODID, "textures/gui/expandable_player.png"), WIDTH, 104);

protected final NetworkWidget network;
private TileInventoryExpanded tile;
private ResourceLocation top = new ResourceLocation(StorageNetworkMod.MODID, "textures/gui/inventory_expanded_top.png");
private ResourceLocation bot = new ResourceLocation(StorageNetworkMod.MODID, "textures/gui/inventory_expanded_bottom.png");

public ScreenNetworkInventoryExpanded(ContainerNetworkInventoryExpanded container, Inventory inv, Component name) {
super(container, inv, name);
Expand All @@ -46,13 +53,33 @@ public void init() {

@Override
public void renderBg(GuiGraphics ms, float partialTicks, int mouseX, int mouseY) {
//get center points from screen size
int xCenter = (width - imageWidth) / 2;
int yCenter = (height - imageHeight) / 2;
ms.blit(top, xCenter, yCenter - imageHeight / 2, 0, 0, imageWidth, imageHeight);
ms.blit(bot, xCenter, yCenter + imageHeight / 2, 0, imageHeight, imageWidth, imageHeight);
//render the top
int ypos = yCenter - imageHeight / 2;
ms.blit(head.texture(), xCenter, ypos, 0, 0, imageWidth, head.height());
//render the rows
// -1 for the top header row, and pixel to math ratio of 2x
final int textureLines = (network.getLines() - 1)*2;
for(int line = 0; line < textureLines; line++) {

ypos += head.height();
ms.blit(row.texture(), xCenter, ypos, 0, 0, imageWidth, row.height());
}
//render player inventory
ypos = ypos - 12; //border buffers of 8+4 overlap
ms.blit(player.texture(), xCenter, ypos, 0, imageHeight, imageWidth, imageHeight);
//update network
network.applySearchTextToSlots();
network.renderItemSlots(ms, mouseX, mouseY, font);
}

@Override
public void resize(Minecraft mc, int w, int h) {
super.resize(mc,w,h);
network.resize(mc,w,h);
}
// all the IGUINETWORK implementations

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
import com.lothrazar.storagenetwork.block.AbstractNetworkScreen;
import com.lothrazar.storagenetwork.gui.NetworkScreenSize;
import com.lothrazar.storagenetwork.gui.NetworkWidget;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Inventory;
import net.minecraftforge.fml.ModList;

public class ScreenNetworkInventory extends AbstractNetworkScreen<ContainerNetworkInventory> {//AbstractContainerScreen<ContainerNetworkInventory> implements IGuiNetwork {
public class ScreenNetworkInventory extends AbstractNetworkScreen<ContainerNetworkInventory> {

protected int HEIGHT = 256;
public int WIDTH = 176;
Expand Down Expand Up @@ -51,6 +52,13 @@ public void renderBg(GuiGraphics ms, float partialTicks, int mouseX, int mouseY)
network.applySearchTextToSlots();
network.renderItemSlots(ms, mouseX, mouseY, font);
}


@Override
public void resize(Minecraft mc, int w, int h) {
super.resize(mc,w,h);
network.resize(mc,w,h);
}
// all the IGUINETWORK implementations

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
import com.lothrazar.storagenetwork.block.AbstractNetworkScreen;
import com.lothrazar.storagenetwork.gui.NetworkScreenSize;
import com.lothrazar.storagenetwork.gui.NetworkWidget;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Inventory;
import net.minecraftforge.fml.ModList;

public class ScreenNetworkTable extends
AbstractNetworkScreen<ContainerNetworkCraftingTable> {
//AbstractContainerScreen<ContainerNetworkCraftingTable> implements IGuiNetwork {
public class ScreenNetworkTable extends AbstractNetworkScreen<ContainerNetworkCraftingTable> {

private static final int HEIGHT = 256;
public static final int WIDTH = 176;
Expand Down Expand Up @@ -54,6 +53,13 @@ public void renderBg(GuiGraphics ms, float partialTicks, int mouseX, int mouseY)
network.applySearchTextToSlots();
network.renderItemSlots(ms, mouseX, mouseY, font);
}


@Override
public void resize(Minecraft mc, int w, int h) {
super.resize(mc,w,h);
network.resize(mc,w,h);
}
// all the IGUINETWORK implementations

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public boolean canClick() {
return System.currentTimeMillis() > lastClick + 100L;
}

int getLines() {
public int getLines() {
return lines;
}

Expand Down Expand Up @@ -452,4 +452,11 @@ public void render() {
jeiBtn.setTextureId(gui.isJeiSearchSynced() ? TextureEnum.JEI_GREEN : TextureEnum.JEI_RED);
}
}

public void resize(Minecraft mc, int width, int height) {

//todo: how many rows? dynamically change size on screen resize from client
//System.out.println("resized width="+width);
// System.out.println("resized height="+height);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.lothrazar.storagenetwork.gui;

import net.minecraft.resources.ResourceLocation;

public record TileableTexture(ResourceLocation texture, int width, int height) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.lothrazar.storagenetwork.block.AbstractNetworkScreen;
import com.lothrazar.storagenetwork.gui.NetworkScreenSize;
import com.lothrazar.storagenetwork.gui.NetworkWidget;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -53,6 +54,12 @@ protected void renderBg(GuiGraphics ms, float partialTicks, int mouseX, int mous
network.renderItemSlots(ms, mouseX, mouseY, font);
}

@Override
public void resize(Minecraft mc, int w, int h) {
super.resize(mc,w,h);
network.resize(mc,w,h);
}

@Override
public boolean getDownwards() {
return ItemStorageCraftingRemote.getDownwards(remote);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.lothrazar.storagenetwork.block.AbstractNetworkScreen;
import com.lothrazar.storagenetwork.gui.NetworkScreenSize;
import com.lothrazar.storagenetwork.gui.NetworkWidget;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -54,6 +55,12 @@ protected void renderBg(GuiGraphics ms, float partialTicks, int mouseX, int mous
network.renderItemSlots(ms, mouseX, mouseY, font);
}

@Override
public void resize(Minecraft mc, int w, int h) {
super.resize(mc,w,h);
network.resize(mc,w,h);
}

@Override
public boolean getDownwards() {
return ItemStorageCraftingRemote.getDownwards(remote);
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit cd4051b

Please sign in to comment.