From c53d3c28fbdb5f1395eee271aa3621c62b9eb2c2 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 5 Dec 2018 19:11:54 +0000 Subject: [PATCH] Register a couple of simple missing redstone blocks --- src/pocketmine/block/BlockFactory.php | 6 +- src/pocketmine/block/RedstoneRepeater.php | 114 ++++++++++++++++++++++ src/pocketmine/block/RedstoneWire.php | 61 ++++++++++++ 3 files changed, 178 insertions(+), 3 deletions(-) create mode 100644 src/pocketmine/block/RedstoneRepeater.php create mode 100644 src/pocketmine/block/RedstoneWire.php diff --git a/src/pocketmine/block/BlockFactory.php b/src/pocketmine/block/BlockFactory.php index ad57b94243..676e6fa7fb 100644 --- a/src/pocketmine/block/BlockFactory.php +++ b/src/pocketmine/block/BlockFactory.php @@ -202,7 +202,7 @@ class BlockFactory{ self::registerBlock(new MonsterSpawner()); self::registerBlock(new WoodenStairs(Block::OAK_STAIRS, 0, "Oak Stairs")); self::registerBlock(new Chest()); - //TODO: REDSTONE_WIRE + self::registerBlock(new RedstoneWire()); self::registerBlock(new DiamondOre()); self::registerBlock(new Diamond()); self::registerBlock(new CraftingTable()); @@ -242,8 +242,8 @@ class BlockFactory{ //TODO: PORTAL self::registerBlock(new LitPumpkin()); self::registerBlock(new Cake()); - //TODO: REPEATER_BLOCK - //TODO: POWERED_REPEATER + self::registerBlock(new RedstoneRepeater()); + self::registerBlock((new RedstoneRepeater())->setPowered()); //TODO: INVISIBLEBEDROCK self::registerBlock(new Trapdoor()); //TODO: MONSTER_EGG diff --git a/src/pocketmine/block/RedstoneRepeater.php b/src/pocketmine/block/RedstoneRepeater.php new file mode 100644 index 0000000000..43f8b0b9a7 --- /dev/null +++ b/src/pocketmine/block/RedstoneRepeater.php @@ -0,0 +1,114 @@ +powered ? Block::POWERED_REPEATER : Block::UNPOWERED_REPEATER; + } + + public function readStateFromMeta(int $meta) : void{ + $this->facing = Bearing::toFacing($meta & 0x03); + $this->delay = ($meta >> 2) + 1; + } + + public function writeStateToMeta() : int{ + return Bearing::fromFacing($this->facing) | (($this->delay - 1) << 2); + } + + public function getStateBitmask() : int{ + return 0b1111; + } + + public function getName() : string{ + return "Redstone Repeater"; + } + + protected function recalculateBoundingBox() : ?AxisAlignedBB{ + return AxisAlignedBB::one()->trim(Facing::UP, 7 / 8); + } + + public function isPowered() : bool{ + return $this->powered; + } + + /** + * @param bool $powered + * + * @return $this + */ + public function setPowered(bool $powered = true) : self{ + $this->powered = $powered; + return $this; + } + + public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ + if(!$blockReplace->getSide(Facing::DOWN)->isTransparent()){ + if($player !== null){ + $this->facing = Facing::opposite(Bearing::toFacing($player->getDirection())); + } + + return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); + } + + return false; + } + + public function onActivate(Item $item, Player $player = null) : bool{ + if(++$this->delay > 4){ + $this->delay = 1; + } + $this->level->setBlock($this, $this); + return true; + } + + public function onNearbyBlockChange() : void{ + if($this->getSide(Facing::DOWN)->isTransparent()){ + $this->level->useBreakOn($this); + } + } + + //TODO: redstone functionality +} diff --git a/src/pocketmine/block/RedstoneWire.php b/src/pocketmine/block/RedstoneWire.php new file mode 100644 index 0000000000..f9dc52266c --- /dev/null +++ b/src/pocketmine/block/RedstoneWire.php @@ -0,0 +1,61 @@ +power = $meta; + } + + protected function writeStateToMeta() : int{ + return $this->power; + } + + public function getStateBitmask() : int{ + return 0b1111; + } + + public function getName() : string{ + return "Redstone"; + } + + public function readStateFromWorld() : void{ + parent::readStateFromWorld(); + //TODO: check connections to nearby redstone components + } +}