From 3bbdc5ab5b609ebe6a78adeca15eaf214e77ae9d Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 23 Dec 2017 15:11:48 +0000 Subject: [PATCH] Implemented chorus fruit --- src/pocketmine/item/ChorusFruit.php | 84 +++++++++++++++++++++++++++++ src/pocketmine/item/ItemFactory.php | 2 +- 2 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 src/pocketmine/item/ChorusFruit.php diff --git a/src/pocketmine/item/ChorusFruit.php b/src/pocketmine/item/ChorusFruit.php new file mode 100644 index 000000000..385596b4b --- /dev/null +++ b/src/pocketmine/item/ChorusFruit.php @@ -0,0 +1,84 @@ +getFloorX() - 8; + $minY = $consumer->getFloorY() - 8; + $minZ = $consumer->getFloorZ() - 8; + + $maxX = $minX + 16; + $maxY = $minY + 16; + $maxZ = $minZ + 16; + + $level = $consumer->getLevel(); + assert($level !== null); + + for($attempts = 0; $attempts < 16; ++$attempts){ + $x = mt_rand($minX, $maxX); + $y = mt_rand($minY, $maxY); + $z = mt_rand($minZ, $maxZ); + + while($y > 0 and !$level->getBlockAt($x, $y, $z)->isSolid()){ + $y--; + } + + $blockUp = $level->getBlockAt($x, $y + 1, $z); + $blockUp2 = $level->getBlockAt($x, $y + 2, $z); + if($blockUp->isSolid() or $blockUp instanceof Liquid or $blockUp2->isSolid() or $blockUp2 instanceof Liquid){ + continue; + } + + //Sounds are broadcasted at both source and destination + $level->addSound(new EndermanTeleportSound($consumer->asVector3())); + $consumer->teleport(new Vector3($x + 0.5, $y + 1, $z + 0.5)); + $level->addSound(new EndermanTeleportSound($consumer->asVector3())); + + break; + } + } +} \ No newline at end of file diff --git a/src/pocketmine/item/ItemFactory.php b/src/pocketmine/item/ItemFactory.php index 37518577c..38876150f 100644 --- a/src/pocketmine/item/ItemFactory.php +++ b/src/pocketmine/item/ItemFactory.php @@ -214,7 +214,7 @@ class ItemFactory{ self::registerItem(new ItemBlock(Block::JUNGLE_DOOR_BLOCK, 0, Item::JUNGLE_DOOR)); self::registerItem(new ItemBlock(Block::ACACIA_DOOR_BLOCK, 0, Item::ACACIA_DOOR)); self::registerItem(new ItemBlock(Block::DARK_OAK_DOOR_BLOCK, 0, Item::DARK_OAK_DOOR)); - //TODO: CHORUS_FRUIT + self::registerItem(new ChorusFruit()); self::registerItem(new Item(Item::CHORUS_FRUIT_POPPED, 0, "Popped Chorus Fruit")); //TODO: DRAGON_BREATH