Block: added a bunch of state manipulation APIs

This commit is contained in:
Dylan K. Taylor
2020-11-03 19:13:32 +00:00
parent 0a8dc3edd3
commit 32929925aa
30 changed files with 374 additions and 0 deletions

View File

@ -64,6 +64,17 @@ class Anvil extends Transparent implements Fallable{
return 0b11;
}
public function getDamage() : int{ return $this->damage; }
/** @return $this */
public function setDamage(int $damage) : self{
if($damage < 0 || $damage > 2){
throw new \InvalidArgumentException("Damage must be in range 0-2");
}
$this->damage = $damage;
return $this;
}
/**
* @return AxisAlignedBB[]
*/

View File

@ -100,6 +100,12 @@ class Bed extends Transparent{
return $this->head;
}
/** @return $this */
public function setHead(bool $head) : self{
$this->head = $head;
return $this;
}
public function isOccupied() : bool{
return $this->occupied;
}

View File

@ -47,4 +47,10 @@ class Bedrock extends Opaque{
public function burnsForever() : bool{
return $this->burnsForever;
}
/** @return $this */
public function setBurnsForever(bool $burnsForever) : self{
$this->burnsForever = $burnsForever;
return $this;
}
}

View File

@ -53,6 +53,14 @@ abstract class Button extends Flowable{
return 0b1111;
}
public function isPressed() : bool{ return $this->pressed; }
/** @return $this */
public function setPressed(bool $pressed) : self{
$this->pressed = $pressed;
return $this;
}
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
//TODO: check valid target block
$this->facing = $face;

View File

@ -56,6 +56,17 @@ class Cactus extends Transparent{
return 0b1111;
}
public function getAge() : int{ return $this->age; }
/** @return $this */
public function setAge(int $age) : self{
if($age < 0 || $age > 15){
throw new \InvalidArgumentException("Age must be in range 0-15");
}
$this->age = $age;
return $this;
}
public function hasEntityCollision() : bool{
return true;
}

View File

@ -67,6 +67,17 @@ class Cake extends Transparent implements FoodSource{
];
}
public function getBites() : int{ return $this->bites; }
/** @return $this */
public function setBites(int $bites) : self{
if($bites < 0 || $bites > 6){
throw new \InvalidArgumentException("Bites must be in range 0-6");
}
$this->bites = $bites;
return $this;
}
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
$down = $this->getSide(Facing::DOWN);
if($down->getId() !== BlockLegacyIds::AIR){

View File

@ -60,6 +60,17 @@ class CocoaBlock extends Transparent{
return 0b1111;
}
public function getAge() : int{ return $this->age; }
/** @return $this */
public function setAge(int $age) : self{
if($age < 0 || $age > 2){
throw new \InvalidArgumentException("Age must be in range 0-2");
}
$this->age = $age;
return $this;
}
/**
* @return AxisAlignedBB[]
*/

View File

@ -53,6 +53,17 @@ abstract class Crops extends Flowable{
return 0b111;
}
public function getAge() : int{ return $this->age; }
/** @return $this */
public function setAge(int $age) : self{
if($age < 0 || $age > 7){
throw new \InvalidArgumentException("Age must be in range 0-7");
}
$this->age = $age;
return $this;
}
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($blockReplace->getSide(Facing::DOWN)->getId() === BlockLegacyIds::FARMLAND){
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);

View File

@ -87,6 +87,30 @@ class Door extends Transparent{
}
}
public function isTop() : bool{ return $this->top; }
/** @return $this */
public function setTop(bool $top) : self{
$this->top = $top;
return $this;
}
public function isHingeRight() : bool{ return $this->hingeRight; }
/** @return $this */
public function setHingeRight(bool $hingeRight) : self{
$this->hingeRight = $hingeRight;
return $this;
}
public function isOpen() : bool{ return $this->open; }
/** @return $this */
public function setOpen(bool $open) : self{
$this->open = $open;
return $this;
}
public function isSolid() : bool{
return false;
}

View File

