Avoid unnecessary allocation in the anvil loader

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2021-09-20 17:49:39 +02:00
parent 860c6b21d1
commit 25055413ff

View File

@ -139,12 +139,16 @@ public class AnvilLoader implements IChunkLoader {
for (int y = 0; y < Chunk.CHUNK_SECTION_SIZE; y++) {
try {
final BlockState blockState = section.get(x, y, z);
Block block = Objects.requireNonNull(Block.fromNamespaceId(blockState.getName()))
.withProperties(blockState.getProperties());
BlockHandler handler = MinecraftServer.getBlockManager().getHandler(block.name());
if (handler != null) {
block = block.withHandler(handler);
}
final String blockName = blockState.getName();
if (blockName.equals("minecraft:air")) continue;
Block block = Objects.requireNonNull(Block.fromNamespaceId(blockName));
// Properties
final Map<String, String> properties = blockState.getProperties();
if (!properties.isEmpty()) block = block.withProperties(properties);
// Handler
final BlockHandler handler = MinecraftServer.getBlockManager().getHandler(block.name());
if (handler != null) block = block.withHandler(handler);
chunk.setBlock(x, y + yOffset, z, block);
} catch (Exception e) {
EXCEPTION_MANAGER.handleException(e);