add redstone controls

This commit is contained in:
Raoul Van den Berge
2015-12-18 15:10:38 +01:00
parent 8bf0f66530
commit 2bae408c59
23 changed files with 376 additions and 98 deletions

View File

@@ -19,7 +19,8 @@ public class StorageCraft {
public static final int CONTROLLER = 0; public static final int CONTROLLER = 0;
public static final int GRID = 1; public static final int GRID = 1;
public static final int DRIVE = 2; 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"; public static final String ID = "storagecraft";

View File

@@ -2,10 +2,12 @@ package storagecraft.block;
import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.ITileEntityProvider;
import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon; import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
import storagecraft.StorageCraft;
import storagecraft.tile.TileStorageProxy; import storagecraft.tile.TileStorageProxy;
public class BlockStorageProxy extends BlockBase implements ITileEntityProvider { public class BlockStorageProxy extends BlockBase implements ITileEntityProvider {
@@ -21,6 +23,15 @@ public class BlockStorageProxy extends BlockBase implements ITileEntityProvider
return new TileStorageProxy(); 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 @Override
public void registerBlockIcons(IIconRegister register) { public void registerBlockIcons(IIconRegister register) {
frontIcon = register.registerIcon("storagecraft:storageProxy"); frontIcon = register.registerIcon("storagecraft:storageProxy");

View File

@@ -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);
}
}

View File

@@ -1,7 +1,5 @@
package storagecraft.gui; package storagecraft.gui;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector; import net.minecraft.util.StatCollector;
@@ -29,37 +27,27 @@ public class GuiController extends GuiContainer {
mc.getTextureManager().bindTexture(CONTROLLER_RESOURCE); 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 @Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { 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("gui.storagecraft:controller"), 7, 7, 4210752);
fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 7, 96, 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) { fontRendererObj.drawString(String.format(StatCollector.translateToLocal("misc.storagecraft:energyStored"), controller.getEnergyStored(null), controller.getMaxEnergyStored(null)), 45, 24, 4210752);
List<String> lines = new ArrayList<String>(); fontRendererObj.drawString(String.format(StatCollector.translateToLocal("misc.storagecraft:energyUsage"), controller.getEnergyUsage()), 45, 44, 4210752);
lines.add(String.format(StatCollector.translateToLocal("misc.storagecraft:energyStored"), energy, maxEnergy));
drawHoveringText(lines, mx, my, fontRendererObj);
}
} }
} }

View File

@@ -1,32 +1,34 @@
package storagecraft.gui; package storagecraft.gui;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector; import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import storagecraft.container.ContainerDrive; 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 static final ResourceLocation DRIVE_RESOURCE = new ResourceLocation("storagecraft:textures/gui/drive.png");
public GuiDrive(ContainerDrive container) { public GuiDrive(ContainerDrive container, TileDrive drive) {
super(container); super(container, drive);
this.xSize = 176; this.xSize = 176;
this.ySize = 190; this.ySize = 190;
} }
@Override @Override
protected void drawGuiContainerBackgroundLayer(float renderPartialTicks, int mouseX, int mouseY) { protected void drawGuiContainerBackgroundLayer(float renderPartialTicks, int mouseX, int mouseY) {
GL11.glColor3f(1.0F, 1.0F, 1.0F); GL11.glColor3f(1.0F, 1.0F, 1.0F);
mc.getTextureManager().bindTexture(DRIVE_RESOURCE); mc.getTextureManager().bindTexture(DRIVE_RESOURCE);
drawTexturedModalRect((this.width - xSize) / 2, (this.height - ySize) / 2, 0, 0, xSize, ySize); drawTexturedModalRect((this.width - xSize) / 2, (this.height - ySize) / 2, 0, 0, xSize, ySize);
} }
@Override @Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { 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("gui.storagecraft:drive"), 7, 7, 4210752);
fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 7, 96, 4210752); fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 7, 96, 4210752);
} }

View File

