Skip to content

Commit

Permalink
expanded feature: add remote version of expanded gui
Browse files Browse the repository at this point in the history
  • Loading branch information
Lothrazar committed Nov 30, 2024
1 parent 22c213a commit 8b23fa9
Show file tree
Hide file tree
Showing 12 changed files with 275 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.lothrazar.storagenetwork.block.inventory.ScreenNetworkInventory;
import com.lothrazar.storagenetwork.block.request.ScreenNetworkTable;
import com.lothrazar.storagenetwork.item.remote.ScreenNetworkCraftingRemote;
import com.lothrazar.storagenetwork.item.remote.ScreenNetworkExpandedRemote;
import com.lothrazar.storagenetwork.item.remote.ScreenNetworkRemote;
import com.lothrazar.storagenetwork.registry.ClientEventRegistry;
import com.lothrazar.storagenetwork.registry.ConfigRegistry;
Expand Down Expand Up @@ -63,8 +64,9 @@ private void setupClient(final FMLClientSetupEvent event) {
MenuScreens.register(SsnRegistry.Menus.INVENTORY_REMOTE.get(), ScreenNetworkRemote::new);
MenuScreens.register(SsnRegistry.Menus.CRAFTING_REMOTE.get(), ScreenNetworkCraftingRemote::new);
MenuScreens.register(SsnRegistry.Menus.INVENTORY.get(), ScreenNetworkInventory::new);
MenuScreens.register(SsnRegistry.Menus.INVENTORY_EXPANDED.get(), ScreenNetworkInventoryExpanded::new);
MenuScreens.register(SsnRegistry.Menus.COLLECTOR.get(), ScreenCollectionFilter::new);
MenuScreens.register(SsnRegistry.Menus.INVENTORY_EXPANDED.get(), ScreenNetworkInventoryExpanded::new);
MenuScreens.register(SsnRegistry.Menus.EXPANDED_REMOTE.get(), ScreenNetworkExpandedRemote::new);
}

private void registerMapping(final RegisterKeyMappingsEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) {
rectX = 63;
rectY = 110 + 200;
}
System.out.println(mouseX + "," + mouseY);
// TODO: revise above .out.println(mouseX + "," + mouseY);
if (isHovering(rectX, rectY, 7, 7, mouseX, mouseY)) {
System.out.println("clear!");

PacketRegistry.INSTANCE.sendToServer(new ClearRecipeMessage());
PacketRegistry.INSTANCE.sendToServer(new RequestMessage(0, ItemStack.EMPTY, false, false));
return true;
Expand All @@ -119,6 +119,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) {
return true;
}

