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 net.minecraftforge.liquids.LiquidStack;
import universalelectricity.core.electricity.ElectricityConnections; import universalelectricity.core.electricity.ElectricityConnections;
import universalelectricity.core.electricity.ElectricityNetwork; import universalelectricity.core.electricity.ElectricityNetwork;
import universalelectricity.core.electricity.ElectricityPack;
import universalelectricity.core.vector.Vector3; import universalelectricity.core.vector.Vector3;
import universalelectricity.prefab.network.IPacketReceiver; import universalelectricity.prefab.network.IPacketReceiver;
import universalelectricity.prefab.network.PacketManager; import universalelectricity.prefab.network.PacketManager;
import universalelectricity.prefab.tile.TileEntityElectricityReceiver; import universalelectricity.prefab.tile.TileEntityElectricityReceiver;
import universalelectricity.prefab.tile.TileEntityElectricityRunnable;
import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteArrayDataInput;
import fluidmech.common.FluidMech; 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); public final double WATTS_PER_TICK = (400 / 20);
double percentPumped = 0.0; double percentPumped = 0.0;
@ -46,8 +48,6 @@ public class TileEntityPump extends TileEntityElectricityReceiver implements IPa
ForgeDirection back = ForgeDirection.EAST; ForgeDirection back = ForgeDirection.EAST;
ForgeDirection side = ForgeDirection.EAST; ForgeDirection side = ForgeDirection.EAST;
ITankContainer fillTarget = null;
@Override @Override
public void initiate() 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); this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord, this.zCoord, FluidMech.blockMachine.blockID);
} }
/**
* gets the side connection for the wire and pipe
*/
public void getConnections() public void getConnections()
{ {
int notchMeta = MetaGroup.getFacingMeta(worldObj.getBlockMetadata(xCoord, yCoord, zCoord)); int notchMeta = MetaGroup.getFacingMeta(worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
back = ForgeDirection.getOrientation(notchMeta); back = ForgeDirection.getOrientation(notchMeta);
side = Vector3.getOrientationFromSide(back, ForgeDirection.WEST); side = Vector3.getOrientationFromSide(back, ForgeDirection.WEST);
if (notchMeta == 2 || notchMeta == 3) if (notchMeta == 2 || notchMeta == 3)
{ {
side = side.getOpposite(); side = side.getOpposite();
} }
} }
@Override
public void onDisable(int duration)
{
disableTimer = duration;
}
@Override
public boolean isDisabled()
{
if (disableTimer <= 0)
{
return false;
}
return true;
}
@Override @Override
public void updateEntity() public void updateEntity()
{ {
@ -90,23 +79,8 @@ public class TileEntityPump extends TileEntityElectricityReceiver implements IPa
if (!this.worldObj.isRemote && !this.isDisabled()) 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) if (this.canPump(xCoord, yCoord - 1, zCoord) && this.joulesReceived >= this.WATTS_PER_TICK)
{ {
joulesReceived -= this.WATTS_PER_TICK; joulesReceived -= this.WATTS_PER_TICK;
this.pos++; this.pos++;
if (pos >= 8) if (pos >= 8)
@ -119,10 +93,6 @@ public class TileEntityPump extends TileEntityElectricityReceiver implements IPa
this.drainBlock(new Vector3(xCoord, yCoord - 1, zCoord)); this.drainBlock(new Vector3(xCoord, yCoord - 1, zCoord));
} }
} }
}
if (!this.worldObj.isRemote)
{
if (this.ticks % 10 == 0) if (this.ticks % 10 == 0)
{ {
// TODO fix this to tell the client its running // 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); 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; return 1;
} }
/** @Override
* causes this to request/drain energy from connected networks public ElectricityPack getRequest()
*/
public void chargeUp()
{ {
// this.joulesReceived += this.WATTS_PER_TICK; //TODO remove after double amps = (this.WATTS_PER_TICK / this.getVoltage());
// testing return new ElectricityPack(amps, this.getVoltage());
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);
}
}
}
}
} }
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 blockID = worldObj.getBlockId(x, y, z);
int meta = worldObj.getBlockMetadata(x, y, z); int meta = worldObj.getBlockMetadata(x, y, z);
LiquidData resource = LiquidHandler.getFromBlockID(blockID); 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; return false;
} }
@ -199,9 +172,7 @@ public class TileEntityPump extends TileEntityElectricityReceiver implements IPa
{ {
return false; return false;
} }
else else if (blockID == Block.waterMoving.blockID || blockID == Block.lavaMoving.blockID)
if (blockID == Block.waterMoving.blockID || blockID == Block.lavaMoving.blockID)
{ {
return false; return false;
} }
@ -218,18 +189,19 @@ public class TileEntityPump extends TileEntityElectricityReceiver implements IPa
* @param loc * @param loc
* @return true if the block was drained * @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 blockID = worldObj.getBlockId(loc.intX(), loc.intY(), loc.intZ());
int meta = worldObj.getBlockMetadata(loc.intX(), loc.intY(), loc.intZ()); int meta = worldObj.getBlockMetadata(loc.intX(), loc.intY(), loc.intZ());
LiquidData resource = LiquidHandler.getFromBlockID(blockID); 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(); LiquidStack stack = resource.getStack();
stack.amount = LiquidContainerRegistry.BUCKET_VOLUME; 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) if (f > 0)
{ {
worldObj.setBlockWithNotify(xCoord, yCoord - 1, zCoord, 0); worldObj.setBlockWithNotify(xCoord, yCoord - 1, zCoord, 0);
@ -240,21 +212,6 @@ public class TileEntityPump extends TileEntityElectricityReceiver implements IPa
return false; 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 @Override
public String getMeterReading(EntityPlayer user, ForgeDirection side) public String getMeterReading(EntityPlayer user, ForgeDirection side)
{ {