From 933b92f41e95fb9788129cc0ff40ac9a8740e7ec Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Sat, 12 Apr 2025 18:49:22 +0300 Subject: [PATCH] falling sand will schedule update onplace --- src/entity/object/FallingSand.php | 59 +++++++++++++++-------------- src/material/block/GenericBlock.php | 40 ++++++++++++------- 2 files changed, 57 insertions(+), 42 deletions(-) diff --git a/src/entity/object/FallingSand.php b/src/entity/object/FallingSand.php index 3271929c..517d4ca7 100644 --- a/src/entity/object/FallingSand.php +++ b/src/entity/object/FallingSand.php @@ -23,36 +23,37 @@ class FallingSand extends Entity{ public function update($now){ if($this->closed) return; - if( $this->data["Tile"] == AIR) $this->close(); - else { - $this->lastX = $this->x; - $this->lastY = $this->y; - $this->lastZ = $this->z; - ++$this->fallTime; - $this->speedY -= 0.04; - $this->move($this->speedX, $this->speedY, $this->speedZ); - - $this->speedX *= 0.98; - $this->speedY *= 0.98; - $this->speedZ *= 0.98; - - $x = floor($this->x); - $y = floor($this->y); - $z = floor($this->z); - - if($this->onGround){ - $this->speedX *= 0.7; - $this->speedZ *= 0.7; - $this->speedY *= -0.5; + if( $this->data["Tile"] == AIR) { + $this->close(); + return; + } + $this->lastX = $this->x; + $this->lastY = $this->y; + $this->lastZ = $this->z; + ++$this->fallTime; + $this->speedY -= 0.04; + $this->move($this->speedX, $this->speedY, $this->speedZ); + + $this->speedX *= 0.98; + $this->speedY *= 0.98; + $this->speedZ *= 0.98; + + $x = floor($this->x); + $y = floor($this->y); + $z = floor($this->z); + + if($this->onGround){ + $this->speedX *= 0.7; + $this->speedZ *= 0.7; + $this->speedY *= -0.5; + $this->close(); + //TODO vanilla-like checking? + $this->level->fastSetBlockUpdate($x, $y, $z, $this->data["Tile"], 0, true); //TODO add metadata + }elseif(($blockAt = $this->level->level->getBlockID($x, $y, $z)) != 0){ + //TODO vanilla-like checking? + if(StaticBlock::getIsTransparent($blockAt) && !StaticBlock::getIsLiquid($blockAt)){ $this->close(); - //TODO vanilla-like checking? - $this->level->fastSetBlockUpdate($x, $y, $z, $this->data["Tile"], 0, true); //TODO add metadata - }elseif(($blockAt = $this->level->level->getBlockID($x, $y, $z)) != 0){ - //TODO vanilla-like checking? - if(StaticBlock::getIsTransparent($blockAt) && !StaticBlock::getIsLiquid($blockAt)){ - $this->close(); - ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->data["Tile"], 0, 1)); //TODO add metadata - } + ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->data["Tile"], 0, 1)); //TODO add metadata } } } diff --git a/src/material/block/GenericBlock.php b/src/material/block/GenericBlock.php index a4867017..e0780dd1 100644 --- a/src/material/block/GenericBlock.php +++ b/src/material/block/GenericBlock.php @@ -47,6 +47,32 @@ class GenericBlock extends Block{ return $this->level->setBlock($this, new AirBlock(), true, false, true); } + public static function onPlace(Level $level, $x, $y, $z){ + [$id, $meta] = $level->level->getBlock($x, $y, $z); + if(StaticBlock::getHasPhysics($id)){ + ServerAPI::request()->api->block->scheduleBlockUpdateXYZ($level, $x, $y, $z, BLOCK_UPDATE_SCHEDULED, 2); //tick delay == 2 + }else{ + parent::onPlace($level, $x, $y, $z); + } + } + + public static function onUpdate(Level $level, $x, $y, $z, $type){ + [$id, $meta] = $level->level->getBlock($x, $y, $z); + $down = $level->level->getBlockID($x, $y - 1, $z); + if($down == AIR || StaticBlock::getIsLiquid($down)){ + $data = array( + "x" => $x + 0.5, + "y" => $y - 0.5, + "z" => $z + 0.5, + "Tile" => $id, + ); + $server = ServerAPI::request(); + $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); + $e = $server->api->entity->add($level, ENTITY_FALLING, FALLING_SAND, $data); + $server->api->entity->spawnToAll($e); + } + } + /** * @param integer $type * @@ -55,19 +81,7 @@ class GenericBlock extends Block{ public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ [$id, $meta] = $level->level->getBlock($x, $y, $z); if(StaticBlock::getHasPhysics($id)){ //TODO move from here to different class - $down = $level->level->getBlockID($x, $y - 1, $z); - if($down == AIR || StaticBlock::getIsLiquid($down)){ - $data = array( - "x" => $x + 0.5, - "y" => $y - 0.5, - "z" => $z + 0.5, - "Tile" => $id, - ); - $server = ServerAPI::request(); - $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true); - $e = $server->api->entity->add($level, ENTITY_FALLING, FALLING_SAND, $data); - $server->api->entity->spawnToAll($e); - } + static::onUpdate($level, $x, $y, $z, BLOCK_UPDATE_NORMAL); } }