Merge pull request #837 from Ourten/fix/energy-generators

Energy generators fix
This commit is contained in:
Modmuss50 2016-12-14 21:12:15 +00:00 committed by GitHub
commit b67e08e267
3 changed files with 69 additions and 45 deletions

View file

@ -11,6 +11,7 @@ import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import reborncore.api.power.EnumPowerTier;
import reborncore.api.tile.IInventoryProvider;
import reborncore.common.IWrenchable;
import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.util.FluidUtils;
import reborncore.common.util.Inventory;
@ -106,31 +107,39 @@ public class TileGasTurbine extends TilePowerAcceptor implements IWrenchable, II
@Override
public void updateEntity() {
super.updateEntity();
if (!world.isRemote) {
FluidUtils.drainContainers(tank, inventory, 0, 1);
tank.compareAndUpdate();
if (!this.world.isRemote) {
if (FluidUtils.drainContainers(this.tank, this.inventory, 0, 1))
this.syncWithAll();
}
if (tank.getFluidAmount() > 0 && getMaxPower() - getEnergy() >= euTick) {
Integer euPerBucket = fluids.get(tank.getFluidType().getName());
if (this.tank.getFluidAmount() > 0 && this.getMaxPower() - this.getEnergy() >= TileGasTurbine.euTick) {
final Integer euPerBucket = this.fluids.get(this.tank.getFluidType().getName());
// float totalTicks = (float)euPerBucket / 8f; //x eu per bucket / 8
// eu per tick
// float millibucketsPerTick = 1000f / totalTicks;
float millibucketsPerTick = 16000f / (float) euPerBucket;
pendingWithdraw += millibucketsPerTick;
final float millibucketsPerTick = 16000f / (float) euPerBucket;
this.pendingWithdraw += millibucketsPerTick;
int currentWithdraw = (int) pendingWithdraw; // float --> int
final int currentWithdraw = (int) this.pendingWithdraw; // float -->
// int
// conversion floors
// the float
pendingWithdraw -= currentWithdraw;
this.pendingWithdraw -= currentWithdraw;
tank.drain(currentWithdraw, true);
addEnergy(euTick);
}
if (tank.getFluidType() != null && getStackInSlot(2) == ItemStack.EMPTY) {
inventory.setInventorySlotContents(2, new ItemStack(tank.getFluidType().getBlock()));
} else if (tank.getFluidType() == null && getStackInSlot(2) != ItemStack.EMPTY) {
setInventorySlotContents(2, ItemStack.EMPTY);
this.tank.drain(currentWithdraw, true);
this.addEnergy(TileGasTurbine.euTick);
if (!this.isActive())
this.world.setBlockState(this.getPos(),
this.world.getBlockState(this.getPos()).withProperty(BlockMachineBase.ACTIVE, true));
} 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);
}
}

View file

