From 93765e8cc752e0a88f68e495e2ba37513f01f6b2 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Fri, 24 Feb 2023 19:39:38 +0300 Subject: [PATCH] more entity metadata --- src/PocketMinecraftServer.php | 1 + src/entity/Entity.php | 11 ++++---- src/entity/ai/tasks/TaskAttackPlayer.php | 12 +++++++++ src/entity/animal/Wolf.php | 19 +++++++++++++ src/entity/monster/Enderman.php | 27 +++++++++++++++++++ .../protocol/packet/SetEntityDataPacket.php | 4 ++- 6 files changed, 67 insertions(+), 7 deletions(-) diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index 9ced5b39..a9a3965d 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -29,6 +29,7 @@ class PocketMinecraftServer{ /*if(defined("DEBUG") and DEBUG >= 0){ @cli_set_process_title("NostalgiaCore ".MAJOR_VERSION); }*/ + console("[INFO] Starting Minecraft PE server on " . ($this->serverip === "0.0.0.0" ? "*" : $this->serverip) . ":" . $this->port); EntityRegistry::registerEntities(); define("BOOTUP_RANDOM", Utils::getRandomBytes(16)); diff --git a/src/entity/Entity.php b/src/entity/Entity.php index df63a37f..60e9ba22 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -835,7 +835,7 @@ class Entity extends Position } } - /* + /** * METADATA VALUES(EXPEREMENTAL) * ***************** * Types: Get input type of @@ -854,11 +854,10 @@ class Entity extends Position * 17 => ["type" => 6, "value" => [0, 0, 0]] --> Bed Position * * - * DATA FLAGS IDS - * 0 - fire - * 1 - crouching - * 2 - riding - no idea why doesnt it work - * 4 - inAction(ex.: using a bow) + * DATA FLAGS IDS
+ * 0 - fire
+ * 1 - crouching
+ * 4 - inAction(ex.: using a bow)
*/ public function getMetadata() { diff --git a/src/entity/ai/tasks/TaskAttackPlayer.php b/src/entity/ai/tasks/TaskAttackPlayer.php index 9d5a89c8..6756a246 100644 --- a/src/entity/ai/tasks/TaskAttackPlayer.php +++ b/src/entity/ai/tasks/TaskAttackPlayer.php @@ -13,6 +13,9 @@ class TaskAttackPlayer extends TaskTempt { if(!($this->target instanceof Entity) || ($ai->entity instanceof Spider && $ai->entity->level->isDay()) || ($this->target instanceof Entity && !$this->target->isPlayer()) || (Utils::distance_noroot($this->target, $ai->entity) > 256) || $this->target->level->getName() != $ai->entity->level->getName()){ $this->reset(); + if($ai->entity instanceof Enderman){ + $ai->entity->setAngry(false); + } return; } @@ -27,12 +30,21 @@ class TaskAttackPlayer extends TaskTempt --$this->attackTime; } + public function onEnd(EntityAI $ai){ + parent::onEnd($ai); + if($ai->entity instanceof Enderman){ + $ai->entity->setAngry(false); + } + } public function canBeExecuted(EntityAI $ai) { $target = $this->findTarget($ai->entity, 16); if(($ai->entity instanceof Spider && !$ai->entity->level->isDay()) || $target instanceof Entity && $target->class === ENTITY_PLAYER && $target->isPlayer()){ $this->target = $target; //TODO get rid of it $ai->entity->target = $target; + if($ai->entity instanceof Enderman){ //TODO find a better way + $ai->entity->setAngry(true); + } return true; } diff --git a/src/entity/animal/Wolf.php b/src/entity/animal/Wolf.php index b4401a5b..77aaa3d8 100644 --- a/src/entity/animal/Wolf.php +++ b/src/entity/animal/Wolf.php @@ -3,6 +3,16 @@ class Wolf extends Animal implements Tameable { const TYPE = MOB_WOLF; + + const WOLF_FLAGS = 14; + + const WF_SITTING = 1; + const WF_ANGRY = 2; + const WF_INTERESTED = 3; + + protected $interested = false; + protected $angry = false; + protected $sitting = false; public function __construct(Level $level, $eid, $class, $type = 0, $data = []){ $this->setSize(0.6, 0.8); parent::__construct($level, $eid, $class, $type, $data); @@ -11,6 +21,15 @@ class Wolf extends Animal implements Tameable $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 10, "generic"); } + public function getMetadata(){ + $ret = parent::getMetadata(); + $ret[self::WOLF_FLAGS] = ["type" => 0, "value" => + (($this->angry) << self::WF_ANGRY) ^ + (($this->interested) << self::WF_INTERESTED) ^ + (($this->sitting) << self::WF_SITTING) + ];//TODO toggles + return $ret; + } public function isTamed() { diff --git a/src/entity/monster/Enderman.php b/src/entity/monster/Enderman.php index 8b5ca28b..8484094c 100644 --- a/src/entity/monster/Enderman.php +++ b/src/entity/monster/Enderman.php @@ -4,8 +4,13 @@ class Enderman extends Monster { const TYPE = MOB_ENDERMAN; + const DATA_BLOCKID = 16; + const DATA_BLOCKMETA = 17; + const DATA_ANGRY = 18; public $forceTeleport; + protected $isAngry; + public function __construct(Level $level, $eid, $class, $type = 0, $data = []){ $this->setSize(0.6, 2.9); parent::__construct($level, $eid, $class, $type, $data); @@ -14,11 +19,33 @@ class Enderman extends Monster $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 40, "generic"); } + public function getMetadata(){ + $ret = parent::getMetadata(); + $ret[self::DATA_ANGRY] = ["type" => 0, "value" => (int)$this->isAngry]; + $ret[self::DATA_BLOCKID] = ["type" => 1, "value" => 0]; + $ret[self::DATA_BLOCKMETA] = ["type" => 1, "value" => 0]; //TODO carry blocks + return $ret; + } + + public function setAngry($t){ + if($this->isAngry != $t){ + $this->isAngry = $t; + $this->updateMetadata(); + } + } + + public function isAngry(){ + return $this->isAngry; + } + public function harm($dmg, $cause = "generic", $force = false){ parent::harm($dmg, $cause, $force); if($cause === "water"){ $this->randomTeleport(); } + if(is_numeric($cause) && $this->level->entityList[$cause]->isPlayer()){ + $this->setAngry(true); //TODO better way to find is it angry or not + } } public function randomTeleport(){ diff --git a/src/network/protocol/packet/SetEntityDataPacket.php b/src/network/protocol/packet/SetEntityDataPacket.php index 8626885d..f9191190 100644 --- a/src/network/protocol/packet/SetEntityDataPacket.php +++ b/src/network/protocol/packet/SetEntityDataPacket.php @@ -9,7 +9,9 @@ class SetEntityDataPacket extends RakNetDataPacket{ } public function decode(){ - + $this->eid = $this->getInt(); + $b = $this->get(true); + $this->metadata = Utils::readMetadata($b, true); } public function encode(){