painting wont be placed if there is a painting already

This commit is contained in:
GameHerobrine 2024-11-28 04:41:55 +03:00
parent d1121e862e
commit 0963f09ea1
5 changed files with 35 additions and 16 deletions

View file

@ -153,21 +153,30 @@ class EntityAPI{
$this->spawnToAll($entity, $pos->level); $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 = []){ public function add(Level $level, $class, $type = 0, $data = []){
$eid = $this->eCnt++; $eid = $this->getNextEID();
$efl = EntityRegistry::$entityList->getEntityFromTypeAndClass($type, $class); $efl = EntityRegistry::$entityList->getEntityFromTypeAndClass($type, $class);
if($efl instanceof PropertyEntity){ if($efl instanceof PropertyEntity){
$class = $efl->getEntityName(); $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{ }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; return $this->addRaw($e);
$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];
} }
public function spawnToAll(Entity $e){ public function spawnToAll(Entity $e){

View file

@ -1115,7 +1115,7 @@ class Player{
0b00000010 - enablePVP 0b00000010 - enablePVP
0b00000100 - enablePVE 0b00000100 - enablePVE
0b00001000 - field_3 (<?>autojump) 0b00001000 - field_3 (<?>autojump)
0b00010000 - field_0 0b00010000 - dayLightCycle (0 enabled 1 disabled)
0b00100000 - field_5 (<?>nametags_visible) 0b00100000 - field_5 (<?>nametags_visible)
0b01000000 - unused 0b01000000 - unused
0b10000000 - unused 0b10000000 - unused

View file

@ -178,6 +178,7 @@ class Entity extends Position
break; break;
case ENTITY_OBJECT: case ENTITY_OBJECT:
if($this->type == OBJECT_PAINTING) break;
$this->x = $this->data["TileX"] ?? $this->x; $this->x = $this->data["TileX"] ?? $this->x;
$this->y = $this->data["TileY"] ?? $this->y; $this->y = $this->data["TileY"] ?? $this->y;
$this->z = $this->data["TileZ"] ?? $this->z; $this->z = $this->data["TileZ"] ?? $this->z;

View file

@ -7,6 +7,9 @@ class Painting extends Entity{
public $motive; public $motive;
public $direction; public $direction;
public $xPos, $yPos, $zPos; public $xPos, $yPos, $zPos;
public $isValid = true;
public function __construct(Level $level, $eid, $class, $type = 0, $data = []){ public function __construct(Level $level, $eid, $class, $type = 0, $data = []){
parent::__construct($level, $eid, $class, $type, $data); parent::__construct($level, $eid, $class, $type, $data);
$this->x = $this->data["TileX"] ?? $this->x; $this->x = $this->data["TileX"] ?? $this->x;
@ -17,7 +20,7 @@ class Painting extends Entity{
$this->zPos = $this->data["zPos"] ?? (int)$this->z; $this->zPos = $this->data["zPos"] ?? (int)$this->z;
$this->yPos = $this->data["yPos"] ?? (int)$this->y; $this->yPos = $this->data["yPos"] ?? (int)$this->y;
$this->setHealth(1, "generic"); $this->health = 1;
$this->canBeAttacked = true; $this->canBeAttacked = true;
$this->width = 1; $this->width = 1;
$this->setSize(0.5, 0.5); $this->setSize(0.5, 0.5);
@ -66,9 +69,8 @@ class Painting extends Entity{
} }
if(count($tochoose) > 0){ if(count($tochoose) > 0){
$ind = mt_rand(0, count($tochoose)-1); $ind = mt_rand(0, count($tochoose)-1);
}else{ //shouldnt be possible in vanilla but possible here }else{
$this->motive = "Kebab"; $this->isValid = false;
$this->setDirection($dir);
return; return;
} }

View file

@ -56,8 +56,15 @@ class PaintingItem extends Item{
"yPos" => $target->y, "yPos" => $target->y,
"zPos" => $target->z, "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){ if(($player->gamemode & 0x01) === 0x00){
$player->removeItem($this->getID(), $this->getMetadata(), 1, false); $player->removeItem($this->getID(), $this->getMetadata(), 1, false);
} }