Optimize CraftBlockData Creation

Avoids a hashmap lookup by cacheing a reference to the CraftBlockData
and cloning it when one is needed.
This commit is contained in:
miclebrick
2018-08-23 11:45:32 -04:00
parent 28ea7bb560
commit 68e76b43b8
2 changed files with 29 additions and 3 deletions

View File

@@ -579,7 +579,17 @@ public class CraftBlockData implements BlockData {
return craft;
}
// Paper start - optimize creating BlockData to not need a map lookup
static {
// Initialize cached data for all IBlockData instances after registration
Block.BLOCK_STATE_REGISTRY.iterator().forEachRemaining(net.minecraft.world.level.block.state.BlockState::createCraftBlockData);
}
public static CraftBlockData fromData(net.minecraft.world.level.block.state.BlockState data) {
return data.createCraftBlockData();
}
public static CraftBlockData createData(net.minecraft.world.level.block.state.BlockState data) {
// Paper end
return CraftBlockData.MAP.getOrDefault(data.getBlock().getClass(), CraftBlockData::new).apply(data);
}