From c8cfbcd38a268056bb06bae7e1c267856b0fb18d Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Mon, 16 Jan 2023 20:07:36 +0300 Subject: [PATCH] sugarcane will drop if it will detect no water nearby --- src/API/BlockAPI.php | 1 - src/material/block/plant/SugarcaneBlock.php | 13 +++++++++++++ src/world/Position.php | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index 0d59cefa..c7d5bd63 100755 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -542,7 +542,6 @@ class BlockAPI{ } return $level; } - public function blockUpdateAround(Position $pos, $type = BLOCK_UPDATE_NORMAL, $delay = false){ if($delay !== false){ $this->scheduleBlockUpdate($pos->getSide(0), $delay, $type); diff --git a/src/material/block/plant/SugarcaneBlock.php b/src/material/block/plant/SugarcaneBlock.php index 691e9494..a93ccf41 100644 --- a/src/material/block/plant/SugarcaneBlock.php +++ b/src/material/block/plant/SugarcaneBlock.php @@ -35,6 +35,19 @@ class SugarcaneBlock extends FlowableBlock{ } public function onUpdate($type){ + + $down = $this->getSide(0); + if($down->getID() === GRASS or $down->getID() === DIRT or $down->getID() === SAND){ + $block0 = $down->getSide(2); + $block1 = $down->getSide(3); + $block2 = $down->getSide(4); + $block3 = $down->getSide(5); + if(!($block0 instanceof WaterBlock) and !($block1 instanceof WaterBlock) and !($block2 instanceof WaterBlock) and !($block3 instanceof WaterBlock)){ + $this->level->setBlock($this, new AirBlock(), true, false, true); + ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(SUGARCANE)); + return true; + } + } if($type === BLOCK_UPDATE_NORMAL){ $down = $this->getSide(0); if($down->isTransparent === true and $down->getID() !== SUGARCANE_BLOCK){ //Replace with common break method diff --git a/src/world/Position.php b/src/world/Position.php index ed6725b9..ec0c98d5 100644 --- a/src/world/Position.php +++ b/src/world/Position.php @@ -27,7 +27,7 @@ class Position extends Vector3{ return parent::distance($x, $y, $z); } - + public function __toString(){ return "Position(level=" . $this->level->getName() . ",x=" . $this->x . ",y=" . $this->y . ",z=" . $this->z . ")"; }