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

this allows cleaning up a whole lot of abusable mess from the API, and we never properly supported overriding built-in block types anyway.
This commit is contained in:
Dylan K. Taylor 2023-03-02 15:50:18 +00:00
parent 33140482bb
commit f64dc01bd1
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
82 changed files with 94 additions and 149 deletions

View File

@ -51,11 +51,11 @@ class Anvil extends Transparent implements Fallable{
private int $damage = self::UNDAMAGED;
protected function describeType(RuntimeDataDescriber $w) : void{
public function describeType(RuntimeDataDescriber $w) : void{
$w->boundedInt(2, self::UNDAMAGED, self::VERY_DAMAGED, $this->damage);
}
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public function describeState(RuntimeDataDescriber $w) : void{
$w->bool($this->ready);
}

View File

@ -38,7 +38,7 @@ class Barrel extends Opaque{
protected bool $open = false;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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);
}
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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);
}
protected function describeState(RuntimeDataDescriber $w) : void{
public function describeState(RuntimeDataDescriber $w) : void{
$w->bellAttachmentType($this->attachmentType);
$w->horizontalFacing($this->facing);
}

View File

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

View File

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

View File

@ -38,7 +38,7 @@ abstract class Button extends Flowable{
protected bool $pressed = false;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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);
}
protected function describeType(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public function describeState(RuntimeDataDescriber $w) : void{
$w->bool($this->top);
}

View File

@ -35,7 +35,7 @@ class EndPortalFrame extends Opaque{
protected bool $eye = false;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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);
}
protected function describeType(RuntimeDataDescriber $w) : void{
public function describeType(RuntimeDataDescriber $w) : void{
$w->froglightType($this->froglightType);
}

View File

@ -32,7 +32,7 @@ class FrostedIce extends Ice{
protected int $age = 0;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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);
}
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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);
}
protected function describeState(RuntimeDataDescriber $w) : void{
public function describeState(RuntimeDataDescriber $w) : void{
$w->bool($this->hanging);
}

View File

@ -47,7 +47,7 @@ class Leaves extends Transparent{
$this->leavesType = $leavesType;
}
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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);
}
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeType(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public function describeState(RuntimeDataDescriber $w) : void{
$w->horizontalAxis($this->axis);
}

View File

@ -37,7 +37,7 @@ class NetherWartPlant extends Flowable{
protected int $age = 0;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public function describeState(RuntimeDataDescriber $w) : void{
$w->railShape($this->railShape);
}

View File

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

View File

@ -44,7 +44,7 @@ class RedstoneComparator extends Flowable{
protected bool $isSubtractMode = false;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public function describeState(RuntimeDataDescriber $w) : void{
parent::describeState($w);
$w->bool($this->lit);
}

View File

@ -151,18 +151,6 @@ 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");
@ -178,22 +166,6 @@ 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;
}
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public function describeState(RuntimeDataDescriber $w) : void{
$w->bool($this->pressed);
}

View File

@ -49,11 +49,11 @@ class Skull extends Flowable{
parent::__construct($idInfo, $name, $typeInfo);
}
protected function describeType(RuntimeDataDescriber $w) : void{
public function describeType(RuntimeDataDescriber $w) : void{
$w->skullType($this->skullType);
}
protected function describeState(RuntimeDataDescriber $w) : void{
public 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();
}
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeType(RuntimeDataDescriber $w) : void{
public function describeType(RuntimeDataDescriber $w) : void{
$w->bool($this->wet);
}

View File

@ -46,7 +46,7 @@ class Stair extends Transparent{
parent::__construct($idInfo, $name, $typeInfo);
}
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public function describeState(RuntimeDataDescriber $w) : void{
$w->straightOnlyRailShape($this->railShape);
}

View File

@ -38,7 +38,7 @@ class Sugarcane extends Flowable{
protected int $age = 0;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeType(RuntimeDataDescriber $w) : void{
public function describeType(RuntimeDataDescriber $w) : void{
$w->bool($this->worksUnderwater);
}
protected function describeState(RuntimeDataDescriber $w) : void{
public function describeState(RuntimeDataDescriber $w) : void{
$w->bool($this->unstable);
}

View File

@ -36,7 +36,7 @@ class Torch extends Flowable{
protected int $facing = Facing::UP;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
}
protected function describeType(RuntimeDataDescriber $w) : void{
public 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 = [];
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public function describeState(RuntimeDataDescriber $w) : void{
$w->horizontalFacing($this->facing);
}

View File

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

View File

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

View File

@ -44,7 +44,7 @@ trait CopperTrait{
parent::__construct($identifier, $name, $typeInfo);
}
protected function describeType(RuntimeDataDescriber $w) : void{
public 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() */
protected function describeType(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public function describeState(RuntimeDataDescriber $w) : void{
$w->axis($this->axis);
}

View File

@ -28,7 +28,7 @@ use pocketmine\data\runtime\RuntimeDataDescriber;
trait RailPoweredByRedstoneTrait{
use PoweredByRedstoneTrait;
protected function describeState(RuntimeDataDescriber $w) : void{
public 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;
protected function describeState(RuntimeDataDescriber $w) : void{
public function describeState(RuntimeDataDescriber $w) : void{
$w->boundedInt(4, 0, 15, $this->rotation);
}

View File

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

View File

@ -62,16 +62,9 @@ class BlockTest extends TestCase{
* Test registering a new block which does not yet exist
*/
public function testRegisterNewBlock() : void{
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");
$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()));
}
/**