From 32929925aa1df27e4ccc1d5f146551726fe43656 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 3 Nov 2020 19:13:32 +0000 Subject: [PATCH] Block: added a bunch of state manipulation APIs --- src/block/Anvil.php | 11 +++++++++ src/block/Bed.php | 6 +++++ src/block/Bedrock.php | 6 +++++ src/block/Button.php | 8 +++++++ src/block/Cactus.php | 11 +++++++++ src/block/Cake.php | 11 +++++++++ src/block/CocoaBlock.php | 11 +++++++++ src/block/Crops.php | 11 +++++++++ src/block/Door.php | 24 +++++++++++++++++++ src/block/DoublePlant.php | 8 +++++++ src/block/EndPortalFrame.php | 8 +++++++ src/block/Farmland.php | 11 +++++++++ src/block/FenceGate.php | 16 +++++++++++++ src/block/Fire.php | 11 +++++++++ src/block/FrostedIce.php | 11 +++++++++ src/block/ItemFrame.php | 13 ++++++++++ src/block/Lantern.php | 8 +++++++ src/block/Leaves.php | 16 +++++++++++++ src/block/Liquid.php | 16 +++++++++++++ src/block/NetherWartPlant.php | 11 +++++++++ src/block/Sapling.php | 8 +++++++ src/block/SeaPickle.php | 19 +++++++++++++++ src/block/SnowLayer.php | 11 +++++++++ src/block/Sponge.php | 8 +++++++ src/block/Stair.php | 16 +++++++++++++ src/block/Sugarcane.php | 11 +++++++++ src/block/Trapdoor.php | 16 +++++++++++++ src/block/Tripwire.php | 32 +++++++++++++++++++++++++ src/block/TripwireHook.php | 16 +++++++++++++ src/block/utils/PillarRotationTrait.php | 9 +++++++ 30 files changed, 374 insertions(+) diff --git a/src/block/Anvil.php b/src/block/Anvil.php index 14b2a8379..313e6ef8c 100644 --- a/src/block/Anvil.php +++ b/src/block/Anvil.php @@ -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[] */ diff --git a/src/block/Bed.php b/src/block/Bed.php index dec248576..958f771dd 100644 --- a/src/block/Bed.php +++ b/src/block/Bed.php @@ -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; } diff --git a/src/block/Bedrock.php b/src/block/Bedrock.php index b7765bcb2..c9429d1a8 100644 --- a/src/block/Bedrock.php +++ b/src/block/Bedrock.php @@ -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; + } } diff --git a/src/block/Button.php b/src/block/Button.php index c3d0c4d23..0f50778ec 100644 --- a/src/block/Button.php +++ b/src/block/Button.php @@ -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; diff --git a/src/block/Cactus.php b/src/block/Cactus.php index 3062dbb82..dde4dac4d 100644 --- a/src/block/Cactus.php +++ b/src/block/Cactus.php @@ -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; } diff --git a/src/block/Cake.php b/src/block/Cake.php index 4575cd99e..53f44a423 100644 --- a/src/block/Cake.php +++ b/src/block/Cake.php @@ -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){ diff --git a/src/block/CocoaBlock.php b/src/block/CocoaBlock.php index 696a2dd97..daf612df5 100644 --- a/src/block/CocoaBlock.php +++ b/src/block/CocoaBlock.php @@ -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[] */ diff --git a/src/block/Crops.php b/src/block/Crops.php index ff0570d87..67f98df95 100644 --- a/src/block/Crops.php +++ b/src/block/Crops.php @@ -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); diff --git a/src/block/Door.php b/src/block/Door.php index 1d0e175f4..ee0bc63bb 100644 --- a/src/block/Door.php +++ b/src/block/Door.php @@ -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; } diff --git a/src/block/DoublePlant.php b/src/block/DoublePlant.php index 3505e1ac6..b558ff756 100644 --- a/src/block/DoublePlant.php +++ b/src/block/DoublePlant.php @@ -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()){ diff --git a/src/block/EndPortalFrame.php b/src/block/EndPortalFrame.php index 254bac34b..221b206d0 100644 --- a/src/block/EndPortalFrame.php +++ b/src/block/EndPortalFrame.php @@ -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; } diff --git a/src/block/Farmland.php b/src/block/Farmland.php index f715f7d81..65a0f77b2 100644 --- a/src/block/Farmland.php +++ b/src/block/Farmland.php @@ -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[] */ diff --git a/src/block/FenceGate.php b/src/block/FenceGate.php index 5191c3d16..2f97c4105 100644 --- a/src/block/FenceGate.php +++ b/src/block/FenceGate.php @@ -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[] */ diff --git a/src/block/Fire.php b/src/block/Fire.php index 4e31baf82..45f3f8f6e 100644 --- a/src/block/Fire.php +++ b/src/block/Fire.php @@ -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; } diff --git a/src/block/FrostedIce.php b/src/block/FrostedIce.php index e28ba8427..70563050a 100644 --- a/src/block/FrostedIce.php +++ b/src/block/FrostedIce.php @@ -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); diff --git a/src/block/ItemFrame.php b/src/block/ItemFrame.php index 0ab780480..3b8a32eba 100644 --- a/src/block/ItemFrame.php +++ b/src/block/ItemFrame.php @@ -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; diff --git a/src/block/Lantern.php b/src/block/Lantern.php index 717911544..aa0a4fe03 100644 --- a/src/block/Lantern.php +++ b/src/block/Lantern.php @@ -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; } diff --git a/src/block/Leaves.php b/src/block/Leaves.php index 058cdb5f9..c9408b0c6 100644 --- a/src/block/Leaves.php +++ b/src/block/Leaves.php @@ -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; } diff --git a/src/block/Liquid.php b/src/block/Liquid.php index 6de3e98d9..1dd195715 100644 --- a/src/block/Liquid.php +++ b/src/block/Liquid.php @@ -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; } diff --git a/src/block/NetherWartPlant.php b/src/block/NetherWartPlant.php index 7ca38d72f..5f635f3ad 100644 --- a/src/block/NetherWartPlant.php +++ b/src/block/NetherWartPlant.php @@ -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){ diff --git a/src/block/Sapling.php b/src/block/Sapling.php index 8b0e74f54..f9d004de3 100644 --- a/src/block/Sapling.php +++ b/src/block/Sapling.php @@ -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){ diff --git a/src/block/SeaPickle.php b/src/block/SeaPickle.php index 87edd0cf5..e96beb131 100644 --- a/src/block/SeaPickle.php +++ b/src/block/SeaPickle.php @@ -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; } diff --git a/src/block/SnowLayer.php b/src/block/SnowLayer.php index 228ebb5f0..1781497ae 100644 --- a/src/block/SnowLayer.php +++ b/src/block/SnowLayer.php @@ -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; } diff --git a/src/block/Sponge.php b/src/block/Sponge.php index a1328ab69..dd6491e7a 100644 --- a/src/block/Sponge.php +++ b/src/block/Sponge.php @@ -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; + } } diff --git a/src/block/Stair.php b/src/block/Stair.php index c70dc7773..9b477e514 100644 --- a/src/block/Stair.php +++ b/src/block/Stair.php @@ -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 = [ diff --git a/src/block/Sugarcane.php b/src/block/Sugarcane.php index c87926d8b..5165e820d 100644 --- a/src/block/Sugarcane.php +++ b/src/block/Sugarcane.php @@ -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)){ diff --git a/src/block/Trapdoor.php b/src/block/Trapdoor.php index f80593a52..7e82f725b 100644 --- a/src/block/Trapdoor.php +++ b/src/block/Trapdoor.php @@ -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[] */ diff --git a/src/block/Tripwire.php b/src/block/Tripwire.php index 6aa56ce30..e1d8c431f 100644 --- a/src/block/Tripwire.php +++ b/src/block/Tripwire.php @@ -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; + } } diff --git a/src/block/TripwireHook.php b/src/block/TripwireHook.php index ac1c8df9a..e7c61c5a0 100644 --- a/src/block/TripwireHook.php +++ b/src/block/TripwireHook.php @@ -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 diff --git a/src/block/utils/PillarRotationTrait.php b/src/block/utils/PillarRotationTrait.php index 7ae8f8cc6..77144c4eb 100644 --- a/src/block/utils/PillarRotationTrait.php +++ b/src/block/utils/PillarRotationTrait.php @@ -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() */