Add activation state change for HeatGenerator + Cleanup side-check code
This commit is contained in:
parent
a0e068cad4
commit
487fdeddcb
1 changed files with 35 additions and 15 deletions
|
@ -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;
|
||||||
|
@ -18,31 +19,50 @@ public class TileHeatGenerator extends TilePowerAcceptor implements IWrenchable
|
||||||
public TileHeatGenerator() {
|
public TileHeatGenerator() {
|
||||||
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) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue