From 65ec0db2de171452aca2a04af8eddd6c672e2c0c Mon Sep 17 00:00:00 2001 From: Ourten Date: Wed, 14 Dec 2016 17:43:33 +0100 Subject: [PATCH 1/4] Fix ThermalGenerator logic and packet updates There is one bug left, the displayed liquid stack is always air. --- .../tiles/generator/TileThermalGenerator.java | 59 ++++++++++--------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/src/main/java/techreborn/tiles/generator/TileThermalGenerator.java b/src/main/java/techreborn/tiles/generator/TileThermalGenerator.java index a44257f96..c099479fa 100644 --- a/src/main/java/techreborn/tiles/generator/TileThermalGenerator.java +++ b/src/main/java/techreborn/tiles/generator/TileThermalGenerator.java @@ -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); } } From caf5d56e3c0cbed8e819643df9cdd79a34c5cb8e Mon Sep 17 00:00:00 2001 From: Ourten Date: Wed, 14 Dec 2016 18:36:43 +0100 Subject: [PATCH 2/4] Fix GasTurbine activate state and fix fluid amount sync --- .../tiles/generator/TileGasTurbine.java | 40 +++++++++++-------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/main/java/techreborn/tiles/generator/TileGasTurbine.java b/src/main/java/techreborn/tiles/generator/TileGasTurbine.java index 46e65b97c..2d37c4ed5 100644 --- a/src/main/java/techreborn/tiles/generator/TileGasTurbine.java +++ b/src/main/java/techreborn/tiles/generator/TileGasTurbine.java @@ -106,31 +106,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); } } From 82ae50f5a8b88ebae9b2c9d02c64b581f28b1004 Mon Sep 17 00:00:00 2001 From: Ourten Date: Wed, 14 Dec 2016 19:22:29 +0100 Subject: [PATCH 3/4] Fix Semifluid generator activate state and fix fluid sync --- .../tiles/generator/TileSemifluidGenerator.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/techreborn/tiles/generator/TileSemifluidGenerator.java b/src/main/java/techreborn/tiles/generator/TileSemifluidGenerator.java index 5aad405f5..e57f4358a 100644 --- a/src/main/java/techreborn/tiles/generator/TileSemifluidGenerator.java +++ b/src/main/java/techreborn/tiles/generator/TileSemifluidGenerator.java @@ -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) { From 4c2a5b3f23b9b542f27d8c10e0d6872e9696788e Mon Sep 17 00:00:00 2001 From: Ourten Date: Wed, 14 Dec 2016 19:51:33 +0100 Subject: [PATCH 4/4] Add missing import in GasTurbine --- src/main/java/techreborn/tiles/generator/TileGasTurbine.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/techreborn/tiles/generator/TileGasTurbine.java b/src/main/java/techreborn/tiles/generator/TileGasTurbine.java index 2d37c4ed5..e136e8e44 100644 --- a/src/main/java/techreborn/tiles/generator/TileGasTurbine.java +++ b/src/main/java/techreborn/tiles/generator/TileGasTurbine.java @@ -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;