diff --git a/src/API/EntityAPI.php b/src/API/EntityAPI.php index 26c09e96..5167617f 100644 --- a/src/API/EntityAPI.php +++ b/src/API/EntityAPI.php @@ -153,21 +153,30 @@ class EntityAPI{ $this->spawnToAll($entity, $pos->level); } + public function getNextEID(){ + return $this->eCnt++; + } + + public function addRaw(Entity $e){ + $eid = $e->eid; + $this->entities[$eid] = $e; + $cX = (int)$this->entities[$eid]->x >> 4; + $cZ = (int)$this->entities[$eid]->z >> 4; + $e->level->entityListPositioned["$cX $cZ"][$eid] = $eid; + $e->level->entityList[$eid] = &$this->entities[$eid]; + $this->server->handle("entity.add", $this->entities[$eid]); + return $e; + } public function add(Level $level, $class, $type = 0, $data = []){ - $eid = $this->eCnt++; + $eid = $this->getNextEID(); $efl = EntityRegistry::$entityList->getEntityFromTypeAndClass($type, $class); if($efl instanceof PropertyEntity){ $class = $efl->getEntityName(); - $this->entities[$eid] = new $class($level, $eid, $efl->getEntityClass(), $efl->getEntityType(), $data); + $e = new $class($level, $eid, $efl->getEntityClass(), $efl->getEntityType(), $data); }else{ - $this->entities[$eid] = new Entity($level, $eid, $class, $type, $data); + $e = new Entity($level, $eid, $class, $type, $data); } - $cX = (int)$this->entities[$eid]->x >> 4; - $cZ = (int)$this->entities[$eid]->z >> 4; - $level->entityListPositioned["$cX $cZ"][$eid] = $eid; - $level->entityList[$eid] = &$this->entities[$eid]; - $this->server->handle("entity.add", $this->entities[$eid]); - return $this->entities[$eid]; + return $this->addRaw($e); } public function spawnToAll(Entity $e){ diff --git a/src/Player.php b/src/Player.php index 3784f8da..6e902d7a 100755 --- a/src/Player.php +++ b/src/Player.php @@ -1115,7 +1115,7 @@ class Player{ 0b00000010 - enablePVP 0b00000100 - enablePVE 0b00001000 - field_3 (autojump) - 0b00010000 - field_0 + 0b00010000 - dayLightCycle (0 enabled 1 disabled) 0b00100000 - field_5 (nametags_visible) 0b01000000 - unused 0b10000000 - unused diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 1b640119..93aa9de4 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -178,6 +178,7 @@ class Entity extends Position break; case ENTITY_OBJECT: + if($this->type == OBJECT_PAINTING) break; $this->x = $this->data["TileX"] ?? $this->x; $this->y = $this->data["TileY"] ?? $this->y; $this->z = $this->data["TileZ"] ?? $this->z; diff --git a/src/entity/object/Painting.php b/src/entity/object/Painting.php index cdc13ec5..21f30927 100644 --- a/src/entity/object/Painting.php +++ b/src/entity/object/Painting.php @@ -7,6 +7,9 @@ class Painting extends Entity{ public $motive; public $direction; public $xPos, $yPos, $zPos; + + public $isValid = true; + public function __construct(Level $level, $eid, $class, $type = 0, $data = []){ parent::__construct($level, $eid, $class, $type, $data); $this->x = $this->data["TileX"] ?? $this->x; @@ -17,7 +20,7 @@ class Painting extends Entity{ $this->zPos = $this->data["zPos"] ?? (int)$this->z; $this->yPos = $this->data["yPos"] ?? (int)$this->y; - $this->setHealth(1, "generic"); + $this->health = 1; $this->canBeAttacked = true; $this->width = 1; $this->setSize(0.5, 0.5); @@ -66,9 +69,8 @@ class Painting extends Entity{ } if(count($tochoose) > 0){ $ind = mt_rand(0, count($tochoose)-1); - }else{ //shouldnt be possible in vanilla but possible here - $this->motive = "Kebab"; - $this->setDirection($dir); + }else{ + $this->isValid = false; return; } diff --git a/src/material/item/generic/PaintingItem.php b/src/material/item/generic/PaintingItem.php index 9beb1d0f..4ce688c8 100644 --- a/src/material/item/generic/PaintingItem.php +++ b/src/material/item/generic/PaintingItem.php @@ -56,8 +56,15 @@ class PaintingItem extends Item{ "yPos" => $target->y, "zPos" => $target->z, ); - $e = $server->api->entity->add($level, ENTITY_OBJECT, OBJECT_PAINTING, $data); - $server->api->entity->spawnToAll($e); + + $painting = new Painting($level, 0, ENTITY_OBJECT, OBJECT_PAINTING, $data); + if(!$painting->isValid){ + $player->sendInventory(); //force resync + return false; + } + $painting->eid = $server->api->entity->getNextEID(); + $server->api->entity->addRaw($painting); + $server->api->entity->spawnToAll($painting); if(($player->gamemode & 0x01) === 0x00){ $player->removeItem($this->getID(), $this->getMetadata(), 1, false); }