diff --git a/src/main/java/com/lothrazar/storagenetwork/StorageNetworkMod.java b/src/main/java/com/lothrazar/storagenetwork/StorageNetworkMod.java index 0a874dcf..cf86bde8 100644 --- a/src/main/java/com/lothrazar/storagenetwork/StorageNetworkMod.java +++ b/src/main/java/com/lothrazar/storagenetwork/StorageNetworkMod.java @@ -6,8 +6,8 @@ import com.lothrazar.storagenetwork.block.cable.inputfilter.ScreenCableImportFilter; import com.lothrazar.storagenetwork.block.cable.linkfilter.ScreenCableFilter; import com.lothrazar.storagenetwork.block.collection.ScreenCollectionFilter; -import com.lothrazar.storagenetwork.block.inventory.ScreenNetworkInventory; import com.lothrazar.storagenetwork.block.expand.ScreenNetworkInventoryExpanded; +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.ScreenNetworkRemote; diff --git a/src/main/java/com/lothrazar/storagenetwork/api/IGuiNetwork.java b/src/main/java/com/lothrazar/storagenetwork/api/IGuiNetwork.java index dac3ac66..a96c6428 100644 --- a/src/main/java/com/lothrazar/storagenetwork/api/IGuiNetwork.java +++ b/src/main/java/com/lothrazar/storagenetwork/api/IGuiNetwork.java @@ -23,9 +23,9 @@ public interface IGuiNetwork extends IGuiPrivate { EnumSortType getSort(); - default BlockPos getPos() { - return null; - } + default BlockPos getPos() { + return null; + } default void syncDataToServer() { PacketRegistry.INSTANCE.sendToServer(new SettingsSyncMessage(getPos(), getDownwards(), getSort(), isJeiSearchSynced(), getAutoFocus())); diff --git a/src/main/java/com/lothrazar/storagenetwork/block/AbstractNetworkScreen.java b/src/main/java/com/lothrazar/storagenetwork/block/AbstractNetworkScreen.java index b9b55ad9..0e76e769 100644 --- a/src/main/java/com/lothrazar/storagenetwork/block/AbstractNetworkScreen.java +++ b/src/main/java/com/lothrazar/storagenetwork/block/AbstractNetworkScreen.java @@ -1,8 +1,9 @@ package com.lothrazar.storagenetwork.block; +import java.util.List; import com.lothrazar.storagenetwork.StorageNetworkMod; import com.lothrazar.storagenetwork.api.IGuiNetwork; -import com.lothrazar.storagenetwork.gui.NetworkWidget; +import com.lothrazar.storagenetwork.gui.NetworkScreenSize; import com.lothrazar.storagenetwork.gui.TextboxInteger; import com.lothrazar.storagenetwork.jei.JeiHooks; import com.lothrazar.storagenetwork.network.ClearRecipeMessage; @@ -15,117 +16,117 @@ import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.ItemStack; -import java.util.List; -public abstract class AbstractNetworkScreen extends AbstractContainerScreen implements IGuiNetwork { +public abstract class AbstractNetworkScreen extends AbstractContainerScreen implements IGuiNetwork { - public AbstractNetworkScreen(T container, Inventory inv, Component name) { - super(container, inv, name); - } + public AbstractNetworkScreen(T container, Inventory inv, Component name) { + super(container, inv, name); + } - @Override - public void setStacks(List stacks) { - getNetwork().setStacks(stacks); - } + @Override + public void setStacks(List stacks) { + getNetwork().setStacks(stacks); + } - @Override - public void drawGradient(GuiGraphics ms, int x, int y, int x2, int y2, int u, int v) { - ms.fillGradient(x, y, x2, y2, u, v); - } + @Override + public void drawGradient(GuiGraphics ms, int x, int y, int x2, int y2, int u, int v) { + ms.fillGradient(x, y, x2, y2, u, v); + } - @Override - public boolean charTyped(char typedChar, int keyCode) { - if (getNetwork().charTyped(typedChar, keyCode)) { - return true; - } - return false; + @Override + public boolean charTyped(char typedChar, int keyCode) { + if (getNetwork().charTyped(typedChar, keyCode)) { + return true; } + return false; + } - @Override - public boolean keyPressed(int keyCode, int scanCode, int b) { - InputConstants.Key mouseKey = InputConstants.getKey(keyCode, scanCode); - if (keyCode == TextboxInteger.KEY_ESC) { - minecraft.player.closeContainer(); - return true; // Forge MC-146650: Needs to return true when the key is handled. - } - if (getNetwork().searchBar.isFocused()) { - if (keyCode == TextboxInteger.KEY_BACKSPACE) { // BACKSPACE - getNetwork().syncTextToJei(); - } - getNetwork().searchBar.keyPressed(keyCode, scanCode, b); - return true; - } - else if (!getNetwork().stackUnderMouse.isEmpty()) { - try { - JeiHooks.testJeiKeybind(mouseKey, getNetwork().stackUnderMouse); - } - catch (Throwable e) { - StorageNetworkMod.LOGGER.error("Error thrown from JEI API ", e); - } - } - //Regardless of above branch, also check this - if (minecraft.options.keyInventory.isActiveAndMatches(mouseKey)) { - minecraft.player.closeContainer(); - return true; // Forge MC-146650: Needs to return true when the key is handled. - } - return super.keyPressed(keyCode, scanCode, b); + @Override + public boolean keyPressed(int keyCode, int scanCode, int b) { + InputConstants.Key mouseKey = InputConstants.getKey(keyCode, scanCode); + if (keyCode == TextboxInteger.KEY_ESC) { + minecraft.player.closeContainer(); + return true; // Forge MC-146650: Needs to return true when the key is handled. } - - // used by ItemSlotNetwork and NetworkWidget - @Override - public boolean isInRegion(int x, int y, int width, int height, double mouseX, double mouseY) { - return super.isHovering(x, y, width, height, mouseX, mouseY); + if (getNetwork().searchBar.isFocused()) { + if (keyCode == TextboxInteger.KEY_BACKSPACE) { // BACKSPACE + getNetwork().syncTextToJei(); + } + getNetwork().searchBar.keyPressed(keyCode, scanCode, b); + return true; + } + else if (!getNetwork().stackUnderMouse.isEmpty()) { + try { + JeiHooks.testJeiKeybind(mouseKey, getNetwork().stackUnderMouse); + } + catch (Throwable e) { + StorageNetworkMod.LOGGER.error("Error thrown from JEI API ", e); + } + } + //Regardless of above branch, also check this + if (minecraft.options.keyInventory.isActiveAndMatches(mouseKey)) { + minecraft.player.closeContainer(); + return true; // Forge MC-146650: Needs to return true when the key is handled. } + return super.keyPressed(keyCode, scanCode, b); + } - public boolean isScrollable(double x, double y) { + // used by ItemSlotNetwork and NetworkWidget + @Override + public boolean isInRegion(int x, int y, int width, int height, double mouseX, double mouseY) { + return super.isHovering(x, y, width, height, mouseX, mouseY); + } - return isHovering(getNetwork().xNetwork, getNetwork().yNetwork, - this.width, getNetwork().scrollHeight, - x, y); - } - @Override - public boolean mouseScrolled(double x, double y, double mouseButton) { - super.mouseScrolled(x, y, mouseButton); - //<0 going down - // >0 going up - if (isScrollable(x, y) && mouseButton != 0) { - getNetwork().mouseScrolled(mouseButton); - } - return true; + public boolean isScrollable(double x, double y) { + return isHovering(getNetwork().xNetwork, getNetwork().yNetwork, + this.width, getNetwork().scrollHeight, + x, y); + } + + @Override + public boolean mouseScrolled(double x, double y, double mouseButton) { + super.mouseScrolled(x, y, mouseButton); + //<0 going down + // >0 going up + if (isScrollable(x, y) && mouseButton != 0) { + getNetwork().mouseScrolled(mouseButton); } + return true; + } - @Override - public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) { - super.mouseClicked(mouseX, mouseY, mouseButton); - getNetwork().mouseClicked(mouseX, mouseY, mouseButton); - if(getNetwork().getSize() == NetworkWidget.NetworkScreenSize.NORMAL) { - //TODO: this is part of crafting grid, to clear it out. should be its own button class - 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; - } - } + @Override + public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) { + super.mouseClicked(mouseX, mouseY, mouseButton); + getNetwork().mouseClicked(mouseX, mouseY, mouseButton); + if (getNetwork().getSize() == NetworkScreenSize.NORMAL) { + //TODO: this is part of crafting grid, to clear it out. should be its own button class + 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; + } - @Override - public void render(GuiGraphics ms, int mouseX, int mouseY, float partialTicks) { - this.renderBackground(ms); - super.render(ms, mouseX, mouseY, partialTicks); - this.renderTooltip(ms, mouseX, mouseY); - getNetwork().searchBar.render(ms, mouseX, mouseY, partialTicks); - getNetwork().render(); - } - @Override - public void renderStackTooltip(GuiGraphics ms, ItemStack stack, int mousex, int mousey) { - ms.renderTooltip(font, stack, mousex, mousey); - } + @Override + public void render(GuiGraphics ms, int mouseX, int mouseY, float partialTicks) { + this.renderBackground(ms); + super.render(ms, mouseX, mouseY, partialTicks); + this.renderTooltip(ms, mouseX, mouseY); + getNetwork().searchBar.render(ms, mouseX, mouseY, partialTicks); + getNetwork().render(); + } - @Override - public void renderLabels(GuiGraphics ms, int mouseX, int mouseY) { - getNetwork().drawGuiContainerForegroundLayer(ms, mouseX, mouseY, font); - } + @Override + public void renderStackTooltip(GuiGraphics ms, ItemStack stack, int mousex, int mousey) { + ms.renderTooltip(font, stack, mousex, mousey); + } + + @Override + public void renderLabels(GuiGraphics ms, int mouseX, int mouseY) { + getNetwork().drawGuiContainerForegroundLayer(ms, mouseX, mouseY, font); + } } diff --git a/src/main/java/com/lothrazar/storagenetwork/block/EntityBlockConnectable.java b/src/main/java/com/lothrazar/storagenetwork/block/EntityBlockConnectable.java index 1fafb422..9cc8a7f6 100644 --- a/src/main/java/com/lothrazar/storagenetwork/block/EntityBlockConnectable.java +++ b/src/main/java/com/lothrazar/storagenetwork/block/EntityBlockConnectable.java @@ -21,41 +21,40 @@ public abstract class EntityBlockConnectable extends EntityBlockFlib { - protected boolean hasGui = true; - - public EntityBlockConnectable() { - this(Block.Properties.of().strength(0.5F).sound(SoundType.STONE)); - } - - public EntityBlockConnectable(BlockBehaviour.Properties p) { - super(p); - } - - @Override - public RenderShape getRenderShape(BlockState bs) { - return RenderShape.MODEL; - } - - - @Override - public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult result) { - if (!world.isClientSide && hasGui) { - if( world.getBlockEntity(pos) instanceof TileConnectable tile) { - if (tile.getMain() == null || tile.getMain().getBlockPos() == null) { - return InteractionResult.PASS; - } - //sync - ServerPlayer sp = (ServerPlayer) player; - PacketRegistry.INSTANCE.sendTo(new SortClientMessage(pos, tile.isDownwards(), tile.getSort()), sp.connection.connection, NetworkDirection.PLAY_TO_CLIENT); - //end sync - if (tile instanceof MenuProvider) { - NetworkHooks.openScreen((ServerPlayer) player, (MenuProvider) tile, tile.getBlockPos()); - } - else { - throw new IllegalStateException("Our named container provider is missing!"); - } + protected boolean hasGui = true; + + public EntityBlockConnectable() { + this(Block.Properties.of().strength(0.5F).sound(SoundType.STONE)); + } + + public EntityBlockConnectable(BlockBehaviour.Properties p) { + super(p); + } + + @Override + public RenderShape getRenderShape(BlockState bs) { + return RenderShape.MODEL; + } + + @Override + public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult result) { + if (!world.isClientSide && hasGui) { + if (world.getBlockEntity(pos) instanceof TileConnectable tile) { + if (tile.getMain() == null || tile.getMain().getBlockPos() == null) { + return InteractionResult.PASS; + } + //sync + ServerPlayer sp = (ServerPlayer) player; + PacketRegistry.INSTANCE.sendTo(new SortClientMessage(pos, tile.isDownwards(), tile.getSort()), sp.connection.connection, NetworkDirection.PLAY_TO_CLIENT); + //end sync + if (tile instanceof MenuProvider) { + NetworkHooks.openScreen((ServerPlayer) player, (MenuProvider) tile, tile.getBlockPos()); } + else { + throw new IllegalStateException("Our named container provider is missing!"); } - return InteractionResult.SUCCESS; + } } + return InteractionResult.SUCCESS; + } } diff --git a/src/main/java/com/lothrazar/storagenetwork/block/TableSize.java b/src/main/java/com/lothrazar/storagenetwork/block/TableSize.java index 3f17e617..c7904ed8 100644 --- a/src/main/java/com/lothrazar/storagenetwork/block/TableSize.java +++ b/src/main/java/com/lothrazar/storagenetwork/block/TableSize.java @@ -1,6 +1,4 @@ package com.lothrazar.storagenetwork.block; - - public enum TableSize { NORMAL, EXPANDED; } diff --git a/src/main/java/com/lothrazar/storagenetwork/block/TileConnectable.java b/src/main/java/com/lothrazar/storagenetwork/block/TileConnectable.java index 942dfe1f..8213ed9d 100644 --- a/src/main/java/com/lothrazar/storagenetwork/block/TileConnectable.java +++ b/src/main/java/com/lothrazar/storagenetwork/block/TileConnectable.java @@ -30,9 +30,10 @@ public TileConnectable(BlockEntityType tileEntityTypeIn, BlockPos pos, BlockS connectable = new CapabilityConnectable(); } - public EnumSortType getSort() { + public EnumSortType getSort() { return EnumSortType.NAME; //unused by some blocks } + public boolean isDownwards() { return false; //unused by some blocks } diff --git a/src/main/java/com/lothrazar/storagenetwork/block/expand/BlockInventoryExpanded.java b/src/main/java/com/lothrazar/storagenetwork/block/expand/BlockInventoryExpanded.java index 74392ec5..759d7b6b 100644 --- a/src/main/java/com/lothrazar/storagenetwork/block/expand/BlockInventoryExpanded.java +++ b/src/main/java/com/lothrazar/storagenetwork/block/expand/BlockInventoryExpanded.java @@ -15,5 +15,4 @@ public BlockInventoryExpanded() { public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { return new TileInventoryExpanded(pos, state); } - } diff --git a/src/main/java/com/lothrazar/storagenetwork/block/expand/ContainerNetworkInventoryExpanded.java b/src/main/java/com/lothrazar/storagenetwork/block/expand/ContainerNetworkInventoryExpanded.java index 0491f83d..d43ee580 100644 --- a/src/main/java/com/lothrazar/storagenetwork/block/expand/ContainerNetworkInventoryExpanded.java +++ b/src/main/java/com/lothrazar/storagenetwork/block/expand/ContainerNetworkInventoryExpanded.java @@ -1,7 +1,5 @@ package com.lothrazar.storagenetwork.block.expand; -import com.lothrazar.storagenetwork.block.inventory.ContainerNetworkInventory; -import com.lothrazar.storagenetwork.block.inventory.TileInventory; import com.lothrazar.storagenetwork.block.main.TileMain; import com.lothrazar.storagenetwork.gui.ContainerNetwork; import com.lothrazar.storagenetwork.registry.SsnRegistry; @@ -12,22 +10,23 @@ import net.minecraft.world.level.Level; public class ContainerNetworkInventoryExpanded extends ContainerNetwork { + TileInventoryExpanded tile; - public ContainerNetworkInventoryExpanded(int windowId, Level world, BlockPos pos, Inventory playerInv, Player player) { + public ContainerNetworkInventoryExpanded(int windowId, Level world, BlockPos pos, Inventory playerInv, Player player) { this(SsnRegistry.Menus.INVENTORY_EXPANDED.get(), windowId, world, pos, playerInv, player); - // super(SsnRegistry.Menus.INVENTORY_EXPANDED.get(), windowId, world, pos, playerInv, player); - } + public ContainerNetworkInventoryExpanded(MenuType menuType, int windowId, Level world, BlockPos pos, Inventory playerInv, Player player) { super(menuType, windowId); tile = (TileInventoryExpanded) world.getBlockEntity(pos); - this.yPlayer = 174 +128; ////////////////// + this.yPlayer = 174 + 128; ////////////////// this.playerInv = playerInv; bindPlayerInvo(this.playerInv); bindHotbar(); } + @Override public boolean isCrafting() { return false; diff --git a/src/main/java/com/lothrazar/storagenetwork/block/expand/ScreenNetworkInventoryExpanded.java b/src/main/java/com/lothrazar/storagenetwork/block/expand/ScreenNetworkInventoryExpanded.java index 98f6bbcd..a9e4880a 100644 --- a/src/main/java/com/lothrazar/storagenetwork/block/expand/ScreenNetworkInventoryExpanded.java +++ b/src/main/java/com/lothrazar/storagenetwork/block/expand/ScreenNetworkInventoryExpanded.java @@ -2,39 +2,29 @@ import com.lothrazar.storagenetwork.StorageNetworkMod; import com.lothrazar.storagenetwork.api.EnumSortType; -import com.lothrazar.storagenetwork.api.IGuiNetwork; import com.lothrazar.storagenetwork.block.AbstractNetworkScreen; -import com.lothrazar.storagenetwork.block.inventory.ContainerNetworkInventory; -import com.lothrazar.storagenetwork.block.inventory.ScreenNetworkInventory; -import com.lothrazar.storagenetwork.block.inventory.TileInventory; +import com.lothrazar.storagenetwork.gui.NetworkScreenSize; import com.lothrazar.storagenetwork.gui.NetworkWidget; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.components.EditBox; -import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; 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.minecraft.world.item.ItemStack; import net.minecraftforge.fml.ModList; -import java.util.List; - public class ScreenNetworkInventoryExpanded extends AbstractNetworkScreen {//AbstractContainerScreen implements IGuiNetwork { protected int HEIGHT = 256; public int WIDTH = 176; - protected final NetworkWidget network; + 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); - tile = container.tile; - network = new NetworkWidget(this, NetworkWidget.NetworkScreenSize.EXPANDED); + network = new NetworkWidget(this, NetworkScreenSize.EXPANDED); imageHeight = HEIGHT; imageWidth = WIDTH; } @@ -43,7 +33,6 @@ public ScreenNetworkInventoryExpanded(ContainerNetworkInventoryExpanded containe public void init() { super.init(); network.init(this.font); - addRenderableWidget(network.directionBtn); addRenderableWidget(network.sortBtn); addRenderableWidget(network.focusBtn); @@ -64,8 +53,7 @@ public void renderBg(GuiGraphics ms, float partialTicks, int mouseX, int mouseY) network.applySearchTextToSlots(); network.renderItemSlots(ms, mouseX, mouseY, font); } - -// all the IGUINETWORK implementations + // all the IGUINETWORK implementations @Override public boolean getDownwards() { @@ -116,5 +104,4 @@ public void setAutoFocus(boolean b) { public NetworkWidget getNetwork() { return network; } - } diff --git a/src/main/java/com/lothrazar/storagenetwork/block/inventory/BlockInventory.java b/src/main/java/com/lothrazar/storagenetwork/block/inventory/BlockInventory.java index 86fc2f0c..9b62433a 100644 --- a/src/main/java/com/lothrazar/storagenetwork/block/inventory/BlockInventory.java +++ b/src/main/java/com/lothrazar/storagenetwork/block/inventory/BlockInventory.java @@ -1,25 +1,9 @@ package com.lothrazar.storagenetwork.block.inventory; -import com.lothrazar.library.block.EntityBlockFlib; import com.lothrazar.storagenetwork.block.EntityBlockConnectable; -import com.lothrazar.storagenetwork.block.TileConnectable; -import com.lothrazar.storagenetwork.network.SortClientMessage; -import com.lothrazar.storagenetwork.registry.PacketRegistry; import net.minecraft.core.BlockPos; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.MenuProvider; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.RenderShape; -import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.BlockHitResult; -import net.minecraftforge.network.NetworkDirection; -import net.minecraftforge.network.NetworkHooks; public class BlockInventory extends EntityBlockConnectable { @@ -31,5 +15,4 @@ public BlockInventory() { public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { return new TileInventory(pos, state); } - } diff --git a/src/main/java/com/lothrazar/storagenetwork/block/inventory/ContainerNetworkInventory.java b/src/main/java/com/lothrazar/storagenetwork/block/inventory/ContainerNetworkInventory.java index c93c2927..6d820b91 100644 --- a/src/main/java/com/lothrazar/storagenetwork/block/inventory/ContainerNetworkInventory.java +++ b/src/main/java/com/lothrazar/storagenetwork/block/inventory/ContainerNetworkInventory.java @@ -7,7 +7,6 @@ import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.MenuType; -import net.minecraft.world.inventory.ResultContainer; import net.minecraft.world.level.Level; public class ContainerNetworkInventory extends ContainerNetwork { 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 b8d397da..4226fa31 100644 --- a/src/main/java/com/lothrazar/storagenetwork/block/inventory/ScreenNetworkInventory.java +++ b/src/main/java/com/lothrazar/storagenetwork/block/inventory/ScreenNetworkInventory.java @@ -1,30 +1,17 @@ package com.lothrazar.storagenetwork.block.inventory; -import java.util.List; import com.lothrazar.storagenetwork.StorageNetworkMod; import com.lothrazar.storagenetwork.api.EnumSortType; -import com.lothrazar.storagenetwork.api.IGuiNetwork; import com.lothrazar.storagenetwork.block.AbstractNetworkScreen; +import com.lothrazar.storagenetwork.gui.NetworkScreenSize; import com.lothrazar.storagenetwork.gui.NetworkWidget; -import com.lothrazar.storagenetwork.gui.NetworkWidget.NetworkScreenSize; -import com.lothrazar.storagenetwork.gui.TextboxInteger; -import com.lothrazar.storagenetwork.jei.JeiHooks; -import com.lothrazar.storagenetwork.network.SettingsSyncMessage; -import com.lothrazar.storagenetwork.registry.PacketRegistry; -import com.mojang.blaze3d.platform.InputConstants; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.components.EditBox; -import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; 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.minecraft.world.item.ItemStack; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.fml.ModList; - public class ScreenNetworkInventory extends AbstractNetworkScreen {//AbstractContainerScreen implements IGuiNetwork { protected int HEIGHT = 256; @@ -45,7 +32,6 @@ public ScreenNetworkInventory(ContainerNetworkInventory container, Inventory inv public void init() { super.init(); network.init(this.font); - addRenderableWidget(network.directionBtn); addRenderableWidget(network.sortBtn); addRenderableWidget(network.focusBtn); @@ -65,9 +51,7 @@ public void renderBg(GuiGraphics ms, float partialTicks, int mouseX, int mouseY) network.applySearchTextToSlots(); network.renderItemSlots(ms, mouseX, mouseY, font); } - -// all the IGUINETWORK implementations - + // all the IGUINETWORK implementations @Override public boolean getDownwards() { @@ -118,5 +102,4 @@ public void setAutoFocus(boolean b) { public NetworkWidget getNetwork() { return network; } - } diff --git a/src/main/java/com/lothrazar/storagenetwork/block/request/ScreenNetworkTable.java b/src/main/java/com/lothrazar/storagenetwork/block/request/ScreenNetworkTable.java index baad5531..ca9c9c74 100644 --- a/src/main/java/com/lothrazar/storagenetwork/block/request/ScreenNetworkTable.java +++ b/src/main/java/com/lothrazar/storagenetwork/block/request/ScreenNetworkTable.java @@ -1,33 +1,20 @@ package com.lothrazar.storagenetwork.block.request; -import java.util.List; import com.lothrazar.storagenetwork.StorageNetworkMod; import com.lothrazar.storagenetwork.api.EnumSortType; -import com.lothrazar.storagenetwork.api.IGuiNetwork; import com.lothrazar.storagenetwork.block.AbstractNetworkScreen; +import com.lothrazar.storagenetwork.gui.NetworkScreenSize; import com.lothrazar.storagenetwork.gui.NetworkWidget; -import com.lothrazar.storagenetwork.gui.NetworkWidget.NetworkScreenSize; -import com.lothrazar.storagenetwork.gui.TextboxInteger; -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; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.components.EditBox; -import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; 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.minecraft.world.item.ItemStack; import net.minecraftforge.fml.ModList; - public class ScreenNetworkTable extends - AbstractNetworkScreen { - //AbstractContainerScreen implements IGuiNetwork { + AbstractNetworkScreen { + //AbstractContainerScreen implements IGuiNetwork { private static final int HEIGHT = 256; public static final int WIDTH = 176; @@ -47,7 +34,6 @@ public ScreenNetworkTable(ContainerNetworkCraftingTable container, Inventory inv public void init() { super.init(); network.init(this.font); - addRenderableWidget(network.directionBtn); addRenderableWidget(network.sortBtn); addRenderableWidget(network.focusBtn); @@ -58,6 +44,7 @@ public void init() { addRenderableWidget(network.jeiBtn); } } + @Override public void renderBg(GuiGraphics ms, float partialTicks, int mouseX, int mouseY) { int xCenter = (width - imageWidth) / 2; @@ -67,11 +54,7 @@ public void renderBg(GuiGraphics ms, float partialTicks, int mouseX, int mouseY) network.applySearchTextToSlots(); network.renderItemSlots(ms, mouseX, mouseY, font); } - - - -// all the IGUINETWORK implementations - + // all the IGUINETWORK implementations @Override public boolean getDownwards() { diff --git a/src/main/java/com/lothrazar/storagenetwork/emi/EMIPlugin.java b/src/main/java/com/lothrazar/storagenetwork/emi/EMIPlugin.java index 9e379cbd..833a3f98 100644 --- a/src/main/java/com/lothrazar/storagenetwork/emi/EMIPlugin.java +++ b/src/main/java/com/lothrazar/storagenetwork/emi/EMIPlugin.java @@ -2,6 +2,7 @@ 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.ScreenNetworkCraftingRemote; @@ -34,7 +35,7 @@ public void register(EmiRegistry registry) { } static { - NetworkWidget.searchHandlers.add(new NetworkWidget.ISearchHandler() { + NetworkWidget.searchHandlers.add(new ISearchHandler() { @Override public void setSearch(String set) { diff --git a/src/main/java/com/lothrazar/storagenetwork/gui/ISearchHandler.java b/src/main/java/com/lothrazar/storagenetwork/gui/ISearchHandler.java new file mode 100644 index 00000000..2f7f03c6 --- /dev/null +++ b/src/main/java/com/lothrazar/storagenetwork/gui/ISearchHandler.java @@ -0,0 +1,9 @@ +package com.lothrazar.storagenetwork.gui; +public interface ISearchHandler { + + public abstract void setSearch(String set); + + public abstract String getSearch(); + + public abstract String getName(); +} \ No newline at end of file diff --git a/src/main/java/com/lothrazar/storagenetwork/gui/NetworkScreenSize.java b/src/main/java/com/lothrazar/storagenetwork/gui/NetworkScreenSize.java new file mode 100644 index 00000000..a8e08ba0 --- /dev/null +++ b/src/main/java/com/lothrazar/storagenetwork/gui/NetworkScreenSize.java @@ -0,0 +1,7 @@ +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; +} \ No newline at end of file diff --git a/src/main/java/com/lothrazar/storagenetwork/gui/NetworkWidget.java b/src/main/java/com/lothrazar/storagenetwork/gui/NetworkWidget.java index 1ccd5e0b..00c2f1b4 100644 --- a/src/main/java/com/lothrazar/storagenetwork/gui/NetworkWidget.java +++ b/src/main/java/com/lothrazar/storagenetwork/gui/NetworkWidget.java @@ -67,12 +67,11 @@ public NetworkWidget(IGuiNetwork gui, NetworkScreenSize size) { this.gui = gui; stacks = Lists.newArrayList(); slots = Lists.newArrayList(); - switch (size) { case NORMAL: setLines(4); scrollHeight = 135; - break; + break; case LARGE: setLines(4 * 2); scrollHeight = (SsnConsts.SQ + 1) * this.getLines(); // 152; @@ -96,7 +95,9 @@ public void setStacks(List stacks) { this.stacks = stacks; } - public NetworkScreenSize getSize(){return size;} + public NetworkScreenSize getSize() { + return size; + } public void applySearchTextToSlots() { String searchText = searchBar.getValue(); @@ -220,31 +221,29 @@ public boolean inSearchBar(double mouseX, double mouseY) { searchBar.getWidth(), searchBar.getHeight(), // width, height mouseX, mouseY); } + public void init(Font font) { this.font = font; - - int searchLeft = gui.getGuiLeft() + 81, searchTop = gui.getGuiTop(), width = 85; - switch(this.size){ - case NORMAL -> { - searchTop += 96; - } - case LARGE -> { - searchTop += 160; - } - case EXPANDED -> { - searchTop += 160 + 128; - } + switch (this.size) { + case NORMAL -> { + searchTop += 96; + } + case LARGE -> { + searchTop += 160; + } + case EXPANDED -> { + searchTop += 160 + 128; + } } initSearchbar(searchLeft, searchTop, width); initButtons(); } private void initSearchbar(int searchLeft, int searchTop, int width) { - searchBar = new EditBox(font, - searchLeft, searchTop, - width, font.lineHeight, null); + searchLeft, searchTop, + width, font.lineHeight, null); searchBar.setMaxLength(30); searchBar.setBordered(false); searchBar.setVisible(true); @@ -305,14 +304,12 @@ else if (this.inSearchBar(mouseX, mouseY)) { lis.add(Component.translatable("gui.storagenetwork.fil.tooltip_tooltip")); //# lis.add(Component.translatable("gui.storagenetwork.fil.tooltip_tags")); //$ lis.add(Component.translatable("gui.storagenetwork.fil.tooltip_clear")); //clear - // Screen screen = ((Screen) gui); ms.renderTooltip(font, lis, Optional.empty(), mouseX - gui.getGuiLeft(), mouseY - gui.getGuiTop()); return; // all done, we have our tts rendered } } //do we have a tooltip if (tooltip != null) { - // Screen screen = ((Screen) gui); ms.renderTooltip(font, Lists.newArrayList(tooltip), Optional.empty(), mouseX - gui.getGuiLeft(), mouseY - gui.getGuiTop()); } } @@ -375,15 +372,14 @@ private boolean inField(int mouseX, int mouseY) { switch (size) { case NORMAL: fieldHeight = 90; - break; + break; case LARGE: fieldHeight = 172; - break; + break; case EXPANDED: - fieldHeight = 172*2; - break; + fieldHeight = 172 * 2; + break; } - boolean inField = mouseX > (gui.getGuiLeft() + 7) && mouseX < (gui.getGuiLeft() + ScreenNetworkTable.WIDTH - 7) && mouseY > (gui.getGuiTop() + 7) && mouseY < (gui.getGuiTop() + fieldHeight); return inField; @@ -456,17 +452,4 @@ public void render() { jeiBtn.setTextureId(gui.isJeiSearchSynced() ? TextureEnum.JEI_GREEN : TextureEnum.JEI_RED); } } - - public interface ISearchHandler { - - public abstract void setSearch(String set); - - public abstract String getSearch(); - - public abstract String getName(); - } - - public enum NetworkScreenSize { - NORMAL, LARGE, EXPANDED; - } } 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 93f9f7e0..5368032e 100644 --- a/src/main/java/com/lothrazar/storagenetwork/item/remote/ScreenNetworkCraftingRemote.java +++ b/src/main/java/com/lothrazar/storagenetwork/item/remote/ScreenNetworkCraftingRemote.java @@ -1,22 +1,11 @@ package com.lothrazar.storagenetwork.item.remote; -import java.util.List; import com.lothrazar.storagenetwork.StorageNetworkMod; import com.lothrazar.storagenetwork.api.EnumSortType; -import com.lothrazar.storagenetwork.api.IGuiNetwork; import com.lothrazar.storagenetwork.block.AbstractNetworkScreen; +import com.lothrazar.storagenetwork.gui.NetworkScreenSize; import com.lothrazar.storagenetwork.gui.NetworkWidget; -import com.lothrazar.storagenetwork.gui.NetworkWidget.NetworkScreenSize; -import com.lothrazar.storagenetwork.gui.TextboxInteger; -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; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.components.EditBox; -import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; @@ -44,7 +33,6 @@ public ScreenNetworkCraftingRemote(ContainerNetworkCraftingRemote screenContaine public void init() { super.init(); network.init(this.font); - addRenderableWidget(network.directionBtn); addRenderableWidget(network.sortBtn); addRenderableWidget(network.focusBtn); diff --git a/src/main/java/com/lothrazar/storagenetwork/item/remote/ScreenNetworkRemote.java b/src/main/java/com/lothrazar/storagenetwork/item/remote/ScreenNetworkRemote.java index 7390e8c5..021ca8f6 100644 --- a/src/main/java/com/lothrazar/storagenetwork/item/remote/ScreenNetworkRemote.java +++ b/src/main/java/com/lothrazar/storagenetwork/item/remote/ScreenNetworkRemote.java @@ -1,27 +1,18 @@ package com.lothrazar.storagenetwork.item.remote; -import java.util.List; import com.lothrazar.storagenetwork.StorageNetworkMod; import com.lothrazar.storagenetwork.api.EnumSortType; -import com.lothrazar.storagenetwork.api.IGuiNetwork; import com.lothrazar.storagenetwork.block.AbstractNetworkScreen; +import com.lothrazar.storagenetwork.gui.NetworkScreenSize; import com.lothrazar.storagenetwork.gui.NetworkWidget; -import com.lothrazar.storagenetwork.gui.NetworkWidget.NetworkScreenSize; -import com.lothrazar.storagenetwork.gui.TextboxInteger; -import com.lothrazar.storagenetwork.jei.JeiHooks; -import com.lothrazar.storagenetwork.network.SettingsSyncMessage; -import com.lothrazar.storagenetwork.registry.PacketRegistry; -import com.mojang.blaze3d.platform.InputConstants; import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.components.EditBox; -import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.item.ItemStack; import net.minecraftforge.fml.ModList; -public class ScreenNetworkRemote extends AbstractNetworkScreen {// extends AbstractContainerScreen implements IGuiNetwork { +public class ScreenNetworkRemote extends AbstractNetworkScreen {// extends AbstractContainerScreen implements IGuiNetwork { private static final int HEIGHT = 256; private static final int WIDTH = 176; @@ -35,18 +26,14 @@ public ScreenNetworkRemote(ContainerNetworkRemote screenContainer, Inventory inv //since the rightclick action forces only MAIN_HAND openings, is ok this.remote = screenContainer.getRemote(); network = new NetworkWidget(this, NetworkScreenSize.LARGE); - this.imageWidth = WIDTH; this.imageHeight = HEIGHT; } - @Override public void init() { super.init(); - network.init(this.font); - addRenderableWidget(network.directionBtn); addRenderableWidget(network.sortBtn); addRenderableWidget(network.focusBtn); diff --git a/src/main/java/com/lothrazar/storagenetwork/jei/JeiPlugin.java b/src/main/java/com/lothrazar/storagenetwork/jei/JeiPlugin.java index b9d649ea..6ae6ee39 100644 --- a/src/main/java/com/lothrazar/storagenetwork/jei/JeiPlugin.java +++ b/src/main/java/com/lothrazar/storagenetwork/jei/JeiPlugin.java @@ -3,6 +3,7 @@ import java.util.Optional; import com.lothrazar.storagenetwork.StorageNetworkMod; import com.lothrazar.storagenetwork.block.request.ContainerNetworkCraftingTable; +import com.lothrazar.storagenetwork.gui.ISearchHandler; import com.lothrazar.storagenetwork.gui.NetworkWidget; import com.lothrazar.storagenetwork.item.remote.ContainerNetworkCraftingRemote; import com.lothrazar.storagenetwork.registry.SsnRegistry; @@ -61,7 +62,7 @@ public Optional> getMenuType() { } static { - NetworkWidget.searchHandlers.add(new NetworkWidget.ISearchHandler() { + NetworkWidget.searchHandlers.add(new ISearchHandler() { @Override public void setSearch(String text) { diff --git a/src/main/java/com/lothrazar/storagenetwork/registry/SsnRegistry.java b/src/main/java/com/lothrazar/storagenetwork/registry/SsnRegistry.java index e7c931f7..a18930b6 100644 --- a/src/main/java/com/lothrazar/storagenetwork/registry/SsnRegistry.java +++ b/src/main/java/com/lothrazar/storagenetwork/registry/SsnRegistry.java @@ -24,7 +24,9 @@ import com.lothrazar.storagenetwork.block.expand.BlockInventoryExpanded; import com.lothrazar.storagenetwork.block.expand.ContainerNetworkInventoryExpanded; import com.lothrazar.storagenetwork.block.expand.TileInventoryExpanded; -import com.lothrazar.storagenetwork.block.inventory.*; +import com.lothrazar.storagenetwork.block.inventory.BlockInventory; +import com.lothrazar.storagenetwork.block.inventory.ContainerNetworkInventory; +import com.lothrazar.storagenetwork.block.inventory.TileInventory; import com.lothrazar.storagenetwork.block.main.BlockMain; import com.lothrazar.storagenetwork.block.main.TileMain; import com.lothrazar.storagenetwork.block.request.BlockRequest; @@ -59,7 +61,7 @@ public class SsnRegistry { public static class Blocks { public static final RegistryObject REQUEST = BLOCKS.register("request", () -> new BlockRequest()); - // public static final RegistryObject REQUEST_EXPANDED = BLOCKS.register("request_expanded", () -> new BlockRequest()); + // public static final RegistryObject REQUEST_EXPANDED = BLOCKS.register("request_expanded", () -> new BlockRequest()); public static final RegistryObject KABEL = BLOCKS.register("kabel", () -> new BlockCable()); public static final RegistryObject MASTER = BLOCKS.register("master", () -> new BlockMain()); public static final RegistryObject STORAGE_KABEL = BLOCKS.register("storage_kabel", () -> new BlockCableLink()); @@ -77,7 +79,7 @@ public static class Blocks { public static class Items { public static final RegistryObject REQUEST = ITEMS.register("request", () -> new BlockItem(Blocks.REQUEST.get(), new Item.Properties())); - // public static final RegistryObject REQUEST_EXPANDED = ITEMS.register("request_expanded", () -> new BlockItem(Blocks.REQUEST_EXPANDED.get(), new Item.Properties())); + // public static final RegistryObject REQUEST_EXPANDED = ITEMS.register("request_expanded", () -> new BlockItem(Blocks.REQUEST_EXPANDED.get(), new Item.Properties())); public static final RegistryObject KABEL = ITEMS.register("kabel", () -> new BlockItem(Blocks.KABEL.get(), new Item.Properties())); public static final RegistryObject INVENTORY = ITEMS.register("inventory", () -> new BlockItem(Blocks.INVENTORY.get(), new Item.Properties())); public static final RegistryObject INVENTORY_EXPANDED = ITEMS.register("inventory_expanded", () -> new BlockItem(Blocks.INVENTORY_EXPANDED.get(), new Item.Properties()));