@Deprecated
protected void blitSegment(GuiGraphics ms, TileableTexture tt, int xpos, int ypos) {
ms.blit(tt.texture(), xpos, ypos, 0, 0, tt.width(), tt.height());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,18 @@

public class ScreenNetworkInventoryExpanded extends AbstractNetworkScreen<ContainerNetworkInventoryExpanded> {

protected int W = 256;
//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"), W, 10);
private TileableTexture head_right = new TileableTexture(new ResourceLocation(StorageNetworkMod.MODID, "textures/gui/expandable_head_right.png"), W, 10);
private TileableTexture row = new TileableTexture(new ResourceLocation(StorageNetworkMod.MODID, "textures/gui/expandable_row.png"), W, SsnConsts.SQ);
private TileableTexture row_right = new TileableTexture(new ResourceLocation(StorageNetworkMod.MODID, "textures/gui/expandable_row_right.png"), W, SsnConsts.SQ);
private TileableTexture crafting = new TileableTexture(new ResourceLocation(StorageNetworkMod.MODID, "textures/gui/expandable_crafting.png"), W, 66);
private TileableTexture crafting_right = new TileableTexture(new ResourceLocation(StorageNetworkMod.MODID, "textures/gui/expandable_crafting_right.png"), W, 66);
private TileableTexture player = new TileableTexture(new ResourceLocation(StorageNetworkMod.MODID, "textures/gui/expandable_player.png"), 176, 84);
protected final NetworkWidget network;
private TileInventoryExpanded tile;

public ScreenNetworkInventoryExpanded(ContainerNetworkInventoryExpanded container, Inventory inv, Component name) {
super(container, inv, name);
tile = container.tile;
network = new NetworkWidget(this, NetworkScreenSize.EXPANDED);
imageHeight = player.height() + crafting.height()
+ row.height() * NetworkScreenSize.EXPANDED.lines()
+ head.height();
imageWidth = W + 12 * 18;//scrollWidth
//TODO: refactor this calculation
imageHeight = NetworkWidget.player.height() + NetworkWidget.crafting.height()
+ NetworkWidget.row.height() * network.getSize().lines()
+ NetworkWidget.head.height();
imageWidth = 256 + 12 * 18;//scrollWidth
}

@Override
Expand All @@ -59,32 +51,11 @@ public void renderBg(GuiGraphics ms, float partialTicks, int mouseX, int mouseY)
//get center points from screen size
final int xCenter = (width - imageWidth) / 2;
final int yCenter = (height - imageHeight) / 2;
//render the top
int xpos = xCenter;
int ypos = yCenter;
blitSegment(ms, head, xpos, ypos);
blitSegment(ms, head_right, xpos + W, ypos);
ypos += head.height();
//render the rows
for (int line = 0; line < network.getLines(); line++) {
blitSegment(ms, row, xpos, ypos);
blitSegment(ms, row_right, xpos + W, ypos);
ypos += row.height();
}
blitSegment(ms, crafting, xpos, ypos);
blitSegment(ms, crafting_right, xpos + W, ypos);
ypos += crafting.height() - 4;
blitSegment(ms, player, xpos, ypos);
network.renderBgExpanded(ms, partialTicks, mouseX, mouseY, xCenter, yCenter);
//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
@@ -1,12 +1,15 @@
package com.lothrazar.storagenetwork.emi;

import com.lothrazar.storagenetwork.block.expand.ContainerNetworkInventoryExpanded;
import com.lothrazar.storagenetwork.block.expand.ScreenNetworkInventoryExpanded;
import com.lothrazar.storagenetwork.block.request.ContainerNetworkCraftingTable;
import com.lothrazar.storagenetwork.block.request.ScreenNetworkTable;
import com.lothrazar.storagenetwork.gui.ISearchHandler;
import com.lothrazar.storagenetwork.gui.NetworkWidget;
import com.lothrazar.storagenetwork.item.remote.ContainerNetworkCraftingRemote;
import com.lothrazar.storagenetwork.item.remote.ContainerNetworkExpandedRemote;
import com.lothrazar.storagenetwork.item.remote.ScreenNetworkCraftingRemote;
import com.lothrazar.storagenetwork.item.remote.ScreenNetworkExpandedRemote;
import com.lothrazar.storagenetwork.registry.SsnRegistry;
import dev.emi.emi.api.EmiApi;
import dev.emi.emi.api.EmiEntrypoint;
Expand All @@ -25,9 +28,11 @@ public void register(EmiRegistry registry) {
registry.addWorkstation(VanillaEmiRecipeCategories.CRAFTING, EmiStack.of(SsnRegistry.Blocks.REQUEST.get()));
registry.addRecipeHandler(SsnRegistry.Menus.REQUEST.get(), new EmiTransferHandler<ContainerNetworkCraftingTable>());
registry.addRecipeHandler(SsnRegistry.Menus.CRAFTING_REMOTE.get(), new EmiTransferHandler<ContainerNetworkCraftingRemote>());
registry.addRecipeHandler(SsnRegistry.Menus.INVENTORY_EXPANDED.get(), new EmiTransferHandler<ContainerNetworkInventoryExpanded>());
registry.addRecipeHandler(SsnRegistry.Menus.EXPANDED_REMOTE.get(), new EmiTransferHandler<ContainerNetworkExpandedRemote>());
// registry.addGenericDragDropHandler(new EmiGhostIngredientHandler());
registry.addGenericStackProvider((scr, x, y) -> {
if (scr instanceof ScreenNetworkTable || scr instanceof ScreenNetworkCraftingRemote || scr instanceof ScreenNetworkInventoryExpanded) {
if (scr instanceof ScreenNetworkTable || scr instanceof ScreenNetworkCraftingRemote || scr instanceof ScreenNetworkInventoryExpanded || scr instanceof ScreenNetworkExpandedRemote) {
net.minecraft.world.inventory.Slot sl = ((AbstractContainerScreen<?>) scr).getSlotUnderMouse();
if (sl != null) return new EmiStackInteraction(EmiStack.of(sl.getItem()), null, false);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.lothrazar.storagenetwork.gui;
public enum NetworkScreenSize {

//normal has the crafting table
//large is the original inventory and remote with no crafting table
NORMAL, LARGE, EXPANDED;
Expand All @@ -9,9 +10,9 @@ public int lines() {
case NORMAL:
return 4;
case LARGE:
return 4 * 2;
return 8;
case EXPANDED:
return 4 * 5 + 1;
return 21;
}
return 0;
}
Expand Down
37 changes: 35 additions & 2 deletions src/main/java/com/lothrazar/storagenetwork/gui/NetworkWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class NetworkWidget {
private int lines = 4;
private int columns = 9;
public int scrollHeight = 152;
public int scrollWidth = 176;
public int scrollWidth = 176;//defaults to WIDTH
//
public int xNetwork = 8;
public int yNetwork = 10;
Expand Down Expand Up @@ -84,7 +84,7 @@ private void setScreenSize() {
case EXPANDED:
buffer = -10;
this.xNetwork = 10; // head.height();
this.scrollWidth = 256 + 12 * 18; //imageWidth
this.scrollWidth = W + 12 * 18; //imageWidth
break;
}
scrollHeight = (SsnConsts.SQ + 1) * this.getLines() + buffer;
Expand Down Expand Up @@ -465,4 +465,37 @@ public void render() {
jeiBtn.setTextureId(gui.isJeiSearchSynced() ? TextureEnum.JEI_GREEN : TextureEnum.JEI_RED);
}
}

protected static final int W = 256;
//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
public static final TileableTexture head = new TileableTexture(new ResourceLocation(StorageNetworkMod.MODID, "textures/gui/expandable_head.png"), W, 10);
public static final TileableTexture head_right = new TileableTexture(new ResourceLocation(StorageNetworkMod.MODID, "textures/gui/expandable_head_right.png"), W, 10);
public static final TileableTexture row = new TileableTexture(new ResourceLocation(StorageNetworkMod.MODID, "textures/gui/expandable_row.png"), W, SsnConsts.SQ);
public static final TileableTexture row_right = new TileableTexture(new ResourceLocation(StorageNetworkMod.MODID, "textures/gui/expandable_row_right.png"), W, SsnConsts.SQ);
public static final TileableTexture crafting = new TileableTexture(new ResourceLocation(StorageNetworkMod.MODID, "textures/gui/expandable_crafting.png"), W, 66);
public static final TileableTexture crafting_right = new TileableTexture(new ResourceLocation(StorageNetworkMod.MODID, "textures/gui/expandable_crafting_right.png"), W, 66);
public static final TileableTexture player = new TileableTexture(new ResourceLocation(StorageNetworkMod.MODID, "textures/gui/expandable_player.png"), 176, 84);

protected void blitSegment(GuiGraphics ms, TileableTexture tt, int xpos, int ypos) {
ms.blit(tt.texture(), xpos, ypos, 0, 0, tt.width(), tt.height());
}

public void renderBgExpanded(GuiGraphics ms, float partialTicks, int mouseX, int mouseY, int xCenter, int yCenter) {
//render the top
int xpos = xCenter;
int ypos = yCenter;
blitSegment(ms, head, xpos, ypos);
blitSegment(ms, head_right, xpos + W, ypos);
ypos += head.height();
//render the rows
for (int line = 0; line < this.getLines(); line++) {
blitSegment(ms, row, xpos, ypos);
blitSegment(ms, row_right, xpos + W, ypos);
ypos += row.height();
}
blitSegment(ms, crafting, xpos, ypos);
blitSegment(ms, crafting_right, xpos + W, ypos);
ypos += crafting.height() - 4;
blitSegment(ms, player, xpos, ypos);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package com.lothrazar.storagenetwork.item.remote;

import com.lothrazar.storagenetwork.StorageNetworkMod;
import com.lothrazar.storagenetwork.api.DimPos;
import com.lothrazar.storagenetwork.block.main.TileMain;
import com.lothrazar.storagenetwork.gui.ContainerNetwork;
import com.lothrazar.storagenetwork.gui.NetworkCraftingInventory;
import com.lothrazar.storagenetwork.gui.slot.SlotCraftingNetwork;
import com.lothrazar.storagenetwork.registry.SsnRegistry;
import com.lothrazar.storagenetwork.util.UtilInventory;
import net.minecraft.world.Container;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import org.apache.commons.lang3.tuple.Triple;
import java.util.HashMap;
import java.util.Map;

public class ContainerNetworkExpandedRemote extends ContainerNetwork {

Map<Integer, ItemStack> matrixStacks = new HashMap<>();
private TileMain root;
private ItemStack remote;

public ContainerNetworkExpandedRemote(int id, Inventory pInv) {
super(SsnRegistry.Menus.EXPANDED_REMOTE.get(), id);
this.yPlayer = 256 + 196;
this.yCrafting = this.yPlayer - 64 + 7;
this.player = pInv.player;
this.remote = pInv.player.getMainHandItem();
if (this.remote.getItem() != SsnRegistry.Items.EXPANDED_REMOTE.get()) {
Triple<String, Integer, ItemStack> result = UtilInventory.getCurioRemote(player, SsnRegistry.Items.EXPANDED_REMOTE.get());
this.remote = result.getRight();
}
DimPos dp = DimPos.getPosStored(remote);
if (dp == null) {
StorageNetworkMod.LOGGER.error("Remote opening with null pos Stored {} ", remote);
}
else {
this.root = dp.getTileEntity(TileMain.class, player.level());
}
setCraftMatrix(new NetworkCraftingInventory(this, matrixStacks));
this.playerInv = pInv;
SlotCraftingNetwork slotCraftOutput = new SlotCraftingNetwork(this, playerInv.player, getCraftMatrix(), resultInventory, 0,
101, yPlayer - 46 + 7);
slotCraftOutput.setTileMain(getTileMain());
addSlot(slotCraftOutput);
bindGrid();
bindPlayerInvo(this.playerInv);
bindHotbar();
slotsChanged(getCraftMatrix());
}

@Override
public boolean stillValid(Player playerIn) {
return !remote.isEmpty();
}

@Override
public TileMain getTileMain() {
if (root == null) {
DimPos dp = DimPos.getPosStored(remote);
if (dp != null) {
root = dp.getTileEntity(TileMain.class, player.level());
}
}
return root;
}

@Override
public void slotsChanged(Container inventoryIn) {
if (recipeLocked) {
// StorageNetwork.log("recipe locked so onCraftMatrixChanged cancelled");
return;
}
// findMatchingRecipe(matrix);
super.slotsChanged(inventoryIn);
}

@Override
public void removed(Player playerIn) {
super.removed(playerIn);
for (int i = 0; i < getCraftMatrix().getContainerSize(); i++) {
UtilInventory.dropItem(player.level(), playerIn.blockPosition(), getCraftMatrix().getItem(i));
}
}

@Override
public void slotChanged() {}

@Override
public boolean isCrafting() {
return true;
}

public ItemStack getRemote() {
return remote;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,11 @@ public Component getDisplayName() {
@Override
public AbstractContainerMenu createMenu(int id, Inventory inv, Player player) {
boolean crafting = (this == SsnRegistry.Items.CRAFTING_REMOTE.get());
if (crafting) {
boolean expanded = (this == SsnRegistry.Items.EXPANDED_REMOTE.get());
if (expanded) {
return new ContainerNetworkExpandedRemote(id, inv);
}
else if (crafting) {
return new ContainerNetworkCraftingRemote(id, inv);
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.fml.ModList;

public class ScreenNetworkCraftingRemote extends AbstractNetworkScreen<ContainerNetworkCraftingRemote> { // extends AbstractContainerScreen<ContainerNetworkCraftingRemote> implements IGuiNetwork {
public class ScreenNetworkCraftingRemote extends AbstractNetworkScreen<ContainerNetworkCraftingRemote> {

private static final int HEIGHT = 256;
private static final int WIDTH = 176;
Expand All @@ -24,10 +24,10 @@ public class ScreenNetworkCraftingRemote extends AbstractNetworkScreen<Container
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);
remote = screenContainer.getRemote();// inv.player.getItemInHand(InteractionHand.MAIN_HAND);
network = new NetworkWidget(this, NetworkScreenSize.NORMAL);
this.imageWidth = WIDTH;
this.imageHeight = HEIGHT;
imageWidth = WIDTH;
imageHeight = HEIGHT;
}

@Override
Expand All @@ -47,19 +47,14 @@ public void init() {

@Override
protected void renderBg(GuiGraphics ms, float partialTicks, int mouseX, int mouseY) {
int xCenter = (this.width - this.imageWidth) / 2;
int yCenter = (this.height - this.imageHeight) / 2;
final int xCenter = (width - imageWidth) / 2;
final int yCenter = (height - imageHeight) / 2;
ms.blit(textureCraft, xCenter, yCenter, 0, 0, this.imageWidth, this.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);
}

@Override
public boolean getDownwards() {
return ItemStorageCraftingRemote.getDownwards(remote);
Expand Down
Loading

0 comments on commit 8b23fa9

Please sign in to comment.