@ -11,6 +11,7 @@ import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import reborncore.api.power.EnumPowerTier;
import reborncore.api.tile.IInventoryProvider;
import reborncore.common.IWrenchable;
import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.util.FluidUtils;
import reborncore.common.util.Inventory;
@ -40,7 +41,7 @@ public class TileSemifluidGenerator extends TilePowerAcceptor implements IWrench
fluids.put("creosote", 3000);
fluids.put("biomass", 8000);
fluids.put("oil", 64000);
fluids.put("fluidoil", 64000);
fluids.put("fluidsodium", 30000);
fluids.put("fluidlithium", 60000);
fluids.put("biofuel", 32000);
@ -113,7 +114,10 @@ public class TileSemifluidGenerator extends TilePowerAcceptor implements IWrench
public void updateEntity() {
super.updateEntity();
if (!world.isRemote)
FluidUtils.drainContainers(tank, inventory, 0, 1);
{
if(FluidUtils.drainContainers(tank, inventory, 0, 1))
this.syncWithAll();
}
if (tank.getFluidAmount() > 0 && getMaxPower() - getEnergy() >= euTick && tank.getFluidType() != null && fluids.containsKey(tank.getFluidType().getName())) {
Integer euPerBucket = fluids.get(tank.getFluidType().getName());
@ -130,7 +134,13 @@ public class TileSemifluidGenerator extends TilePowerAcceptor implements IWrench
tank.drain(currentWithdraw, true);
addEnergy(euTick);
if(!this.isActive())
this.world.setBlockState(this.getPos(),
this.world.getBlockState(this.getPos()).withProperty(BlockMachineBase.ACTIVE, true));
}
else if(this.isActive())
this.world.setBlockState(this.getPos(),
this.world.getBlockState(this.getPos()).withProperty(BlockMachineBase.ACTIVE, false));
if (tank.getFluidType() != null && getStackInSlot(2) == ItemStack.EMPTY) {
inventory.setInventorySlotContents(2, new ItemStack(tank.getFluidType().getBlock()));
} else if (tank.getFluidType() == null && getStackInSlot(2) != ItemStack.EMPTY) {

View file

@ -92,42 +92,47 @@ public class TileThermalGenerator extends TilePowerAcceptor implements IWrenchab
readFromNBT(packet.getNbtCompound());
}
private long lastOutput = 0;
@Override
// TODO optimise this code
public void updateEntity() {
super.updateEntity();
if (!world.isRemote) {
FluidUtils.drainContainers(tank, inventory, 0, 1);
for (EnumFacing direction : EnumFacing.values()) {
if (world.getBlockState(new BlockPos(getPos().getX() + direction.getFrontOffsetX(),
getPos().getY() + direction.getFrontOffsetY(), getPos().getZ() + direction.getFrontOffsetZ()))
.getBlock() == Blocks.LAVA) {
addEnergy(1);
}
}
if (world.getTotalWorldTime() % 40 == 0) {
BlockMachineBase bmb = (BlockMachineBase) world.getBlockState(pos).getBlock();
boolean didFindLava = false;
for (EnumFacing direction : EnumFacing.values()) {
if (world.getBlockState(new BlockPos(getPos().getX() + direction.getFrontOffsetX(),
getPos().getY() + direction.getFrontOffsetY(),
getPos().getZ() + direction.getFrontOffsetZ())).getBlock() == Blocks.LAVA) {
didFindLava = true;
}
if (!this.world.isRemote) {
if (FluidUtils.drainContainers(this.tank, this.inventory, 0, 1))
this.syncWithAll();
for (final EnumFacing direction : EnumFacing.values()) {
if (this.world
.getBlockState(new BlockPos(this.getPos().getX() + direction.getFrontOffsetX(),
this.getPos().getY() + direction.getFrontOffsetY(),
this.getPos().getZ() + direction.getFrontOffsetZ()))
.getBlock() == Blocks.LAVA) {
this.addEnergy(1);
this.lastOutput = this.world.getTotalWorldTime();
}
bmb.setActive(didFindLava, world, pos);
}
}
if (tank.getFluidAmount() > 0 && getMaxPower() - getEnergy() >= euTick) {
tank.drain(1, true);
addEnergy(euTick);
if (this.tank.getFluidAmount() > 0 && this.getMaxPower() - this.getEnergy() >= TileThermalGenerator.euTick) {
this.tank.drain(1, true);
this.addEnergy(TileThermalGenerator.euTick);
this.lastOutput = this.world.getTotalWorldTime();
}
if (tank.getFluidType() != null && getStackInSlot(2) == ItemStack.EMPTY) {
// inventory.setInventorySlotContents(2, new ItemStack(tank
// .getFluidType().getBlock()));
} else if (tank.getFluidType() == null && getStackInSlot(2) != ItemStack.EMPTY) {
setInventorySlotContents(2, ItemStack.EMPTY);
if (!this.world.isRemote) {
if (this.world.getTotalWorldTime() - this.lastOutput < 30 && !this.isActive())
this.world.setBlockState(this.getPos(),
this.world.getBlockState(this.getPos()).withProperty(BlockMachineBase.ACTIVE, true));
else if (this.world.getTotalWorldTime() - this.lastOutput > 30 && 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.inventory.setInventorySlotContents(2, ItemStack.EMPTY);
}
}