add redstone controls
This commit is contained in:
@@ -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";
|
||||
|
@@ -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");
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
@@ -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<String> lines = new ArrayList<String>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@@ -1,16 +1,16 @@
|
||||
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;
|
||||
@@ -27,6 +27,8 @@ public class GuiDrive extends GuiContainer {
|
||||
|
||||
@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);
|
||||
}
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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:
|
||||
|
@@ -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) {
|
||||
|
61
src/main/java/storagecraft/gui/GuiMachine.java
Normal file
61
src/main/java/storagecraft/gui/GuiMachine.java
Normal file
@@ -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<String> lines = new ArrayList<String>();
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
32
src/main/java/storagecraft/gui/GuiStorageProxy.java
Normal file
32
src/main/java/storagecraft/gui/GuiStorageProxy.java
Normal file
@@ -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);
|
||||
}
|
||||
}
|
@@ -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<MessageRedstoneModeUpdate, IMessage> {
|
||||
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;
|
||||
}
|
||||
}
|
@@ -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());
|
||||
|
||||
|
23
src/main/java/storagecraft/tile/RedstoneMode.java
Normal file
23
src/main/java/storagecraft/tile/RedstoneMode.java
Normal file
@@ -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;
|
||||
}
|
||||
}
|
@@ -21,7 +21,7 @@ public class TileBase extends TileEntity {
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
|
||||
++ticks;
|
||||
ticks++;
|
||||
|
||||
if (!worldObj.isRemote) {
|
||||
if (this instanceof INetworkTile) {
|
||||
|
@@ -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));
|
||||
|
@@ -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();
|
||||
|
@@ -3,6 +3,10 @@ package storagecraft.tile;
|
||||
public class TileGrid extends TileMachine {
|
||||
@Override
|
||||
public int getEnergyUsage() {
|
||||
return 10;
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMachine() {
|
||||
}
|
||||
}
|
||||
|
@@ -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,10 +19,12 @@ 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()) {
|
||||
@Override
|
||||
public void updateMachine() {
|
||||
TileEntity tile = worldObj.getTileEntity(xCoord + getDirection().offsetX, yCoord + getDirection().offsetY, zCoord + getDirection().offsetZ);
|
||||
|
||||
if (tile instanceof IInventory) {
|
||||
@@ -52,7 +56,6 @@ public class TileImporter extends TileMachine implements IInventory {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canImport(ItemStack stack) {
|
||||
int slots = 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);
|
||||
}
|
||||
|
@@ -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();
|
||||
}
|
||||
|
@@ -10,30 +10,29 @@ import storagecraft.storage.StorageItem;
|
||||
import storagecraft.util.InventoryUtils;
|
||||
|
||||
public class TileStorageProxy extends TileMachine implements IStorageProvider, IStorage {
|
||||
private IInventory inventory;
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
|
||||
if (!worldObj.isRemote && isConnected()) {
|
||||
public IInventory getInventory() {
|
||||
TileEntity tile = worldObj.getTileEntity(xCoord + getDirection().offsetX, yCoord + getDirection().offsetY, zCoord + getDirection().offsetZ);
|
||||
|
||||
if (tile instanceof IInventory) {
|
||||
inventory = (IInventory) tile;
|
||||
}
|
||||
} else {
|
||||
inventory = null;
|
||||
return (IInventory) tile;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyUsage() {
|
||||
return 5;
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMachine() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addItems(List<StorageItem> 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;
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
Reference in New Issue
Block a user