diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 5fb78ba7..27034bfb 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -555,7 +555,7 @@ class Entity extends Position $id = $this->level->level->getBlockID($x, $y, $z); if($id > 0){ - Block::$class[$id]::onEntityCollidedWithBlock($this->level, $x, $y, $z, $this); + StaticBlock::$prealloc[$id]::onEntityCollidedWithBlock($this->level, $x, $y, $z, $this); } } } diff --git a/src/material/StaticBlock.php b/src/material/StaticBlock.php index 09b59a10..1bca3311 100644 --- a/src/material/StaticBlock.php +++ b/src/material/StaticBlock.php @@ -8,6 +8,7 @@ class StaticBlock const DEFAULT_HARDNESS = 0; private static $NULL_BOUNDS; + public static $prealloc = []; public static $isSolid = []; public static $isTransparent = []; public static $isFlowable = []; @@ -39,7 +40,7 @@ class StaticBlock self::$slipperiness[$b->getID()] = $b->slipperiness; self::$boundingBoxes[$b->getID()] = $b->boundingBox; self::$hardness[$b->getID()] = $b->getHardness(); - + self::$prealloc[$b->getID()] = $b; FireBlock::setFlammabilityAndCatchingChance($b->getID(), 0, 0); self::setBlockBounds($b->getID(), 0, 0, 0, 1, 1, 1); @@ -116,7 +117,7 @@ class StaticBlock } public static function getBlock($id){ - return Block::$class[$id] ?? Block::$class[0]; + return self::$prealloc[$id] ?? self::$prealloc[0]; //accessing preallocated instances is faster Block::$class[$id] ?? Block::$class[0]; } public static function getHardness($id){ diff --git a/src/world/Level.php b/src/world/Level.php index becf112e..345ba3fd 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -218,7 +218,7 @@ class Level{ $v16 = ($y + 1) - LiquidBlock::getPercentAir($meta); if($maxY >= $v16){ $appliedVelocity = true; - Block::$class[$block]::addVelocityToEntity($this, $x, $y, $z, $entity, $velocityVec); + StaticBlock::$prealloc[$block]::addVelocityToEntity($this, $x, $y, $z, $entity, $velocityVec); } } @@ -256,7 +256,7 @@ class Level{ for($y = $y0 - 1; $y < $y1; ++$y) { $bid = $this->level->getBlockID($x, $y, $z); if($bid > 0){ - $blockBounds = Block::$class[$bid]::getCollisionBoundingBoxes($this, $x, $y, $z, $e); //StaticBlock::getBoundingBoxForBlockCoords($b, $x, $y, $z); + $blockBounds = StaticBlock::$prealloc[$bid]::getCollisionBoundingBoxes($this, $x, $y, $z, $e); //StaticBlock::getBoundingBoxForBlockCoords($b, $x, $y, $z); foreach($blockBounds as $blockBound){ if($aABB->intersectsWith($blockBound)) $aABBs[] = $blockBound; @@ -512,7 +512,7 @@ class Level{ $y = ($xyz >> 16) & 0x7f; $id = $this->level->fastGetBlockID($cX, $y >> 4, $cZ, $x, $y & 0xf, $z, $index); if(isset(self::$randomUpdateBlocks[$id])){ - $cl = Block::$class[$id]; + $cl = StaticBlock::$prealloc[$id]; $cl::onRandomTick($this, ($cX << 4) + $x, $y, $z + ($cZ << 4)); } }