Improved force field projector CPU load (less calls to getTileEntity)
This commit is contained in:
parent
b796502b4a
commit
7093343d75
3 changed files with 17 additions and 10 deletions
|
@ -237,10 +237,11 @@ public class BlockForceField extends BlockAbstractForceField implements IDamageR
|
|||
return !blockAccess.isSideSolid(blockPosSide, opposite, false);
|
||||
}
|
||||
|
||||
protected TileEntityForceFieldProjector getProjector(final World world, @Nonnull final BlockPos blockPos) {
|
||||
protected TileEntityForceFieldProjector getProjector(@Nonnull final World world, @Nonnull final BlockPos blockPos,
|
||||
@Nullable final TileEntityForceFieldProjector tileEntityForceFieldProjectorCandidate) {
|
||||
final TileEntity tileEntity = world.getTileEntity(blockPos);
|
||||
if (tileEntity instanceof TileEntityForceField) {
|
||||
return ((TileEntityForceField) tileEntity).getProjector();
|
||||
return ((TileEntityForceField) tileEntity).getProjector(tileEntityForceFieldProjectorCandidate);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -389,7 +390,7 @@ public class BlockForceField extends BlockAbstractForceField implements IDamageR
|
|||
|
||||
private void downgrade(final World world, final BlockPos blockPos) {
|
||||
if (enumTier.getIndex() > 1) {
|
||||
final TileEntityForceFieldProjector tileEntityForceFieldProjector = getProjector(world, blockPos);
|
||||
final TileEntityForceFieldProjector tileEntityForceFieldProjector = getProjector(world, blockPos, null);
|
||||
final IBlockState blockState = world.getBlockState(blockPos);
|
||||
final int frequency = blockState.getBlock() == this ? blockState.getValue(FREQUENCY) : 0;
|
||||
world.setBlockState(blockPos, WarpDrive.blockForceFields[enumTier.getIndex() - 1].getDefaultState().withProperty(FREQUENCY, (frequency + 1) % 16), 2);
|
||||
|
|
|
@ -134,8 +134,14 @@ public class TileEntityForceField extends TileEntity {
|
|||
world.notifyBlockUpdate(pos, blockState, blockState, 3);
|
||||
}
|
||||
|
||||
public TileEntityForceFieldProjector getProjector() {
|
||||
public TileEntityForceFieldProjector getProjector(@Nullable final TileEntityForceFieldProjector tileEntityForceFieldProjectorCandidate) {
|
||||
if (blockPosProjector != null) {
|
||||
// test candidate to save a call to getTileEntity()
|
||||
if ( tileEntityForceFieldProjectorCandidate != null
|
||||
&& blockPosProjector.equals(tileEntityForceFieldProjectorCandidate.getPos()) ) {
|
||||
return tileEntityForceFieldProjectorCandidate;
|
||||
}
|
||||
|
||||
final TileEntity tileEntity = world.getTileEntity(blockPosProjector);
|
||||
if (tileEntity instanceof TileEntityForceFieldProjector) {
|
||||
final TileEntityForceFieldProjector tileEntityForceFieldProjector = (TileEntityForceFieldProjector) tileEntity;
|
||||
|
@ -172,7 +178,7 @@ public class TileEntityForceField extends TileEntity {
|
|||
}
|
||||
|
||||
public ForceFieldSetup getForceFieldSetup() {
|
||||
final TileEntityForceFieldProjector tileEntityForceFieldProjector = getProjector();
|
||||
final TileEntityForceFieldProjector tileEntityForceFieldProjector = getProjector(null);
|
||||
if (tileEntityForceFieldProjector == null) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -485,8 +485,8 @@ public class TileEntityForceFieldProjector extends TileEntityAbstractForceField
|
|||
blockState = Blocks.AIR.getDefaultState();
|
||||
|
||||
} else {
|
||||
final TileEntityForceField tileEntityForceField = ((TileEntityForceField)tileEntity);
|
||||
final TileEntityForceFieldProjector tileEntityForceFieldProjector = tileEntityForceField.getProjector();
|
||||
final TileEntityForceField tileEntityForceField = ((TileEntityForceField) tileEntity);
|
||||
final TileEntityForceFieldProjector tileEntityForceFieldProjector = tileEntityForceField.getProjector(this);
|
||||
if (tileEntityForceFieldProjector == null) {
|
||||
// orphan force field, probably from an explosion
|
||||
// => recover it
|
||||
|
@ -571,7 +571,7 @@ public class TileEntityForceFieldProjector extends TileEntityAbstractForceField
|
|||
// recover forcefield blocks from recalculation or chunk loading
|
||||
if (blockState.getBlock() == WarpDrive.blockForceFields[enumTier.getIndex()] && !vForceFields.contains(vector)) {
|
||||
final TileEntity tileEntity = world.getTileEntity(vector.getBlockPos());
|
||||
if (tileEntity instanceof TileEntityForceField && (((TileEntityForceField) tileEntity).getProjector() == this)) {
|
||||
if (tileEntity instanceof TileEntityForceField && (((TileEntityForceField) tileEntity).getProjector(this) == this)) {
|
||||
vForceFields.add(vector);
|
||||
}
|
||||
}
|
||||
|
@ -584,7 +584,7 @@ public class TileEntityForceFieldProjector extends TileEntityAbstractForceField
|
|||
// remove our own force field block
|
||||
if (blockState.getBlock() == WarpDrive.blockForceFields[enumTier.getIndex()]) {
|
||||
assert blockState.getBlock() instanceof BlockForceField;
|
||||
if (((BlockForceField) blockState.getBlock()).getProjector(world, vector.getBlockPos()) == this) {
|
||||
if (((BlockForceField) blockState.getBlock()).getProjector(world, vector.getBlockPos(), this) == this) {
|
||||
world.setBlockToAir(vector.getBlockPos());
|
||||
vForceFields.remove(vector);
|
||||
}
|
||||
|
@ -814,7 +814,7 @@ public class TileEntityForceFieldProjector extends TileEntityAbstractForceField
|
|||
if (blockState.getBlock() == WarpDrive.blockForceFields[enumTier.getIndex()]) {
|
||||
final TileEntity tileEntity = world.getTileEntity(blockPos);
|
||||
if ( tileEntity instanceof TileEntityForceField
|
||||
&& (((TileEntityForceField) tileEntity).getProjector() == this) ) {
|
||||
&& (((TileEntityForceField) tileEntity).getProjector(this) == this) ) {
|
||||
world.setBlockToAir(vector.getBlockPos());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue