a mess of stuff

This commit is contained in:
Robert 2013-11-29 19:36:06 -05:00
parent e8fbf3131f
commit aecf41bfbc
14 changed files with 342 additions and 63 deletions

View file

@ -193,4 +193,6 @@ public class ElectricityPack implements Cloneable
{
return this.amperes == electricityPack.amperes && this.voltage == electricityPack.voltage;
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 5.5 KiB

View file

@ -0,0 +1,76 @@
package dark.api;
import universalelectricity.core.electricity.ElectricityPack;
import net.minecraft.nbt.NBTTagCompound;
import dark.api.energy.EnergyPack;
import dark.api.save.ISaveObj;
import dark.api.save.NBTFileHelper;
/** Wrapper for data to be sent threw a network to a device
*
* @author DarkGuardsman */
public class DataPack implements ISaveObj, Cloneable
{
private Object[] data;
public DataPack(Object... data)
{
this.data = data;
}
public Object[] getData()
{
return this.data;
}
@Override
public void save(NBTTagCompound nbt)
{
if (data != null)
{
nbt.setInteger("dataCnt", data.length);
for (int i = 0; i < data.length; i++)
{
if (data[i] != null)
{
NBTFileHelper.saveObject(nbt, "data" + i, data[i]);
}
}
}
}
@Override
public void load(NBTTagCompound nbt)
{
if (nbt.hasKey("dataCnt"))
{
int dataLength = nbt.getInteger("dataCnt");
data = new Object[dataLength];
for (int i = 0; i < dataLength; i++)
{
if (nbt.hasKey("data" + i))
{
data[i] = NBTFileHelper.loadObject(nbt, "data" + i);
}
}
}
}
@Override
public DataPack clone()
{
return new DataPack(this.data);
}
public boolean isEqual(DataPack pack)
{
return this.data != null && pack.data != null && this.data.equals(pack.data);
}
@Override
public String toString()
{
return "DataPack [Obj:" + (this.data != null ? data.length : "none") + "]";
}
}

View file

@ -0,0 +1,109 @@
package dark.api.energy;
import net.minecraft.nbt.NBTTagCompound;
import universalelectricity.core.electricity.ElectricityPack;
/** Wrapper for storing information about electricity packets
*
* @author DarkGuardsman */
public class ElecPack extends EnergyPack
{
protected float volts, amps;
public ElecPack(Object... data)
{
super("Electric", 0, data);
}
public ElecPack(float amps, float volts, Object... data)
{
super("Electric", amps * volts, data);
this.volts = volts;
this.amps = amps;
}
public ElecPack setVoltAmp(float volt, float amp)
{
this.volts = volt;
this.amps = amp;
this.energyStored = volts * amps;
return this;
}
public ElecPack setVoltWatt(float volt, float watt)
{
this.volts = volt;
this.amps = watt / volt;
this.energyStored = watt;
return this;
}
@Override
public void save(NBTTagCompound nbt)
{
super.save(nbt);
nbt.setFloat("volts", this.volts);
nbt.setFloat("amps", this.amps);
}
@Override
public void load(NBTTagCompound nbt)
{
super.load(nbt);
this.volts = nbt.getFloat("volts");
this.amps = nbt.getFloat("amps");
}
public float getVolt()
{
return volts;
}
public float solveVolt()
{
return energyStored / amps;
}
public float getAmps()
{
return amps;
}
public float solveAmps()
{
return energyStored / volts;
}
public float getWatts()
{
return this.energyStored;
}
public float solveWatts()
{
return amps * volts;
}
@Override
public ElecPack clone()
{
return new ElecPack(0, 0, this.getData()).setVoltAmp(this.volts, this.amps);
}
@Override
public String toString()
{
return "ElecPack [Amps:" + this.amps + " Volts:" + this.volts + "]";
}
public boolean isEqual(ElecPack electricityPack)
{
return this.amps == electricityPack.amps && this.volts == electricityPack.volts;
}
public boolean isEqual(ElectricityPack electricityPack)
{
return this.amps == electricityPack.amperes && this.volts == electricityPack.voltage;
}
}

View file

@ -0,0 +1,58 @@
package dark.api.energy;
import net.minecraft.nbt.NBTTagCompound;
import dark.api.DataPack;
/** Container for energy data
*
* @author DarkGuardsman */
public class EnergyPack extends DataPack
{
protected String energyType;
protected float energyStored;
public EnergyPack(String type, float energySum, Object... data)
{
super(data);
this.energyType = type;
this.energyStored = energySum;
}
public float getJoules()
{
return energyStored;
}
@Override
public void save(NBTTagCompound nbt)
{
super.save(nbt);
nbt.setFloat("energy", this.energyStored);
nbt.setString("energyType", this.energyType);
}
@Override
public void load(NBTTagCompound nbt)
{
super.load(nbt);
this.energyStored = nbt.getFloat("energy");
this.energyType = nbt.getString("energyType");
}
@Override
public EnergyPack clone()
{
return new EnergyPack(this.energyType, this.energyStored, this.getData());
}
public boolean isEqual(EnergyPack pack)
{
return this.energyType.equalsIgnoreCase(pack.energyType);
}
@Override
public String toString()
{
return "EnergyPack [Joules:" + this.energyStored + "]";
}
}

View file

@ -1,19 +0,0 @@
package dark.api.energy;
/** Container for energy data
*
* @author DarkGuardsman */
public class EnergyPacket
{
protected String energyType;
protected float energyStored;
protected Object[] data;
public EnergyPacket(String type, float energySum, Object... data)
{
this.energyType = type;
this.energyStored = energySum;
this.data = data;
}
}

View file

@ -4,7 +4,7 @@ import net.minecraftforge.common.ForgeDirection;
public interface IEnergyConsumer extends IEnergyDevice
{
public float receiveEnergy(ForgeDirection from, EnergyPacket receive, boolean doReceive);
public float receiveEnergy(ForgeDirection from, EnergyPack receive, boolean doReceive);
public EnergyPacket getRequest(ForgeDirection direction);
public EnergyPack getRequest(ForgeDirection direction);
}

View file

@ -4,7 +4,7 @@ import net.minecraftforge.common.ForgeDirection;
public interface IEnergyProvider extends IEnergyDevice
{
public EnergyPacket provideEnergy(ForgeDirection from, EnergyPacket request, boolean doProvide);
public EnergyPack provideEnergy(ForgeDirection from, EnergyPack request, boolean doProvide);
public EnergyPacket getEnergyProduce(ForgeDirection direction);
public EnergyPack getEnergyProduce(ForgeDirection direction);
}

View file

@ -0,0 +1,12 @@
package dark.api.save;
import net.minecraft.nbt.NBTTagCompound;
public interface ISaveObj
{
/** Saves the object to NBT */
public void save(NBTTagCompound nbt);
/** Load the object from NBT */
public void load(NBTTagCompound nbt);
}

View file

@ -8,7 +8,7 @@ import net.minecraft.nbt.NBTTagCompound;
* since its not connected with the world
*
* @author DarkGuardsman */
public interface IVirtualObject
public interface IVirtualObject extends ISaveObj
{
/** File this is saved as, don't create anything here as the manager will do that for you */
public File getSaveFile();
@ -17,9 +17,5 @@ public interface IVirtualObject
* loaded from and decide if it wants to use the location as its getSaveFile return */
public void setSaveFile(File file);
/** Saves the object to NBT */
public void save(NBTTagCompound nbt);
/** Load the object from NBT */
public void load(NBTTagCompound nbt);
}

View file

@ -12,6 +12,7 @@ import cpw.mods.fml.client.FMLClientHandler;
import dark.core.common.DarkMain;
import dark.core.prefab.invgui.GuiBase;
import dark.core.prefab.invgui.GuiButtonImage;
import dark.core.prefab.invgui.GuiButtonImage.ButtonIcon;
import dark.core.prefab.machine.TileEntityMachine;
/** To be used with all machine that have a gui to allow generic settings and feature all all devices
@ -27,6 +28,7 @@ public class GuiMachineBase extends GuiBase
protected EntityPlayer entityPlayer;
protected Object mod;
protected int guiID = -1, guiID2 = -1, guiID3 = -1;
protected ButtonIcon guiIcon = ButtonIcon.CHEST, guiIcon2 = ButtonIcon.PERSON, guiIcon3 = ButtonIcon.BLANK;
protected String invName = "Home", invName2 = "2", invName3 = "3";
public GuiMachineBase(Object mod, EntityPlayer player, TileEntityMachine tileEntity)
@ -37,6 +39,7 @@ public class GuiMachineBase extends GuiBase
this.mod = mod;
}
@SuppressWarnings("unchecked")
@Override
public void initGui()
{
@ -45,14 +48,14 @@ public class GuiMachineBase extends GuiBase
// Inventory, Should be the Gui the machine opens to unless it has no inventory
if (guiID != -1)
this.buttonList.add(new GuiButtonImage(0, (this.width - this.guiSize.intX()) / 2 - 22, (this.height - this.guiSize.intY()) / 2 + 0, 3));
this.buttonList.add(new GuiButtonImage(0, (this.width - this.guiSize.intX()) / 2 - 22, (this.height - this.guiSize.intY()) / 2 + 0, guiIcon));
// Machine settings
if (guiID2 != -1)
this.buttonList.add(new GuiButtonImage(1, (this.width - this.guiSize.intX()) / 2 - 22, (this.height - this.guiSize.intY()) / 2 + 22, 0));
this.buttonList.add(new GuiButtonImage(1, (this.width - this.guiSize.intX()) / 2 - 22, (this.height - this.guiSize.intY()) / 2 + 22, guiIcon2));
if (guiID3 != -1)
this.buttonList.add(new GuiButtonImage(2, (this.width - this.guiSize.intX()) / 2 - 22, (this.height - this.guiSize.intY()) / 2 + 44, 2));
this.buttonList.add(new GuiButtonImage(2, (this.width - this.guiSize.intX()) / 2 - 22, (this.height - this.guiSize.intY()) / 2 + 44, guiIcon3));
}

View file

@ -14,6 +14,7 @@ import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import dark.core.prefab.invgui.GuiButtonImage;
import dark.core.prefab.invgui.GuiButtonImage.ButtonIcon;
import dark.core.prefab.machine.TileEntityMachine;
@SideOnly(Side.CLIENT)
@ -24,6 +25,7 @@ public abstract class GuiMachineContainer extends GuiContainer
protected EntityPlayer entityPlayer;
protected Object mod;
protected int guiID = -1, guiID2 = -1, guiID3 = -1;
protected ButtonIcon guiIcon = ButtonIcon.CHEST, guiIcon2 = ButtonIcon.PERSON, guiIcon3 = ButtonIcon.BLANK;
protected String invName = "Home", invName2 = "2", invName3 = "3";
public GuiMachineContainer(Object mod, Container container, InventoryPlayer inventoryPlayer, TileEntityMachine tileEntity)
@ -42,11 +44,11 @@ public abstract class GuiMachineContainer extends GuiContainer
this.buttonList.clear();
if (guiID != -1)
this.buttonList.add(new GuiButtonImage(0, (this.width - this.xSize) / 2 - 22, (this.height - this.ySize) / 2 + 0, 3));
this.buttonList.add(new GuiButtonImage(0, (this.width - this.xSize) / 2 - 22, (this.height - this.ySize) / 2 + 0, guiIcon));
if (guiID2 != -1)
this.buttonList.add(new GuiButtonImage(1, (this.width - this.xSize) / 2 - 22, (this.height - this.ySize) / 2 + 22, 0));
this.buttonList.add(new GuiButtonImage(1, (this.width - this.xSize) / 2 - 22, (this.height - this.ySize) / 2 + 22, guiIcon2));
if (guiID3 != -1)
this.buttonList.add(new GuiButtonImage(2, (this.width - this.xSize) / 2 - 22, (this.height - this.ySize) / 2 + 44, 2));
this.buttonList.add(new GuiButtonImage(2, (this.width - this.xSize) / 2 - 22, (this.height - this.ySize) / 2 + 44, guiIcon3));
}

View file

@ -5,9 +5,29 @@ import dark.api.ColorCode;
public class TileEntityWire extends TileEntityUniversalConductor
{
protected int updateTick = 0;
protected int updateTick = 1;
protected ColorCode color = ColorCode.BLACK;
@Override
public void updateEntity()
{
super.updateEntity();
if (!worldObj.isRemote)
{
if (ticks % this.updateTick == 0)
{
this.updateTick = this.worldObj.rand.nextInt(5) * 40 + 20;
this.refresh();
}
}
}
@Override
public boolean canUpdate()
{
return true;
}
@Override
public float getResistance()
{

View file

@ -16,45 +16,33 @@ public class GuiButtonImage extends GuiButton
{
public static final ResourceLocation TEXTURE = new ResourceLocation(DarkMain.getInstance().DOMAIN, DarkMain.GUI_DIRECTORY + "gui_button.png");
private int type = 0;
private ButtonIcon buttonIcon = ButtonIcon.BLANK;
public GuiButtonImage(int par1, int par2, int par3, int type)
public GuiButtonImage(int buttonID, int xx, int yy, ButtonIcon icon)
{
super(par1, par2, par3, 20, 20, "");
this.type = type;
super(buttonID, xx, yy, 20, 20, "");
this.buttonIcon = icon;
this.width = icon.sizeX;
this.height = icon.sizeY;
}
/** Draws this button to the screen. */
@Override
public void drawButton(Minecraft par1Minecraft, int width, int hight)
public void drawButton(Minecraft mc, int width, int hight)
{
if (this.drawButton)
{
FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
boolean var4 = width >= this.xPosition && hight >= this.yPosition && width < this.xPosition + this.width && hight < this.yPosition + this.height;
int var5 = 106;
int var6 = 0;
if (var4)
boolean hovering = width >= this.xPosition && hight >= this.yPosition && width < this.xPosition + this.width && hight < this.yPosition + this.height;
int vv = buttonIcon.vv;
int uu = buttonIcon.uu;
if (hovering)
{
var5 += this.height;
}
switch (type)
{
case 0:
var5 += 40;
break;
case 1:
var5 += 40;
var6 += 20;
break;
case 2:
var5 += 40;
var6 += 40;
break;
vv += this.height;
}
this.drawTexturedModalRect(this.xPosition, this.yPosition, var6, var5, this.width, this.height);
this.drawTexturedModalRect(this.xPosition, this.yPosition, uu, vv, this.width, this.height);
}
}
@ -62,6 +50,38 @@ public class GuiButtonImage extends GuiButton
public boolean isIntersect(int x, int y)
{
return x >= this.xPosition && y >= this.yPosition && x < this.xPosition + this.width && y < this.yPosition + this.height;
}
public static enum ButtonIcon
{
PERSON(0, 0),
ARROW_LEFT(30, 0),
ARROW_RIGHT(20, 0),
ARROW_DOWN(30, 20),
ARROW_UP(20, 20),
CHEST(60, 0),
LOCKED(80, 0),
UNLOCKED(100, 0),
BLANK(120, 0),
RED_ON(140, 0),
RED_OFF(160, 0),
FURNACE_OFF(180, 0),
FURNACE_ON(200, 0);
int vv, uu;
int sizeX = 20, sizeY = 20;
private ButtonIcon(int xx, int yy)
{
this.vv = xx;
this.uu = yy;
}
private ButtonIcon(int xx, int yy, int cx, int cy)
{
this(xx, yy);
this.sizeX = cx;
this.sizeY = cy;
}
}
}