SPIGOT-5826: Don't store chunk in block states

This commit is contained in:
md_5 2020-06-26 09:34:25 +10:00
parent 6abb4398b9
commit 6b20d04c71
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11

View File

@ -23,7 +23,6 @@ import org.bukkit.plugin.Plugin;
public class CraftBlockState implements BlockState {
protected final CraftWorld world;
private final CraftChunk chunk;
private final BlockPosition position;
protected IBlockData data;
protected int flag;
@ -32,7 +31,6 @@ public class CraftBlockState implements BlockState {
this.world = (CraftWorld) block.getWorld();
this.position = ((CraftBlock) block).getPosition();
this.data = ((CraftBlock) block).getNMS();
this.chunk = (CraftChunk) block.getChunk();
this.flag = 3;
}
@ -44,7 +42,6 @@ public class CraftBlockState implements BlockState {
public CraftBlockState(Material material) {
world = null;
data = CraftMagicNumbers.getBlock(material).getBlockData();
chunk = null;
position = BlockPosition.ZERO;
}
@ -80,7 +77,7 @@ public class CraftBlockState implements BlockState {
@Override
public Chunk getChunk() {
requirePlaced();
return chunk;
return world.getChunkAt(getX() >> 4, getZ() >> 4);
}
public void setData(IBlockData data) {
@ -263,25 +260,25 @@ public class CraftBlockState implements BlockState {
@Override
public void setMetadata(String metadataKey, MetadataValue newMetadataValue) {
requirePlaced();
chunk.getCraftWorld().getBlockMetadata().setMetadata(getBlock(), metadataKey, newMetadataValue);
world.getBlockMetadata().setMetadata(getBlock(), metadataKey, newMetadataValue);
}
@Override
public List<MetadataValue> getMetadata(String metadataKey) {
requirePlaced();
return chunk.getCraftWorld().getBlockMetadata().getMetadata(getBlock(), metadataKey);
return world.getBlockMetadata().getMetadata(getBlock(), metadataKey);
}
@Override
public boolean hasMetadata(String metadataKey) {
requirePlaced();
return chunk.getCraftWorld().getBlockMetadata().hasMetadata(getBlock(), metadataKey);
return world.getBlockMetadata().hasMetadata(getBlock(), metadataKey);
}
@Override
public void removeMetadata(String metadataKey, Plugin owningPlugin) {
requirePlaced();
chunk.getCraftWorld().getBlockMetadata().removeMetadata(getBlock(), metadataKey, owningPlugin);
world.getBlockMetadata().removeMetadata(getBlock(), metadataKey, owningPlugin);
}
@Override