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

This reverts commit f64dc01bd1c14ff3f79bd6c18d0c337dbc0e87e0.

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
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
82 changed files with 149 additions and 94 deletions

View File

@ -51,11 +51,11 @@ class Anvil extends Transparent implements Fallable{
private int $damage = self::UNDAMAGED;
public function describeType(RuntimeDataDescriber $w) : void{
protected function describeType(RuntimeDataDescriber $w) : void{
$w->boundedInt(2, self::UNDAMAGED, self::VERY_DAMAGED, $this->damage);
}
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->horizontalFacing($this->facing);
}

View File

@ -55,7 +55,7 @@ class Bamboo extends Transparent{
protected bool $ready = false;
protected int $leafSize = self::NO_LEAVES;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->boundedInt(2, self::NO_LEAVES, self::LARGE_LEAVES, $this->leafSize);
$w->bool($this->thick);
$w->bool($this->ready);

View File

@ -36,7 +36,7 @@ use pocketmine\world\BlockTransaction;
final class BambooSapling extends Flowable{
private bool $ready = false;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->bool($this->ready);
}

View File

@ -38,7 +38,7 @@ class Barrel extends Opaque{
protected bool $open = false;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->facing($this->facing);
$w->bool($this->open);
}

View File

@ -53,7 +53,7 @@ class Bed extends Transparent{
parent::__construct($idInfo, $name, $typeInfo);
}
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->horizontalFacing($this->facing);
$w->bool($this->occupied);
$w->bool($this->head);

View File

@ -28,7 +28,7 @@ use pocketmine\data\runtime\RuntimeDataDescriber;
class Bedrock extends Opaque{
private bool $burnsForever = false;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->bool($this->burnsForever);
}

View File

@ -48,7 +48,7 @@ final class Bell extends Transparent{
parent::__construct($idInfo, $name, $typeInfo);
}
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->bellAttachmentType($this->attachmentType);
$w->horizontalFacing($this->facing);
}

View File

@ -214,11 +214,11 @@ class Block{
return $writer->getValue();
}
public function describeType(RuntimeDataDescriber $w) : void{
protected function describeType(RuntimeDataDescriber $w) : void{
//NOOP
}
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
//NOOP
}

View File

@ -43,7 +43,7 @@ class BrewingStand extends Transparent{
*/
protected array $slots = [];
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->brewingStandSlots($this->slots);
}

View File

@ -38,7 +38,7 @@ abstract class Button extends Flowable{
protected bool $pressed = false;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->facing($this->facing);
$w->bool($this->pressed);
}

View File

@ -41,7 +41,7 @@ class Cactus extends Transparent{
protected int $age = 0;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->boundedInt(4, 0, self::MAX_AGE, $this->age);
}

View File

@ -36,7 +36,7 @@ class Cake extends BaseCake{
protected int $bites = 0;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->boundedInt(3, 0, self::MAX_BITES, $this->bites);
}

View File

@ -46,7 +46,7 @@ class Candle extends Transparent{
private int $count = self::MIN_COUNT;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$this->encodeLitState($w);
$w->boundedInt(2, self::MIN_COUNT, self::MAX_COUNT, $this->count);
}

View File

@ -49,7 +49,7 @@ final class ChorusFlower extends Flowable{
private int $age = self::MIN_AGE;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->boundedInt(3, self::MIN_AGE, self::MAX_AGE, $this->age);
}

View File

@ -46,7 +46,7 @@ class CocoaBlock extends Transparent{
protected int $age = 0;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->horizontalFacing($this->facing);
$w->boundedInt(2, 0, self::MAX_AGE, $this->age);
}

View File

@ -38,7 +38,7 @@ abstract class Crops extends Flowable{
protected int $age = 0;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->boundedInt(3, 0, self::MAX_AGE, $this->age);
}

View File

@ -41,7 +41,7 @@ class DaylightSensor extends Transparent{
protected bool $inverted = false;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->boundedInt(4, 0, 15, $this->signalStrength);
$w->bool($this->inverted);
}

View File

@ -28,7 +28,7 @@ use pocketmine\data\runtime\RuntimeDataDescriber;
class DetectorRail extends StraightOnlyRail{
protected bool $activated = false;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
parent::describeState($w);
$w->bool($this->activated);
}

View File

@ -45,7 +45,7 @@ class Dirt extends Opaque{
parent::__construct($idInfo, $name, $typeInfo);
}
public function describeType(RuntimeDataDescriber $w) : void{
protected function describeType(RuntimeDataDescriber $w) : void{
$w->dirtType($this->dirtType);
}

View File

@ -41,7 +41,7 @@ class Door extends Transparent{
protected bool $hingeRight = false;
protected bool $open = false;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->horizontalFacing($this->facing);
$w->bool($this->top);
$w->bool($this->hingeRight);

View File

@ -33,7 +33,7 @@ use pocketmine\world\BlockTransaction;
class DoublePlant extends Flowable{
protected bool $top = false;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->bool($this->top);
}

View File

@ -35,7 +35,7 @@ class EndPortalFrame extends Opaque{
protected bool $eye = false;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->horizontalFacing($this->facing);
$w->bool($this->eye);
}

View File

@ -37,7 +37,7 @@ class Farmland extends Transparent{
protected int $wetness = 0; //"moisture" blockstate property in PC
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->boundedInt(3, 0, self::MAX_WETNESS, $this->wetness);
}

View File

@ -42,7 +42,7 @@ class FenceGate extends Transparent{
protected bool $open = false;
protected bool $inWall = false;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->horizontalFacing($this->facing);
$w->bool($this->open);
$w->bool($this->inWall);

View File

@ -37,7 +37,7 @@ abstract class FillableCauldron extends Transparent{
private int $fillLevel = self::MIN_FILL_LEVEL;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->boundedInt(3, self::MIN_FILL_LEVEL, self::MAX_FILL_LEVEL, $this->fillLevel);
}

View File

@ -39,7 +39,7 @@ class Fire extends BaseFire{
protected int $age = 0;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->boundedInt(4, 0, self::MAX_AGE, $this->age);
}

View File

@ -37,7 +37,7 @@ use function rad2deg;
final class FloorCoralFan extends BaseCoral{
private int $axis = Axis::X;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->horizontalAxis($this->axis);
}

View File

@ -35,7 +35,7 @@ final class Froglight extends SimplePillar{
parent::__construct($idInfo, $name, $typeInfo);
}
public function describeType(RuntimeDataDescriber $w) : void{
protected function describeType(RuntimeDataDescriber $w) : void{
$w->froglightType($this->froglightType);
}

View File

@ -32,7 +32,7 @@ class FrostedIce extends Ice{
protected int $age = 0;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->boundedInt(2, 0, self::MAX_AGE, $this->age);
}

View File

@ -46,7 +46,7 @@ class Furnace extends Opaque{
parent::__construct($idInfo, $name, $typeInfo);
}
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->horizontalFacing($this->facing);
$w->bool($this->lit);
}

View File

@ -39,7 +39,7 @@ class Hopper extends Transparent{
private int $facing = Facing::DOWN;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->facingExcept($this->facing, Facing::UP);
$w->bool($this->powered);
}

View File

@ -50,7 +50,7 @@ class ItemFrame extends Flowable{
protected int $itemRotation = 0;
protected float $itemDropChance = 1.0;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->facing($this->facing);
$w->bool($this->hasMap);
}

View File

@ -43,7 +43,7 @@ class Lantern extends Transparent{
parent::__construct($idInfo, $name, $typeInfo);
}
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->bool($this->hanging);
}

View File

@ -47,7 +47,7 @@ class Leaves extends Transparent{
$this->leavesType = $leavesType;
}
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->bool($this->noDecay);
$w->bool($this->checkDecay);
}

View File

@ -46,7 +46,7 @@ class Lectern extends Transparent{
protected bool $producingSignal = false;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->horizontalFacing($this->facing);
$w->bool($this->producingSignal);
}

View File

@ -44,7 +44,7 @@ class Lever extends Flowable{
parent::__construct($idInfo, $name, $typeInfo);
}
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->leverFacing($this->facing);
$w->bool($this->activated);
}

View File

@ -34,7 +34,7 @@ final class Light extends Flowable{
private int $level = self::MAX_LIGHT_LEVEL;
public function describeType(RuntimeDataDescriber $w) : void{
protected function describeType(RuntimeDataDescriber $w) : void{
$w->boundedInt(4, self::MIN_LIGHT_LEVEL, self::MAX_LIGHT_LEVEL, $this->level);
}

View File

@ -48,7 +48,7 @@ abstract class Liquid extends Transparent{
protected int $decay = 0; //PC "level" property
protected bool $still = false;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->boundedInt(3, 0, self::MAX_DECAY, $this->decay);
$w->bool($this->falling);
$w->bool($this->still);

View File

@ -34,7 +34,7 @@ class NetherPortal extends Transparent{
protected int $axis = Axis::X;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->horizontalAxis($this->axis);
}

View File

@ -37,7 +37,7 @@ class NetherWartPlant extends Flowable{
protected int $age = 0;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->boundedInt(2, 0, self::MAX_AGE, $this->age);
}

View File

@ -34,7 +34,7 @@ class Rail extends BaseRail{
private int $railShape = BlockLegacyMetadata::RAIL_STRAIGHT_NORTH_SOUTH;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->railShape($this->railShape);
}

View File

@ -36,7 +36,7 @@ class RedMushroomBlock extends Opaque{
parent::__construct($idInfo, $name, $typeInfo);
}
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->mushroomBlockType($this->mushroomBlockType);
}

View File

@ -44,7 +44,7 @@ class RedstoneComparator extends Flowable{
protected bool $isSubtractMode = false;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->horizontalFacing($this->facing);
$w->bool($this->isSubtractMode);
$w->bool($this->powered);

View File

@ -29,7 +29,7 @@ use pocketmine\data\runtime\RuntimeDataDescriber;
class RedstoneLamp extends Opaque{
use PoweredByRedstoneTrait;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->bool($this->powered);
}

View File

@ -33,7 +33,7 @@ use function mt_rand;
class RedstoneOre extends Opaque{
protected bool $lit = false;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->bool($this->lit);
}

View File

@ -43,7 +43,7 @@ class RedstoneRepeater extends Flowable{
protected int $delay = self::MIN_DELAY;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->horizontalFacing($this->facing);
$w->boundedInt(2, self::MIN_DELAY, self::MAX_DELAY, $this->delay);
$w->bool($this->powered);

View File

@ -28,7 +28,7 @@ use pocketmine\data\runtime\RuntimeDataDescriber;
class RedstoneTorch extends Torch{
protected bool $lit = true;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
parent::describeState($w);
$w->bool($this->lit);
}

View File

@ -151,6 +151,18 @@ class RuntimeBlockStateRegistry{
}
}
/**
* @internal
* Returns the default state of the block type associated with the given type ID.
*/
public function fromTypeId(int $typeId) : Block{
if(isset($this->typeIndex[$typeId])){
return clone $this->typeIndex[$typeId];
}
throw new \InvalidArgumentException("Block ID $typeId is not registered");
}
public function fromStateId(int $stateId) : Block{
if($stateId < 0){
throw new \InvalidArgumentException("Block state ID cannot be negative");
@ -166,6 +178,22 @@ class RuntimeBlockStateRegistry{
return $block;
}
/**
* Returns whether a specified block state is already registered in the block factory.
*/
public function isRegistered(int $typeId) : bool{
$b = $this->typeIndex[$typeId] ?? null;
return $b !== null && !($b instanceof UnknownBlock);
}
/**
* @return Block[]
* @phpstan-return array<int, Block>
*/
public function getAllKnownTypes() : array{
return $this->typeIndex;
}
/**
* @return Block[]
*/

View File

@ -46,7 +46,7 @@ class Sapling extends Flowable{
$this->treeType = $treeType;
}
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->bool($this->ready);
}

View File

@ -38,7 +38,7 @@ class SeaPickle extends Transparent{
protected int $count = self::MIN_COUNT;
protected bool $underwater = false;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->boundedInt(2, self::MIN_COUNT, self::MAX_COUNT, $this->count);
$w->bool($this->underwater);
}

View File

@ -34,7 +34,7 @@ use pocketmine\world\BlockTransaction;
class ShulkerBox extends Opaque{
use AnyFacingTrait;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
//NOOP - we don't read or write facing here, because the tile persists it
}

View File

@ -28,7 +28,7 @@ use pocketmine\data\runtime\RuntimeDataDescriber;
abstract class SimplePressurePlate extends PressurePlate{
protected bool $pressed = false;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->bool($this->pressed);
}

View File

@ -49,11 +49,11 @@ class Skull extends Flowable{
parent::__construct($idInfo, $name, $typeInfo);
}
public function describeType(RuntimeDataDescriber $w) : void{
protected function describeType(RuntimeDataDescriber $w) : void{
$w->skullType($this->skullType);
}
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->facingExcept($this->facing, Facing::DOWN);
}

View File

@ -41,7 +41,7 @@ class Slab extends Transparent{
$this->slabType = SlabType::BOTTOM();
}
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->slabType($this->slabType);
}

View File

@ -46,7 +46,7 @@ class SnowLayer extends Flowable implements Fallable{
protected int $layers = self::MIN_LAYERS;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->boundedInt(3, self::MIN_LAYERS, self::MAX_LAYERS, $this->layers);
}

View File

@ -28,7 +28,7 @@ use pocketmine\data\runtime\RuntimeDataDescriber;
class Sponge extends Opaque{
protected bool $wet = false;
public function describeType(RuntimeDataDescriber $w) : void{
protected function describeType(RuntimeDataDescriber $w) : void{
$w->bool($this->wet);
}

View File

@ -46,7 +46,7 @@ class Stair extends Transparent{
parent::__construct($idInfo, $name, $typeInfo);
}
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->horizontalFacing($this->facing);
$w->bool($this->upsideDown);
}

View File

@ -36,7 +36,7 @@ class StraightOnlyRail extends BaseRail{
private int $railShape = BlockLegacyMetadata::RAIL_STRAIGHT_NORTH_SOUTH;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->straightOnlyRailShape($this->railShape);
}

View File

@ -38,7 +38,7 @@ class Sugarcane extends Flowable{
protected int $age = 0;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->boundedInt(4, 0, self::MAX_AGE, $this->age);
}

View File

@ -45,7 +45,7 @@ class SweetBerryBush extends Flowable{
protected int $age = self::STAGE_SAPLING;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->boundedInt(3, self::STAGE_SAPLING, self::STAGE_MATURE, $this->age);
}

View File

@ -45,11 +45,11 @@ class TNT extends Opaque{
protected bool $unstable = false; //TODO: Usage unclear, seems to be a weird hack in vanilla
protected bool $worksUnderwater = false;
public function describeType(RuntimeDataDescriber $w) : void{
protected function describeType(RuntimeDataDescriber $w) : void{
$w->bool($this->worksUnderwater);
}
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->bool($this->unstable);
}

View File

@ -36,7 +36,7 @@ class Torch extends Flowable{
protected int $facing = Facing::UP;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->facingExcept($this->facing, Facing::DOWN);
}

View File

@ -40,7 +40,7 @@ class Trapdoor extends Transparent{
protected bool $open = false;
protected bool $top = false;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->horizontalFacing($this->facing);
$w->bool($this->top);
$w->bool($this->open);

View File

@ -33,7 +33,7 @@ class Tripwire extends Flowable{
protected bool $connected = false;
protected bool $disarmed = false;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->bool($this->triggered);
$w->bool($this->suspended);
$w->bool($this->connected);

View File

@ -38,7 +38,7 @@ class TripwireHook extends Flowable{
protected bool $connected = false;
protected bool $powered = false;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->horizontalFacing($this->facing);
$w->bool($this->connected);
$w->bool($this->powered);

View File

@ -38,7 +38,7 @@ class UnknownBlock extends Transparent{
$this->stateData = $stateData;
}
public function describeType(RuntimeDataDescriber $w) : void{
protected function describeType(RuntimeDataDescriber $w) : void{
//use type instead of state, so we don't lose any information like colour
//this might be an improperly registered plugin block
$w->int(Block::INTERNAL_STATE_DATA_BITS, $this->stateData);

View File

@ -39,7 +39,7 @@ class Vine extends Flowable{
/** @var int[] */
protected array $faces = [];
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->horizontalFacingFlags($this->faces);
}

View File

@ -42,7 +42,7 @@ class Wall extends Transparent{
protected array $connections = [];
protected bool $post = false;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->wallConnections($this->connections);
$w->bool($this->post);
}

View File

@ -36,7 +36,7 @@ use pocketmine\world\BlockTransaction;
final class WallCoralFan extends BaseCoral{
use HorizontalFacingTrait;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->horizontalFacing($this->facing);
}

View File

@ -38,7 +38,7 @@ class Wood extends Opaque{
private bool $stripped = false;
public function describeType(RuntimeDataDescriber $w) : void{
protected function describeType(RuntimeDataDescriber $w) : void{
$w->bool($this->stripped);
}

View File

@ -28,7 +28,7 @@ use pocketmine\data\runtime\RuntimeDataDescriber;
trait AnalogRedstoneSignalEmitterTrait{
protected int $signalStrength = 0;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->boundedInt(4, 0, 15, $this->signalStrength);
}

View File

@ -29,7 +29,7 @@ use pocketmine\math\Facing;
trait AnyFacingTrait{
protected int $facing = Facing::DOWN;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->facing($this->facing);
}

View File

@ -39,7 +39,7 @@ use pocketmine\world\sound\FlintSteelSound;
trait CandleTrait{
private bool $lit = false;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->bool($this->lit);
}

View File

@ -31,7 +31,7 @@ trait ColoredTrait{
private $color;
/** @see Block::describeType() */
public function describeType(RuntimeDataDescriber $w) : void{
protected function describeType(RuntimeDataDescriber $w) : void{
$w->dyeColor($this->color);
}

View File

@ -44,7 +44,7 @@ trait CopperTrait{
parent::__construct($identifier, $name, $typeInfo);
}
public function describeType(RuntimeDataDescriber $w) : void{
protected function describeType(RuntimeDataDescriber $w) : void{
$w->copperOxidation($this->oxidation);
$w->bool($this->waxed);
}

View File

@ -31,7 +31,7 @@ trait CoralTypeTrait{
protected bool $dead = false;
/** @see Block::describeType() */
public function describeType(RuntimeDataDescriber $w) : void{
protected function describeType(RuntimeDataDescriber $w) : void{
$w->coralType($this->coralType);
$w->bool($this->dead);
}

View File

@ -30,7 +30,7 @@ use pocketmine\math\Facing;
trait HorizontalFacingTrait{
protected int $facing = Facing::NORTH;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->horizontalFacing($this->facing);
}

View File

@ -35,7 +35,7 @@ use pocketmine\world\BlockTransaction;
trait PillarRotationTrait{
protected int $axis = Axis::Y;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->axis($this->axis);
}

View File

@ -28,7 +28,7 @@ use pocketmine\data\runtime\RuntimeDataDescriber;
trait RailPoweredByRedstoneTrait{
use PoweredByRedstoneTrait;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
parent::describeState($w);
$w->bool($this->powered);
}

View File

@ -30,7 +30,7 @@ trait SignLikeRotationTrait{
/** @var int */
private $rotation = 0;
public function describeState(RuntimeDataDescriber $w) : void{
protected function describeState(RuntimeDataDescriber $w) : void{
$w->boundedInt(4, 0, 15, $this->rotation);
}

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;
}
}

View File

@ -62,9 +62,16 @@ class BlockTest extends TestCase{
* Test registering a new block which does not yet exist
*/
public function testRegisterNewBlock() : void{
$b = new StrangeNewBlock(new BlockIdentifier(BlockTypeIds::newId()), "Strange New Block", new BlockTypeInfo(BlockBreakInfo::instant()));
$this->blockFactory->register($b);
self::assertInstanceOf(StrangeNewBlock::class, $this->blockFactory->fromStateId($b->getStateId()));
for($i = BlockTypeIds::FIRST_UNUSED_BLOCK_ID; $i < BlockTypeIds::FIRST_UNUSED_BLOCK_ID + 256; ++$i){
if(!$this->blockFactory->isRegistered($i)){
$b = new StrangeNewBlock(new BlockIdentifier($i), "Strange New Block", new BlockTypeInfo(BlockBreakInfo::instant()));
$this->blockFactory->register($b);
self::assertInstanceOf(StrangeNewBlock::class, $this->blockFactory->fromStateId($b->getStateId()));
return;
}
}
throw new \RuntimeException("Can't test registering new blocks because no unused spaces left");
}
/**