37 private const TAG_LEGACY_ENTITY_TYPE_ID =
"EntityId";
38 private const TAG_ENTITY_TYPE_ID =
"EntityIdentifier";
39 private const TAG_SPAWN_DELAY =
"Delay";
40 private const TAG_SPAWN_POTENTIALS =
"SpawnPotentials";
41 private const TAG_SPAWN_DATA =
"SpawnData";
42 private const TAG_MIN_SPAWN_DELAY =
"MinSpawnDelay";
43 private const TAG_MAX_SPAWN_DELAY =
"MaxSpawnDelay";
44 private const TAG_SPAWN_PER_ATTEMPT =
"SpawnCount";
45 private const TAG_MAX_NEARBY_ENTITIES =
"MaxNearbyEntities";
46 private const TAG_REQUIRED_PLAYER_RANGE =
"RequiredPlayerRange";
47 private const TAG_SPAWN_RANGE =
"SpawnRange";
48 private const TAG_ENTITY_WIDTH =
"DisplayEntityWidth";
49 private const TAG_ENTITY_HEIGHT =
"DisplayEntityHeight";
50 private const TAG_ENTITY_SCALE =
"DisplayEntityScale";
52 public const DEFAULT_MIN_SPAWN_DELAY = 200;
53 public const DEFAULT_MAX_SPAWN_DELAY = 800;
55 public const DEFAULT_MAX_NEARBY_ENTITIES = 6;
56 public const DEFAULT_SPAWN_RANGE = 4;
57 public const DEFAULT_REQUIRED_PLAYER_RANGE = 16;
60 private string $entityTypeId =
":";
62 private ?
ListTag $spawnPotentials =
null;
66 private float $displayEntityWidth = 1.0;
67 private float $displayEntityHeight = 1.0;
68 private float $displayEntityScale = 1.0;
70 private int $spawnDelay = self::DEFAULT_MIN_SPAWN_DELAY;
71 private int $minSpawnDelay = self::DEFAULT_MIN_SPAWN_DELAY;
72 private int $maxSpawnDelay = self::DEFAULT_MAX_SPAWN_DELAY;
73 private int $spawnPerAttempt = 1;
74 private int $maxNearbyEntities = self::DEFAULT_MAX_NEARBY_ENTITIES;
75 private int $spawnRange = self::DEFAULT_SPAWN_RANGE;
76 private int $requiredPlayerRange = self::DEFAULT_REQUIRED_PLAYER_RANGE;
78 public function readSaveData(
CompoundTag $nbt) :
void{
79 if(($legacyIdTag = $nbt->
getTag(self::TAG_LEGACY_ENTITY_TYPE_ID)) instanceof
IntTag){
81 $this->entityTypeId = LegacyEntityIdToStringIdMap::getInstance()->legacyToString($legacyIdTag->getValue()) ??
":";
82 }elseif(($idTag = $nbt->
getTag(self::TAG_ENTITY_TYPE_ID)) instanceof
StringTag){
83 $this->entityTypeId = $idTag->getValue();
85 $this->entityTypeId =
":";
89 $this->spawnPotentials = $nbt->
getListTag(self::TAG_SPAWN_POTENTIALS);
91 $this->spawnDelay = $nbt->getShort(self::TAG_SPAWN_DELAY, self::DEFAULT_MIN_SPAWN_DELAY);
92 $this->minSpawnDelay = $nbt->getShort(self::TAG_MIN_SPAWN_DELAY, self::DEFAULT_MIN_SPAWN_DELAY);
93 $this->maxSpawnDelay = $nbt->getShort(self::TAG_MAX_SPAWN_DELAY, self::DEFAULT_MAX_SPAWN_DELAY);
94 $this->spawnPerAttempt = $nbt->getShort(self::TAG_SPAWN_PER_ATTEMPT, 1);
95 $this->maxNearbyEntities = $nbt->getShort(self::TAG_MAX_NEARBY_ENTITIES, self::DEFAULT_MAX_NEARBY_ENTITIES);
96 $this->requiredPlayerRange = $nbt->getShort(self::TAG_REQUIRED_PLAYER_RANGE, self::DEFAULT_REQUIRED_PLAYER_RANGE);
97 $this->spawnRange = $nbt->getShort(self::TAG_SPAWN_RANGE, self::DEFAULT_SPAWN_RANGE);
99 $this->displayEntityWidth = $nbt->getFloat(self::TAG_ENTITY_WIDTH, 1.0);
100 $this->displayEntityHeight = $nbt->getFloat(self::TAG_ENTITY_HEIGHT, 1.0);
101 $this->displayEntityScale = $nbt->getFloat(self::TAG_ENTITY_SCALE, 1.0);
105 $nbt->setString(self::TAG_ENTITY_TYPE_ID, $this->entityTypeId);
106 if($this->spawnData !==
null){
107 $nbt->
setTag(self::TAG_SPAWN_DATA, clone $this->spawnData);
109 if($this->spawnPotentials !==
null){
110 $nbt->
setTag(self::TAG_SPAWN_POTENTIALS, clone $this->spawnPotentials);
113 $nbt->
setShort(self::TAG_SPAWN_DELAY, $this->spawnDelay);
114 $nbt->
setShort(self::TAG_MIN_SPAWN_DELAY, $this->minSpawnDelay);
115 $nbt->
setShort(self::TAG_MAX_SPAWN_DELAY, $this->maxSpawnDelay);
116 $nbt->
setShort(self::TAG_SPAWN_PER_ATTEMPT, $this->spawnPerAttempt);
117 $nbt->
setShort(self::TAG_MAX_NEARBY_ENTITIES, $this->maxNearbyEntities);
118 $nbt->
setShort(self::TAG_REQUIRED_PLAYER_RANGE, $this->requiredPlayerRange);
119 $nbt->
setShort(self::TAG_SPAWN_RANGE, $this->spawnRange);
121 $nbt->
setFloat(self::TAG_ENTITY_WIDTH, $this->displayEntityWidth);
122 $nbt->
setFloat(self::TAG_ENTITY_HEIGHT, $this->displayEntityHeight);
123 $nbt->
setFloat(self::TAG_ENTITY_SCALE, $this->displayEntityScale);
127 $nbt->setString(self::TAG_ENTITY_TYPE_ID, $this->entityTypeId);
131 $nbt->
setFloat(self::TAG_ENTITY_SCALE, $this->displayEntityScale);