Revert "ItemBlock: drop the charade about overriding built-in block types"

This reverts commit f64dc01bd1.

I forgot that the ItemBlock constructor implicitly strips off any states
of the origin block, which is something that we unfortunately can't do
any other way right now, since the blocks don't remember their default
states.
This commit is contained in:
Dylan K. Taylor
2023-03-02 15:51:55 +00:00
parent f64dc01bd1
commit 7c974a12e1
82 changed files with 149 additions and 94 deletions

View File

@@ -24,6 +24,8 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\RuntimeBlockStateRegistry;
use pocketmine\block\VanillaBlocks;
use pocketmine\data\runtime\RuntimeDataDescriber;
/**
@@ -33,29 +35,47 @@ use pocketmine\data\runtime\RuntimeDataDescriber;
* just place wheat crops when used on the ground).
*/
final class ItemBlock extends Item{
public function __construct(
private Block $block
){
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 describeType(RuntimeDataDescriber $w) : void{
$this->block->describeType($w);
$w->int(Block::INTERNAL_STATE_DATA_BITS, $this->blockTypeData);
}
public function getBlock(?int $clickedFace = null) : Block{
return clone $this->block;
//TODO: HACKY MESS, CLEAN IT UP
$factory = RuntimeBlockStateRegistry::getInstance();
if(!$factory->isRegistered($this->blockTypeId)){
return VanillaBlocks::AIR();
}
$blockType = $factory->fromTypeId($this->blockTypeId);
$blockType->decodeTypeData($this->blockTypeData);
return $blockType;
}
public function getFuelTime() : int{
return $this->block->getFuelTime();
return $this->fuelTime;
}
public function isFireProof() : bool{
return $this->block->isFireProofAsItem();
return $this->fireProof;
}
public function getMaxStackSize() : int{
return $this->block->getMaxStackSize();
return $this->maxStackSize;
}
}