Worked on battery box

This commit is contained in:
Robert 2013-12-03 07:57:51 -05:00
parent 3f99e996dd
commit a055a4a2ca
9 changed files with 239 additions and 22 deletions

View file

@ -38,6 +38,10 @@
<exclude name=".git/**"/>
<exclude name="**/*.xml"/>
</fileset>
<fileset dir="${dir.development}Built-Broken-Lib">
<exclude name=".git/**"/>
<exclude name="**/*.xml"/>
</fileset>
<fileset dir="${dir.development}APIs">
<exclude name=".git/**"/>
<exclude name="**/*.xml"/>

View file

@ -12,11 +12,13 @@ import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import dark.core.client.gui.GuiBatteryBox;
import dark.core.client.renders.BlockRenderingHandler;
import dark.core.client.renders.ItemRenderFluidCan;
import dark.core.client.renders.RenderTestCar;
import dark.core.common.CommonProxy;
import dark.core.common.CoreRecipeLoader;
import dark.core.common.machines.TileEntityBatteryBox;
import dark.core.prefab.ModPrefab;
import dark.core.prefab.vehicles.EntityTestCar;
@ -25,7 +27,7 @@ public class ClientProxy extends CommonProxy
{
/** Renders a laser beam from one power to another by a set color for a set time
*
*
* @param world - world this laser is to be rendered in
* @param position - start vector3
* @param target - end vector3
@ -61,6 +63,10 @@ public class ClientProxy extends CommonProxy
if (tileEntity != null)
{
if (ID == GUI_BATTERY_BOX && tileEntity instanceof TileEntityBatteryBox)
{
return new GuiBatteryBox(player.inventory, (TileEntityBatteryBox) tileEntity);
}
}
return null;

View file

@ -0,0 +1,64 @@
package dark.core.client.gui;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11;
import universalelectricity.core.electricity.ElectricityDisplay;
import universalelectricity.core.electricity.ElectricityDisplay.ElectricUnit;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import dark.core.common.DarkMain;
import dark.core.common.machines.ContainerBatteryBox;
import dark.core.common.machines.TileEntityBatteryBox;
@SideOnly(Side.CLIENT)
public class GuiBatteryBox extends GuiContainer
{
private static final ResourceLocation TEXTURE = new ResourceLocation(DarkMain.getInstance().DOMAIN, DarkMain.GUI_DIRECTORY + "battery_box.png");
private TileEntityBatteryBox tileEntity;
private int containerWidth;
private int containerHeight;
public GuiBatteryBox(InventoryPlayer par1InventoryPlayer, TileEntityBatteryBox batteryBox)
{
super(new ContainerBatteryBox(par1InventoryPlayer, batteryBox));
this.tileEntity = batteryBox;
}
/** Draw the foreground layer for the GuiContainer (everything in front of the items) */
@Override
protected void drawGuiContainerForegroundLayer(int par1, int par2)
{
this.fontRenderer.drawString(this.tileEntity.getInvName(), 65, 6, 4210752);
String displayJoules = ElectricityDisplay.getDisplayShort(tileEntity.getEnergyStored(), ElectricUnit.JOULES) + " of";
String displayMaxJoules = ElectricityDisplay.getDisplay(tileEntity.getMaxEnergyStored(), ElectricUnit.JOULES);
String displayVoltage = "Voltage: " + (int) (this.tileEntity.getVoltage() * 1000);
this.fontRenderer.drawString(displayJoules, 122 - this.fontRenderer.getStringWidth(displayJoules) / 2, 30, 4210752);
this.fontRenderer.drawString(displayMaxJoules, 122 - this.fontRenderer.getStringWidth(displayMaxJoules) / 2, 40, 4210752);
this.fontRenderer.drawString(displayVoltage, 122 - this.fontRenderer.getStringWidth(displayVoltage) / 2, 60, 4210752);
this.fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
}
/** Draw the background layer for the GuiContainer (everything behind the items) */
@Override
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
{
this.mc.renderEngine.bindTexture(TEXTURE);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.containerWidth = (this.width - this.xSize) / 2;
this.containerHeight = (this.height - this.ySize) / 2;
// Background energy bar
this.drawTexturedModalRect(containerWidth, containerHeight, 0, 0, this.xSize, this.ySize);
// Foreground energy bar
int scale = (int) ((this.tileEntity.getEnergyStored() / this.tileEntity.getMaxEnergyStored()) * 72);
this.drawTexturedModalRect(containerWidth + 87, containerHeight + 52, 176, 0, scale, 20);
}
}

View file

@ -7,7 +7,9 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import universalelectricity.core.vector.Vector3;
import cpw.mods.fml.common.network.IGuiHandler;
import dark.core.common.machines.ContainerBatteryBox;
import dark.core.common.machines.ContainerCoalGenerator;
import dark.core.common.machines.TileEntityBatteryBox;
import dark.core.common.machines.TileEntitySteamGen;
import dark.core.network.PacketManagerEffects;
@ -63,6 +65,10 @@ public class CommonProxy implements IGuiHandler
{
return new ContainerCoalGenerator(player.inventory, ((TileEntitySteamGen) tileEntity));
}
else if (ID == GUI_BATTERY_BOX && tileEntity instanceof TileEntityBatteryBox)
{
return new ContainerBatteryBox(player.inventory, (TileEntityBatteryBox) tileEntity);
}
}
return null;

View file

@ -18,6 +18,7 @@ import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.UniversalElectricity;
import universalelectricity.core.block.IConductor;
import universalelectricity.core.vector.Vector3;
import dark.core.common.CommonProxy;
import dark.core.common.DMCreativeTab;
import dark.core.common.DarkMain;
import dark.core.helpers.MathHelper;
@ -46,6 +47,19 @@ public class BlockEnergyStorage extends BlockMachine
}
@Override
public boolean onMachineActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ)
{
int metadata = par1World.getBlockMetadata(x, y, z);
if (!par1World.isRemote)
{
par5EntityPlayer.openGui(DarkMain.getInstance(), CommonProxy.GUI_BATTERY_BOX, par1World, x, y, z);
}
return true;
}
@Override
public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
{
@ -63,14 +77,7 @@ public class BlockEnergyStorage extends BlockMachine
@Override
public TileEntity createTileEntity(World world, int metadata)
{
switch (metadata / 4)
{
case 0:
return new TileEntityBatteryBox();
}
return super.createTileEntity(world, metadata);
return new TileEntityBatteryBox();
}
@Override

View file

@ -0,0 +1,105 @@
package dark.core.common.machines;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import universalelectricity.core.item.IItemElectric;
import universalelectricity.prefab.SlotSpecific;
public class ContainerBatteryBox extends Container
{
private TileEntityBatteryBox tileEntity;
public ContainerBatteryBox(InventoryPlayer par1InventoryPlayer, TileEntityBatteryBox batteryBox)
{
this.tileEntity = batteryBox;
// Top slot for battery output
this.addSlotToContainer(new SlotSpecific(batteryBox, 0, 33, 24, IItemElectric.class));
// Bottom slot for batter input
this.addSlotToContainer(new SlotSpecific(batteryBox, 1, 33, 48, IItemElectric.class));
int var3;
for (var3 = 0; var3 < 3; ++var3)
{
for (int var4 = 0; var4 < 9; ++var4)
{
this.addSlotToContainer(new Slot(par1InventoryPlayer, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18));
}
}
for (var3 = 0; var3 < 9; ++var3)
{
this.addSlotToContainer(new Slot(par1InventoryPlayer, var3, 8 + var3 * 18, 142));
}
}
@Override
public boolean canInteractWith(EntityPlayer par1EntityPlayer)
{
return this.tileEntity.isUseableByPlayer(par1EntityPlayer);
}
/** Called to transfer a stack from one inventory to the other eg. when shift clicking. */
@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int slotID)
{
ItemStack returnStack = null;
Slot slot = (Slot) this.inventorySlots.get(slotID);
if (slot != null && slot.getHasStack())
{
ItemStack itemStack = slot.getStack();
returnStack = itemStack.copy();
if (slotID != 0 && slotID != 1)
{
if (this.getSlot(0).isItemValid(itemStack))
{
if (((IItemElectric) itemStack.getItem()).getElectricityStored(itemStack) > 0)
{
if (!this.mergeItemStack(itemStack, 1, 2, false))
{
return null;
}
}
else
{
if (!this.mergeItemStack(itemStack, 0, 1, false))
{
return null;
}
}
}
else if (slotID >= 30 && slotID < 38 && !this.mergeItemStack(itemStack, 3, 30, false))
{
return null;
}
}
else if (!this.mergeItemStack(itemStack, 3, 38, false))
{
return null;
}
if (itemStack.stackSize == 0)
{
slot.putStack((ItemStack) null);
}
else
{
slot.onSlotChanged();
}
if (itemStack.stackSize == returnStack.stackSize)
{
return null;
}
slot.onPickupFromSlot(par1EntityPlayer, itemStack);
}
return returnStack;
}
}

View file

@ -1,7 +1,10 @@
package dark.core.common.machines;
import java.io.IOException;
import java.util.EnumSet;
import com.google.common.io.ByteArrayDataInput;
import net.minecraft.network.packet.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
@ -12,19 +15,23 @@ import universalelectricity.core.grid.IElectricityNetwork;
import universalelectricity.core.vector.Vector3;
import universalelectricity.core.vector.VectorHelper;
import universalelectricity.prefab.network.PacketManager;
import cpw.mods.fml.common.network.Player;
import cpw.mods.fml.common.registry.LanguageRegistry;
import dark.core.helpers.EnergyHelper;
import dark.core.network.PacketHandler;
import dark.core.prefab.machine.TileEntityEnergyMachine;
import dark.core.prefab.machine.TileEntityMachine.SimplePacketTypes;
/** Simple in out battery box
*
*
* @author DarkGuardsman */
public class TileEntityBatteryBox extends TileEntityEnergyMachine
{
public TileEntityBatteryBox()
{
super(0, 5000);
this.invSlots = 2;
this.hasGUI = true;
}
@Override
@ -32,7 +39,7 @@ public class TileEntityBatteryBox extends TileEntityEnergyMachine
{
super.updateEntity();
if (!this.isDisabled())
if (!this.canFunction())
{
if (!this.worldObj.isRemote)
{
@ -77,7 +84,7 @@ public class TileEntityBatteryBox extends TileEntityEnergyMachine
}
/** Gradually lose energy. */
this.setEnergyStored(this.getEnergyStored() - 0.00005f);
this.consumePower(0.000005f, true);
}
@Override
@ -92,10 +99,34 @@ public class TileEntityBatteryBox extends TileEntityEnergyMachine
return EnumSet.of(ForgeDirection.getOrientation(this.getBlockMetadata()).getOpposite());
}
@Override
public boolean simplePacket(String id, ByteArrayDataInput dis, Player player)
{
boolean r = super.simplePacket(id, dis, player);
try
{
if (this.worldObj.isRemote && !r)
{
if (id.equalsIgnoreCase("desc"))
{
this.setEnergyStored(dis.readFloat());
this.MAX_JOULES_STORED = dis.readFloat();
return true;
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
return r;
}
@Override
public Packet getDescriptionPacket()
{
return PacketManager.getPacket(this.getChannel(), this, this.getEnergyStored(), this.disabledTicks);
return PacketHandler.instance().getTilePacket(this.getChannel(), this, "desc", this.getEnergyStored(), this.getMaxEnergyStored());
}
@Override
@ -110,12 +141,6 @@ public class TileEntityBatteryBox extends TileEntityEnergyMachine
return 1;
}
@Override
public float getMaxEnergyStored()
{
return 5000;
}
@Override
public boolean isInvNameLocalized()
{

View file

@ -14,7 +14,7 @@ public class TileEntitySolarPanel extends TileEntityEnergyMachine
public TileEntitySolarPanel()
{
this.MAX_WATTS = 1;
this.MAX_JOULES_STORED = 1;
}
@Override

View file

@ -31,7 +31,7 @@ public class TileEntitySteamPiston extends TileEntityEnergyMachine
{
heatTicks++;
}
this.wattsOut = this.MAX_WATTS * (heatTicks / heatUpTime);
this.wattsOut = this.MAX_JOULES_STORED * (heatTicks / heatUpTime);
this.produceAllSides();
}
else