SpawnMarker class
Пакет: com.hypixel.hytale.server.spawning.assets.spawnmarker.config
Файл: com/hypixel/hytale/server/spawning/assets/spawnmarker/config/SpawnMarker.java
implements: JsonAssetWithMap<String, DefaultAssetMap<String, SpawnMarker>>
Поля (13)
| Модификаторы | Тип | Имя |
|---|---|---|
|
|
ASSET_STORE |
final |
AssetBuilderCodec<String, SpawnMarker> |
CODEC |
|
public static final BuilderCodec<SpawnMarker.SpawnConfiguration> |
CODEC |
|
public static final SpawnMarker.SpawnConfiguration[] |
EMPTY_ARRAY |
|
protected String |
flockDefinitionId |
|
protected int |
flockDefinitionIndex |
|
protected String |
npc |
|
protected double |
realtimeRespawnTime |
|
protected Duration |
spawnAfterGameTime |
|
int |
var1 |
|
int |
var1 |
|
IWeightedMap |
var3 |
|
protected double |
weight |
Методы (23)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
abstract |
throw new |
IllegalArgumentExceptionthrow new IllegalArgumentException("Unknown key! " + this.flockDefinitionId) |
|
public |
SpawnConfigurationpublic SpawnConfiguration(String var1, double var2, double var4, Duration var6, String var7) |
|
protected |
SpawnConfigurationprotected SpawnConfiguration() |
static |
DefaultAssetMap<String, SpawnMarker> |
getAssetMapDefaultAssetMap<String, SpawnMarker> getAssetMap() |
static |
AssetStore<String, SpawnMarker, DefaultAssetMap<String, SpawnMarker>> |
getAssetStoreAssetStore<String, SpawnMarker, DefaultAssetMap<String, SpawnMarker>> getAssetStore() |
public |
double |
getDeactivationDistancedouble getDeactivationDistance() |
public |
double |
getDeactivationTimedouble getDeactivationTime() |
public |
double |
getExclusionRadiusdouble getExclusionRadius() |
|
public FlockAsset |
getFlockDefinitionpublic FlockAsset getFlockDefinition() |
|
public String |
getFlockDefinitionIdpublic String getFlockDefinitionId() |
|
public int |
getFlockDefinitionIndexpublic int getFlockDefinitionIndex() |
public |
String |
getIdString getId() |
public |
double |
getMaxDropHeightSquareddouble getMaxDropHeightSquared() |
public |
String |
getModelString getModel() |
|
public String |
getNpcpublic String getNpc() |
|
public double |
getRealtimeRespawnTimepublic double getRealtimeRespawnTime() |
|
public Duration |
getSpawnAfterGameTimepublic Duration getSpawnAfterGameTime() |
|
public double |
getWeightpublic double getWeight() |
|
|
if if(ASSET_STORE == null) |
|
|
if if(this.flockDefinitionIndex == Integer.MIN_VALUE && this.flockDefinitionId != null) |
|
|
if if(var1 == Integer.MIN_VALUE) |
public |
boolean |
isManualTriggerboolean isManualTrigger() |
public |
boolean |
isRealtimeRespawnboolean isRealtimeRespawn() |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.server.spawning.assets.spawnmarker.config;
class="kw">import com.hypixel.hytale.assetstore.AssetExtraInfo;
class="kw">import com.hypixel.hytale.assetstore.AssetKeyValidator;
class="kw">import com.hypixel.hytale.assetstore.AssetRegistry;
class="kw">import com.hypixel.hytale.assetstore.AssetStore;
class="kw">import com.hypixel.hytale.assetstore.codec.AssetBuilderCodec;
class="kw">import com.hypixel.hytale.assetstore.map.DefaultAssetMap;
class="kw">import com.hypixel.hytale.assetstore.map.JsonAssetWithMap;
class="kw">import com.hypixel.hytale.codec.Codec;
class="kw">import com.hypixel.hytale.codec.KeyedCodec;
class="kw">import com.hypixel.hytale.codec.builder.BuilderCodec;
class="kw">import com.hypixel.hytale.codec.schema.metadata.ui.UIPropertyTitle;
class="kw">import com.hypixel.hytale.codec.validation.ValidatorCache;
class="kw">import com.hypixel.hytale.codec.validation.Validators;
class="kw">import com.hypixel.hytale.common.map.IWeightedElement;
class="kw">import com.hypixel.hytale.common.map.IWeightedMap;
class="kw">import com.hypixel.hytale.server.core.asset.type.model.config.ModelAsset;
class="kw">import com.hypixel.hytale.server.core.codec.WeightedMapCodec;
class="kw">import com.hypixel.hytale.server.flock.config.FlockAsset;
class="kw">import com.hypixel.hytale.server.npc.validators.NPCRoleValidator;
class="kw">import java.time.Duration;
class="kw">import javax.annotation.Nullable;
class="kw">public class SpawnMarker class="kw">implements JsonAssetWithMap<String, DefaultAssetMap<String, SpawnMarker>> {
class="kw">public class="kw">static class="kw">final AssetBuilderCodec<String, SpawnMarker> CODEC = AssetBuilderCodec.<String, SpawnMarker>builder(
SpawnMarker.class,
SpawnMarker::new,
Codec.STRING,
(var0, var1) -> var0.id = var1,
var0 -> var0.id,
(var0, var1) -> var0.data = var1,
var0 -> var0.data
)
.documentation(
"A marker designed to spawn NPCs with its current position and rotation. When the NPC dies, a new NPC will spawn after a defined cooldown. This cooldown can be specified either in terms of game time or real time and begins to count down from the moment the mob dies."
)
.<String>appendInherited(
new KeyedCodec<>("Model", Codec.STRING), (var0, var1) -> var0.model = var1, var0 -> var0.model, (var0, var1) -> var0.model = var1.model
)
.documentation(
"The optional visual representation to use in the world when in creative mode (this has a class="kw">default value which can be specified using **DefaultSpawnMarkerModel** in the server config for the spawning plugin)."
)
.addValidator(ModelAsset.VALIDATOR_CACHE.getValidator())
.add()
.<IWeightedMap<SpawnMarker.SpawnConfiguration>>appendInherited(
new KeyedCodec<>("NPCs", new WeightedMapCodec<>(SpawnMarker.SpawnConfiguration.CODEC, SpawnMarker.SpawnConfiguration.EMPTY_ARRAY)),
(var0, var1) -> var0.weightedConfigurations = var1,
var0 -> var0.weightedConfigurations,
(var0, var1) -> var0.weightedConfigurations = var1.weightedConfigurations
)
.documentation("A weighted list of NPCs and their configurations.")
.metadata(new UIPropertyTitle("NPCs"))
.addValidator(Validators.nonNull())
.add()
.<Double>appendInherited(
new KeyedCodec<>("ExclusionRadius", Codec.DOUBLE),
(var0, var1) -> var0.exclusionRadius = var1,
var0 -> var0.exclusionRadius,
(var0, var1) -> var0.exclusionRadius = var1.exclusionRadius
)
.documentation("A radius used to prevent a marker from spawning new NPCs if a player in adventure mode is within range.")
.addValidator(Validators.greaterThanOrEqual(0.0))
.add()
.<Double>appendInherited(
new KeyedCodec<>("MaxDropHeight", Codec.DOUBLE),
(var0, var1) -> var0.maxDropHeightSquared = var1 * var1,
var0 -> Math.sqrt(var0.maxDropHeightSquared),
(var0, var1) -> var0.maxDropHeightSquared = var1.maxDropHeightSquared
)
.documentation(
"A maximum offset from the marker's position at which the mob can be spawned. Ground mobs are spawned directly on the ground, so if the marker is high in the air due to the building having been destroyed, if the distance between the marker and the ground is greater than this, the marker will not spawn mobs."
)
.addValidator(Validators.greaterThan(0.0))
.add()
.<Boolean>appendInherited(
new KeyedCodec<>("RealtimeRespawn", Codec.BOOLEAN),
(var0, var1) -> var0.realtimeRespawn = var1,
var0 -> var0.realtimeRespawn,
(var0, var1) -> var0.realtimeRespawn = var1.realtimeRespawn
)
.documentation("Whether to use real time or game time for the respawn timer.")
.add()
.<Boolean>appendInherited(
new KeyedCodec<>("ManualTrigger", Codec.BOOLEAN),
(var0, var1) -> var0.manualTrigger = var1,
var0 -> var0.manualTrigger,
(var0, var1) -> var0.manualTrigger = var1.manualTrigger
)
.documentation("Indicates if the spawn marker has to be triggered manually or not.")
.add()
.<Double>appendInherited(
new KeyedCodec<>("DeactivationDistance", Codec.DOUBLE),
(var0, var1) -> var0.deactivationDistance = var1,
var0 -> var0.deactivationDistance,
(var0, var1) -> var0.deactivationDistance = var1.deactivationDistance
)
.documentation("If no players are inside this range, the spawn marker will deactivate and store its NPCs once this distance is exceeded.")
.addValidator(Validators.greaterThan(0.0))
.add()
.<Double>appendInherited(
new KeyedCodec<>("DeactivationTime", Codec.DOUBLE),
(var0, var1) -> var0.deactivationTime = var1,
var0 -> var0.deactivationTime,
(var0, var1) -> var0.deactivationTime = var1.deactivationTime
)
.documentation("The delay before deactivation happens when no players are in range.")
.addValidator(Validators.greaterThan(0.0))
.add()
.validator(
(var0, var1) -> {
boolean var2 = var0.isRealtimeRespawn();
IWeightedMap var3 = var0.getWeightedConfigurations();
if (var3 != null && var3.size() != 0) {
var3.forEach(
var3x -> {
if (var2 && var3x.getRealtimeRespawnTime() <= 0.0) {
var1.fail(
String.format(
"Value for RealtimeRespawn in %s:%s must be greater than zero if using realtime spawning", var0.getId(), var3x.getNpc()
)
);
} else if (!var2 && var3x.getSpawnAfterGameTime() == null) {
var1.fail(
String.format("Value for SpawnAfterGameTime in %s:%s must be provided if using game time spawning", var0.getId(), var3x.getNpc())
);
} else {
if (var3x.getSpawnAfterGameTime() != null && var3x.getRealtimeRespawnTime() > 0.0) {
var1.warn(
String.format(
"%s:%s defines both RealtimeRespawn and SpawnAfterGameTime despite being set to %s spawning",
var0.getId(),
var3x.getNpc(),
var2 ? "realtime" : "game time"
)
);
}
}
}
);
} else {
var1.fail(String.format("Spawn marker %s must define at least one NPC configuration to spawn", var0.getId()));
}
}
)
.build();
class="kw">public class="kw">static class="kw">final ValidatorCache<String> VALIDATOR_CACHE = new ValidatorCache<>(new AssetKeyValidator<>(SpawnMarker::getAssetStore));
class="kw">private class="kw">static AssetStore<String, SpawnMarker, DefaultAssetMap<String, SpawnMarker>> ASSET_STORE;
class="kw">private AssetExtraInfo.Data data;
class="kw">protected String id;
class="kw">protected String model;
@Nullable
class="kw">protected IWeightedMap<SpawnMarker.SpawnConfiguration> weightedConfigurations;
class="kw">protected double exclusionRadius;
class="kw">protected double maxDropHeightSquared = 4.0;
class="kw">protected boolean realtimeRespawn;
class="kw">protected boolean manualTrigger;
class="kw">protected double deactivationDistance = 40.0;
class="kw">protected double deactivationTime = 5.0;
class="kw">public class="kw">static AssetStore<String, SpawnMarker, DefaultAssetMap<String, SpawnMarker>> getAssetStore() {
if (ASSET_STORE == null) {
ASSET_STORE = AssetRegistry.getAssetStore(SpawnMarker.class);
}
class="kw">return ASSET_STORE;
}
class="kw">public class="kw">static DefaultAssetMap<String, SpawnMarker> getAssetMap() {
class="kw">return (DefaultAssetMap<String, SpawnMarker>)getAssetStore().getAssetMap();
}
class="kw">protected SpawnMarker() {
}
@Nullable
class="kw">public IWeightedMap<SpawnMarker.SpawnConfiguration> getWeightedConfigurations() {
class="kw">return this.weightedConfigurations;
}
class="kw">public String getId() {
class="kw">return this.id;
}
class="kw">public String getModel() {
class="kw">return this.model;
}
class="kw">public double getExclusionRadius() {
class="kw">return this.exclusionRadius;
}
class="kw">public double getMaxDropHeightSquared() {
class="kw">return this.maxDropHeightSquared;
}
class="kw">public boolean isRealtimeRespawn() {
class="kw">return this.realtimeRespawn;
}
class="kw">public boolean isManualTrigger() {
class="kw">return this.manualTrigger;
}
class="kw">public double getDeactivationDistance() {
class="kw">return this.deactivationDistance;
}
class="kw">public double getDeactivationTime() {
class="kw">return this.deactivationTime;
}
class="kw">public class="kw">static class SpawnConfiguration class="kw">implements IWeightedElement {
class="kw">public class="kw">static class="kw">final BuilderCodec<SpawnMarker.SpawnConfiguration> CODEC = BuilderCodec.<SpawnMarker.SpawnConfiguration>builder(
SpawnMarker.SpawnConfiguration.class, SpawnMarker.SpawnConfiguration::new
)
.documentation(
"A configuration for an individual weighted NPC to spawn. **Note:** At least one of **RealtimeRespawnTime** and **SpawnAfterGameTime** must be set, matching the **RealtimeRespawn** flag on the marker."
)
.<String>append(new KeyedCodec<>("Name", Codec.STRING), (var0, var1) -> var0.npc = var1, var0 -> var0.npc)
.documentation("The role name of the NPC to spawn (omitting this results in a no-op spawn, i.e. a weighted chance of spawning nothing).")
.addValidator(Validators.nonEmptyString())
.addValidator(NPCRoleValidator.INSTANCE)
.add()
.<Double>append(new KeyedCodec<>("Weight", Codec.DOUBLE, true), (var0, var1) -> var0.weight = var1, var0 -> var0.weight)
.documentation("The spawn chance, relative to the total sum of all weights in this pool.")
.addValidator(Validators.greaterThan(0.0))
.add()
.<Double>append(
new KeyedCodec<>("RealtimeRespawnTime", Codec.DOUBLE), (var0, var1) -> var0.realtimeRespawnTime = var1, var0 -> var0.realtimeRespawnTime
)
.documentation("A value in seconds that specifies how long after the death of this mob a new mob will be spawned.")
.add()
.<Duration>append(
new KeyedCodec<>("SpawnAfterGameTime", Codec.DURATION), (var0, var1) -> var0.spawnAfterGameTime = var1, var0 -> var0.spawnAfterGameTime
)
.documentation(
"A Duration string e.g. of form P2DT3H4M (2 days, 3 hours, and 4 minutes) that specifies how long after the death of this mob a new mob will be spawned based on in-game time."
)
.add()
.<String>append(new KeyedCodec<>("Flock", FlockAsset.CHILD_ASSET_CODEC), (var0, var1) -> var0.flockDefinitionId = var1, var0 -> var0.flockDefinitionId)
.documentation("The optional flock definition to spawn around this NPC.")
.addValidator(FlockAsset.VALIDATOR_CACHE.getValidator())
.add()
.build();
class="kw">public class="kw">static class="kw">final SpawnMarker.SpawnConfiguration[] EMPTY_ARRAY = new SpawnMarker.SpawnConfiguration[0];
class="kw">protected String npc;
class="kw">protected double weight;
class="kw">protected double realtimeRespawnTime;
class="kw">protected Duration spawnAfterGameTime;
class="kw">protected String flockDefinitionId;
class="kw">protected int flockDefinitionIndex = Integer.MIN_VALUE;
class="kw">public SpawnConfiguration(String var1, double var2, double var4, Duration var6, String var7) {
this.npc = var1;
this.weight = var2;
this.realtimeRespawnTime = var4;
this.spawnAfterGameTime = var6;
this.flockDefinitionId = var7;
}
class="kw">protected SpawnConfiguration() {
}
class="kw">public String getNpc() {
class="kw">return this.npc;
}
class="kw">public double getRealtimeRespawnTime() {
class="kw">return this.realtimeRespawnTime;
}
class="kw">public Duration getSpawnAfterGameTime() {
class="kw">return this.spawnAfterGameTime;
}
class="kw">public String getFlockDefinitionId() {
class="kw">return this.flockDefinitionId;
}
class="kw">public int getFlockDefinitionIndex() {
if (this.flockDefinitionIndex == Integer.MIN_VALUE && this.flockDefinitionId != null) {
int var1 = FlockAsset.getAssetMap().getIndex(this.flockDefinitionId);
if (var1 == Integer.MIN_VALUE) {
throw new IllegalArgumentException("Unknown key! " + this.flockDefinitionId);
}
this.flockDefinitionIndex = var1;
}
class="kw">return this.flockDefinitionIndex;
}
@Nullable
class="kw">public FlockAsset getFlockDefinition() {
int var1 = this.getFlockDefinitionIndex();
class="kw">return var1 != Integer.MIN_VALUE ? FlockAsset.getAssetMap().getAsset(var1) : null;
}
@Override
class="kw">public double getWeight() {
class="kw">return this.weight;
}
}
}