Fixed NPE regression in non loaded chunks access

Improved blockstate updater logic
This commit is contained in:
Unknown 2019-01-19 16:58:57 +01:00 committed by unknown
parent a6c8068d72
commit c0c8a6b23b
4 changed files with 20 additions and 20 deletions

View file

@ -465,7 +465,9 @@ public class Commons {
while(!toIterate.isEmpty() && range < maxRange) {
toIterateNext = new HashSet<>();
for (final BlockPos current : toIterate) {
if (whitelist.contains(new VectorI(current).getBlockState_noChunkLoading(world).getBlock())) {
final IBlockState blockStateCurrent = VectorI.getBlockState_noChunkLoading(world, current);
if ( blockStateCurrent != null
&& whitelist.contains(blockStateCurrent.getBlock()) ) {
iterated.add(current);
}
@ -474,7 +476,9 @@ public class Commons {
current.getY() + direction.y,
current.getZ() + direction.z );
if (!iterated.contains(next) && !toIgnore.contains(next) && !toIterate.contains(next) && !toIterateNext.contains(next)) {
if (whitelist.contains(new VectorI(next).getBlockState_noChunkLoading(world).getBlock())) {
final IBlockState blockStateNext = VectorI.getBlockState_noChunkLoading(world, next);
if ( blockStateNext != null
&& whitelist.contains(blockStateNext.getBlock())) {
toIterateNext.add(next);
}
}

View file

@ -127,6 +127,9 @@ public abstract class TileEntityAbstractBase extends TileEntity implements IBloc
blockState.getBlock(), this, blockState_in, property, value));
return;
}
if (blockState.getValue(property) == value) {
return;
}
blockState = blockState.withProperty(property, value);
}
if (getBlockMetadata() != blockState.getBlock().getMetaFromState(blockState)) {

View file

@ -25,6 +25,7 @@ import java.util.Set;
import java.util.TreeMap;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
@ -202,8 +203,12 @@ public class AcceleratorSetup extends GlobalPosition {
WarpDrive.blockVoidShellGlass);
TrajectoryPoint trajectoryPoint = null;
for (final EnumFacing direction : EnumFacing.HORIZONTALS) {
final VectorI next = firstVoidShell.clone(direction);
if (whitelist.contains(next.getBlockState_noChunkLoading(world).getBlock())) {
final BlockPos next = new BlockPos(firstVoidShell.x + direction.getXOffset(),
firstVoidShell.y + direction.getYOffset(),
firstVoidShell.z + direction.getZOffset() );
final IBlockState blockStateNext = VectorI.getBlockState_noChunkLoading(world, next);
if ( blockStateNext != null
&& whitelist.contains(blockStateNext.getBlock()) ) {
trajectoryPoint = new TrajectoryPoint(world, firstVoidShell.translate(direction), direction);
break;
}

View file

@ -93,14 +93,10 @@ public class VectorI implements Cloneable {
return blockAccess.getBlockState(new BlockPos(x, y, z)).getBlock();
}
public IBlockState getBlockState(IBlockAccess blockAccess) {
public IBlockState getBlockState(final IBlockAccess blockAccess) {
return blockAccess.getBlockState(new BlockPos(x, y, z));
}
public boolean isChunkLoaded(final IBlockAccess blockAccess) {
return isChunkLoaded(blockAccess, x, z);
}
static public boolean isChunkLoaded(final IBlockAccess blockAccess, final int x, final int z) {
if (blockAccess instanceof WorldServer) {
return ChunkHandler.isLoaded((WorldServer) blockAccess, x, 64, z);
@ -121,24 +117,16 @@ public class VectorI implements Cloneable {
return true;
}
public IBlockState getBlockState_noChunkLoading(final IBlockAccess blockAccess, final EnumFacing side) {
return getBlockState_noChunkLoading(blockAccess, x + side.getXOffset(), y + side.getYOffset(), z + side.getZOffset());
}
public IBlockState getBlockState_noChunkLoading(final IBlockAccess blockAccess) {
return getBlockState_noChunkLoading(blockAccess, x, y, z);
}
static public IBlockState getBlockState_noChunkLoading(final IBlockAccess blockAccess, final int x, final int y, final int z) {
static public IBlockState getBlockState_noChunkLoading(final IBlockAccess blockAccess, final BlockPos blockPos) {
// skip unloaded worlds
if (blockAccess == null) {
return null;
}
// skip unloaded chunks
if (!isChunkLoaded(blockAccess, x, z)) {
if (!isChunkLoaded(blockAccess, blockPos.getX(), blockPos.getZ())) {
return null;
}
return blockAccess.getBlockState(new BlockPos(x, y, z));
return blockAccess.getBlockState(blockPos);
}
public TileEntity getTileEntity(final IBlockAccess blockAccess) {