ProjectileConfig class
Пакет: com.hypixel.hytale.server.core.modules.projectile.config
Файл: com/hypixel/hytale/server/core/modules/projectile/config/ProjectileConfig.java
implements: JsonAssetWithMap<String, DefaultAssetMap<String, ProjectileConfig>>,
NetworkSerializable<com.hypixel.hytale.protocol.ProjectileConfig>,
BallisticData
Поля (6)
| Модификаторы | Тип | Имя |
|---|---|---|
|
|
ASSET_STORE |
|
com.hypixel.hytale.protocol.ProjectileConfig |
var1 |
|
ModelAsset |
var2 |
|
ModelAsset |
var2 |
|
float |
var3 |
|
Vector3d |
var3 |
Методы (14)
| Модификаторы | Возврат | Сигнатура |
|---|---|---|
public |
double |
getLaunchForcedouble getLaunchForce() |
public |
int |
getLaunchWorldSoundEventIndexint getLaunchWorldSoundEventIndex() |
public |
int |
getProjectileSoundEventIndexint getProjectileSoundEventIndex() |
|
|
if if(ASSET_STORE == null) |
|
|
if if(this.launchWorldSoundEventId != null) |
|
|
if if(this.launchLocalSoundEventId != null) |
|
|
if if(this.projectileSoundEventId != null) |
|
|
if if(this.generatedModel != null) |
|
|
if if(!this.useModelScale) |
|
|
if if(this.rotateSpawnOffsetByPitch) |
|
|
if if(this.rotateSpawnOffsetByYaw) |
public |
boolean |
isRotateSpawnOffsetByPitchboolean isRotateSpawnOffsetByPitch() |
public |
boolean |
isRotateSpawnOffsetByYawboolean isRotateSpawnOffsetByYaw() |
protected |
void |
processConfigvoid processConfig() |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.server.core.modules.projectile.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.codecs.map.EnumMapCodec;
class="kw">import com.hypixel.hytale.codec.validation.ValidatorCache;
class="kw">import com.hypixel.hytale.codec.validation.Validators;
class="kw">import com.hypixel.hytale.math.vector.Vector3fUtil;
class="kw">import com.hypixel.hytale.protocol.Direction;
class="kw">import com.hypixel.hytale.protocol.InteractionType;
class="kw">import com.hypixel.hytale.server.core.asset.type.model.config.Model;
class="kw">import com.hypixel.hytale.server.core.asset.type.model.config.ModelAsset;
class="kw">import com.hypixel.hytale.server.core.asset.type.soundevent.config.SoundEvent;
class="kw">import com.hypixel.hytale.server.core.asset.type.soundevent.validator.SoundEventValidators;
class="kw">import com.hypixel.hytale.server.core.codec.ProtocolCodecs;
class="kw">import com.hypixel.hytale.server.core.io.NetworkSerializable;
class="kw">import com.hypixel.hytale.server.core.modules.interaction.interaction.config.RootInteraction;
class="kw">import java.util.Collections;
class="kw">import java.util.EnumMap;
class="kw">import java.util.Map;
class="kw">import java.util.Map.Entry;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">import org.joml.Vector3d;
class="kw">import org.joml.Vector3f;
class="kw">public class ProjectileConfig
class="kw">implements JsonAssetWithMap<String, DefaultAssetMap<String, ProjectileConfig>>,
NetworkSerializable<com.hypixel.hytale.protocol.ProjectileConfig>,
BallisticData {
@Nonnull
class="kw">public class="kw">static class="kw">final AssetBuilderCodec<String, ProjectileConfig> CODEC = AssetBuilderCodec.builder(
ProjectileConfig.class,
ProjectileConfig::new,
Codec.STRING,
(var0, var1) -> var0.id = var1,
var0 -> var0.id,
(var0, var1) -> var0.data = var1,
var0 -> var0.data
)
.appendInherited(
new KeyedCodec<>("Physics", PhysicsConfig.CODEC),
(var0, var1) -> var0.physicsConfig = var1,
var0 -> var0.physicsConfig,
(var0, var1) -> var0.physicsConfig = var1.physicsConfig
)
.add()
.<String>appendInherited(
new KeyedCodec<>("Model", Codec.STRING), (var0, var1) -> var0.model = var1, var0 -> var0.model, (var0, var1) -> var0.model = var1.model
)
.addValidator(Validators.nonNull())
.addValidator(ModelAsset.VALIDATOR_CACHE.getValidator())
.add()
.<Boolean>appendInherited(
new KeyedCodec<>("UseModelScale", Codec.BOOLEAN),
(var0, var1) -> var0.useModelScale = var1,
var0 -> var0.useModelScale,
(var0, var1) -> var0.useModelScale = var1.useModelScale
)
.documentation(
"Whether the projectile's scale is derived from the model asset's MinScale/MaxScale range. When false (the class="kw">default), the projectile always spawns at scale 1.0 regardless of the model's configured range."
)
.add()
.appendInherited(
new KeyedCodec<>("LaunchForce", Codec.DOUBLE),
(var0, var1) -> var0.launchForce = var1,
var0 -> var0.launchForce,
(var0, var1) -> var0.launchForce = var1.launchForce
)
.add()
.<Vector3f>appendInherited(
new KeyedCodec<>("SpawnOffset", Vector3fUtil.CODEC),
(var0, var1) -> var0.spawnOffset = var1,
var0 -> var0.spawnOffset,
(var0, var1) -> var0.spawnOffset = var1.spawnOffset
)
.addValidator(Validators.nonNull())
.add()
.<Direction>appendInherited(new KeyedCodec<>("SpawnRotationOffset", ProtocolCodecs.DIRECTION), (var0, var1) -> {
var0.spawnRotationOffset = var1;
var0.spawnRotationOffset.yaw *= (float) (Math.PI / 180.0);
var0.spawnRotationOffset.pitch *= (float) (Math.PI / 180.0);
var0.spawnRotationOffset.roll *= (float) (Math.PI / 180.0);
}, var0 -> var0.spawnRotationOffset, (var0, var1) -> var0.spawnRotationOffset = var1.spawnRotationOffset)
.addValidator(Validators.nonNull())
.add()
.<Boolean>appendInherited(
new KeyedCodec<>("RotateSpawnOffsetByPitch", Codec.BOOLEAN),
(var0, var1) -> var0.rotateSpawnOffsetByPitch = var1,
var0 -> var0.rotateSpawnOffsetByPitch,
(var0, var1) -> var0.rotateSpawnOffsetByPitch = var1.rotateSpawnOffsetByPitch
)
.documentation("Whether SpawnOffset should be rotated by the entity's pitch.")
.add()
.<Boolean>appendInherited(
new KeyedCodec<>("RotateSpawnOffsetByYaw", Codec.BOOLEAN),
(var0, var1) -> var0.rotateSpawnOffsetByYaw = var1,
var0 -> var0.rotateSpawnOffsetByYaw,
(var0, var1) -> var0.rotateSpawnOffsetByYaw = var1.rotateSpawnOffsetByYaw
)
.documentation("Whether SpawnOffset should be rotated by the entity's yaw.")
.add()
.<Map<InteractionType, String>>appendInherited(
new KeyedCodec<>("Interactions", new EnumMapCodec<>(InteractionType.class, RootInteraction.CHILD_ASSET_CODEC)),
(var0, var1) -> var0.interactions = var1,
var0 -> var0.interactions,
(var0, var1) -> var0.interactions = var1.interactions
)
.addValidatorLate(() -> RootInteraction.VALIDATOR_CACHE.getMapValueValidator().late())
.addValidator(Validators.nonNull())
.add()
.<String>appendInherited(
new KeyedCodec<>("LaunchLocalSoundEventId", Codec.STRING),
(var0, var1) -> var0.launchLocalSoundEventId = var1,
var0 -> var0.launchLocalSoundEventId,
(var0, var1) -> var0.launchLocalSoundEventId = var1.launchLocalSoundEventId
)
.addValidator(SoundEventValidators.ONESHOT)
.documentation("The sound event played to the throwing player when the projectile is spawned/launched")
.add()
.<String>appendInherited(
new KeyedCodec<>("LaunchWorldSoundEventId", Codec.STRING),
(var0, var1) -> var0.launchWorldSoundEventId = var1,
var0 -> var0.launchWorldSoundEventId,
(var0, var1) -> var0.launchWorldSoundEventId = var1.launchWorldSoundEventId
)
.addValidator(SoundEventValidators.MONO)
.addValidator(SoundEventValidators.ONESHOT)
.documentation("The positioned sound event played to surrounding players when the projectile is spawned/launched")
.add()
.<String>appendInherited(
new KeyedCodec<>("ProjectileSoundEventId", Codec.STRING),
(var0, var1) -> var0.projectileSoundEventId = var1,
var0 -> var0.projectileSoundEventId,
(var0, var1) -> var0.projectileSoundEventId = var1.projectileSoundEventId
)
.addValidator(SoundEventValidators.LOOPING)
.addValidator(SoundEventValidators.MONO)
.documentation("The looping sound event to attach to the projectile.")
.add()
.afterDecode(ProjectileConfig::processConfig)
.build();
@Nullable
class="kw">private class="kw">static AssetStore<String, ProjectileConfig, DefaultAssetMap<String, ProjectileConfig>> ASSET_STORE;
@Nonnull
class="kw">public class="kw">static class="kw">final ValidatorCache<String> VALIDATOR_CACHE = new ValidatorCache<>(new AssetKeyValidator<>(ProjectileConfig::getAssetStore));
@Nullable
class="kw">protected AssetExtraInfo.Data data;
@Nullable
class="kw">protected String id;
@Nonnull
class="kw">protected PhysicsConfig physicsConfig = StandardPhysicsConfig.DEFAULT;
class="kw">protected String model;
class="kw">protected Model generatedModel;
class="kw">protected boolean useModelScale;
class="kw">protected double launchForce = 1.0;
@Nonnull
class="kw">protected Vector3f spawnOffset = new Vector3f(0.0F, 0.0F, 0.0F);
@Nonnull
class="kw">protected Direction spawnRotationOffset = new Direction(0.0F, 0.0F, 0.0F);
class="kw">protected boolean rotateSpawnOffsetByPitch = true;
class="kw">protected boolean rotateSpawnOffsetByYaw = true;
@Nonnull
class="kw">protected Map<InteractionType, String> interactions = Collections.emptyMap();
class="kw">protected String launchLocalSoundEventId;
class="kw">protected String launchWorldSoundEventId;
class="kw">protected String projectileSoundEventId;
class="kw">protected int launchLocalSoundEventIndex = 0;
class="kw">protected int launchWorldSoundEventIndex = 0;
class="kw">protected int projectileSoundEventIndex = 0;
class="kw">public ProjectileConfig() {
}
@Nonnull
class="kw">public class="kw">static AssetStore<String, ProjectileConfig, DefaultAssetMap<String, ProjectileConfig>> getAssetStore() {
if (ASSET_STORE == null) {
ASSET_STORE = AssetRegistry.getAssetStore(ProjectileConfig.class);
}
class="kw">return ASSET_STORE;
}
@Nonnull
class="kw">public class="kw">static DefaultAssetMap<String, ProjectileConfig> getAssetMap() {
class="kw">return (DefaultAssetMap<String, ProjectileConfig>)getAssetStore().getAssetMap();
}
@Nullable
class="kw">public String getId() {
class="kw">return this.id;
}
class="kw">protected void processConfig() {
if (this.launchWorldSoundEventId != null) {
this.launchWorldSoundEventIndex = SoundEvent.getAssetMap().getIndex(this.launchWorldSoundEventId);
}
if (this.launchLocalSoundEventId != null) {
this.launchLocalSoundEventIndex = SoundEvent.getAssetMap().getIndex(this.launchLocalSoundEventId);
}
if (this.projectileSoundEventId != null) {
this.projectileSoundEventIndex = SoundEvent.getAssetMap().getIndex(this.projectileSoundEventId);
}
}
@Nonnull
class="kw">public PhysicsConfig getPhysicsConfig() {
class="kw">return this.physicsConfig;
}
@Nullable
class="kw">public ModelAsset getModelAsset() {
class="kw">return ModelAsset.getAssetMap().getAsset(this.model);
}
@Nonnull
class="kw">public Model getModel() {
if (this.generatedModel != null) {
class="kw">return this.generatedModel;
}
this.generatedModel = Model.createUnitScaleModel(this.getModelAsset());
class="kw">return this.generatedModel;
}
@Nonnull
class="kw">public Model createSpawnModel(@Nullable Long var1) {
ModelAsset var2 = this.getModelAsset();
if (!this.useModelScale) {
class="kw">return Model.createScaledModel(var2, 1.0F, null);
}
float var3 = var1 == null ? var2.generateRandomScale() : var2.generateDeterministicScale(var1);
class="kw">return Model.createScaledModel(var2, var3, null);
}
class="kw">public double getLaunchForce() {
class="kw">return this.launchForce;
}
@Override
class="kw">public double getMuzzleVelocity() {
class="kw">return this.launchForce;
}
@Override
class="kw">public double getGravity() {
class="kw">return this.physicsConfig.getGravity();
}
@Override
class="kw">public double getVerticalCenterShot() {
class="kw">return this.spawnOffset.y;
}
@Override
class="kw">public double getHorizontalCenterShot() {
class="kw">return this.spawnOffset.x;
}
@Override
class="kw">public double getDepthShot() {
class="kw">return this.spawnOffset.z;
}
@Override
class="kw">public boolean isPitchAdjustShot() {
class="kw">return this.rotateSpawnOffsetByPitch;
}
@Nonnull
class="kw">public Map<InteractionType, String> getInteractions() {
class="kw">return this.interactions;
}
class="kw">public int getLaunchWorldSoundEventIndex() {
class="kw">return this.launchWorldSoundEventIndex;
}
class="kw">public int getProjectileSoundEventIndex() {
class="kw">return this.projectileSoundEventIndex;
}
@Nonnull
class="kw">public Vector3f getSpawnOffset() {
class="kw">return this.spawnOffset;
}
class="kw">public boolean isRotateSpawnOffsetByPitch() {
class="kw">return this.rotateSpawnOffsetByPitch;
}
class="kw">public boolean isRotateSpawnOffsetByYaw() {
class="kw">return this.rotateSpawnOffsetByYaw;
}
@Nonnull
class="kw">public Direction getSpawnRotationOffset() {
class="kw">return this.spawnRotationOffset;
}
@Nonnull
class="kw">public Vector3d getCalculatedOffset(float var1, float var2) {
Vector3d var3 = new Vector3d(this.spawnOffset.x, this.spawnOffset.y, this.spawnOffset.z);
if (this.rotateSpawnOffsetByPitch) {
var3.rotateX(var1);
}
if (this.rotateSpawnOffsetByYaw) {
var3.rotateY(var2);
}
class="kw">return var3;
}
@Nonnull
class="kw">public com.hypixel.hytale.protocol.ProjectileConfig toPacket() {
com.hypixel.hytale.protocol.ProjectileConfig var1 = new com.hypixel.hytale.protocol.ProjectileConfig();
var1.physicsConfig = this.physicsConfig.toPacket();
var1.model = this.getModel().toPacket();
ModelAsset var2 = this.getModelAsset();
var1.minScale = this.useModelScale ? var2.getMinScale() : 1.0F;
var1.maxScale = this.useModelScale ? var2.getMaxScale() : 1.0F;
var1.launchForce = this.launchForce;
var1.spawnOffset = this.spawnOffset;
var1.rotationOffset = this.spawnRotationOffset;
var1.rotateSpawnOffsetByPitch = this.rotateSpawnOffsetByPitch;
var1.rotateSpawnOffsetByYaw = this.rotateSpawnOffsetByYaw;
var1.launchLocalSoundEventIndex = this.launchLocalSoundEventIndex;
var1.launchWorldSoundEventIndex = this.launchWorldSoundEventIndex;
var1.projectileSoundEventIndex = this.projectileSoundEventIndex;
var1.interactions = new EnumMap<>(InteractionType.class);
for (Entry var4 : this.interactions.entrySet()) {
var1.interactions.put(var4.getKey(), RootInteraction.getRootInteractionIdOrUnknown(var4.getValue()));
}
class="kw">return var1;
}
}