mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 09:56:06 +00:00
This was first attempted in f64dc01bd1
, but reverted, since I hadn't considered how to handle stripping state data from blocks.
This removes the abusable API RuntimeBlockStateRegistry::fromTypeId() and related methods. These were only used to allow ItemBlocks to magically start referencing other blocks if the blocks were overridden by a plugin, but this was never a well-supported use-case anyway.
Instead of relying on RuntimeBlockStateRegistry, we remember the state that the block had during its constructor, and use that to normalize the non-item properties for asItem().
closes #5609
71 lines
2.2 KiB
PHP
71 lines
2.2 KiB
PHP
<?php
|
|
|
|
/*
|
|
*
|
|
* ____ _ _ __ __ _ __ __ ____
|
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* @author PocketMine Team
|
|
* @link http://www.pocketmine.net/
|
|
*
|
|
*
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace pocketmine\block;
|
|
|
|
use pocketmine\block\utils\MushroomBlockType;
|
|
use pocketmine\data\runtime\RuntimeDataDescriber;
|
|
use pocketmine\item\Item;
|
|
use function mt_rand;
|
|
|
|
class RedMushroomBlock extends Opaque{
|
|
protected MushroomBlockType $mushroomBlockType;
|
|
|
|
public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){
|
|
$this->mushroomBlockType = MushroomBlockType::ALL_CAP();
|
|
parent::__construct($idInfo, $name, $typeInfo);
|
|
}
|
|
|
|
public function describeType(RuntimeDataDescriber $w) : void{
|
|
//these blocks always drop as all-cap, but may exist in other forms in the inventory (particularly creative),
|
|
//so this information needs to be kept in the type info
|
|
$w->mushroomBlockType($this->mushroomBlockType);
|
|
}
|
|
|
|
public function getMushroomBlockType() : MushroomBlockType{ return $this->mushroomBlockType; }
|
|
|
|
/** @return $this */
|
|
public function setMushroomBlockType(MushroomBlockType $mushroomBlockType) : self{
|
|
$this->mushroomBlockType = $mushroomBlockType;
|
|
return $this;
|
|
}
|
|
|
|
public function getDropsForCompatibleTool(Item $item) : array{
|
|
return [
|
|
VanillaBlocks::RED_MUSHROOM()->asItem()->setCount(mt_rand(0, 2))
|
|
];
|
|
}
|
|
|
|
public function isAffectedBySilkTouch() : bool{
|
|
return true;
|
|
}
|
|
|
|
public function getSilkTouchDrops(Item $item) : array{
|
|
return [(clone $this)->setMushroomBlockType(MushroomBlockType::ALL_CAP())->asItem()];
|
|
}
|
|
|
|
public function getPickedItem(bool $addUserData = false) : Item{
|
|
return (clone $this)->setMushroomBlockType(MushroomBlockType::ALL_CAP())->asItem();
|
|
}
|
|
}
|