From 5c5d96d00b69015017110d6876656861b55e49de Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 27 Aug 2022 18:04:11 +0100 Subject: [PATCH] ItemBlock: remember fuel time, fireproof and max stack size this avoids repeatedly creating blocks for no reason when calling these methods. This does assume that these methods always return the same result for a given block type, but I think that's a fair enough assumption. --- src/item/ItemBlock.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/item/ItemBlock.php b/src/item/ItemBlock.php index b923b9d7e..20504e8d0 100644 --- a/src/item/ItemBlock.php +++ b/src/item/ItemBlock.php @@ -38,10 +38,18 @@ final class ItemBlock extends Item{ private int $blockTypeId; private int $blockTypeData; + private int $fuelTime; + private bool $fireProof; + private int $maxStackSize; + public function __construct(Block $block){ parent::__construct(ItemIdentifier::fromBlock($block), $block->getName()); $this->blockTypeId = $block->getTypeId(); $this->blockTypeData = $block->computeTypeData(); + + $this->fuelTime = $block->getFuelTime(); + $this->fireProof = $block->isFireProofAsItem(); + $this->maxStackSize = $block->getMaxStackSize(); } protected function encodeType(RuntimeDataWriter $w) : void{ @@ -60,14 +68,14 @@ final class ItemBlock extends Item{ } public function getFuelTime() : int{ - return $this->getBlock()->getFuelTime(); + return $this->fuelTime; } public function isFireProof() : bool{ - return $this->getBlock()->isFireProofAsItem(); + return $this->fireProof; } public function getMaxStackSize() : int{ - return $this->getBlock()->getMaxStackSize(); + return $this->maxStackSize; } }