RoleSpawnParameters class
Пакет: com.hypixel.hytale.server.spawning.assets.spawns.config
Файл: com/hypixel/hytale/server/spawning/assets/spawns/config/RoleSpawnParameters.java
implements: IWeightedElement
Поля (7)
| Модификаторы | Тип | Имя |
|---|---|---|
final |
BuilderCodec<RoleSpawnParameters> |
CODEC |
|
int |
var1 |
|
int |
var1 |
|
double[] |
var2 |
|
EnumSet |
var3 |
|
EnumSet |
var4 |
|
EnumSet |
var5 |
Методы (22)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
abstract |
throw new |
IllegalArgumentExceptionthrow new IllegalArgumentException("Unknown key! " + var0.spawnBlockSet) |
abstract |
throw new |
IllegalArgumentExceptionthrow new IllegalArgumentException("Unknown key! " + this.flockDefinitionId) |
public |
boolean |
claimSpawnOverYRangeReportboolean claimSpawnOverYRangeReport() |
public |
boolean |
getEnableSafeSpawningboolean getEnableSafeSpawning() |
public |
String |
getFlockDefinitionIdString getFlockDefinitionId() |
public |
int |
getFlockDefinitionIndexint getFlockDefinitionIndex() |
public |
String |
getIdString getId() |
public |
String |
getSpawnBlockSetString getSpawnBlockSet() |
public |
int |
getSpawnBlockSetIndexint getSpawnBlockSetIndex() |
public |
int |
getSpawnFluidTagIndexint getSpawnFluidTagIndex() |
|
|
if if(var0.spawnBlockSet != null) |
|
|
if if(var1 == Integer.MIN_VALUE) |
|
|
if if(var0.spawnFluidTag != null) |
|
|
if if(var0.configMovementModeWeights != null) |
|
|
if if(var3 < 0.0) |
|
|
if if(var2[0] == 0.0) |
|
|
if if(this.flockDefinitionIndex == Integer.MIN_VALUE && this.flockDefinitionId != null) |
|
|
if if(var1 == Integer.MIN_VALUE) |
|
|
if if(this.noValidMovementModes) |
|
|
if if(this.cachedMovementModeWeights != null) |
|
|
if if(this.cachedMovementModeWeights == null) |
|
|
if if(this.reportedSpawnOverYRange) |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.server.spawning.assets.spawns.config;
class="kw">import com.hypixel.hytale.assetstore.AssetRegistry;
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.codecs.map.EnumMapCodec;
class="kw">import com.hypixel.hytale.codec.validation.Validators;
class="kw">import com.hypixel.hytale.common.map.IWeightedElement;
class="kw">import com.hypixel.hytale.server.core.asset.type.blockset.config.BlockSet;
class="kw">import com.hypixel.hytale.server.flock.config.FlockAsset;
class="kw">import com.hypixel.hytale.server.npc.movement.MovementMode;
class="kw">import com.hypixel.hytale.server.npc.validators.NPCRoleValidator;
class="kw">import com.hypixel.hytale.server.spawning.ISpawnable;
class="kw">import com.hypixel.hytale.server.spawning.SpawningContext;
class="kw">import com.hypixel.hytale.server.spawning.SpawningPlugin;
class="kw">import java.util.Collections;
class="kw">import java.util.EnumSet;
class="kw">import java.util.Map;
class="kw">import java.util.logging.Level;
class="kw">import java.util.stream.Collectors;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">public class RoleSpawnParameters class="kw">implements IWeightedElement {
class="kw">public class="kw">static class="kw">final BuilderCodec<RoleSpawnParameters> CODEC = BuilderCodec.<RoleSpawnParameters>builder(RoleSpawnParameters.class, RoleSpawnParameters::new)
.documentation("A set of parameters that configure spawning for a single NPC type.")
.<String>append(new KeyedCodec<>("Id", Codec.STRING), (var0, var1) -> var0.id = var1, var0 -> var0.id)
.documentation("The Role ID of the NPC to spawn.")
.addValidator(Validators.nonNull())
.addValidator(NPCRoleValidator.INSTANCE)
.add()
.<Double>append(new KeyedCodec<>("Weight", Codec.DOUBLE, true), (var0, var1) -> var0.weight = var1, var0 -> var0.weight)
.documentation("The relative weight of this NPC (chance of being spawned is this value relative to the sum of all weights).")
.addValidator(Validators.nonNull())
.addValidator(Validators.greaterThan(0.0))
.add()
.<String>append(new KeyedCodec<>("SpawnBlockSet", Codec.STRING), (var0, var1) -> var0.spawnBlockSet = var1, var0 -> var0.spawnBlockSet)
.addValidator(BlockSet.VALIDATOR_CACHE.getValidator())
.documentation("An optional BlockSet reference that defines which blocks this NPC can spawn on.")
.add()
.<String>append(new KeyedCodec<>("SpawnFluidTag", Codec.STRING), (var0, var1) -> var0.spawnFluidTag = var1, var0 -> var0.spawnFluidTag)
.documentation("An optional tag reference that defines which fluids this NPC can spawn on.")
.add()
.<Map<MovementMode, Double>>append(
new KeyedCodec<>(
"MovementModes",
new EnumMapCodec<>(MovementMode.class, Codec.DOUBLE)
.documentKey(MovementMode.WALK, "NPC will spawn on dry solid ground if permitted")
.documentKey(MovementMode.WADE, "NPC will spawn in shallow water if permitted")
.documentKey(MovementMode.UNDERWATER_WALK, "NPC will spawn on the ground underwater if permitted")
.documentKey(MovementMode.DIVE, "NPC will spawn fully submerged underwater if permitted")
.documentKey(MovementMode.FLY, "NPC will spawn in the air flying")
),
(var0, var1) -> var0.configMovementModeWeights = var1,
var0 -> var0.configMovementModeWeights
)
.documentation(
"An optional map of movement modes with weights >0.0 that this NPC will use to spawn. If not set then the NPC will use backwards compatible defaults."
)
.add()
.<Boolean>append(new KeyedCodec<>("EnableSafeSpawning", Codec.BOOLEAN), (var0, var1) -> var0.enableSafeSpawning = var1, var0 -> var0.enableSafeSpawning)
.documentation(
"When true (class="kw">default), movement modes that are unsafe for this NPC's configuration are excluded from spawning. Set to false to allow spawning in all supported movement modes."
)
.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()
.afterDecode(var0 -> {
if (var0.spawnBlockSet != null) {
int var1 = BlockSet.getAssetMap().getIndex(var0.spawnBlockSet);
if (var1 == Integer.MIN_VALUE) {
throw new IllegalArgumentException("Unknown key! " + var0.spawnBlockSet);
}
var0.spawnBlockSetIndex = var1;
}
if (var0.spawnFluidTag != null) {
var0.spawnFluidTagIndex = AssetRegistry.getOrCreateTagIndex(var0.spawnFluidTag);
}
})
.validator((var0, var1) -> {
if (var0.configMovementModeWeights != null) {
if (var0.configMovementModeWeights.isEmpty()) {
var0.configMovementModeWeights = Collections.emptyMap();
} else {
double[] var2 = new double[]{0.0};
var0.configMovementModeWeights.forEach((var2x, var3) -> {
if (var3 < 0.0) {
var1.fail(String.format("Movement mode weights must be greater or equal 0! Invalid weight for %s", var2x));
}
var2[0] += var3;
});
if (var2[0] == 0.0) {
var1.fail("At least one movement mode weight must be greater than 0!");
}
var0.configMovementModeWeights = Collections.unmodifiableMap(var0.configMovementModeWeights);
}
}
})
.build();
class="kw">public class="kw">static class="kw">final RoleSpawnParameters[] EMPTY_ARRAY = new RoleSpawnParameters[0];
class="kw">protected String id;
class="kw">protected double weight;
class="kw">protected String spawnBlockSet;
class="kw">protected int spawnBlockSetIndex = Integer.MIN_VALUE;
class="kw">protected String spawnFluidTag;
class="kw">protected int spawnFluidTagIndex = Integer.MIN_VALUE;
@Nullable
class="kw">protected Map<MovementMode, Double> configMovementModeWeights;
class="kw">protected boolean enableSafeSpawning = true;
@Nullable
class="kw">private double[] cachedMovementModeWeights;
class="kw">private boolean noValidMovementModes;
class="kw">private boolean reportedSpawnOverYRange;
class="kw">protected String flockDefinitionId;
class="kw">protected int flockDefinitionIndex = Integer.MIN_VALUE;
class="kw">public RoleSpawnParameters(String var1, double var2, String var4, String var5) {
this.id = var1;
this.weight = var2;
this.spawnBlockSet = var4;
this.flockDefinitionId = var5;
}
class="kw">protected RoleSpawnParameters() {
}
class="kw">public String getId() {
class="kw">return this.id;
}
@Override
class="kw">public double getWeight() {
class="kw">return this.weight;
}
class="kw">public String getSpawnBlockSet() {
class="kw">return this.spawnBlockSet;
}
class="kw">public int getSpawnBlockSetIndex() {
class="kw">return this.spawnBlockSetIndex;
}
class="kw">public int getSpawnFluidTagIndex() {
class="kw">return this.spawnFluidTagIndex;
}
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;
}
class="kw">public boolean getEnableSafeSpawning() {
class="kw">return this.enableSafeSpawning;
}
@Nullable
class="kw">public Map<MovementMode, Double> getConfigMovementModeWeights() {
class="kw">return Collections.unmodifiableMap(this.configMovementModeWeights);
}
@Nullable
class="kw">public double[] getOrComputeMovementModeWeights(@Nonnull ISpawnable var1, @Nonnull SpawningContext var2) {
if (this.noValidMovementModes) {
class="kw">return null;
}
if (this.cachedMovementModeWeights != null) {
class="kw">return this.cachedMovementModeWeights;
}
EnumSet var3 = EnumSet.noneOf(MovementMode.class);
EnumSet var4 = EnumSet.noneOf(MovementMode.class);
EnumSet var5 = EnumSet.noneOf(MovementMode.class);
var1.getMovementModes(var2, var3, var4, var5);
this.cachedMovementModeWeights = SpawningContext.buildMovementModeWeights(
this.configMovementModeWeights, var3, var4, this.enableSafeSpawning ? var5 : null
);
if (this.cachedMovementModeWeights == null) {
this.noValidMovementModes = true;
SpawningPlugin.get()
.getLogger()
.at(Level.WARNING)
.log(
"Role '%s' cannot be spawned: no valid movement mode exists (supported=%s, defaults=%s, safe=%s, enableSafeSpawning=%s)",
this.id,
var3,
var4,
var5,
this.enableSafeSpawning
);
}
class="kw">return this.cachedMovementModeWeights;
}
class="kw">public boolean claimSpawnOverYRangeReport() {
if (this.reportedSpawnOverYRange) {
class="kw">return false;
}
this.reportedSpawnOverYRange = true;
class="kw">return true;
}
@Nullable
class="kw">public FlockAsset getFlockDefinition() {
int var1 = this.getFlockDefinitionIndex();
class="kw">return var1 != Integer.MIN_VALUE ? FlockAsset.getAssetMap().getAsset(var1) : null;
}
@Nonnull
@Override
class="kw">public String toString() {
class="kw">return "RoleSpawnParameters{id='"
+ this.id
+ "', weight="
+ this.weight
+ ", spawnBlockSet="
+ this.spawnBlockSet
+ ", movementModeWeights="
+ (
this.configMovementModeWeights != null
? this.configMovementModeWeights
.entrySet()
.stream()
.map(var0 -> var0.getKey() + "=" + var0.getValue())
.collect(Collectors.joining(", ", "{", "}"))
: "null"
)
+ ", enableSafeSpawning="
+ this.enableSafeSpawning
+ ", flockDefinitionId="
+ this.flockDefinitionId
+ "}";
}
}