add gui for controllers
This commit is contained in:
@@ -2,6 +2,7 @@ package storagecraft;
|
|||||||
|
|
||||||
import cpw.mods.fml.common.Mod;
|
import cpw.mods.fml.common.Mod;
|
||||||
import cpw.mods.fml.common.Mod.EventHandler;
|
import cpw.mods.fml.common.Mod.EventHandler;
|
||||||
|
import cpw.mods.fml.common.Mod.Instance;
|
||||||
import cpw.mods.fml.common.SidedProxy;
|
import cpw.mods.fml.common.SidedProxy;
|
||||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||||
@@ -15,6 +16,10 @@ import storagecraft.proxy.CommonProxy;
|
|||||||
|
|
||||||
@Mod(modid = SC.ID, version = SC.VERSION)
|
@Mod(modid = SC.ID, version = SC.VERSION)
|
||||||
public class SC {
|
public class SC {
|
||||||
|
public static class GUI {
|
||||||
|
public static final int CONTROLLER = 0;
|
||||||
|
}
|
||||||
|
|
||||||
public static final String ID = "storagecraft";
|
public static final String ID = "storagecraft";
|
||||||
public static final String VERSION = "1.0";
|
public static final String VERSION = "1.0";
|
||||||
public static final SimpleNetworkWrapper NETWORK = NetworkRegistry.INSTANCE.newSimpleChannel(ID);
|
public static final SimpleNetworkWrapper NETWORK = NetworkRegistry.INSTANCE.newSimpleChannel(ID);
|
||||||
@@ -26,6 +31,8 @@ public class SC {
|
|||||||
};
|
};
|
||||||
@SidedProxy(clientSide = "storagecraft.proxy.ClientProxy", serverSide = "storagecraft.proxy.ServerProxy")
|
@SidedProxy(clientSide = "storagecraft.proxy.ClientProxy", serverSide = "storagecraft.proxy.ServerProxy")
|
||||||
public static CommonProxy PROXY;
|
public static CommonProxy PROXY;
|
||||||
|
@Instance
|
||||||
|
public static SC INSTANCE;
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void preInit(FMLPreInitializationEvent e) {
|
public void preInit(FMLPreInitializationEvent e) {
|
||||||
|
@@ -3,8 +3,8 @@ package storagecraft.block;
|
|||||||
import net.minecraft.block.ITileEntityProvider;
|
import net.minecraft.block.ITileEntityProvider;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.ChatComponentText;
|
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import storagecraft.SC;
|
||||||
import storagecraft.tile.TileController;
|
import storagecraft.tile.TileController;
|
||||||
|
|
||||||
public class BlockController extends BlockSC implements ITileEntityProvider {
|
public class BlockController extends BlockSC implements ITileEntityProvider {
|
||||||
@@ -20,10 +20,7 @@ public class BlockController extends BlockSC implements ITileEntityProvider {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
|
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
|
||||||
if (!world.isRemote) {
|
if (!world.isRemote) {
|
||||||
TileController controller = (TileController) world.getTileEntity(x, y, z);
|
player.openGui(SC.INSTANCE, SC.GUI.CONTROLLER, world, x, y, z);
|
||||||
|
|
||||||
player.addChatComponentMessage(new ChatComponentText("RF stored: " + controller.getEnergyStored(null)));
|
|
||||||
player.addChatComponentMessage(new ChatComponentText("RF/t usage: " + controller.getEnergyUsage()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
60
src/main/java/storagecraft/gui/GuiController.java
Normal file
60
src/main/java/storagecraft/gui/GuiController.java
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
package storagecraft.gui;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||||
|
import net.minecraft.inventory.Container;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
import storagecraft.tile.TileController;
|
||||||
|
|
||||||
|
public class GuiController extends GuiContainer {
|
||||||
|
public static final ResourceLocation CONTROLLER_RESOURCE = new ResourceLocation("storagecraft:textures/gui/controller.png");
|
||||||
|
|
||||||
|
private TileController controller;
|
||||||
|
|
||||||
|
public GuiController(Container container, TileController controller) {
|
||||||
|
super(container);
|
||||||
|
|
||||||
|
this.controller = controller;
|
||||||
|
|
||||||
|
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(CONTROLLER_RESOURCE);
|
||||||
|
|
||||||
|
int x = (this.width - xSize) / 2;
|
||||||
|
int y = (this.height - ySize) / 2;
|
||||||
|
|
||||||
|
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
|
||||||
|
|
||||||
|
int barWidth = 16;
|
||||||
|
int barHeight = 59;
|
||||||
|
int barX = x + 17;
|
||||||
|
int barY = y + 25;
|
||||||
|
|
||||||
|
int energy = controller.getEnergyStored(null);
|
||||||
|
int maxEnergy = controller.getMaxEnergyStored(null);
|
||||||
|
|
||||||
|
int height = (int) ((float) energy / (float) maxEnergy * (float) barHeight);
|
||||||
|
|
||||||
|
drawTexturedModalRect(barX, barY + barHeight - height, 178, 0, barWidth, height);
|
||||||
|
|
||||||
|
fontRendererObj.drawString("Controller", x + 7, y + 7, 4210752);
|
||||||
|
fontRendererObj.drawString("Inventory", x + 7, y + 96, 4210752);
|
||||||
|
fontRendererObj.drawString("Energy usage: " + controller.getEnergyUsage() + " RF/t", x + 45, y + 24, 4210752);
|
||||||
|
|
||||||
|
if (mouseX >= barX && mouseX <= barX + barWidth && mouseY >= barY && mouseY <= barY + barHeight) {
|
||||||
|
List<String> lines = new ArrayList<String>();
|
||||||
|
|
||||||
|
lines.add(energy + " / " + maxEnergy + " RF");
|
||||||
|
|
||||||
|
drawHoveringText(lines, mouseX, mouseY, fontRendererObj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
38
src/main/java/storagecraft/gui/GuiHandler.java
Normal file
38
src/main/java/storagecraft/gui/GuiHandler.java
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package storagecraft.gui;
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.network.IGuiHandler;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.inventory.Container;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import storagecraft.SC;
|
||||||
|
import storagecraft.inventory.ContainerController;
|
||||||
|
import storagecraft.tile.TileController;
|
||||||
|
|
||||||
|
public class GuiHandler implements IGuiHandler {
|
||||||
|
private Container getContainer(int ID, EntityPlayer player) {
|
||||||
|
switch (ID) {
|
||||||
|
case SC.GUI.CONTROLLER:
|
||||||
|
return new ContainerController(player);
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||||
|
return getContainer(ID, player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||||
|
TileEntity tile = world.getTileEntity(x, y, z);
|
||||||
|
|
||||||
|
switch (ID) {
|
||||||
|
case SC.GUI.CONTROLLER:
|
||||||
|
return new GuiController(getContainer(ID, player), (TileController) tile);
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,11 @@
|
|||||||
|
package storagecraft.inventory;
|
||||||
|
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
|
||||||
|
public class ContainerController extends ContainerSC {
|
||||||
|
public ContainerController(EntityPlayer player) {
|
||||||
|
super(player);
|
||||||
|
|
||||||
|
addPlayerInventory(8, 108);
|
||||||
|
}
|
||||||
|
}
|
40
src/main/java/storagecraft/inventory/ContainerSC.java
Normal file
40
src/main/java/storagecraft/inventory/ContainerSC.java
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
package storagecraft.inventory;
|
||||||
|
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.inventory.Container;
|
||||||
|
import net.minecraft.inventory.Slot;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
|
public class ContainerSC extends Container {
|
||||||
|
private EntityPlayer player;
|
||||||
|
|
||||||
|
public ContainerSC(EntityPlayer player) {
|
||||||
|
this.player = player;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addPlayerInventory(int xInventory, int yInventory) {
|
||||||
|
int id = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < 9; i++) {
|
||||||
|
addSlotToContainer(new Slot(player.inventory, id, xInventory + i * 18, yInventory + 4 + (3 * 18)));
|
||||||
|
id++;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int y = 0; y < 3; y++) {
|
||||||
|
for (int x = 0; x < 9; x++) {
|
||||||
|
addSlotToContainer(new Slot(player.inventory, id, xInventory + x * 18, yInventory + y * 18));
|
||||||
|
id++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canInteractWith(EntityPlayer player) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
103
src/main/java/storagecraft/inventory/InventoryBasic.java
Normal file
103
src/main/java/storagecraft/inventory/InventoryBasic.java
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
package storagecraft.inventory;
|
||||||
|
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.inventory.IInventory;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
|
public class InventoryBasic implements IInventory {
|
||||||
|
private ItemStack[] inventory;
|
||||||
|
private int inventorySize;
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public InventoryBasic(String name, int size) {
|
||||||
|
this.name = name;
|
||||||
|
this.inventorySize = size;
|
||||||
|
this.inventory = new ItemStack[inventorySize];
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInventoryStack(ItemStack[] stack) {
|
||||||
|
this.inventory = stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSizeInventory() {
|
||||||
|
return inventory.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getStackInSlot(int slotIndex) {
|
||||||
|
return inventory[slotIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack decrStackSize(int slotIndex, int decrementAmount) {
|
||||||
|
ItemStack itemStack = getStackInSlot(slotIndex);
|
||||||
|
if (itemStack != null) {
|
||||||
|
if (itemStack.stackSize <= decrementAmount) {
|
||||||
|
setInventorySlotContents(slotIndex, null);
|
||||||
|
} else {
|
||||||
|
itemStack = itemStack.splitStack(decrementAmount);
|
||||||
|
|
||||||
|
if (itemStack.stackSize == 0) {
|
||||||
|
setInventorySlotContents(slotIndex, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return itemStack;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getStackInSlotOnClosing(int slotIndex) {
|
||||||
|
ItemStack itemStack = getStackInSlot(slotIndex);
|
||||||
|
if (itemStack != null) {
|
||||||
|
setInventorySlotContents(slotIndex, null);
|
||||||
|
}
|
||||||
|
return itemStack;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setInventorySlotContents(int slotIndex, ItemStack itemStack) {
|
||||||
|
if (itemStack != null && itemStack.stackSize > getInventoryStackLimit()) {
|
||||||
|
itemStack.stackSize = getInventoryStackLimit();
|
||||||
|
}
|
||||||
|
|
||||||
|
inventory[slotIndex] = itemStack;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getInventoryName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasCustomInventoryName() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getInventoryStackLimit() {
|
||||||
|
return 64;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isUseableByPlayer(EntityPlayer var1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void openInventory() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void closeInventory() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isItemValidForSlot(int var1, ItemStack var2) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void markDirty() {
|
||||||
|
}
|
||||||
|
}
|
@@ -3,10 +3,12 @@ package storagecraft.proxy;
|
|||||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||||
|
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||||
import cpw.mods.fml.common.registry.GameRegistry;
|
import cpw.mods.fml.common.registry.GameRegistry;
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import storagecraft.SC;
|
import storagecraft.SC;
|
||||||
import storagecraft.SCBlocks;
|
import storagecraft.SCBlocks;
|
||||||
|
import storagecraft.gui.GuiHandler;
|
||||||
import storagecraft.network.MessageTileUpdate;
|
import storagecraft.network.MessageTileUpdate;
|
||||||
import storagecraft.tile.TileCable;
|
import storagecraft.tile.TileCable;
|
||||||
import storagecraft.tile.TileController;
|
import storagecraft.tile.TileController;
|
||||||
@@ -15,19 +17,21 @@ import storagecraft.tile.TileGrid;
|
|||||||
public class CommonProxy {
|
public class CommonProxy {
|
||||||
public void preInit(FMLPreInitializationEvent e) {
|
public void preInit(FMLPreInitializationEvent e) {
|
||||||
SC.NETWORK.registerMessage(MessageTileUpdate.class, MessageTileUpdate.class, 0, Side.CLIENT);
|
SC.NETWORK.registerMessage(MessageTileUpdate.class, MessageTileUpdate.class, 0, Side.CLIENT);
|
||||||
|
|
||||||
|
NetworkRegistry.INSTANCE.registerGuiHandler(SC.INSTANCE, new GuiHandler());
|
||||||
|
|
||||||
GameRegistry.registerTileEntity(TileController.class, "controller");
|
GameRegistry.registerTileEntity(TileController.class, "controller");
|
||||||
GameRegistry.registerTileEntity(TileCable.class, "cable");
|
GameRegistry.registerTileEntity(TileCable.class, "cable");
|
||||||
GameRegistry.registerTileEntity(TileGrid.class, "grid");
|
GameRegistry.registerTileEntity(TileGrid.class, "grid");
|
||||||
|
|
||||||
GameRegistry.registerBlock(SCBlocks.CONTROLLER, "controller");
|
GameRegistry.registerBlock(SCBlocks.CONTROLLER, "controller");
|
||||||
GameRegistry.registerBlock(SCBlocks.CABLE, "cable");
|
GameRegistry.registerBlock(SCBlocks.CABLE, "cable");
|
||||||
GameRegistry.registerBlock(SCBlocks.GRID, "grid");
|
GameRegistry.registerBlock(SCBlocks.GRID, "grid");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(FMLInitializationEvent e) {
|
public void init(FMLInitializationEvent e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void postInit(FMLPostInitializationEvent e) {
|
public void postInit(FMLPostInitializationEvent e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,15 +2,17 @@ package storagecraft.tile;
|
|||||||
|
|
||||||
import cofh.api.energy.EnergyStorage;
|
import cofh.api.energy.EnergyStorage;
|
||||||
import cofh.api.energy.IEnergyHandler;
|
import cofh.api.energy.IEnergyHandler;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
|
|
||||||
public class TileController extends TileSC implements IEnergyHandler {
|
public class TileController extends TileSC implements IEnergyHandler, INetworkTile {
|
||||||
public static final int BASE_ENERGY_USAGE = 100;
|
public static final int BASE_ENERGY_USAGE = 100;
|
||||||
|
|
||||||
|
private int energyUsage;
|
||||||
private EnergyStorage storage = new EnergyStorage(32000);
|
private EnergyStorage storage = new EnergyStorage(32000);
|
||||||
private List<IMachine> connectedMachines = new ArrayList<IMachine>();
|
private List<IMachine> connectedMachines = new ArrayList<IMachine>();
|
||||||
private int ticks = 0;
|
private int ticks = 0;
|
||||||
@@ -51,6 +53,12 @@ public class TileController extends TileSC implements IEnergyHandler {
|
|||||||
connectedMachines = machines;
|
connectedMachines = machines;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
energyUsage = BASE_ENERGY_USAGE;
|
||||||
|
|
||||||
|
for (IMachine machine : connectedMachines) {
|
||||||
|
energyUsage += machine.getEnergyUsage();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
storage.extractEnergy(getEnergyUsage(), false);
|
storage.extractEnergy(getEnergyUsage(), false);
|
||||||
@@ -103,12 +111,6 @@ public class TileController extends TileSC implements IEnergyHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getEnergyUsage() {
|
public int getEnergyUsage() {
|
||||||
int energyUsage = BASE_ENERGY_USAGE;
|
|
||||||
|
|
||||||
for (IMachine machine : connectedMachines) {
|
|
||||||
energyUsage += machine.getEnergyUsage();
|
|
||||||
}
|
|
||||||
|
|
||||||
return energyUsage;
|
return energyUsage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,4 +122,16 @@ public class TileController extends TileSC implements IEnergyHandler {
|
|||||||
public boolean isActive() {
|
public boolean isActive() {
|
||||||
return storage.getEnergyStored() >= getEnergyUsage();
|
return storage.getEnergyStored() >= getEnergyUsage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fromBytes(ByteBuf buf) {
|
||||||
|
storage.setEnergyStored(buf.readInt());
|
||||||
|
energyUsage = buf.readInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void toBytes(ByteBuf buf) {
|
||||||
|
buf.writeInt(storage.getEnergyStored());
|
||||||
|
buf.writeInt(energyUsage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
After Width: | Height: | Size: 2.1 KiB |
Reference in New Issue
Block a user