Merge pull request #844 from Ourten/fix/energy-generators-2

More Energy Generators fixes
This commit is contained in:
Modmuss50 2016-12-15 17:07:26 +00:00 committed by GitHub
commit aa7785706f
5 changed files with 119 additions and 27 deletions

View file

@ -8,6 +8,7 @@ import net.minecraft.util.math.BlockPos;
import reborncore.api.power.EnumPowerTier; import reborncore.api.power.EnumPowerTier;
import reborncore.api.tile.IInventoryProvider; import reborncore.api.tile.IInventoryProvider;
import reborncore.common.IWrenchable; import reborncore.common.IWrenchable;
import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.powerSystem.TilePowerAcceptor; import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.util.Inventory; import reborncore.common.util.Inventory;
import techreborn.config.ConfigTechReborn; import techreborn.config.ConfigTechReborn;
@ -22,18 +23,43 @@ public class TileDragonEggSiphoner extends TilePowerAcceptor implements IWrencha
super(2); super(2);
} }
private long lastOutput = 0;
@Override @Override
public void updateEntity() { public void updateEntity() {
super.updateEntity(); super.updateEntity();
if (!world.isRemote) { if (!world.isRemote) {
if (world.getBlockState(new BlockPos(getPos().getX(), getPos().getY() + 1, getPos().getZ())) if (world.getBlockState(new BlockPos(getPos().getX(), getPos().getY() + 1, getPos().getZ()))
.getBlock() == Blocks.DRAGON_EGG) { .getBlock() == Blocks.DRAGON_EGG) {
addEnergy(euTick); if(tryAddingEnergy(euTick))
this.lastOutput = this.world.getTotalWorldTime();
} }
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));
} }
} }
private boolean tryAddingEnergy(int amount)
{
if(this.getMaxPower() - this.getEnergy() >= amount)
{
addEnergy(amount);
return true;
}
else if(this.getMaxPower() - this.getEnergy() > 0)
{
addEnergy(this.getMaxPower() - this.getEnergy());
return true;
}
return false;
}
@Override @Override
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side) { public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side) {
return false; return false;

View file

@ -113,7 +113,7 @@ public class TileGasTurbine extends TilePowerAcceptor implements IWrenchable, II
this.syncWithAll(); this.syncWithAll();
} }
if (this.tank.getFluidAmount() > 0 && this.getMaxPower() - this.getEnergy() >= TileGasTurbine.euTick) { if (this.tank.getFluidAmount() > 0 && tryAddingEnergy(euTick)) {
final Integer euPerBucket = this.fluids.get(this.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
@ -128,7 +128,6 @@ public class TileGasTurbine extends TilePowerAcceptor implements IWrenchable, II
this.pendingWithdraw -= currentWithdraw; this.pendingWithdraw -= currentWithdraw;
this.tank.drain(currentWithdraw, true); this.tank.drain(currentWithdraw, true);
this.addEnergy(TileGasTurbine.euTick);
if (!this.isActive()) if (!this.isActive())
this.world.setBlockState(this.getPos(), this.world.setBlockState(this.getPos(),
@ -136,6 +135,7 @@ public class TileGasTurbine extends TilePowerAcceptor implements IWrenchable, II
} else if (this.isActive()) } else if (this.isActive())
this.world.setBlockState(this.getPos(), this.world.setBlockState(this.getPos(),
this.world.getBlockState(this.getPos()).withProperty(BlockMachineBase.ACTIVE, false)); this.world.getBlockState(this.getPos()).withProperty(BlockMachineBase.ACTIVE, false));
if (this.tank.getFluidType() != null && this.getStackInSlot(2) == ItemStack.EMPTY) { if (this.tank.getFluidType() != null && this.getStackInSlot(2) == ItemStack.EMPTY) {
this.inventory.setInventorySlotContents(2, new ItemStack(this.tank.getFluidType().getBlock())); this.inventory.setInventorySlotContents(2, new ItemStack(this.tank.getFluidType().getBlock()));
} else if (this.tank.getFluidType() == null && this.getStackInSlot(2) != ItemStack.EMPTY) { } else if (this.tank.getFluidType() == null && this.getStackInSlot(2) != ItemStack.EMPTY) {
@ -143,6 +143,21 @@ public class TileGasTurbine extends TilePowerAcceptor implements IWrenchable, II
} }
} }
private boolean tryAddingEnergy(int amount)
{
if(this.getMaxPower() - this.getEnergy() >= amount)
{
addEnergy(amount);
return true;
}
else if(this.getMaxPower() - this.getEnergy() > 0)
{
addEnergy(this.getMaxPower() - this.getEnergy());
return true;
}
return false;
}
@Override @Override
public double getMaxPower() { public double getMaxPower() {
return ConfigTechReborn.ThermalGeneratorCharge; return ConfigTechReborn.ThermalGeneratorCharge;

View file

@ -7,6 +7,7 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import reborncore.api.power.EnumPowerTier; import reborncore.api.power.EnumPowerTier;
import reborncore.common.IWrenchable; import reborncore.common.IWrenchable;
import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.powerSystem.TilePowerAcceptor; import reborncore.common.powerSystem.TilePowerAcceptor;
import techreborn.config.ConfigTechReborn; import techreborn.config.ConfigTechReborn;
import techreborn.init.ModBlocks; import techreborn.init.ModBlocks;
@ -19,31 +20,50 @@ public class TileHeatGenerator extends TilePowerAcceptor implements IWrenchable
super(1); super(1);
} }
private long lastOutput = 0;
@Override @Override
public void updateEntity() { public void updateEntity() {
super.updateEntity(); super.updateEntity();
if (!world.isRemote) { if (!world.isRemote) {
if (world.getBlockState(new BlockPos(getPos().getX() + 1, getPos().getY(), getPos().getZ())) for (final EnumFacing direction : EnumFacing.values()) {
.getBlock() == Blocks.LAVA) { if(direction.equals(EnumFacing.UP))
addEnergy(euTick); continue;
} else if (world.getBlockState(new BlockPos(getPos().getX(), getPos().getY(), getPos().getZ() + 1)) if (this.world
.getBlock() == Blocks.LAVA) { .getBlockState(new BlockPos(this.getPos().getX() + direction.getFrontOffsetX(),
addEnergy(euTick); this.getPos().getY() + direction.getFrontOffsetY(),
} else if (world.getBlockState(new BlockPos(getPos().getX(), getPos().getY(), getPos().getZ() - 1)) this.getPos().getZ() + direction.getFrontOffsetZ()))
.getBlock() == Blocks.LAVA) { .getBlock() == Blocks.LAVA) {
addEnergy(euTick); if(tryAddingEnergy(euTick))
} else if (world.getBlockState(new BlockPos(getPos().getX() - 1, getPos().getY(), getPos().getZ())) this.lastOutput = this.world.getTotalWorldTime();
.getBlock() == Blocks.LAVA) { }
addEnergy(euTick);
} else if (world.getBlockState(new BlockPos(getPos().getX(), getPos().getY() - 1, getPos().getZ()))
.getBlock() == Blocks.LAVA) {
addEnergy(euTick);
} }
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));
} }
} }
private boolean tryAddingEnergy(int amount)
{
if(this.getMaxPower() - this.getEnergy() >= amount)
{
addEnergy(amount);
return true;
}
else if(this.getMaxPower() - this.getEnergy() > 0)
{
addEnergy(this.getMaxPower() - this.getEnergy());
return true;
}
return false;
}
@Override @Override
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side) { public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side) {
return false; return false;

View file

@ -119,7 +119,7 @@ public class TileSemifluidGenerator extends TilePowerAcceptor implements IWrench
this.syncWithAll(); this.syncWithAll();
} }
if (tank.getFluidAmount() > 0 && getMaxPower() - getEnergy() >= euTick && tank.getFluidType() != null && fluids.containsKey(tank.getFluidType().getName())) { if (tank.getFluidAmount() > 0 && tank.getFluidType() != null && fluids.containsKey(tank.getFluidType().getName()) && tryAddingEnergy(euTick)) {
Integer euPerBucket = fluids.get(tank.getFluidType().getName()); Integer euPerBucket = fluids.get(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
@ -133,7 +133,6 @@ public class TileSemifluidGenerator extends TilePowerAcceptor implements IWrench
pendingWithdraw -= currentWithdraw; pendingWithdraw -= currentWithdraw;
tank.drain(currentWithdraw, true); tank.drain(currentWithdraw, true);
addEnergy(euTick);
if(!this.isActive()) if(!this.isActive())
this.world.setBlockState(this.getPos(), this.world.setBlockState(this.getPos(),
this.world.getBlockState(this.getPos()).withProperty(BlockMachineBase.ACTIVE, true)); this.world.getBlockState(this.getPos()).withProperty(BlockMachineBase.ACTIVE, true));
@ -148,6 +147,21 @@ public class TileSemifluidGenerator extends TilePowerAcceptor implements IWrench
} }
} }
private boolean tryAddingEnergy(int amount)
{
if(this.getMaxPower() - this.getEnergy() >= amount)
{
addEnergy(amount);
return true;
}
else if(this.getMaxPower() - this.getEnergy() > 0)
{
addEnergy(this.getMaxPower() - this.getEnergy());
return true;
}
return false;
}
@Override @Override
public double getMaxPower() { public double getMaxPower() {
return ConfigTechReborn.ThermalGeneratorCharge; return ConfigTechReborn.ThermalGeneratorCharge;

View file

@ -108,16 +108,18 @@ public class TileThermalGenerator extends TilePowerAcceptor implements IWrenchab
this.getPos().getY() + direction.getFrontOffsetY(), this.getPos().getY() + direction.getFrontOffsetY(),
this.getPos().getZ() + direction.getFrontOffsetZ())) this.getPos().getZ() + direction.getFrontOffsetZ()))
.getBlock() == Blocks.LAVA) { .getBlock() == Blocks.LAVA) {
this.addEnergy(1); if(this.tryAddingEnergy(1))
this.lastOutput = this.world.getTotalWorldTime(); this.lastOutput = this.world.getTotalWorldTime();
} }
} }
} }
if (this.tank.getFluidAmount() > 0 && this.getMaxPower() - this.getEnergy() >= TileThermalGenerator.euTick) { if (this.tank.getFluidAmount() > 0) {
this.tank.drain(1, true); if(tryAddingEnergy(euTick))
this.addEnergy(TileThermalGenerator.euTick); {
this.lastOutput = this.world.getTotalWorldTime(); this.tank.drain(1, true);
this.lastOutput = this.world.getTotalWorldTime();
}
} }
if (!this.world.isRemote) { if (!this.world.isRemote) {
@ -136,6 +138,21 @@ public class TileThermalGenerator extends TilePowerAcceptor implements IWrenchab
} }
} }
private boolean tryAddingEnergy(int amount)
{
if(this.getMaxPower() - this.getEnergy() >= amount)
{
addEnergy(amount);
return true;
}
else if(this.getMaxPower() - this.getEnergy() > 0)
{
addEnergy(this.getMaxPower() - this.getEnergy());
return true;
}
return false;
}
@Override @Override
public double getMaxPower() { public double getMaxPower() {
return ConfigTechReborn.ThermalGeneratorCharge; return ConfigTechReborn.ThermalGeneratorCharge;