From 2bae408c5990ae1421bcfd643cc9a58d9c02c6bc Mon Sep 17 00:00:00 2001 From: Raoul Van den Berge Date: Fri, 18 Dec 2015 15:10:38 +0100 Subject: [PATCH] add redstone controls --- src/main/java/storagecraft/StorageCraft.java | 3 +- .../storagecraft/block/BlockStorageProxy.java | 11 ++++ .../container/ContainerStorageProxy.java | 11 ++++ .../java/storagecraft/gui/GuiController.java | 42 +++++------- src/main/java/storagecraft/gui/GuiDrive.java | 22 ++++--- src/main/java/storagecraft/gui/GuiGrid.java | 7 +- .../java/storagecraft/gui/GuiHandler.java | 8 ++- .../java/storagecraft/gui/GuiImporter.java | 13 ++-- .../java/storagecraft/gui/GuiMachine.java | 61 +++++++++++++++++ .../storagecraft/gui/GuiStorageProxy.java | 32 +++++++++ .../network/MessageRedstoneModeUpdate.java | 60 +++++++++++++++++ .../java/storagecraft/proxy/CommonProxy.java | 2 + .../java/storagecraft/tile/RedstoneMode.java | 23 +++++++ src/main/java/storagecraft/tile/TileBase.java | 2 +- .../java/storagecraft/tile/TileCable.java | 2 +- .../java/storagecraft/tile/TileDrive.java | 4 ++ src/main/java/storagecraft/tile/TileGrid.java | 6 +- .../java/storagecraft/tile/TileImporter.java | 62 +++++++++--------- .../java/storagecraft/tile/TileMachine.java | 60 ++++++++++++++++- .../storagecraft/tile/TileStorageProxy.java | 33 ++++++---- .../assets/storagecraft/lang/en_US.lang | 5 ++ .../assets/storagecraft/lang/nl_NL.lang | 5 ++ .../textures/gui/storageProxy.png | Bin 0 -> 1788 bytes 23 files changed, 376 insertions(+), 98 deletions(-) create mode 100644 src/main/java/storagecraft/container/ContainerStorageProxy.java create mode 100644 src/main/java/storagecraft/gui/GuiMachine.java create mode 100644 src/main/java/storagecraft/gui/GuiStorageProxy.java create mode 100644 src/main/java/storagecraft/network/MessageRedstoneModeUpdate.java create mode 100644 src/main/java/storagecraft/tile/RedstoneMode.java create mode 100644 src/main/resources/assets/storagecraft/textures/gui/storageProxy.png diff --git a/src/main/java/storagecraft/StorageCraft.java b/src/main/java/storagecraft/StorageCraft.java index b4ec2759c..7aa288132 100644 --- a/src/main/java/storagecraft/StorageCraft.java +++ b/src/main/java/storagecraft/StorageCraft.java @@ -19,7 +19,8 @@ public class StorageCraft { public static final int CONTROLLER = 0; public static final int GRID = 1; public static final int DRIVE = 2; - public static final int IMPORTER = 3; + public static final int STORAGE_PROXY = 3; + public static final int IMPORTER = 4; } public static final String ID = "storagecraft"; diff --git a/src/main/java/storagecraft/block/BlockStorageProxy.java b/src/main/java/storagecraft/block/BlockStorageProxy.java index a2bd4401d..acf169f9f 100644 --- a/src/main/java/storagecraft/block/BlockStorageProxy.java +++ b/src/main/java/storagecraft/block/BlockStorageProxy.java @@ -2,10 +2,12 @@ package storagecraft.block; import net.minecraft.block.ITileEntityProvider; import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; +import storagecraft.StorageCraft; import storagecraft.tile.TileStorageProxy; public class BlockStorageProxy extends BlockBase implements ITileEntityProvider { @@ -21,6 +23,15 @@ public class BlockStorageProxy extends BlockBase implements ITileEntityProvider return new TileStorageProxy(); } + @Override + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) { + if (!world.isRemote) { + player.openGui(StorageCraft.INSTANCE, StorageCraft.GUI.STORAGE_PROXY, world, x, y, z); + } + + return true; + } + @Override public void registerBlockIcons(IIconRegister register) { frontIcon = register.registerIcon("storagecraft:storageProxy"); diff --git a/src/main/java/storagecraft/container/ContainerStorageProxy.java b/src/main/java/storagecraft/container/ContainerStorageProxy.java new file mode 100644 index 000000000..e73d1cf49 --- /dev/null +++ b/src/main/java/storagecraft/container/ContainerStorageProxy.java @@ -0,0 +1,11 @@ +package storagecraft.container; + +import net.minecraft.entity.player.EntityPlayer; + +public class ContainerStorageProxy extends ContainerBase { + public ContainerStorageProxy(EntityPlayer player) { + super(player); + + addPlayerInventory(8, 50); + } +} diff --git a/src/main/java/storagecraft/gui/GuiController.java b/src/main/java/storagecraft/gui/GuiController.java index 046605465..bb5bd0bf6 100644 --- a/src/main/java/storagecraft/gui/GuiController.java +++ b/src/main/java/storagecraft/gui/GuiController.java @@ -1,7 +1,5 @@ package storagecraft.gui; -import java.util.ArrayList; -import java.util.List; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; @@ -29,37 +27,27 @@ public class GuiController extends GuiContainer { mc.getTextureManager().bindTexture(CONTROLLER_RESOURCE); - drawTexturedModalRect((this.width - xSize) / 2, (this.height - ySize) / 2, 0, 0, xSize, ySize); + int x = (this.width - xSize) / 2; + int y = (this.height - ySize) / 2; + + drawTexturedModalRect(x, y, 0, 0, xSize, ySize); + + int bx = 17; + int by = 25; + int bw = 16; + int bh = 58; + + int nbh = (int) ((float) controller.getEnergyStored(null) / (float) controller.getMaxEnergyStored(null) * (float) bh); + + drawTexturedModalRect(x + bx, y + by + bh - nbh, 178, 0, bw, nbh); } @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - int mx = mouseX - ((this.width - xSize) / 2); - int my = mouseY - ((this.height - ySize) / 2); - - int barWidth = 16; - int barHeight = 58; - - int barX = 17; - int barY = 25; - - int energy = controller.getEnergyStored(null); - int maxEnergy = controller.getMaxEnergyStored(null); - - int newBarHeight = (int) ((float) energy / (float) maxEnergy * (float) barHeight); - - drawTexturedModalRect(barX, barY + barHeight - newBarHeight, 178, 0, barWidth, newBarHeight); - fontRendererObj.drawString(StatCollector.translateToLocal("gui.storagecraft:controller"), 7, 7, 4210752); fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 7, 96, 4210752); - fontRendererObj.drawString(String.format(StatCollector.translateToLocal("misc.storagecraft:energyUsage"), controller.getEnergyUsage()), 45, 24, 4210752); - if (mx >= barX && mx <= barX + barWidth && my >= barY && my <= barY + barHeight) { - List lines = new ArrayList(); - - lines.add(String.format(StatCollector.translateToLocal("misc.storagecraft:energyStored"), energy, maxEnergy)); - - drawHoveringText(lines, mx, my, fontRendererObj); - } + fontRendererObj.drawString(String.format(StatCollector.translateToLocal("misc.storagecraft:energyStored"), controller.getEnergyStored(null), controller.getMaxEnergyStored(null)), 45, 24, 4210752); + fontRendererObj.drawString(String.format(StatCollector.translateToLocal("misc.storagecraft:energyUsage"), controller.getEnergyUsage()), 45, 44, 4210752); } } diff --git a/src/main/java/storagecraft/gui/GuiDrive.java b/src/main/java/storagecraft/gui/GuiDrive.java index ed8204348..7ce2b7958 100644 --- a/src/main/java/storagecraft/gui/GuiDrive.java +++ b/src/main/java/storagecraft/gui/GuiDrive.java @@ -1,32 +1,34 @@ package storagecraft.gui; -import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; import org.lwjgl.opengl.GL11; import storagecraft.container.ContainerDrive; +import storagecraft.tile.TileDrive; -public class GuiDrive extends GuiContainer { +public class GuiDrive extends GuiMachine { public static final ResourceLocation DRIVE_RESOURCE = new ResourceLocation("storagecraft:textures/gui/drive.png"); - - public GuiDrive(ContainerDrive container) { - super(container); - + + public GuiDrive(ContainerDrive container, TileDrive drive) { + super(container, drive); + this.xSize = 176; this.ySize = 190; } - + @Override protected void drawGuiContainerBackgroundLayer(float renderPartialTicks, int mouseX, int mouseY) { GL11.glColor3f(1.0F, 1.0F, 1.0F); - + mc.getTextureManager().bindTexture(DRIVE_RESOURCE); - + drawTexturedModalRect((this.width - xSize) / 2, (this.height - ySize) / 2, 0, 0, xSize, ySize); } - + @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { + super.drawGuiContainerForegroundLayer(mouseX, mouseY); + fontRendererObj.drawString(StatCollector.translateToLocal("gui.storagecraft:drive"), 7, 7, 4210752); fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 7, 96, 4210752); } diff --git a/src/main/java/storagecraft/gui/GuiGrid.java b/src/main/java/storagecraft/gui/GuiGrid.java index f71f4b04b..3d7ca0484 100644 --- a/src/main/java/storagecraft/gui/GuiGrid.java +++ b/src/main/java/storagecraft/gui/GuiGrid.java @@ -1,6 +1,5 @@ package storagecraft.gui; -import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; @@ -14,7 +13,7 @@ import storagecraft.network.MessageStoragePush; import storagecraft.tile.TileController; import storagecraft.tile.TileGrid; -public class GuiGrid extends GuiContainer { +public class GuiGrid extends GuiMachine { public static final ResourceLocation GRID_RESOURCE = new ResourceLocation("storagecraft:textures/gui/grid.png"); private ContainerGrid container; @@ -23,7 +22,7 @@ public class GuiGrid extends GuiContainer { private int hoveringSlot; public GuiGrid(ContainerGrid container, TileGrid grid) { - super(container); + super(container, grid); this.container = container; this.grid = grid; @@ -43,6 +42,8 @@ public class GuiGrid extends GuiContainer { @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { + super.drawGuiContainerForegroundLayer(mouseX, mouseY); + fontRendererObj.drawString(StatCollector.translateToLocal("gui.storagecraft:grid"), 7, 7, 4210752); fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 7, 96, 4210752); diff --git a/src/main/java/storagecraft/gui/GuiHandler.java b/src/main/java/storagecraft/gui/GuiHandler.java index d83cc2f18..2b980c671 100644 --- a/src/main/java/storagecraft/gui/GuiHandler.java +++ b/src/main/java/storagecraft/gui/GuiHandler.java @@ -10,10 +10,12 @@ import storagecraft.container.ContainerController; import storagecraft.container.ContainerDrive; import storagecraft.container.ContainerGrid; import storagecraft.container.ContainerImporter; +import storagecraft.container.ContainerStorageProxy; import storagecraft.tile.TileController; import storagecraft.tile.TileDrive; import storagecraft.tile.TileGrid; import storagecraft.tile.TileImporter; +import storagecraft.tile.TileStorageProxy; public class GuiHandler implements IGuiHandler { private Container getContainer(int ID, EntityPlayer player, TileEntity tile) { @@ -24,6 +26,8 @@ public class GuiHandler implements IGuiHandler { return new ContainerGrid(player); case StorageCraft.GUI.DRIVE: return new ContainerDrive(player, (TileDrive) tile); + case StorageCraft.GUI.STORAGE_PROXY: + return new ContainerStorageProxy(player); case StorageCraft.GUI.IMPORTER: return new ContainerImporter(player, (TileImporter) tile); default: @@ -46,7 +50,9 @@ public class GuiHandler implements IGuiHandler { case StorageCraft.GUI.GRID: return new GuiGrid((ContainerGrid) getContainer(ID, player, tile), (TileGrid) tile); case StorageCraft.GUI.DRIVE: - return new GuiDrive((ContainerDrive) getContainer(ID, player, tile)); + return new GuiDrive((ContainerDrive) getContainer(ID, player, tile), (TileDrive) tile); + case StorageCraft.GUI.STORAGE_PROXY: + return new GuiStorageProxy((ContainerStorageProxy) getContainer(ID, player, tile), (TileStorageProxy) tile); case StorageCraft.GUI.IMPORTER: return new GuiImporter((ContainerImporter) getContainer(ID, player, tile), (TileImporter) tile); default: diff --git a/src/main/java/storagecraft/gui/GuiImporter.java b/src/main/java/storagecraft/gui/GuiImporter.java index d3b371cdc..14a5e5dd5 100644 --- a/src/main/java/storagecraft/gui/GuiImporter.java +++ b/src/main/java/storagecraft/gui/GuiImporter.java @@ -1,7 +1,6 @@ package storagecraft.gui; import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; import org.lwjgl.opengl.GL11; @@ -11,7 +10,7 @@ import storagecraft.network.MessageImporterUpdate; import storagecraft.tile.TileImporter; import storagecraft.util.InventoryUtils; -public class GuiImporter extends GuiContainer { +public class GuiImporter extends GuiMachine { public static final ResourceLocation IMPORTER_RESOURCE = new ResourceLocation("storagecraft:textures/gui/importer.png"); private TileImporter importer; @@ -22,7 +21,7 @@ public class GuiImporter extends GuiContainer { private GuiButton compareDamage; public GuiImporter(ContainerImporter container, TileImporter importer) { - super(container); + super(container, importer); this.xSize = 176; this.ySize = 182; @@ -37,8 +36,8 @@ public class GuiImporter extends GuiContainer { int x = (this.width - xSize) / 2; int y = (this.height - ySize) / 2; - buttonList.add(compareNBT = new GuiButton(0, x + 7, y + 41, 100, 20, "...")); - buttonList.add(compareDamage = new GuiButton(1, x + 7, y + 63, 120, 20, "...")); + buttonList.add(compareNBT = new GuiButton(1, x + 7, y + 41, 100, 20, "...")); + buttonList.add(compareDamage = new GuiButton(2, x + 7, y + 63, 120, 20, "...")); } @Override @@ -77,12 +76,16 @@ public class GuiImporter extends GuiContainer { @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { + super.drawGuiContainerForegroundLayer(mouseX, mouseY); + fontRendererObj.drawString(StatCollector.translateToLocal("gui.storagecraft:importer"), 7, 7, 4210752); fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 7, 89, 4210752); } @Override protected void actionPerformed(GuiButton button) { + super.actionPerformed(button); + int flags = compareFlags; if (button.id == compareNBT.id) { diff --git a/src/main/java/storagecraft/gui/GuiMachine.java b/src/main/java/storagecraft/gui/GuiMachine.java new file mode 100644 index 000000000..4cf22f4e0 --- /dev/null +++ b/src/main/java/storagecraft/gui/GuiMachine.java @@ -0,0 +1,61 @@ +package storagecraft.gui; + +import java.util.ArrayList; +import java.util.List; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.init.Items; +import net.minecraft.inventory.Container; +import net.minecraft.item.ItemStack; +import net.minecraft.util.StatCollector; +import storagecraft.StorageCraft; +import storagecraft.network.MessageRedstoneModeUpdate; +import storagecraft.tile.TileMachine; + +public abstract class GuiMachine extends GuiContainer { + private TileMachine machine; + + private int bx; + private int by = 6; + private int bw = 20; + private int bh = 20; + + public GuiMachine(Container container, TileMachine machine) { + super(container); + + this.bx = xSize - 1; + this.machine = machine; + } + + @Override + public void initGui() { + super.initGui(); + + buttonList.add(new GuiButton(0, ((this.width - xSize) / 2) + bx, ((this.height - ySize) / 2) + by, bw, bh, "")); + } + + @Override + protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { + int mx = mouseX - ((this.width - xSize) / 2); + int my = mouseY - ((this.height - ySize) / 2); + + itemRender.renderItemIntoGUI(fontRendererObj, mc.getTextureManager(), new ItemStack(Items.redstone, 1), bx + 2, by + 1); + + if (mx >= bx && mx <= bx + bw && my >= by && my <= by + bh) { + List lines = new ArrayList(); + + lines.add(StatCollector.translateToLocal("misc.storagecraft:redstoneMode." + machine.getRedstoneMode().id)); + + this.drawHoveringText(lines, mx, my, fontRendererObj); + } + } + + @Override + protected void actionPerformed(GuiButton button) { + super.actionPerformed(button); + + if (button.id == 0) { + StorageCraft.NETWORK.sendToServer(new MessageRedstoneModeUpdate(machine.xCoord, machine.yCoord, machine.zCoord)); + } + } +} diff --git a/src/main/java/storagecraft/gui/GuiStorageProxy.java b/src/main/java/storagecraft/gui/GuiStorageProxy.java new file mode 100644 index 000000000..d675e1c57 --- /dev/null +++ b/src/main/java/storagecraft/gui/GuiStorageProxy.java @@ -0,0 +1,32 @@ +package storagecraft.gui; + +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.StatCollector; +import org.lwjgl.opengl.GL11; +import storagecraft.container.ContainerStorageProxy; +import storagecraft.tile.TileStorageProxy; + +public class GuiStorageProxy extends GuiMachine { + public static final ResourceLocation STORAGE_PROXY_RESOURCE = new ResourceLocation("storagecraft:textures/gui/storageProxy.png"); + + public GuiStorageProxy(ContainerStorageProxy container, TileStorageProxy storageProxy) { + super(container, storageProxy); + } + + @Override + protected void drawGuiContainerBackgroundLayer(float renderPartialTicks, int mouseX, int mouseY) { + GL11.glColor3f(1.0F, 1.0F, 1.0F); + + mc.getTextureManager().bindTexture(STORAGE_PROXY_RESOURCE); + + drawTexturedModalRect((this.width - xSize) / 2, (this.height - ySize) / 2, 0, 0, xSize, ySize); + } + + @Override + protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { + super.drawGuiContainerForegroundLayer(mouseX, mouseY); + + fontRendererObj.drawString(StatCollector.translateToLocal("gui.storagecraft:storageProxy"), 7, 7, 4210752); + fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 7, 39, 4210752); + } +} diff --git a/src/main/java/storagecraft/network/MessageRedstoneModeUpdate.java b/src/main/java/storagecraft/network/MessageRedstoneModeUpdate.java new file mode 100644 index 000000000..d770ea1bc --- /dev/null +++ b/src/main/java/storagecraft/network/MessageRedstoneModeUpdate.java @@ -0,0 +1,60 @@ +package storagecraft.network; + +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import io.netty.buffer.ByteBuf; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.tileentity.TileEntity; +import storagecraft.tile.RedstoneMode; +import storagecraft.tile.TileMachine; + +public class MessageRedstoneModeUpdate implements IMessage, IMessageHandler { + private int x; + private int y; + private int z; + + public MessageRedstoneModeUpdate() { + } + + public MessageRedstoneModeUpdate(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + } + + @Override + public void fromBytes(ByteBuf buf) { + x = buf.readInt(); + y = buf.readInt(); + z = buf.readInt(); + } + + @Override + public void toBytes(ByteBuf buf) { + buf.writeInt(x); + buf.writeInt(y); + buf.writeInt(z); + } + + @Override + public IMessage onMessage(MessageRedstoneModeUpdate message, MessageContext context) { + EntityPlayerMP player = context.getServerHandler().playerEntity; + + TileEntity tile = player.worldObj.getTileEntity(message.x, message.y, message.z); + + if (tile instanceof TileMachine) { + TileMachine machine = (TileMachine) tile; + + int id = machine.getRedstoneMode().id + 1; + + if (RedstoneMode.getById(id) == null) { + id = 0; + } + + machine.setRedstoneMode(RedstoneMode.getById(id)); + } + + return null; + } +} diff --git a/src/main/java/storagecraft/proxy/CommonProxy.java b/src/main/java/storagecraft/proxy/CommonProxy.java index cbfdaa1ab..1104f373c 100644 --- a/src/main/java/storagecraft/proxy/CommonProxy.java +++ b/src/main/java/storagecraft/proxy/CommonProxy.java @@ -11,6 +11,7 @@ import storagecraft.StorageCraftBlocks; import storagecraft.StorageCraftItems; import storagecraft.gui.GuiHandler; import storagecraft.network.MessageImporterUpdate; +import storagecraft.network.MessageRedstoneModeUpdate; import storagecraft.network.MessageStoragePull; import storagecraft.network.MessageStoragePush; import storagecraft.network.MessageTileUpdate; @@ -27,6 +28,7 @@ public class CommonProxy { StorageCraft.NETWORK.registerMessage(MessageStoragePush.class, MessageStoragePush.class, 1, Side.SERVER); StorageCraft.NETWORK.registerMessage(MessageStoragePull.class, MessageStoragePull.class, 2, Side.SERVER); StorageCraft.NETWORK.registerMessage(MessageImporterUpdate.class, MessageImporterUpdate.class, 3, Side.SERVER); + StorageCraft.NETWORK.registerMessage(MessageRedstoneModeUpdate.class, MessageRedstoneModeUpdate.class, 4, Side.SERVER); NetworkRegistry.INSTANCE.registerGuiHandler(StorageCraft.INSTANCE, new GuiHandler()); diff --git a/src/main/java/storagecraft/tile/RedstoneMode.java b/src/main/java/storagecraft/tile/RedstoneMode.java new file mode 100644 index 000000000..36e106beb --- /dev/null +++ b/src/main/java/storagecraft/tile/RedstoneMode.java @@ -0,0 +1,23 @@ +package storagecraft.tile; + +public enum RedstoneMode { + IGNORE(0), + HIGH(1), + LOW(2); + + public final int id; + + RedstoneMode(int id) { + this.id = id; + } + + public static RedstoneMode getById(int id) { + for (RedstoneMode control : values()) { + if (control.id == id) { + return control; + } + } + + return null; + } +} diff --git a/src/main/java/storagecraft/tile/TileBase.java b/src/main/java/storagecraft/tile/TileBase.java index 5169e86e3..1e22536cb 100644 --- a/src/main/java/storagecraft/tile/TileBase.java +++ b/src/main/java/storagecraft/tile/TileBase.java @@ -21,7 +21,7 @@ public class TileBase extends TileEntity { public void updateEntity() { super.updateEntity(); - ++ticks; + ticks++; if (!worldObj.isRemote) { if (this instanceof INetworkTile) { diff --git a/src/main/java/storagecraft/tile/TileCable.java b/src/main/java/storagecraft/tile/TileCable.java index 95265e90a..ad86c22b2 100644 --- a/src/main/java/storagecraft/tile/TileCable.java +++ b/src/main/java/storagecraft/tile/TileCable.java @@ -53,7 +53,7 @@ public class TileCable extends TileBase { TileEntity tile = worldObj.getTileEntity(x, y, z); - if (tile instanceof TileMachine) { + if (tile instanceof TileMachine && ((TileMachine) tile).isEnabled()) { machines.add((TileMachine) tile); visited.add(Vec3.createVectorHelper(x, y, z)); diff --git a/src/main/java/storagecraft/tile/TileDrive.java b/src/main/java/storagecraft/tile/TileDrive.java index 3cf0bed51..9ad550fce 100644 --- a/src/main/java/storagecraft/tile/TileDrive.java +++ b/src/main/java/storagecraft/tile/TileDrive.java @@ -27,6 +27,10 @@ public class TileDrive extends TileMachine implements IInventory, IStorageProvid return base; } + @Override + public void updateMachine() { + } + @Override public int getSizeInventory() { return inventory.getSizeInventory(); diff --git a/src/main/java/storagecraft/tile/TileGrid.java b/src/main/java/storagecraft/tile/TileGrid.java index 3fededdd0..2b72ad56f 100644 --- a/src/main/java/storagecraft/tile/TileGrid.java +++ b/src/main/java/storagecraft/tile/TileGrid.java @@ -3,6 +3,10 @@ package storagecraft.tile; public class TileGrid extends TileMachine { @Override public int getEnergyUsage() { - return 10; + return 5; + } + + @Override + public void updateMachine() { } } diff --git a/src/main/java/storagecraft/tile/TileImporter.java b/src/main/java/storagecraft/tile/TileImporter.java index 165071b17..806bc16c1 100644 --- a/src/main/java/storagecraft/tile/TileImporter.java +++ b/src/main/java/storagecraft/tile/TileImporter.java @@ -10,6 +10,8 @@ import storagecraft.inventory.InventorySimple; import storagecraft.util.InventoryUtils; public class TileImporter extends TileMachine implements IInventory { + public static final String NBT_COMPARE_FLAGS = "CompareFlags"; + private InventorySimple inventory = new InventorySimple("importer", 9); private int compareFlags = InventoryUtils.COMPARE_NBT | InventoryUtils.COMPARE_DAMAGE; @@ -17,39 +19,40 @@ public class TileImporter extends TileMachine implements IInventory { private int currentSlot = 0; @Override - public void updateEntity() { - super.updateEntity(); + public int getEnergyUsage() { + return 2; + } - if (!worldObj.isRemote && isConnected()) { - TileEntity tile = worldObj.getTileEntity(xCoord + getDirection().offsetX, yCoord + getDirection().offsetY, zCoord + getDirection().offsetZ); + @Override + public void updateMachine() { + TileEntity tile = worldObj.getTileEntity(xCoord + getDirection().offsetX, yCoord + getDirection().offsetY, zCoord + getDirection().offsetZ); - if (tile instanceof IInventory) { - IInventory connectedInventory = (IInventory) tile; + if (tile instanceof IInventory) { + IInventory connectedInventory = (IInventory) tile; - if (ticks % 5 == 0) { - ItemStack slot; - - while ((slot = connectedInventory.getStackInSlot(currentSlot)) == null) { - currentSlot++; - - if (currentSlot > connectedInventory.getSizeInventory() - 1) { - break; - } - } - - if (slot != null && canImport(slot)) { - if (getController().push(slot.copy())) { - connectedInventory.setInventorySlotContents(currentSlot, null); - connectedInventory.markDirty(); - } - } + if (ticks % 5 == 0) { + ItemStack slot; + while ((slot = connectedInventory.getStackInSlot(currentSlot)) == null) { currentSlot++; if (currentSlot > connectedInventory.getSizeInventory() - 1) { - currentSlot = 0; + break; } } + + if (slot != null && canImport(slot)) { + if (getController().push(slot.copy())) { + connectedInventory.setInventorySlotContents(currentSlot, null); + connectedInventory.markDirty(); + } + } + + currentSlot++; + + if (currentSlot > connectedInventory.getSizeInventory() - 1) { + currentSlot = 0; + } } } } @@ -80,11 +83,6 @@ public class TileImporter extends TileMachine implements IInventory { this.compareFlags = flags; } - @Override - public int getEnergyUsage() { - return 3; - } - @Override public int getSizeInventory() { return inventory.getSizeInventory(); @@ -149,8 +147,8 @@ public class TileImporter extends TileMachine implements IInventory { public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); - if (nbt.hasKey("CompareFlags")) { - compareFlags = nbt.getInteger("CompareFlags"); + if (nbt.hasKey(NBT_COMPARE_FLAGS)) { + compareFlags = nbt.getInteger(NBT_COMPARE_FLAGS); } InventoryUtils.restoreInventory(this, nbt); @@ -160,7 +158,7 @@ public class TileImporter extends TileMachine implements IInventory { public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); - nbt.setInteger("CompareFlags", compareFlags); + nbt.setInteger(NBT_COMPARE_FLAGS, compareFlags); InventoryUtils.saveInventory(this, nbt); } diff --git a/src/main/java/storagecraft/tile/TileMachine.java b/src/main/java/storagecraft/tile/TileMachine.java index 09cdb1d6f..39658d1ef 100644 --- a/src/main/java/storagecraft/tile/TileMachine.java +++ b/src/main/java/storagecraft/tile/TileMachine.java @@ -1,16 +1,22 @@ package storagecraft.tile; import io.netty.buffer.ByteBuf; +import net.minecraft.nbt.NBTTagCompound; public abstract class TileMachine extends TileBase implements INetworkTile { + public static final String NBT_REDSTONE_MODE = "RedstoneMode"; + protected boolean connected = false; + private RedstoneMode redstoneMode = RedstoneMode.IGNORE; + private int xController; private int yController; private int zController; public void onConnected(TileController controller) { this.connected = true; + this.xController = controller.xCoord; this.yController = controller.yCoord; this.zController = controller.zCoord; @@ -24,16 +30,44 @@ public abstract class TileMachine extends TileBase implements INetworkTile { worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); } + @Override + public void updateEntity() { + super.updateEntity(); + + if (!worldObj.isRemote && isConnected()) { + updateMachine(); + } + } + public boolean isConnected() { return connected; } + public boolean isEnabled() { + switch (redstoneMode) { + case IGNORE: + return true; + case HIGH: + return worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord); + case LOW: + return !worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord); + } + + return false; + } + + public RedstoneMode getRedstoneMode() { + return redstoneMode; + } + + public void setRedstoneMode(RedstoneMode mode) { + this.redstoneMode = mode; + } + public TileController getController() { return (TileController) worldObj.getTileEntity(xController, yController, zController); } - public abstract int getEnergyUsage(); - @Override public void fromBytes(ByteBuf buf) { connected = buf.readBoolean(); @@ -43,6 +77,8 @@ public abstract class TileMachine extends TileBase implements INetworkTile { yController = buf.readInt(); zController = buf.readInt(); } + + redstoneMode = RedstoneMode.getById(buf.readInt()); } @Override @@ -54,5 +90,25 @@ public abstract class TileMachine extends TileBase implements INetworkTile { buf.writeInt(yController); buf.writeInt(zController); } + + buf.writeInt(redstoneMode.id); } + + @Override + public void readFromNBT(NBTTagCompound nbt) { + super.readFromNBT(nbt); + + redstoneMode = RedstoneMode.getById(nbt.getInteger(NBT_REDSTONE_MODE)); + } + + @Override + public void writeToNBT(NBTTagCompound nbt) { + super.writeToNBT(nbt); + + nbt.setInteger(NBT_REDSTONE_MODE, redstoneMode.id); + } + + public abstract int getEnergyUsage(); + + public abstract void updateMachine(); } diff --git a/src/main/java/storagecraft/tile/TileStorageProxy.java b/src/main/java/storagecraft/tile/TileStorageProxy.java index da21eae76..9e7ae6181 100644 --- a/src/main/java/storagecraft/tile/TileStorageProxy.java +++ b/src/main/java/storagecraft/tile/TileStorageProxy.java @@ -10,30 +10,29 @@ import storagecraft.storage.StorageItem; import storagecraft.util.InventoryUtils; public class TileStorageProxy extends TileMachine implements IStorageProvider, IStorage { - private IInventory inventory; + public IInventory getInventory() { + TileEntity tile = worldObj.getTileEntity(xCoord + getDirection().offsetX, yCoord + getDirection().offsetY, zCoord + getDirection().offsetZ); - @Override - public void updateEntity() { - super.updateEntity(); - - if (!worldObj.isRemote && isConnected()) { - TileEntity tile = worldObj.getTileEntity(xCoord + getDirection().offsetX, yCoord + getDirection().offsetY, zCoord + getDirection().offsetZ); - - if (tile instanceof IInventory) { - inventory = (IInventory) tile; - } - } else { - inventory = null; + if (tile instanceof IInventory) { + return (IInventory) tile; } + + return null; } @Override public int getEnergyUsage() { - return 5; + return 2; + } + + @Override + public void updateMachine() { } @Override public void addItems(List items) { + IInventory inventory = getInventory(); + if (inventory != null) { for (int i = 0; i < inventory.getSizeInventory(); ++i) { if (inventory.getStackInSlot(i) != null) { @@ -45,6 +44,8 @@ public class TileStorageProxy extends TileMachine implements IStorageProvider, I @Override public void push(ItemStack stack) { + IInventory inventory = getInventory(); + if (inventory == null) { return; } @@ -78,6 +79,8 @@ public class TileStorageProxy extends TileMachine implements IStorageProvider, I @Override public int take(ItemStack stack) { + IInventory inventory = getInventory(); + if (inventory == null) { return 0; } @@ -107,6 +110,8 @@ public class TileStorageProxy extends TileMachine implements IStorageProvider, I @Override public boolean canPush(ItemStack stack) { + IInventory inventory = getInventory(); + if (inventory == null) { return false; } diff --git a/src/main/resources/assets/storagecraft/lang/en_US.lang b/src/main/resources/assets/storagecraft/lang/en_US.lang index ef71d8238..623b7550d 100644 --- a/src/main/resources/assets/storagecraft/lang/en_US.lang +++ b/src/main/resources/assets/storagecraft/lang/en_US.lang @@ -3,6 +3,7 @@ itemGroup.storagecraft=StorageCraft gui.storagecraft:controller=Controller gui.storagecraft:grid=Grid gui.storagecraft:drive=Drive +gui.storagecraft:storageProxy=Storage Proxy gui.storagecraft:importer=Importer misc.storagecraft:energyStored=%d / %d RF @@ -17,6 +18,10 @@ misc.storagecraft:compareDamage=Compare Damage misc.storagecraft:on=On misc.storagecraft:off=Off +misc.storagecraft:redstoneMode.0=Ignore +misc.storagecraft:redstoneMode.1=High +misc.storagecraft:redstoneMode.2=Low + block.storagecraft:controller.name=Controller block.storagecraft:cable.name=Cable block.storagecraft:grid.name=Grid diff --git a/src/main/resources/assets/storagecraft/lang/nl_NL.lang b/src/main/resources/assets/storagecraft/lang/nl_NL.lang index 35e8322d8..57ab193ee 100644 --- a/src/main/resources/assets/storagecraft/lang/nl_NL.lang +++ b/src/main/resources/assets/storagecraft/lang/nl_NL.lang @@ -3,6 +3,7 @@ itemGroup.storagecraft=StorageCraft gui.storagecraft:controller=Controleur gui.storagecraft:grid=Rooster gui.storagecraft:drive=Schijf +gui.storagecraft:storageProxy=Opslag Proxy gui.storagecraft:importer=Importeur misc.storagecraft:energyStored=%d / %d RF @@ -17,6 +18,10 @@ misc.storagecraft:compareDamage=Damage vergelijken misc.storagecraft:on=Aan misc.storagecraft:off=Uit +misc.storagecraft:redstoneMode.0=Negeren +misc.storagecraft:redstoneMode.1=Hoog +misc.storagecraft:redstoneMode.2=Laag + block.storagecraft:controller.name=Controleur block.storagecraft:cable.name=Kabel block.storagecraft:grid.name=Rooster diff --git a/src/main/resources/assets/storagecraft/textures/gui/storageProxy.png b/src/main/resources/assets/storagecraft/textures/gui/storageProxy.png new file mode 100644 index 0000000000000000000000000000000000000000..c0c97a66ec2dc4b9a32b246d39f270a9ea63f774 GIT binary patch literal 1788 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K58911MRQ8&P5D>38$lZxy-8q?;Kn_c~qpu?a z!^VE@KZ&di49pAxJ|V6^adUI?(9qEC?(Sp9j{X1tA1E>kMnhnPgh10{aTQRmDGBlm z1}6TI3>bpHv#SE5owL9rvY3H^?=T269?xHq0u+=eag8Vm&QB{TPb^AhC`ioAE78kK zEm1JhGte{p)02Fkfq^O1)5S5QBJS<&i&?iFBw7Nm_TB$K@$RmfQHtTm-uQ1m^OJ+; zP3sLA7DmUu-+yl`|NX1)cj4{jjE%|5@Bja{G46r>f#Z6ydZ$_C7%G3U0ShyQ?{Q+F zWccKzGz$Ym!=36#5O2crd;uU;^gb0--Z{+M2Q1SVPVAiyEYcWoYh?QHy88N?oAq`x z*>=>u{&v|9q#6Wve%}OP0LgXp|1bEzbbgr;&xH4S>CN}cHl^#&^6}jb3Xje`}St(