@ -50,6 +50,14 @@ class DoublePlant extends Flowable{
return 0b1000;
}
public function isTop() : bool{ return $this->top; }
/** @return $this */
public function setTop(bool $top) : self{
$this->top = $top;
return $this;
}
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
$id = $blockReplace->getSide(Facing::DOWN)->getId();
if(($id === BlockLegacyIds::GRASS or $id === BlockLegacyIds::DIRT) and $blockReplace->getSide(Facing::UP)->canBeReplaced()){

View File

@ -55,6 +55,14 @@ class EndPortalFrame extends Opaque{
return 0b111;
}
public function hasEye() : bool{ return $this->eye; }
/** @return $this */
public function setEye(bool $eye) : self{
$this->eye = $eye;
return $this;
}
public function getLightLevel() : int{
return 1;
}

View File

@ -49,6 +49,17 @@ class Farmland extends Transparent{
return 0b111;
}
public function getWetness() : int{ return $this->wetness; }
/** @return $this */
public function setWetness(int $wetness) : self{
if($wetness < 0 || $wetness > 7){
throw new \InvalidArgumentException("Wetness must be in range 0-7");
}
$this->wetness = $wetness;
return $this;
}
/**
* @return AxisAlignedBB[]
*/

View File

@ -61,6 +61,22 @@ class FenceGate extends Transparent{
return 0b1111;
}
public function isOpen() : bool{ return $this->open; }
/** @return $this */
public function setOpen(bool $open) : self{
$this->open = $open;
return $this;
}
public function isInWall() : bool{ return $this->inWall; }
/** @return $this */
public function setInWall(bool $inWall) : self{
$this->inWall = $inWall;
return $this;
}
/**
* @return AxisAlignedBB[]
*/

View File

@ -56,6 +56,17 @@ class Fire extends Flowable{
return 0b1111;
}
public function getAge() : int{ return $this->age; }
/** @return $this */
public function setAge(int $age) : self{
if($age < 0 || $age > 15){
throw new \InvalidArgumentException("Age must be in range 0-15");
}
$this->age = $age;
return $this;
}
public function hasEntityCollision() : bool{
return true;
}

View File

@ -48,6 +48,17 @@ class FrostedIce extends Ice{
return 0b11;
}
public function getAge() : int{ return $this->age; }
/** @return $this */
public function setAge(int $age) : self{
if($age < 0 || $age > 3){
throw new \InvalidArgumentException("Age must be in range 0-3");
}
$this->age = $age;
return $this;
}
public function onNearbyBlockChange() : void{
if(!$this->checkAdjacentBlocks(2)){
$this->pos->getWorld()->useBreakOn($this->pos);

View File

@ -122,6 +122,19 @@ class ItemFrame extends Flowable{
return $this;
}
public function hasMap() : bool{ return $this->hasMap; }
/**
* This can be set irrespective of whether the frame actually contains a map or not. When set, the frame stretches
* to the edges of the block without leaving space around the edges.
*
* @return $this
*/
public function setHasMap(bool $hasMap) : self{
$this->hasMap = $hasMap;
return $this;
}
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($this->framedItem !== null){
$this->itemRotation = ($this->itemRotation + 1) % self::ROTATIONS;

View File

@ -48,6 +48,14 @@ class Lantern extends Transparent{
return 0b1;
}
public function isHanging() : bool{ return $this->hanging; }
/** @return $this */
public function setHanging(bool $hanging) : self{
$this->hanging = $hanging;
return $this;
}
public function getLightLevel() : int{
return 15;
}

View File

@ -63,6 +63,22 @@ class Leaves extends Transparent{
return 0b1100;
}
public function isNoDecay() : bool{ return $this->noDecay; }
/** @return $this */
public function setNoDecay(bool $noDecay) : self{
$this->noDecay = $noDecay;
return $this;
}
public function isCheckDecay() : bool{ return $this->checkDecay; }
/** @return $this */
public function setCheckDecay(bool $checkDecay) : self{
$this->checkDecay = $checkDecay;
return $this;
}
public function blocksDirectSkyLight() : bool{
return true;
}

View File

@ -84,6 +84,22 @@ abstract class Liquid extends Transparent{
return 0b1111;
}
public function isFalling() : bool{ return $this->falling; }
/** @return $this */
public function setFalling(bool $falling) : self{
$this->falling = $falling;
return $this;
}
public function getDecay() : int{ return $this->decay; }
/** @return $this */
public function setDecay(int $decay) : self{
$this->decay = $decay;
return $this;
}
public function hasEntityCollision() : bool{
return true;
}

View File

@ -53,6 +53,17 @@ class NetherWartPlant extends Flowable{
return 0b11;
}
public function getAge() : int{ return $this->age; }
/** @return $this */
public function setAge(int $age) : self{
if($age < 0 || $age > 3){
throw new \InvalidArgumentException("Age must be in range 0-3");
}
$this->age = $age;
return $this;
}
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
$down = $this->getSide(Facing::DOWN);
if($down->getId() === BlockLegacyIds::SOUL_SAND){

View File

@ -58,6 +58,14 @@ class Sapling extends Flowable{
return 0b1000;
}
public function isReady() : bool{ return $this->ready; }
/** @return $this */
public function setReady(bool $ready) : self{
$this->ready = $ready;
return $this;
}
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
$down = $this->getSide(Facing::DOWN);
if($down->getId() === BlockLegacyIds::GRASS or $down->getId() === BlockLegacyIds::DIRT or $down->getId() === BlockLegacyIds::FARMLAND){

View File

@ -52,6 +52,25 @@ class SeaPickle extends Transparent{
return 0b111;
}
public function getCount() : int{ return $this->count; }
/** @return $this */
public function setCount(int $count) : self{
if($count < 1 || $count > 4){
throw new \InvalidArgumentException("Count must be in range 1-4");
}
$this->count = $count;
return $this;
}
public function isUnderwater() : bool{ return $this->underwater; }
/** @return $this */
public function setUnderwater(bool $underwater) : self{
$this->underwater = $underwater;
return $this;
}
public function isSolid() : bool{
return false;
}

View File

@ -59,6 +59,17 @@ class SnowLayer extends Flowable implements Fallable{
return 0b111;
}
public function getLayers() : int{ return $this->layers; }
/** @return $this */
public function setLayers(int $layers) : self{
if($layers < 1 || $layers > 8){
throw new \InvalidArgumentException("Layers must be in range 1-8");
}
$this->layers = $layers;
return $this;
}
public function canBeReplaced() : bool{
return $this->layers < 8;
}

View File

@ -47,4 +47,12 @@ class Sponge extends Opaque{
public function getNonPersistentStateBitmask() : int{
return 0;
}
public function isWet() : bool{ return $this->wet; }
/** @return $this */
public function setWet(bool $wet) : self{
$this->wet = $wet;
return $this;
}
}

View File

@ -73,6 +73,22 @@ class Stair extends Transparent{
}
}
public function isUpsideDown() : bool{ return $this->upsideDown; }
/** @return $this */
public function setUpsideDown(bool $upsideDown) : self{
$this->upsideDown = $upsideDown;
return $this;
}
public function getShape() : StairShape{ return $this->shape; }
/** @return $this */
public function setShape(StairShape $shape) : self{
$this->shape = $shape;
return $this;
}
protected function recalculateCollisionBoxes() : array{
$topStepFace = $this->upsideDown ? Facing::DOWN : Facing::UP;
$bbs = [

View File

@ -74,6 +74,17 @@ class Sugarcane extends Flowable{
$this->pos->getWorld()->setBlock($this->pos, $this);
}
public function getAge() : int{ return $this->age; }
/** @return $this */
public function setAge(int $age) : self{
if($age < 0 || $age > 15){
throw new \InvalidArgumentException("Age must be in range 0-15");
}
$this->age = $age;
return $this;
}
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($item instanceof Fertilizer){
if(!$this->getSide(Facing::DOWN)->isSameType($this)){

View File

@ -57,6 +57,22 @@ class Trapdoor extends Transparent{
return 0b1111;
}
public function isOpen() : bool{ return $this->open; }
/** @return $this */
public function setOpen(bool $open) : self{
$this->open = $open;
return $this;
}
public function isTop() : bool{ return $this->top; }
/** @return $this */
public function setTop(bool $top) : self{
$this->top = $top;
return $this;
}
/**
* @return AxisAlignedBB[]
*/

View File

@ -55,4 +55,36 @@ class Tripwire extends Flowable{
public function getStateBitmask() : int{
return 0b1111;
}
public function isTriggered() : bool{ return $this->triggered; }
/** @return $this */
public function setTriggered(bool $triggered) : self{
$this->triggered = $triggered;
return $this;
}
public function isSuspended() : bool{ return $this->suspended; }
/** @return $this */
public function setSuspended(bool $suspended) : self{
$this->suspended = $suspended;
return $this;
}
public function isConnected() : bool{ return $this->connected; }
/** @return $this */
public function setConnected(bool $connected) : self{
$this->connected = $connected;
return $this;
}
public function isDisarmed() : bool{ return $this->disarmed; }
/** @return $this */
public function setDisarmed(bool $disarmed) : self{
$this->disarmed = $disarmed;
return $this;
}
}

View File

@ -60,6 +60,22 @@ class TripwireHook extends Flowable{
return 0b1111;
}
public function isConnected() : bool{ return $this->connected; }
/** @return $this */
public function setConnected(bool $connected) : self{
$this->connected = $connected;
return $this;
}
public function isPowered() : bool{ return $this->powered; }
/** @return $this */
public function setPowered(bool $powered) : self{
$this->powered = $powered;
return $this;
}
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if(Facing::axis($face) !== Axis::Y){
//TODO: check face is valid

View File

@ -82,6 +82,15 @@ trait PillarRotationTrait{
][$this->axis] << $this->getAxisMetaShift();
}
/** @see Axis */
public function getAxis() : int{ return $this->axis; }
/** @return $this */
public function setAxis(int $axis) : self{
$this->axis = $axis;
return $this;
}
/**
* @see Block::place()
*/