mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 03:59:43 +00:00
painting wont be placed if there is a painting already
This commit is contained in:
parent
d1121e862e
commit
0963f09ea1
5 changed files with 35 additions and 16 deletions
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue