fixed infinite water bug *again*

i think i fixed it this time threw but knowing how its been it might
crop up again. Need to clean up my code badly and find a way to recyle
code better.
This commit is contained in:
Rseifert 2012-09-04 01:01:54 -04:00
parent 34f2d5572e
commit df6e890c43
3 changed files with 77 additions and 63 deletions

View file

@ -44,30 +44,32 @@ public class ItemGuage extends Item
}
public boolean tryPlaceIntoWorld(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
{
if(par1ItemStack.getItemDamage() == 0)
if(!par3World.isRemote)
{
TileEntity blockEntity = par3World.getBlockTileEntity(par4, par5, par6);
if(blockEntity instanceof TileEntityPipe)
{
TileEntityPipe pipeEntity = (TileEntityPipe) blockEntity;
int type = pipeEntity.getType();
int steam = pipeEntity.getStoredLiquid(type);
String typeName = getType(type);
String print = "Error";
if(steam < 0)
{
print = "No pressure or Volume";
}
else
{
print = typeName +" " + steam + 1*Math.random() +" @ 16PSI";
}
par2EntityPlayer.addChatMessage(print);
return true;
}
}
if(par1ItemStack.getItemDamage() == 0)
{
TileEntity blockEntity = par3World.getBlockTileEntity(par4, par5, par6);
if(blockEntity instanceof TileEntityPipe)
{
TileEntityPipe pipeEntity = (TileEntityPipe) blockEntity;
int type = pipeEntity.getType();
int steam = pipeEntity.getStoredLiquid(type);
String typeName = getType(type);
String print = "Error";
if(steam <= 0)
{
print = "No pressure or Volume";
}
else
{
print = typeName +" " + steam +" @ 16PSI";
}
par2EntityPlayer.addChatMessage(print);
return true;
}
}
}
return false;
}

View file

@ -54,32 +54,33 @@ public class TileEntityPipe extends TileEntity implements ILiquidConsumer,IPacke
private int getNumSide(ForgeDirection side) {
private int getNumSide(ForgeDirection side)
{
if(side == ForgeDirection.DOWN)
{
return 0;
}
if(side == ForgeDirection.UP)
{
return 1;
}
if(side == ForgeDirection.NORTH)
{
return 2;
}
if(side == ForgeDirection.SOUTH)
{
return 3;
}
if(side == ForgeDirection.WEST)
{
return 4;
}
if(side == ForgeDirection.EAST)
{
return 5;
}
if(side == ForgeDirection.DOWN)
{
return 0;
}
if(side == ForgeDirection.UP)
{
return 1;
}
if(side == ForgeDirection.NORTH)
{
return 2;
}
if(side == ForgeDirection.SOUTH)
{
return 3;
}
if(side == ForgeDirection.WEST)
{
return 4;
}
if(side == ForgeDirection.EAST)
{
return 5;
}
return 0;
@ -98,9 +99,9 @@ if(side == ForgeDirection.EAST)
{
if(type == this.type)
{
int rejectedVolume = Math.max((this.getStoredLiquid(type) + vol) - this.capacity, 0);
this.liquidStored += vol - rejectedVolume;
return rejectedVolume;
int rejectedVolume = Math.max((this.getStoredLiquid(type) + vol) - this.capacity, 0);
this.liquidStored = Math.min(Math.max((liquidStored + vol - rejectedVolume),0),this.capacity);
return rejectedVolume;
}
return vol;
}
@ -175,7 +176,7 @@ if(side == ForgeDirection.EAST)
{
if(((ILiquidProducer)connectedBlocks[i]).canProduceLiquid(this.type,ForgeDirection.getOrientation(i)))
{
int gainedVolume = ((ILiquidProducer)connectedBlocks[i]).onProduceLiquid(this.type,5-this.liquidStored, ForgeDirection.getOrientation(i));
int gainedVolume = ((ILiquidProducer)connectedBlocks[i]).onProduceLiquid(this.type,this.capacity-this.liquidStored, ForgeDirection.getOrientation(i));
this.onReceiveLiquid(this.type, gainedVolume, ForgeDirection.getOrientation(i));
}
}
@ -191,14 +192,22 @@ if(side == ForgeDirection.EAST)
@Override
public int getStoredLiquid(int type)
{
if(type == this.type)
{
return this.liquidStored;
}
return 0;
}
@Override
public int getLiquidCapacity(int type)
{
return 5;
if(type == this.type)
{
return 5;
}
return 0;
}
/**

View file

@ -133,7 +133,7 @@ public class TileEntitySteamPiston extends TileEntityMachine implements IPacketR
{
--steamStored;
++steamConsumed;
if(steamConsumed >= SteamPowerMain.steamOutBoiler)
if(steamConsumed >= 10)
{
++waterStored;
steamConsumed = 0;
@ -321,11 +321,10 @@ public class TileEntitySteamPiston extends TileEntityMachine implements IPacketR
public int onProduceLiquid(int type, int Vol, ForgeDirection side) {
if(type == 1)
{
if(this.waterStored > 0)
{
int rejectedSteam = Math.max(Math.max((this.waterStored - Vol), 0),waterStored);
this.waterStored += waterStored - rejectedSteam;
return rejectedSteam;
if(this.waterStored >= 1)
{
this.waterStored--;
return 1;
}
}
return 0;
@ -344,9 +343,9 @@ public class TileEntitySteamPiston extends TileEntityMachine implements IPacketR
public int onReceiveLiquid(int type, int vol, ForgeDirection side) {
if(type == 0)
{
int rejectedSteam = Math.max((this.steamStored + vol) - 100, 0);
this.steamStored += vol - rejectedSteam;
return rejectedSteam;
int rejectedSteam = Math.max((this.steamStored + vol) - 100, 0);
this.steamStored += vol - rejectedSteam;
return rejectedSteam;
}
return vol;
}
@ -364,7 +363,11 @@ public class TileEntitySteamPiston extends TileEntityMachine implements IPacketR
public int getStoredLiquid(int type) {
if(type == 0)
{
return this.steamStored;
return this.steamStored;
}
if(type == 1)
{
return this.waterStored;
}
return 0;
}
@ -373,7 +376,7 @@ public class TileEntitySteamPiston extends TileEntityMachine implements IPacketR
public int getLiquidCapacity(int type) {
if(type == 0)
{
return 100;
return 100;
}
return 0;
}