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.
This commit is contained in:
Dylan K. Taylor
2022-08-27 18:04:11 +01:00
parent 4dabac8420
commit 5c5d96d00b

View File

@@ -38,10 +38,18 @@ final class ItemBlock extends Item{
private int $blockTypeId; private int $blockTypeId;
private int $blockTypeData; private int $blockTypeData;
private int $fuelTime;
private bool $fireProof;
private int $maxStackSize;
public function __construct(Block $block){ public function __construct(Block $block){
parent::__construct(ItemIdentifier::fromBlock($block), $block->getName()); parent::__construct(ItemIdentifier::fromBlock($block), $block->getName());
$this->blockTypeId = $block->getTypeId(); $this->blockTypeId = $block->getTypeId();
$this->blockTypeData = $block->computeTypeData(); $this->blockTypeData = $block->computeTypeData();
$this->fuelTime = $block->getFuelTime();
$this->fireProof = $block->isFireProofAsItem();
$this->maxStackSize = $block->getMaxStackSize();
} }
protected function encodeType(RuntimeDataWriter $w) : void{ protected function encodeType(RuntimeDataWriter $w) : void{
@@ -60,14 +68,14 @@ final class ItemBlock extends Item{
} }
public function getFuelTime() : int{ public function getFuelTime() : int{
return $this->getBlock()->getFuelTime(); return $this->fuelTime;
} }
public function isFireProof() : bool{ public function isFireProof() : bool{
return $this->getBlock()->isFireProofAsItem(); return $this->fireProof;
} }
public function getMaxStackSize() : int{ public function getMaxStackSize() : int{
return $this->getBlock()->getMaxStackSize(); return $this->maxStackSize;
} }
} }