From cf13bd4c430b0da4b289f16fd243a3243e981253 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Sun, 13 Nov 2022 02:47:35 +0300 Subject: [PATCH] zombies and skeletons will burn now: --- src/PocketMinecraftServer.php | 2 +- src/entity/Entity.php | 8 +--- src/entity/animal/Chicken.php | 1 + src/entity/monster/Skeleton.php | 25 +++++++++++ src/entity/monster/Zombie.php | 43 ++++++++++--------- .../protocol/packet/EntityEventPacket.php | 2 + 6 files changed, 54 insertions(+), 27 deletions(-) diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index e21cda8e..6a00d1cb 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -24,7 +24,7 @@ class PocketMinecraftServer{ private function load(){ global $dolog; - + $this->version = new VersionString(); /*if(defined("DEBUG") and DEBUG >= 0){ @cli_set_process_title("NostalgiaCore ".MAJOR_VERSION); diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 33150754..30230cb8 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -1285,12 +1285,8 @@ class Entity extends Position if($harm === true){ $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 + $pk->event = EntityEventPacket::ENTITY_DAMAGE; + $this->server->api->player->broadcastPacket($this->level->players, $pk); } if($this->player instanceof Player){ $pk = new SetHealthPacket(); diff --git a/src/entity/animal/Chicken.php b/src/entity/animal/Chicken.php index 06b207fc..27554646 100644 --- a/src/entity/animal/Chicken.php +++ b/src/entity/animal/Chicken.php @@ -17,6 +17,7 @@ class Chicken extends Animal{ } public function update(){ + parent::update(); if($this->timeUntilEgg-- <= 0){ $this->dropAnEgg(); $this->timeUntilEgg = mt_rand(0,6000) + 6000; diff --git a/src/entity/monster/Skeleton.php b/src/entity/monster/Skeleton.php index 73f49751..963923d8 100644 --- a/src/entity/monster/Skeleton.php +++ b/src/entity/monster/Skeleton.php @@ -10,6 +10,31 @@ class Skeleton extends Monster{ $this->update(); } + public function updateBurning(){ + if($this->fire > 0 or $this->server->api->time->getPhase($this->level->getTime()) != "day"){ + return false; + } + + for($y = $this->y; $y < 129; $y++){ + $block = $this->level->getBlockWithoutVector($this->x, $y, $this->z); + if($block->isSolid){ + return false; + } + } + if($block->getID() === AIR){ + $this->fire = 160; //Value from 0.8.1 + $this->updateMetadata(); + return true; + }else{ + return false; + } + } + + public function update(){ + $this->updateBurning(); + parent::update(); + } + public function getDrops(){ return [ [ARROW, 0, mt_rand(0,2)], diff --git a/src/entity/monster/Zombie.php b/src/entity/monster/Zombie.php index 723fa84d..0a38a623 100644 --- a/src/entity/monster/Zombie.php +++ b/src/entity/monster/Zombie.php @@ -8,28 +8,31 @@ 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 updateBurning(){ + if($this->fire > 0 or $this->server->api->time->getPhase($this->level->getTime()) != "day"){ + return false; + } + + for($y = $this->y; $y < 129; $y++){ + $block = $this->level->getBlockWithoutVector($this->x, $y, $this->z); + if($block->isSolid){ + return false; + } + } + if($block->getID() === AIR){ + $this->fire = 160; //Value from 0.8.1 + $this->updateMetadata(); + return true; + }else{ + return false; + } + } + + public function update(){ + $this->updateBurning(); + parent::update(); } public function getDrops(){ diff --git a/src/network/protocol/packet/EntityEventPacket.php b/src/network/protocol/packet/EntityEventPacket.php index 75c4d570..fed2c035 100644 --- a/src/network/protocol/packet/EntityEventPacket.php +++ b/src/network/protocol/packet/EntityEventPacket.php @@ -4,6 +4,8 @@ class EntityEventPacket extends RakNetDataPacket{ public $eid; public $event; + const ENTITY_DAMAGE = 2; + public function pid(){ return ProtocolInfo::ENTITY_EVENT_PACKET; }