Improved air generator tick rate logic
This commit is contained in:
parent
f058f72c0a
commit
a6c8068d72
1 changed files with 17 additions and 20 deletions
|
@ -18,7 +18,7 @@ public class TileEntityAirGeneratorTiered extends TileEntityAbstractEnergyConsum
|
||||||
// (none)
|
// (none)
|
||||||
|
|
||||||
// computed properties
|
// computed properties
|
||||||
private int cooldownTicks = 0;
|
private int tickUpdate;
|
||||||
|
|
||||||
public TileEntityAirGeneratorTiered() {
|
public TileEntityAirGeneratorTiered() {
|
||||||
super();
|
super();
|
||||||
|
@ -38,6 +38,13 @@ public class TileEntityAirGeneratorTiered extends TileEntityAbstractEnergyConsum
|
||||||
"HV", 2, "HV", 0);
|
"HV", 2, "HV", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onFirstUpdateTick() {
|
||||||
|
super.onFirstUpdateTick();
|
||||||
|
|
||||||
|
tickUpdate = world.rand.nextInt(WarpDriveConfig.BREATHING_AIR_GENERATION_TICKS);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
super.update();
|
super.update();
|
||||||
|
@ -50,31 +57,21 @@ public class TileEntityAirGeneratorTiered extends TileEntityAbstractEnergyConsum
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tickUpdate--;
|
||||||
|
if (tickUpdate >= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
tickUpdate = WarpDriveConfig.BREATHING_AIR_GENERATION_TICKS;
|
||||||
|
|
||||||
// Air generator works only in space & hyperspace
|
// Air generator works only in space & hyperspace
|
||||||
final IBlockState blockState = world.getBlockState(pos);
|
final IBlockState blockState = world.getBlockState(pos);
|
||||||
if (CelestialObjectManager.hasAtmosphere(world, pos.getX(), pos.getZ())) {
|
if (CelestialObjectManager.hasAtmosphere(world, pos.getX(), pos.getZ())) {
|
||||||
if (blockState.getValue(BlockProperties.ACTIVE)) {
|
updateBlockState(blockState, BlockProperties.ACTIVE, false);
|
||||||
world.setBlockState(pos, blockState.withProperty(BlockProperties.ACTIVE, false)); // set disabled texture
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cooldownTicks++;
|
final boolean isActive = releaseAir(blockState.getValue(BlockProperties.FACING));
|
||||||
if (cooldownTicks > WarpDriveConfig.BREATHING_AIR_GENERATION_TICKS) {
|
updateBlockState(blockState, BlockProperties.ACTIVE, isActive);
|
||||||
final boolean isActive = releaseAir(blockState.getValue(BlockProperties.FACING));
|
|
||||||
if (isActive) {
|
|
||||||
if (!blockState.getValue(BlockProperties.ACTIVE)) {
|
|
||||||
world.setBlockState(pos, blockState.withProperty(BlockProperties.ACTIVE, true)); // set enabled texture
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (blockState.getValue(BlockProperties.ACTIVE)) {
|
|
||||||
world.setBlockState(pos, blockState.withProperty(BlockProperties.ACTIVE, false)); // set disabled texture
|
|
||||||
}
|
|
||||||
}
|
|
||||||
releaseAir(blockState.getValue(BlockProperties.FACING));
|
|
||||||
|
|
||||||
cooldownTicks = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean releaseAir(final EnumFacing direction) {
|
private boolean releaseAir(final EnumFacing direction) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue