mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 09:56:06 +00:00
Added getMushroomBlockType() / setMushroomBlockType() APIs to Red/BrownMushroomBlock
This commit is contained in:
@ -23,32 +23,45 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\block\utils\InvalidBlockStateException;
|
||||
use pocketmine\block\utils\MushroomBlockType;
|
||||
use pocketmine\data\bedrock\MushroomBlockTypeIdMap;
|
||||
use pocketmine\item\Item;
|
||||
use function mt_rand;
|
||||
|
||||
class RedMushroomBlock extends Opaque{
|
||||
|
||||
/**
|
||||
* @var int
|
||||
* In PC they have blockstate properties for each of the sides (pores/not pores). Unfortunately, we can't support
|
||||
* that because we can't serialize 2^6 combinations into a 4-bit metadata value, so this has to stick with storing
|
||||
* the legacy crap for now.
|
||||
* TODO: change this once proper blockstates are implemented
|
||||
*/
|
||||
protected int $rotationData = 0;
|
||||
protected MushroomBlockType $mushroomBlockType;
|
||||
|
||||
public function __construct(BlockIdentifier $idInfo, string $name, BlockBreakInfo $breakInfo){
|
||||
$this->mushroomBlockType = MushroomBlockType::PORES();
|
||||
parent::__construct($idInfo, $name, $breakInfo);
|
||||
}
|
||||
|
||||
protected function writeStateToMeta() : int{
|
||||
return $this->rotationData;
|
||||
return MushroomBlockTypeIdMap::getInstance()->toId($this->mushroomBlockType);
|
||||
}
|
||||
|
||||
public function readStateFromData(int $id, int $stateMeta) : void{
|
||||
$this->rotationData = $stateMeta;
|
||||
$type = MushroomBlockTypeIdMap::getInstance()->fromId($stateMeta);
|
||||
if($type === null){
|
||||
throw new InvalidBlockStateException("No such mushroom variant $stateMeta");
|
||||
}
|
||||
$this->mushroomBlockType = $type;
|
||||
}
|
||||
|
||||
public function getStateBitmask() : int{
|
||||
return 0b1111;
|
||||
}
|
||||
|
||||
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))
|
||||
|
63
src/block/utils/MushroomBlockType.php
Normal file
63
src/block/utils/MushroomBlockType.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?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\utils;
|
||||
|
||||
use pocketmine\utils\EnumTrait;
|
||||
|
||||
/**
|
||||
* This doc-block is generated automatically, do not modify it manually.
|
||||
* This must be regenerated whenever registry members are added, removed or changed.
|
||||
* @see \pocketmine\utils\RegistryUtils::_generateMethodAnnotations()
|
||||
*
|
||||
* @method static MushroomBlockType ALL_CAP()
|
||||
* @method static MushroomBlockType CAP_EAST()
|
||||
* @method static MushroomBlockType CAP_MIDDLE()
|
||||
* @method static MushroomBlockType CAP_NORTH()
|
||||
* @method static MushroomBlockType CAP_NORTHEAST()
|
||||
* @method static MushroomBlockType CAP_NORTHWEST()
|
||||
* @method static MushroomBlockType CAP_SOUTH()
|
||||
* @method static MushroomBlockType CAP_SOUTHEAST()
|
||||
* @method static MushroomBlockType CAP_SOUTHWEST()
|
||||
* @method static MushroomBlockType CAP_WEST()
|
||||
* @method static MushroomBlockType PORES()
|
||||
*/
|
||||
final class MushroomBlockType{
|
||||
use EnumTrait;
|
||||
|
||||
protected static function setup() : void{
|
||||
self::registerAll(
|
||||
new self("PORES"),
|
||||
new self("CAP_NORTHWEST"),
|
||||
new self("CAP_NORTH"),
|
||||
new self("CAP_NORTHEAST"),
|
||||
new self("CAP_WEST"),
|
||||
new self("CAP_MIDDLE"),
|
||||
new self("CAP_EAST"),
|
||||
new self("CAP_SOUTHWEST"),
|
||||
new self("CAP_SOUTH"),
|
||||
new self("CAP_SOUTHEAST"),
|
||||
new self("ALL_CAP")
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user