Fix GasTurbine activate state and fix fluid amount sync

This commit is contained in:
Ourten 2016-12-14 18:36:43 +01:00
parent 65ec0db2de
commit caf5d56e3c

View file

@ -106,31 +106,39 @@ public class TileGasTurbine extends TilePowerAcceptor implements IWrenchable, II
@Override @Override
public void updateEntity() { public void updateEntity() {
super.updateEntity(); super.updateEntity();
if (!world.isRemote) {
FluidUtils.drainContainers(tank, inventory, 0, 1); if (!this.world.isRemote) {
tank.compareAndUpdate(); if (FluidUtils.drainContainers(this.tank, this.inventory, 0, 1))
this.syncWithAll();
} }
if (tank.getFluidAmount() > 0 && getMaxPower() - getEnergy() >= euTick) { if (this.tank.getFluidAmount() > 0 && this.getMaxPower() - this.getEnergy() >= TileGasTurbine.euTick) {
Integer euPerBucket = fluids.get(tank.getFluidType().getName()); final Integer euPerBucket = this.fluids.get(this.tank.getFluidType().getName());
// float totalTicks = (float)euPerBucket / 8f; //x eu per bucket / 8 // float totalTicks = (float)euPerBucket / 8f; //x eu per bucket / 8
// eu per tick // eu per tick
// float millibucketsPerTick = 1000f / totalTicks; // float millibucketsPerTick = 1000f / totalTicks;
float millibucketsPerTick = 16000f / (float) euPerBucket; final float millibucketsPerTick = 16000f / (float) euPerBucket;
pendingWithdraw += millibucketsPerTick; this.pendingWithdraw += millibucketsPerTick;
int currentWithdraw = (int) pendingWithdraw; // float --> int final int currentWithdraw = (int) this.pendingWithdraw; // float -->
// int
// conversion floors // conversion floors
// the float // the float
pendingWithdraw -= currentWithdraw; this.pendingWithdraw -= currentWithdraw;
tank.drain(currentWithdraw, true); this.tank.drain(currentWithdraw, true);
addEnergy(euTick); this.addEnergy(TileGasTurbine.euTick);
}
if (tank.getFluidType() != null && getStackInSlot(2) == ItemStack.EMPTY) { if (!this.isActive())
inventory.setInventorySlotContents(2, new ItemStack(tank.getFluidType().getBlock())); this.world.setBlockState(this.getPos(),
} else if (tank.getFluidType() == null && getStackInSlot(2) != ItemStack.EMPTY) { this.world.getBlockState(this.getPos()).withProperty(BlockMachineBase.ACTIVE, true));
setInventorySlotContents(2, ItemStack.EMPTY); } else if (this.isActive())
this.world.setBlockState(this.getPos(),
this.world.getBlockState(this.getPos()).withProperty(BlockMachineBase.ACTIVE, false));
if (this.tank.getFluidType() != null && this.getStackInSlot(2) == ItemStack.EMPTY) {
this.inventory.setInventorySlotContents(2, new ItemStack(this.tank.getFluidType().getBlock()));
} else if (this.tank.getFluidType() == null && this.getStackInSlot(2) != ItemStack.EMPTY) {
this.setInventorySlotContents(2, ItemStack.EMPTY);
} }
} }