@@ -1,6 +1,5 @@
package storagecraft.gui; package storagecraft.gui;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Slot; import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
@@ -14,7 +13,7 @@ import storagecraft.network.MessageStoragePush;
import storagecraft.tile.TileController; import storagecraft.tile.TileController;
import storagecraft.tile.TileGrid; 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"); public static final ResourceLocation GRID_RESOURCE = new ResourceLocation("storagecraft:textures/gui/grid.png");
private ContainerGrid container; private ContainerGrid container;
@@ -23,7 +22,7 @@ public class GuiGrid extends GuiContainer {
private int hoveringSlot; private int hoveringSlot;
public GuiGrid(ContainerGrid container, TileGrid grid) { public GuiGrid(ContainerGrid container, TileGrid grid) {
super(container); super(container, grid);
this.container = container; this.container = container;
this.grid = grid; this.grid = grid;
@@ -43,6 +42,8 @@ public class GuiGrid extends GuiContainer {
@Override @Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { 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("gui.storagecraft:grid"), 7, 7, 4210752);
fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 7, 96, 4210752); fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 7, 96, 4210752);

View File

@@ -10,10 +10,12 @@ import storagecraft.container.ContainerController;
import storagecraft.container.ContainerDrive; import storagecraft.container.ContainerDrive;
import storagecraft.container.ContainerGrid; import storagecraft.container.ContainerGrid;
import storagecraft.container.ContainerImporter; import storagecraft.container.ContainerImporter;
import storagecraft.container.ContainerStorageProxy;
import storagecraft.tile.TileController; import storagecraft.tile.TileController;
import storagecraft.tile.TileDrive; import storagecraft.tile.TileDrive;
import storagecraft.tile.TileGrid; import storagecraft.tile.TileGrid;
import storagecraft.tile.TileImporter; import storagecraft.tile.TileImporter;
import storagecraft.tile.TileStorageProxy;
public class GuiHandler implements IGuiHandler { public class GuiHandler implements IGuiHandler {
private Container getContainer(int ID, EntityPlayer player, TileEntity tile) { private Container getContainer(int ID, EntityPlayer player, TileEntity tile) {
@@ -24,6 +26,8 @@ public class GuiHandler implements IGuiHandler {
return new ContainerGrid(player); return new ContainerGrid(player);
case StorageCraft.GUI.DRIVE: case StorageCraft.GUI.DRIVE:
return new ContainerDrive(player, (TileDrive) tile); return new ContainerDrive(player, (TileDrive) tile);
case StorageCraft.GUI.STORAGE_PROXY:
return new ContainerStorageProxy(player);
case StorageCraft.GUI.IMPORTER: case StorageCraft.GUI.IMPORTER:
return new ContainerImporter(player, (TileImporter) tile); return new ContainerImporter(player, (TileImporter) tile);
default: default:
@@ -46,7 +50,9 @@ public class GuiHandler implements IGuiHandler {
case StorageCraft.GUI.GRID: case StorageCraft.GUI.GRID:
return new GuiGrid((ContainerGrid) getContainer(ID, player, tile), (TileGrid) tile); return new GuiGrid((ContainerGrid) getContainer(ID, player, tile), (TileGrid) tile);
case StorageCraft.GUI.DRIVE: 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: case StorageCraft.GUI.IMPORTER:
return new GuiImporter((ContainerImporter) getContainer(ID, player, tile), (TileImporter) tile); return new GuiImporter((ContainerImporter) getContainer(ID, player, tile), (TileImporter) tile);
default: default:

View File

@@ -1,7 +1,6 @@
package storagecraft.gui; package storagecraft.gui;
import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector; import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
@@ -11,7 +10,7 @@ import storagecraft.network.MessageImporterUpdate;
import storagecraft.tile.TileImporter; import storagecraft.tile.TileImporter;
import storagecraft.util.InventoryUtils; 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"); public static final ResourceLocation IMPORTER_RESOURCE = new ResourceLocation("storagecraft:textures/gui/importer.png");
private TileImporter importer; private TileImporter importer;
@@ -22,7 +21,7 @@ public class GuiImporter extends GuiContainer {
private GuiButton compareDamage; private GuiButton compareDamage;
public GuiImporter(ContainerImporter container, TileImporter importer) { public GuiImporter(ContainerImporter container, TileImporter importer) {
super(container); super(container, importer);
this.xSize = 176; this.xSize = 176;
this.ySize = 182; this.ySize = 182;
@@ -37,8 +36,8 @@ public class GuiImporter extends GuiContainer {
int x = (this.width - xSize) / 2; int x = (this.width - xSize) / 2;
int y = (this.height - ySize) / 2; int y = (this.height - ySize) / 2;
buttonList.add(compareNBT = new GuiButton(0, x + 7, y + 41, 100, 20, "...")); buttonList.add(compareNBT = new GuiButton(1, x + 7, y + 41, 100, 20, "..."));
buttonList.add(compareDamage = new GuiButton(1, x + 7, y + 63, 120, 20, "...")); buttonList.add(compareDamage = new GuiButton(2, x + 7, y + 63, 120, 20, "..."));
} }
@Override @Override
@@ -77,12 +76,16 @@ public class GuiImporter extends GuiContainer {
@Override @Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { 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("gui.storagecraft:importer"), 7, 7, 4210752);
fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 7, 89, 4210752); fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 7, 89, 4210752);
} }
@Override @Override
protected void actionPerformed(GuiButton button) { protected void actionPerformed(GuiButton button) {
super.actionPerformed(button);
int flags = compareFlags; int flags = compareFlags;
if (button.id == compareNBT.id) { if (button.id == compareNBT.id) {

View 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));
}
}
}

View 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);
}
}

View File

@@ -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;
}
}

View File

@@ -11,6 +11,7 @@ import storagecraft.StorageCraftBlocks;
import storagecraft.StorageCraftItems; import storagecraft.StorageCraftItems;
import storagecraft.gui.GuiHandler; import storagecraft.gui.GuiHandler;
import storagecraft.network.MessageImporterUpdate; import storagecraft.network.MessageImporterUpdate;
import storagecraft.network.MessageRedstoneModeUpdate;
import storagecraft.network.MessageStoragePull; import storagecraft.network.MessageStoragePull;
import storagecraft.network.MessageStoragePush; import storagecraft.network.MessageStoragePush;
import storagecraft.network.MessageTileUpdate; import storagecraft.network.MessageTileUpdate;
@@ -27,6 +28,7 @@ public class CommonProxy {
StorageCraft.NETWORK.registerMessage(MessageStoragePush.class, MessageStoragePush.class, 1, Side.SERVER); StorageCraft.NETWORK.registerMessage(MessageStoragePush.class, MessageStoragePush.class, 1, Side.SERVER);
StorageCraft.NETWORK.registerMessage(MessageStoragePull.class, MessageStoragePull.class, 2, 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(MessageImporterUpdate.class, MessageImporterUpdate.class, 3, Side.SERVER);
StorageCraft.NETWORK.registerMessage(MessageRedstoneModeUpdate.class, MessageRedstoneModeUpdate.class, 4, Side.SERVER);
NetworkRegistry.INSTANCE.registerGuiHandler(StorageCraft.INSTANCE, new GuiHandler()); NetworkRegistry.INSTANCE.registerGuiHandler(StorageCraft.INSTANCE, new GuiHandler());

View 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;
}
}

View File

@@ -21,7 +21,7 @@ public class TileBase extends TileEntity {
public void updateEntity() { public void updateEntity() {
super.updateEntity(); super.updateEntity();
++ticks; ticks++;
if (!worldObj.isRemote) { if (!worldObj.isRemote) {
if (this instanceof INetworkTile) { if (this instanceof INetworkTile) {

View File

@@ -53,7 +53,7 @@ public class TileCable extends TileBase {
TileEntity tile = worldObj.getTileEntity(x, y, z); TileEntity tile = worldObj.getTileEntity(x, y, z);
if (tile instanceof TileMachine) { if (tile instanceof TileMachine && ((TileMachine) tile).isEnabled()) {
machines.add((TileMachine) tile); machines.add((TileMachine) tile);
visited.add(Vec3.createVectorHelper(x, y, z)); visited.add(Vec3.createVectorHelper(x, y, z));

View File

@@ -27,6 +27,10 @@ public class TileDrive extends TileMachine implements IInventory, IStorageProvid
return base; return base;
} }
@Override
public void updateMachine() {
}
@Override @Override
public int getSizeInventory() { public int getSizeInventory() {
return inventory.getSizeInventory(); return inventory.getSizeInventory();

View File

@@ -3,6 +3,10 @@ package storagecraft.tile;
public class TileGrid extends TileMachine { public class TileGrid extends TileMachine {
@Override @Override
public int getEnergyUsage() { public int getEnergyUsage() {
return 10; return 5;
}
@Override
public void updateMachine() {
} }
} }

View File

@@ -10,6 +10,8 @@ import storagecraft.inventory.InventorySimple;
import storagecraft.util.InventoryUtils; import storagecraft.util.InventoryUtils;
public class TileImporter extends TileMachine implements IInventory { public class TileImporter extends TileMachine implements IInventory {
public static final String NBT_COMPARE_FLAGS = "CompareFlags";
private InventorySimple inventory = new InventorySimple("importer", 9); private InventorySimple inventory = new InventorySimple("importer", 9);
private int compareFlags = InventoryUtils.COMPARE_NBT | InventoryUtils.COMPARE_DAMAGE; private int compareFlags = InventoryUtils.COMPARE_NBT | InventoryUtils.COMPARE_DAMAGE;
@@ -17,39 +19,40 @@ public class TileImporter extends TileMachine implements IInventory {
private int currentSlot = 0; private int currentSlot = 0;
@Override @Override
public void updateEntity() { public int getEnergyUsage() {
super.updateEntity(); return 2;
}
if (!worldObj.isRemote && isConnected()) { @Override
TileEntity tile = worldObj.getTileEntity(xCoord + getDirection().offsetX, yCoord + getDirection().offsetY, zCoord + getDirection().offsetZ); public void updateMachine() {
TileEntity tile = worldObj.getTileEntity(xCoord + getDirection().offsetX, yCoord + getDirection().offsetY, zCoord + getDirection().offsetZ);
if (tile instanceof IInventory) { if (tile instanceof IInventory) {
IInventory connectedInventory = (IInventory) tile; IInventory connectedInventory = (IInventory) tile;
if (ticks % 5 == 0) { if (ticks % 5 == 0) {
ItemStack slot; 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();
}
}
while ((slot = connectedInventory.getStackInSlot(currentSlot)) == null) {
currentSlot++; currentSlot++;
if (currentSlot > connectedInventory.getSizeInventory() - 1) { 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; this.compareFlags = flags;
} }
@Override
public int getEnergyUsage() {
return 3;
}
@Override @Override
public int getSizeInventory() { public int getSizeInventory() {
return inventory.getSizeInventory(); return inventory.getSizeInventory();
@@ -149,8 +147,8 @@ public class TileImporter extends TileMachine implements IInventory {
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
if (nbt.hasKey("CompareFlags")) { if (nbt.hasKey(NBT_COMPARE_FLAGS)) {
compareFlags = nbt.getInteger("CompareFlags"); compareFlags = nbt.getInteger(NBT_COMPARE_FLAGS);
} }
InventoryUtils.restoreInventory(this, nbt); InventoryUtils.restoreInventory(this, nbt);
@@ -160,7 +158,7 @@ public class TileImporter extends TileMachine implements IInventory {
public void writeToNBT(NBTTagCompound nbt) { public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt); super.writeToNBT(nbt);
nbt.setInteger("CompareFlags", compareFlags); nbt.setInteger(NBT_COMPARE_FLAGS, compareFlags);
InventoryUtils.saveInventory(this, nbt); InventoryUtils.saveInventory(this, nbt);
} }

View File

@@ -1,16 +1,22 @@
package storagecraft.tile; package storagecraft.tile;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import net.minecraft.nbt.NBTTagCompound;
public abstract class TileMachine extends TileBase implements INetworkTile { public abstract class TileMachine extends TileBase implements INetworkTile {
public static final String NBT_REDSTONE_MODE = "RedstoneMode";
protected boolean connected = false; protected boolean connected = false;
private RedstoneMode redstoneMode = RedstoneMode.IGNORE;
private int xController; private int xController;
private int yController; private int yController;
private int zController; private int zController;
public void onConnected(TileController controller) { public void onConnected(TileController controller) {
this.connected = true; this.connected = true;
this.xController = controller.xCoord; this.xController = controller.xCoord;
this.yController = controller.yCoord; this.yController = controller.yCoord;
this.zController = controller.zCoord; this.zController = controller.zCoord;
@@ -24,16 +30,44 @@ public abstract class TileMachine extends TileBase implements INetworkTile {
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
} }
@Override
public void updateEntity() {
super.updateEntity();
if (!worldObj.isRemote && isConnected()) {
updateMachine();
}
}
public boolean isConnected() { public boolean isConnected() {
return connected; 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() { public TileController getController() {
return (TileController) worldObj.getTileEntity(xController, yController, zController); return (TileController) worldObj.getTileEntity(xController, yController, zController);
} }
public abstract int getEnergyUsage();
@Override @Override
public void fromBytes(ByteBuf buf) { public void fromBytes(ByteBuf buf) {
connected = buf.readBoolean(); connected = buf.readBoolean();
@@ -43,6 +77,8 @@ public abstract class TileMachine extends TileBase implements INetworkTile {
yController = buf.readInt(); yController = buf.readInt();
zController = buf.readInt(); zController = buf.readInt();
} }
redstoneMode = RedstoneMode.getById(buf.readInt());
} }
@Override @Override
@@ -54,5 +90,25 @@ public abstract class TileMachine extends TileBase implements INetworkTile {
buf.writeInt(yController); buf.writeInt(yController);
buf.writeInt(zController); 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();
} }

View File

@@ -10,30 +10,29 @@ import storagecraft.storage.StorageItem;
import storagecraft.util.InventoryUtils; import storagecraft.util.InventoryUtils;
public class TileStorageProxy extends TileMachine implements IStorageProvider, IStorage { 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 if (tile instanceof IInventory) {
public void updateEntity() { return (IInventory) tile;
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;
} }
return null;
} }
@Override @Override
public int getEnergyUsage() { public int getEnergyUsage() {
return 5; return 2;
}
@Override
public void updateMachine() {
} }
@Override @Override
public void addItems(List<StorageItem> items) { public void addItems(List<StorageItem> items) {
IInventory inventory = getInventory();
if (inventory != null) { if (inventory != null) {
for (int i = 0; i < inventory.getSizeInventory(); ++i) { for (int i = 0; i < inventory.getSizeInventory(); ++i) {
if (inventory.getStackInSlot(i) != null) { if (inventory.getStackInSlot(i) != null) {
@@ -45,6 +44,8 @@ public class TileStorageProxy extends TileMachine implements IStorageProvider, I
@Override @Override
public void push(ItemStack stack) { public void push(ItemStack stack) {
IInventory inventory = getInventory();
if (inventory == null) { if (inventory == null) {
return; return;
} }
@@ -78,6 +79,8 @@ public class TileStorageProxy extends TileMachine implements IStorageProvider, I
@Override @Override
public int take(ItemStack stack) { public int take(ItemStack stack) {
IInventory inventory = getInventory();
if (inventory == null) { if (inventory == null) {
return 0; return 0;
} }
@@ -107,6 +110,8 @@ public class TileStorageProxy extends TileMachine implements IStorageProvider, I
@Override @Override
public boolean canPush(ItemStack stack) { public boolean canPush(ItemStack stack) {
IInventory inventory = getInventory();
if (inventory == null) { if (inventory == null) {
return false; return false;
} }

View File

@@ -3,6 +3,7 @@ itemGroup.storagecraft=StorageCraft
gui.storagecraft:controller=Controller gui.storagecraft:controller=Controller
gui.storagecraft:grid=Grid gui.storagecraft:grid=Grid
gui.storagecraft:drive=Drive gui.storagecraft:drive=Drive
gui.storagecraft:storageProxy=Storage Proxy
gui.storagecraft:importer=Importer gui.storagecraft:importer=Importer
misc.storagecraft:energyStored=%d / %d RF misc.storagecraft:energyStored=%d / %d RF
@@ -17,6 +18,10 @@ misc.storagecraft:compareDamage=Compare Damage
misc.storagecraft:on=On misc.storagecraft:on=On
misc.storagecraft:off=Off 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:controller.name=Controller
block.storagecraft:cable.name=Cable block.storagecraft:cable.name=Cable
block.storagecraft:grid.name=Grid block.storagecraft:grid.name=Grid

View File

@@ -3,6 +3,7 @@ itemGroup.storagecraft=StorageCraft
gui.storagecraft:controller=Controleur gui.storagecraft:controller=Controleur
gui.storagecraft:grid=Rooster gui.storagecraft:grid=Rooster
gui.storagecraft:drive=Schijf gui.storagecraft:drive=Schijf
gui.storagecraft:storageProxy=Opslag Proxy
gui.storagecraft:importer=Importeur gui.storagecraft:importer=Importeur
misc.storagecraft:energyStored=%d / %d RF misc.storagecraft:energyStored=%d / %d RF
@@ -17,6 +18,10 @@ misc.storagecraft:compareDamage=Damage vergelijken
misc.storagecraft:on=Aan misc.storagecraft:on=Aan
misc.storagecraft:off=Uit 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:controller.name=Controleur
block.storagecraft:cable.name=Kabel block.storagecraft:cable.name=Kabel
block.storagecraft:grid.name=Rooster block.storagecraft:grid.name=Rooster

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB