Worked on pump

Still need to work on this more to fix some issue before the 1.5 update
This commit is contained in:
RSeifert 2013-03-09 04:24:42 -05:00
parent fc6fbcb560
commit 3783314c6f

View file

@ -21,16 +21,18 @@ import net.minecraftforge.liquids.LiquidContainerRegistry;
import net.minecraftforge.liquids.LiquidStack;
import universalelectricity.core.electricity.ElectricityConnections;
import universalelectricity.core.electricity.ElectricityNetwork;
import universalelectricity.core.electricity.ElectricityPack;
import universalelectricity.core.vector.Vector3;
import universalelectricity.prefab.network.IPacketReceiver;
import universalelectricity.prefab.network.PacketManager;
import universalelectricity.prefab.tile.TileEntityElectricityReceiver;
import universalelectricity.prefab.tile.TileEntityElectricityRunnable;
import com.google.common.io.ByteArrayDataInput;
import fluidmech.common.FluidMech;
public class TileEntityPump extends TileEntityElectricityReceiver implements IPacketReceiver, IReadOut, IPsiCreator
public class TileEntityPump extends TileEntityElectricityRunnable implements IPacketReceiver, IReadOut, IPsiCreator
{
public final double WATTS_PER_TICK = (400 / 20);
double percentPumped = 0.0;
@ -46,8 +48,6 @@ public class TileEntityPump extends TileEntityElectricityReceiver implements IPa
ForgeDirection back = ForgeDirection.EAST;
ForgeDirection side = ForgeDirection.EAST;
ITankContainer fillTarget = null;
@Override
public void initiate()
{
@ -56,33 +56,22 @@ public class TileEntityPump extends TileEntityElectricityReceiver implements IPa
this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord, this.zCoord, FluidMech.blockMachine.blockID);
}
/**
* gets the side connection for the wire and pipe
*/
public void getConnections()
{
int notchMeta = MetaGroup.getFacingMeta(worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
back = ForgeDirection.getOrientation(notchMeta);
side = Vector3.getOrientationFromSide(back, ForgeDirection.WEST);
if (notchMeta == 2 || notchMeta == 3)
{
side = side.getOpposite();
}
}
@Override
public void onDisable(int duration)
{
disableTimer = duration;
}
@Override
public boolean isDisabled()
{
if (disableTimer <= 0)
{
return false;
}
return true;
}
@Override
public void updateEntity()
{
@ -90,23 +79,8 @@ public class TileEntityPump extends TileEntityElectricityReceiver implements IPa
if (!this.worldObj.isRemote && !this.isDisabled())
{
// consume/give away stored units
this.chargeUp();
TileEntity ent = worldObj.getBlockTileEntity(xCoord + side.offsetX, yCoord + side.offsetY, zCoord + side.offsetZ);
if (ent instanceof ITankContainer)
{
this.fillTarget = (ITankContainer) ent;
}
else
{
ent = null;
}
if (this.canPump(xCoord, yCoord - 1, zCoord) && this.joulesReceived >= this.WATTS_PER_TICK)
{
joulesReceived -= this.WATTS_PER_TICK;
this.pos++;
if (pos >= 8)
@ -119,10 +93,6 @@ public class TileEntityPump extends TileEntityElectricityReceiver implements IPa
this.drainBlock(new Vector3(xCoord, yCoord - 1, zCoord));
}
}
}
if (!this.worldObj.isRemote)
{
if (this.ticks % 10 == 0)
{
// TODO fix this to tell the client its running
@ -130,6 +100,33 @@ public class TileEntityPump extends TileEntityElectricityReceiver implements IPa
PacketManager.sendPacketToClients(packet, worldObj, new Vector3(this), 60);
}
}
}
@Override
public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput data)
{
try
{
this.color = ColorCode.get(data.readInt());
this.joulesReceived = data.readDouble();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public ITankContainer getFillTarget()
{
TileEntity ent = worldObj.getBlockTileEntity(xCoord + side.offsetX, yCoord + side.offsetY, zCoord + side.offsetZ);
if (ent instanceof ITankContainer)
{
return (ITankContainer) ent;
}
return null;
}
/**
@ -151,47 +148,23 @@ public class TileEntityPump extends TileEntityElectricityReceiver implements IPa
return 1;
}
/**
* causes this to request/drain energy from connected networks
*/
public void chargeUp()
@Override
public ElectricityPack getRequest()
{
// this.joulesReceived += this.WATTS_PER_TICK; //TODO remove after
// testing
int notchMeta = MetaGroup.getFacingMeta(worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
ForgeDirection facing = ForgeDirection.getOrientation(notchMeta).getOpposite();
for (int i = 2; i < 6; i++)
{
ForgeDirection dir = ForgeDirection.getOrientation(i);
if (dir == this.back || dir == this.side)
{
TileEntity inputTile = Vector3.getTileEntityFromSide(this.worldObj, new Vector3(this), dir);
ElectricityNetwork network = ElectricityNetwork.getNetworkFromTileEntity(inputTile, dir);
if (network != null)
{
if (this.canPump(xCoord, yCoord - 1, zCoord))
{
network.startRequesting(this, WATTS_PER_TICK / this.getVoltage(), this.getVoltage());
this.joulesReceived = Math.max(Math.min(this.joulesReceived + network.consumeElectricity(this).getWatts(), WATTS_PER_TICK), 0);
}
else
{
network.stopRequesting(this);
}
}
}
}
double amps = (this.WATTS_PER_TICK / this.getVoltage());
return new ElectricityPack(amps, this.getVoltage());
}
public boolean canPump(int x, int y, int z)
boolean canPump(int x, int y, int z)
{
int blockID = worldObj.getBlockId(x, y, z);
int meta = worldObj.getBlockMetadata(x, y, z);
LiquidData resource = LiquidHandler.getFromBlockID(blockID);
if (this.fillTarget == null || this.fillTarget.fill(side, this.color.getLiquidData().getStack(), false) == 0)
ITankContainer fillTarget = getFillTarget();
if (fillTarget == null || fillTarget.fill(side, this.color.getLiquidData().getStack(), false) == 0)
{
return false;
}
@ -199,9 +172,7 @@ public class TileEntityPump extends TileEntityElectricityReceiver implements IPa
{
return false;
}
else
if (blockID == Block.waterMoving.blockID || blockID == Block.lavaMoving.blockID)
else if (blockID == Block.waterMoving.blockID || blockID == Block.lavaMoving.blockID)
{
return false;
}
@ -218,18 +189,19 @@ public class TileEntityPump extends TileEntityElectricityReceiver implements IPa
* @param loc
* @return true if the block was drained
*/
public boolean drainBlock(Vector3 loc)
boolean drainBlock(Vector3 loc)
{
int blockID = worldObj.getBlockId(loc.intX(), loc.intY(), loc.intZ());
int meta = worldObj.getBlockMetadata(loc.intX(), loc.intY(), loc.intZ());
LiquidData resource = LiquidHandler.getFromBlockID(blockID);
if (resource == color.getLiquidData() && meta == 0 && this.fillTarget.fill(back, resource.getStack(), false) != 0)
if (color.isValidLiquid(resource) && meta == 0 && getFillTarget().fill(back, resource.getStack(), false) != 0)
{
LiquidStack stack = resource.getStack();
stack.amount = LiquidContainerRegistry.BUCKET_VOLUME;
int f = this.fillTarget.fill(back, this.color.getLiquidData().getStack(), true);
int f = getFillTarget().fill(back, this.color.getLiquidData().getStack(), true);
if (f > 0)
{
worldObj.setBlockWithNotify(xCoord, yCoord - 1, zCoord, 0);
@ -240,21 +212,6 @@ public class TileEntityPump extends TileEntityElectricityReceiver implements IPa
return false;
}
@Override
public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput data)
{
try
{
this.color = ColorCode.get(data.readInt());
this.joulesReceived = data.readDouble();
}
catch (Exception e)
{
e.printStackTrace();
}
}
@Override
public String getMeterReading(EntityPlayer user, ForgeDirection side)
{