mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 23:38:25 +01:00
Optimise getType calls
Remove the map lookup for converting from Block->Bukkit Material
This commit is contained in:
parent
093bd60eae
commit
f24af9bc9c
6 changed files with 24 additions and 5 deletions
|
@ -0,0 +1,19 @@
|
|||
--- a/net/minecraft/world/level/block/state/BlockState.java
|
||||
+++ b/net/minecraft/world/level/block/state/BlockState.java
|
||||
@@ -10,6 +10,16 @@
|
||||
public class BlockState extends BlockBehaviour.BlockStateBase {
|
||||
public static final Codec<BlockState> CODEC = codec(BuiltInRegistries.BLOCK.byNameCodec(), Block::defaultBlockState).stable();
|
||||
|
||||
+ // Paper start - optimise getType calls
|
||||
+ org.bukkit.Material cachedMaterial;
|
||||
+
|
||||
+ public final org.bukkit.Material getBukkitMaterial() {
|
||||
+ if (this.cachedMaterial == null) {
|
||||
+ this.cachedMaterial = org.bukkit.craftbukkit.block.CraftBlockType.minecraftToBukkit(this.getBlock());
|
||||
+ }
|
||||
+ return this.cachedMaterial;
|
||||
+ }
|
||||
+ // Paper end - optimise getType calls
|
||||
public BlockState(Block block, Reference2ObjectArrayMap<Property<?>, Comparable<?>> propertyMap, MapCodec<BlockState> codec) {
|
||||
super(block, propertyMap, codec);
|
||||
}
|
|
@ -100,7 +100,7 @@ public class CraftChunkSnapshot implements ChunkSnapshot {
|
|||
public Material getBlockType(int x, int y, int z) {
|
||||
this.validateChunkCoordinates(x, y, z);
|
||||
|
||||
return CraftBlockType.minecraftToBukkit(this.blockids[this.getSectionIndex(y)].get(x, y & 0xF, z).getBlock());
|
||||
return this.blockids[this.getSectionIndex(y)].get(x, y & 0xF, z).getBukkitMaterial(); // Paper - optimise getType calls
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -220,7 +220,7 @@ public class CraftBlock implements Block {
|
|||
|
||||
@Override
|
||||
public Material getType() {
|
||||
return CraftBlockType.minecraftToBukkit(this.world.getBlockState(this.position).getBlock());
|
||||
return this.world.getBlockState(this.position).getBukkitMaterial(); // Paper - optimise getType calls
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -175,7 +175,7 @@ public class CraftBlockState implements BlockState {
|
|||
|
||||
@Override
|
||||
public Material getType() {
|
||||
return CraftBlockType.minecraftToBukkit(this.data.getBlock());
|
||||
return this.data.getBukkitMaterial(); // Paper - optimise getType calls
|
||||
}
|
||||
|
||||
public void setFlag(int flag) {
|
||||
|
|
|
@ -63,7 +63,7 @@ public class CraftBlockData implements BlockData {
|
|||
|
||||
@Override
|
||||
public Material getMaterial() {
|
||||
return CraftBlockType.minecraftToBukkit(this.state.getBlock());
|
||||
return this.state.getBukkitMaterial(); // Paper - optimise getType calls
|
||||
}
|
||||
|
||||
public net.minecraft.world.level.block.state.BlockState getState() {
|
||||
|
|
|
@ -96,7 +96,7 @@ public final class CraftChunkData implements ChunkGenerator.ChunkData {
|
|||
|
||||
@Override
|
||||
public Material getType(int x, int y, int z) {
|
||||
return CraftBlockType.minecraftToBukkit(this.getTypeId(x, y, z).getBlock());
|
||||
return this.getTypeId(x, y, z).getBukkitMaterial(); // Paper - optimise getType calls
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue