From a1aaa76e8441380dc3ea503762d0c0dffc821faa Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Wed, 7 Sep 2022 22:52:03 +0300 Subject: [PATCH] some changes to dirt & grass update --- src/PocketMinecraftServer.php | 1 - src/entity/object/Arrow.php | 19 ++++++++----------- src/material/block/solid/Dirt.php | 6 ++---- src/material/block/solid/Grass.php | 12 +++--------- 4 files changed, 13 insertions(+), 25 deletions(-) diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index ce28d625..69aece05 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -425,7 +425,6 @@ class PocketMinecraftServer{ if(!is_callable($callback)){ return false; } - $chcnt = $this->scheduleCnt++; $this->schedule[$chcnt] = [$callback, $data, $eventName]; $this->query("INSERT INTO actions (ID, interval, last, repeat) VALUES(" . $chcnt . ", " . ($ticks / 20) . ", " . microtime(true) . ", " . (((bool) $repeat) === true ? 1 : 0) . ");"); diff --git a/src/entity/object/Arrow.php b/src/entity/object/Arrow.php index af368ee2..40ebbf0e 100644 --- a/src/entity/object/Arrow.php +++ b/src/entity/object/Arrow.php @@ -4,9 +4,14 @@ class Arrow extends Projectile{ const TYPE = OBJECT_ARROW; function __construct(Level $level, $eid, $class, $type = 0, $data = array()){ parent::__construct($level, $eid, $class, $type, $data); - $this->server->schedule(1210, array($this, "update")); //Despawn + //$this->server->schedule(1210, array($this, "update")); //Despawn } public function update(){ + $now = microtime(true); + if(($now - $this->spawntime) >= 60){ + $this->close(); + return false; + } $f3 = 0.99; $f5 = 0.03; $this->move(new Vector3($this->speedX, $this->speedY, $this->speedZ)); @@ -16,7 +21,8 @@ class Arrow extends Projectile{ $this->server->api->handle("entity.move", $this); $this->server->api->handle("entity.motion", $this); $this->handleUpdate(); - $this->server->schedule(0, array($this, "update")); + $this->server->schedule(1, array($this, "update"), false); + $this->lastUpdate = $now; } public function handleUpdate(){ $pk = new MoveEntityPacket_PosRot; @@ -28,15 +34,6 @@ class Arrow extends Projectile{ $pk->pitch = $this->pitch; $this->server->api->player->broadcastPacket($this->level->players, $pk); } - public function environmentUpdate(){ - parent::environmentUpdate(); - $time = microtime(true); - if(($time - $this->spawntime) >= 60){ - $this->close(); - return false; - } - return true; - } public function shoot($d, $d1, $d2, $f, $f1){ //original name from 0.8.1 IDA decompilation, var names are taken from b1.7.3 $f2 = sqrt($d * $d + $d1 * $d1 + $d2 * $d2); diff --git a/src/material/block/solid/Dirt.php b/src/material/block/solid/Dirt.php index 60373e2e..976db4a8 100644 --- a/src/material/block/solid/Dirt.php +++ b/src/material/block/solid/Dirt.php @@ -20,18 +20,16 @@ class DirtBlock extends SolidBlock{ } public function onUpdate($type){ - $this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM); if($type === BLOCK_UPDATE_RANDOM){ if(mt_rand(0, 3) == 0){ $up = $this->getSide(1); if(($up->isTransparent === false) or ($up->isLiquid) or ($up->getID() == 60)) return false; if($this->getGrassInRadius()){ $this->level->setBlock($this, BlockAPI::get(GRASS, 0), true, false, true); - return BLOCK_UPDATE_RANDOM; } } } - return false; + return BLOCK_UPDATE_RANDOM; } public function getBlockID($x, $y, $z){ @@ -42,7 +40,7 @@ class DirtBlock extends SolidBlock{ $x = $this->x; $y = $this->y; $z = $this->z; - + if($this->getBlockID($x+1, $y, $z+1) == 2) return true; if($this->getBlockID($x+1, $y, $z) == 2) return true; if($this->getBlockID($x+1, $y, $z-1) == 2) return true; diff --git a/src/material/block/solid/Grass.php b/src/material/block/solid/Grass.php index 4b5ec7df..bbc6c580 100644 --- a/src/material/block/solid/Grass.php +++ b/src/material/block/solid/Grass.php @@ -46,16 +46,10 @@ class GrassBlock extends SolidBlock{ } public function onUpdate($type){ - $this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM); - if($type === BLOCK_UPDATE_RANDOM){ - if(mt_rand(0, 2) == 1){ - if($this->getSide(1)->isTransparent === false){ - $this->level->setBlock($this, BlockAPI::get(DIRT, 0), true, false, true); - return BLOCK_UPDATE_RANDOM; - } - } - return false; + if($type === BLOCK_UPDATE_RANDOM && !$this->getSide(1)->isTransparent && mt_rand(0, 2) == 1){ + $this->level->setBlock($this, BlockAPI::get(DIRT, 0), true, false, true); } + return BLOCK_UPDATE_RANDOM; } } \ No newline at end of file