Tesla integration for Battery

This commit is contained in:
Aidan Brady 2013-08-05 11:32:01 -04:00
parent d77d6292f6
commit 6db24c8dd6
2 changed files with 18 additions and 29 deletions

View file

@ -11,8 +11,10 @@ import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import resonantinduction.PacketHandler;
import resonantinduction.api.IBattery;
import resonantinduction.api.ITesla;
import resonantinduction.base.IPacketReceiver;
import resonantinduction.base.ListUtil;
import resonantinduction.base.TileEntityBase;
@ -24,7 +26,7 @@ import com.google.common.io.ByteArrayDataInput;
*
* @author AidanBrady
*/
public class TileEntityBattery extends TileEntityBase implements IPacketReceiver, IInventory
public class TileEntityBattery extends TileEntityBase implements IPacketReceiver, IInventory, ITesla
{
public SynchronizedBatteryData structure = SynchronizedBatteryData.getBase(this);
@ -93,6 +95,7 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
for(int tagCount = 0; tagCount < tagList.tagCount(); tagCount++)
{
System.out.println("Read");
NBTTagCompound tagCompound = (NBTTagCompound)tagList.tagAt(tagCount);
int slotID = tagCompound.getInteger("Slot");
structure.inventory.add(slotID, ItemStack.loadItemStackFromNBT(tagCompound));
@ -140,6 +143,7 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
{
if(structure.inventory.get(slotCount) != null)
{
System.out.println("Save");
NBTTagCompound tagCompound = new NBTTagCompound();
tagCompound.setInteger("Slot", slotCount);
structure.inventory.get(slotCount).writeToNBT(tagCompound);
@ -468,4 +472,16 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
{
return false;
}
@Override
public float transfer(float transferEnergy, boolean doTransfer)
{
return addEnergy(transferEnergy, doTransfer);
}
@Override
public boolean canReceive(TileEntity transferTile)
{
return true;
}
}

View file

@ -29,7 +29,7 @@ import com.google.common.io.ByteArrayDataInput;
* @author AidanBrady
*
*/
public class TileEntityEMContractor extends TileEntityBase implements IPacketReceiver, ITesla
public class TileEntityEMContractor extends TileEntityBase implements IPacketReceiver
{
public static int MAX_REACH = 40;
public static int PUSH_DELAY = 5;
@ -41,8 +41,6 @@ public class TileEntityEMContractor extends TileEntityBase implements IPacketRec
private int pushDelay;
private float energyStored;
private AxisAlignedBB operationBounds;
private AxisAlignedBB suckBounds;
@ -159,8 +157,6 @@ public class TileEntityEMContractor extends TileEntityBase implements IPacketRec
if (operationBounds != null)
{
energyStored -= ENERGY_USAGE;
for (EntityItem entityItem : (List<EntityItem>) worldObj.getEntitiesWithinAABB(EntityItem.class, operationBounds))
{
if (this.worldObj.isRemote && this.ticks % 5 == 0)
@ -417,7 +413,6 @@ public class TileEntityEMContractor extends TileEntityBase implements IPacketRec
this.facing = ForgeDirection.getOrientation(nbt.getInteger("facing"));
this.suck = nbt.getBoolean("suck");
this.energyStored = nbt.getFloat("energyStored");
this.dyeID = nbt.getInteger("dyeID");
this.tempLinkVector = new Vector3(nbt.getInteger("link_x"), nbt.getInteger("link_y"), nbt.getInteger("link_z"));
updateBounds();
@ -430,7 +425,6 @@ public class TileEntityEMContractor extends TileEntityBase implements IPacketRec
nbt.setInteger("facing", facing.ordinal());
nbt.setBoolean("suck", suck);
nbt.setFloat("energyStored", energyStored);
nbt.setInteger("dyeID", this.dyeID);
if (this.linked != null)
@ -448,7 +442,6 @@ public class TileEntityEMContractor extends TileEntityBase implements IPacketRec
{
facing = ForgeDirection.getOrientation(input.readInt());
suck = input.readBoolean();
energyStored = input.readFloat();
this.dyeID = input.readInt();
if (input.readBoolean())
@ -469,7 +462,6 @@ public class TileEntityEMContractor extends TileEntityBase implements IPacketRec
{
data.add(facing.ordinal());
data.add(suck);
data.add(energyStored);
data.add(this.dyeID);
if (this.linked != null)
@ -487,25 +479,6 @@ public class TileEntityEMContractor extends TileEntityBase implements IPacketRec
return data;
}
@Override
public float transfer(float transferEnergy, boolean doTransfer)
{
float energyToUse = Math.min(transferEnergy, ENERGY_USAGE - energyStored);
if (doTransfer)
{
energyStored += energyToUse;
}
return energyToUse;
}
@Override
public boolean canReceive(TileEntity transferTile)
{
return true;
}
/**
* Link between two TileEntities, do pathfinding operation.
*/