more entity metadata

This commit is contained in:
GameHerobrine 2023-02-24 19:39:38 +03:00
parent 447638816e
commit 93765e8cc7
6 changed files with 67 additions and 7 deletions

View file

@ -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));

View file

@ -835,7 +835,7 @@ class Entity extends Position
}
}
/*
/**
* METADATA VALUES(EXPEREMENTAL)
* *****************
* Types: Get input type of <value>
@ -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<br>
* 0 - fire<br>
* 1 - crouching<br>
* 4 - inAction(ex.: using a bow)<br>
*/
public function getMetadata()
{

View file

@ -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;
}

View file

@ -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()
{

View file

@ -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(){

View file

@ -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(){