From 32b07e094055c42859e6ac9d937b4b055063cf3a Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 24 Jan 2022 21:07:51 +0000 Subject: [PATCH] World: avoid repeated getInstance() calls in hot paths --- src/world/World.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/world/World.php b/src/world/World.php index 8fff731dd..1707e8e17 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -947,6 +947,8 @@ class World implements ChunkManager{ public function createBlockUpdatePackets(array $blocks) : array{ $packets = []; + $blockMapping = RuntimeBlockMapping::getInstance(); + foreach($blocks as $b){ if(!($b instanceof Vector3)){ throw new \TypeError("Expected Vector3 in blocks array, got " . (is_object($b) ? get_class($b) : gettype($b))); @@ -956,7 +958,7 @@ class World implements ChunkManager{ $blockPosition = BlockPosition::fromVector3($b); $packets[] = UpdateBlockPacket::create( $blockPosition, - RuntimeBlockMapping::getInstance()->toRuntimeId($fullBlock->getFullId()), + $blockMapping->toRuntimeId($fullBlock->getFullId()), UpdateBlockPacket::FLAG_NETWORK, UpdateBlockPacket::DATA_LAYER_NORMAL ); @@ -1105,6 +1107,7 @@ class World implements ChunkManager{ $entity->onRandomUpdate(); } + $blockFactory = BlockFactory::getInstance(); foreach($chunk->getSubChunks() as $Y => $subChunk){ if(!$subChunk->isEmptyFast()){ $k = 0; @@ -1121,8 +1124,7 @@ class World implements ChunkManager{ $state = $subChunk->getFullBlock($x, $y, $z); if(isset($this->randomTickBlocks[$state])){ - /** @var Block $block */ - $block = BlockFactory::getInstance()->fromFullBlock($state); + $block = $blockFactory->fromFullBlock($state); $block->position($this, $chunkX * Chunk::EDGE_LENGTH + $x, ($Y << SubChunk::COORD_BIT_SIZE) + $y, $chunkZ * Chunk::EDGE_LENGTH + $z); $block->onRandomTick(); }