From c0f4821fbc8d1901ec1f97d1adc314a3f9788d01 Mon Sep 17 00:00:00 2001 From: ArkQuark <74979909+ArkQuark@users.noreply.github.com> Date: Thu, 3 Nov 2022 17:02:47 +0300 Subject: [PATCH] Sheep can eat grass, zombie can burn on day --- src/entity/Entity.php | 22 +++++++++++++++------- src/entity/animal/Sheep.php | 22 +++++++++++++++++++++- src/entity/monster/Zombie.php | 22 ++++++++++++++++++++++ 3 files changed, 58 insertions(+), 8 deletions(-) diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 6c3a51d2..ae38e60b 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -1278,10 +1278,14 @@ class Entity extends Position $this->health = min(127, max(- 127, $health)); $this->server->query("UPDATE entities SET health = " . $this->health . " WHERE EID = " . $this->eid . ";"); if($harm === true){ - $this->server->api->dhandle("entity.event", array( + $pk = new EntityEventPacket; + $pk->eid = $this->eid; + $pk->event = 2; + $this->server->api->player->broadcastPacket($this->level->players, $pk); + /*$this->server->api->dhandle("entity.event", array( "entity" => $this, "event" => 2 - )); // Ouch! sound + )); // Ouch! sound*/ } if($this->player instanceof Player){ $pk = new SetHealthPacket(); @@ -1306,18 +1310,22 @@ class Entity extends Position $pk->yaw = 0; $pk->pitch = 0; $this->server->api->player->broadcastPacket($this->level->players, $pk); - } else{ - $this->server->api->dhandle("entity.event", array( + }else{ + $pk = new EntityEventPacket; + $pk->eid = $this->eid; + $pk->event = 3; + $this->server->api->player->broadcastPacket($this->level->players, $pk); + /*$this->server->api->dhandle("entity.event", [ "entity" => $this, "event" => 3 - )); // Entity dead + ]); // Entity dead*/ } if($this->player instanceof Player){ $this->player->blocked = true; - $this->server->api->dhandle("player.death", array( + $this->server->api->dhandle("player.death", [ "player" => $this->player, "cause" => $cause - )); + ]); if($this->server->api->getProperty("hardcore") == 1){ $this->server->api->ban->ban($this->player->username); } diff --git a/src/entity/animal/Sheep.php b/src/entity/animal/Sheep.php index 2b6f5c14..5930c2ab 100644 --- a/src/entity/animal/Sheep.php +++ b/src/entity/animal/Sheep.php @@ -11,6 +11,25 @@ class Sheep extends Animal{ $this->setSize($this->isBaby() ? 0.45 : 0.9, $this->isBaby() ? 0.675 : 1.3); $this->setSpeed(0.25); $this->update(); + if($this->isSheared() and Entity::$updateOnTick){ //if ai enabled + $this->server->schedule(mt_rand(60, 400), [$this, "eatGrass"], null, true); //unknown time + }elseif($this->isBaby() and Entity::$updateOnTick){ + $this->server->schedule(mt_rand(400, 1000), [$this, "eatGrass"], null, true); //unknown time + } + } + + public function eatGrass(){ + $downBlock = $this->level->getBlock(new Vector3($this->x, $this->y-1, $this->z)); + if($downBlock->getID() !== GRASS){ + //console("eww i don't wanna eat this $downBlock"); + return false; + } + $pk = new EntityEventPacket; + $pk->eid = $this->eid; + $pk->event = 10; + $this->server->api->player->broadcastPacket($this->level->players, $pk); + $this->server->schedule(38, [$this, "setSheared"], false); + $this->level->setblock(new Position($this->x, $this->y-1, $this->z, $this->level), new DirtBlock()); } public function setSheared($v = null){ @@ -28,7 +47,7 @@ class Sheep extends Animal{ public function getDrops(){ return $this->isBaby() ? parent::getDrops() : [ - [WOOL, $this->getColor() & 0x0F, 1], + [WOOL, $this->getColor() & 0x0F, 1] ]; } @@ -43,6 +62,7 @@ class Sheep extends Animal{ if(!$this->isSheared()){ $this->setSheared(1); $this->server->api->entity->drop($this, BlockAPI::getItem(WOOL, $this->getColor(), mt_rand(1, 3))); + //$this->server->schedule(20, [$this, "eatGrass"]); if($slot->getMetadata() >= $slot->getMaxDurability()){ $this->removeItem($slot->getID(), $slot->getMetadata(), $slot->count, true); } diff --git a/src/entity/monster/Zombie.php b/src/entity/monster/Zombie.php index f19a795f..723fa84d 100644 --- a/src/entity/monster/Zombie.php +++ b/src/entity/monster/Zombie.php @@ -8,6 +8,28 @@ class Zombie extends Monster{ $this->setSize(0.6, 1.85); $this->setSpeed(0.23); $this->update(); + //$this->server->schedule(20, [$this, "burnable"], null, true); //todo + } + + public function burnable(){ + if($this->fire > 0 or $this->server->api->time->getPhase($this->level->getTime()) == "day"){ + return; + } + $y = $this->y; + for(; $y < 129; $y++){ + $block = $this->level->getBlock(new Vector3($this->x, $y, $this->z)); + if($block->isSolid){ //? + return false; + } + } + $block = $this->level->getBlock(new Vector3($this->x, $y, $this->z))->getID(); + if($block === AIR){ + $this->fire = 200; + $this->updateMetadata(); + return true; + }else{ + return false; + } } public function getDrops(){