package com.hypixel.hytale.server.core.modules.projectile.config;
import com.hypixel.hytale.assetstore.AssetExtraInfo;
import com.hypixel.hytale.assetstore.AssetKeyValidator;
import com.hypixel.hytale.assetstore.AssetRegistry;
import com.hypixel.hytale.assetstore.AssetStore;
import com.hypixel.hytale.assetstore.codec.AssetBuilderCodec;
import com.hypixel.hytale.assetstore.map.DefaultAssetMap;
import com.hypixel.hytale.assetstore.map.JsonAssetWithMap;
import com.hypixel.hytale.codec.Codec;
import com.hypixel.hytale.codec.KeyedCodec;
import com.hypixel.hytale.codec.codecs.map.EnumMapCodec;
import com.hypixel.hytale.codec.validation.ValidatorCache;
import com.hypixel.hytale.codec.validation.Validators;
import com.hypixel.hytale.math.vector.Vector3d;
import com.hypixel.hytale.protocol.Direction;
import com.hypixel.hytale.protocol.InteractionType;
import com.hypixel.hytale.protocol.Vector3f;
import com.hypixel.hytale.server.core.asset.type.model.config.Model;
import com.hypixel.hytale.server.core.asset.type.model.config.ModelAsset;
import com.hypixel.hytale.server.core.asset.type.soundevent.config.SoundEvent;
import com.hypixel.hytale.server.core.asset.type.soundevent.validator.SoundEventValidators;
import com.hypixel.hytale.server.core.codec.ProtocolCodecs;
import com.hypixel.hytale.server.core.io.NetworkSerializable;
import com.hypixel.hytale.server.core.modules.interaction.interaction.config.RootInteraction;
import java.util.Collections;
import java.util.EnumMap;
import java.util.Map;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class ProjectileConfig implements JsonAssetWithMap<String, DefaultAssetMap<String, ProjectileConfig>>, NetworkSerializable<com.hypixel.hytale.protocol.ProjectileConfig>, BallisticData {
@Nonnull
public static final AssetBuilderCodec<String, ProjectileConfig> CODEC;
@Nullable
private static AssetStore<String, ProjectileConfig, DefaultAssetMap<String, ProjectileConfig>> ASSET_STORE;
@Nonnull
public static final ValidatorCache<String> VALIDATOR_CACHE;
@Nullable
protected AssetExtraInfo.Data data;
@Nullable
protected String id;
@Nonnull
protected PhysicsConfig physicsConfig;
protected String model;
protected Model generatedModel;
protected double launchForce;
@Nonnull
protected Vector3f spawnOffset;
@Nonnull
protected Direction spawnRotationOffset;
@Nonnull
protected Map<InteractionType, String> interactions;
protected String launchLocalSoundEventId;
protected String launchWorldSoundEventId;
protected String projectileSoundEventId;
protected int launchLocalSoundEventIndex;
protected int launchWorldSoundEventIndex;
protected int projectileSoundEventIndex;
public ProjectileConfig() {
this.physicsConfig = StandardPhysicsConfig.DEFAULT;
this.launchForce = 1.0;
this.spawnOffset = new Vector3f(0.0F, 0.0F, 0.0F);
this.spawnRotationOffset = new Direction(0.0F, 0.0F, 0.0F);
this.interactions = Collections.emptyMap();
this.launchLocalSoundEventIndex = 0;
this.launchWorldSoundEventIndex = 0;
this.projectileSoundEventIndex = 0;
}
@Nonnull
public static AssetStore<String, ProjectileConfig, DefaultAssetMap<String, ProjectileConfig>> getAssetStore() {
if (ASSET_STORE == null) {
ASSET_STORE = AssetRegistry.<String, ProjectileConfig, DefaultAssetMap<String, ProjectileConfig>>getAssetStore(ProjectileConfig.class);
}
return ASSET_STORE;
}
@Nonnull
public static DefaultAssetMap<String, ProjectileConfig> getAssetMap() {
return (DefaultAssetMap)getAssetStore().getAssetMap();
}
@Nullable
public String getId() {
return this.id;
}
protected void processConfig() {
if (this.launchWorldSoundEventId != null) {
this.launchWorldSoundEventIndex = this.launchLocalSoundEventIndex = 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
public PhysicsConfig getPhysicsConfig() {
return this.physicsConfig;
}
@Nonnull
public Model getModel() {
if (this.generatedModel != null) {
return this.generatedModel;
} else {
ModelAsset modelAsset = (ModelAsset)ModelAsset.getAssetMap().getAsset(this.model);
this.generatedModel = Model.createUnitScaleModel(modelAsset);
return this.generatedModel;
}
}
public double getLaunchForce() {
return this.launchForce;
}
public double getMuzzleVelocity() {
return this.launchForce;
}
public double getGravity() {
return this.physicsConfig.getGravity();
}
public double getVerticalCenterShot() {
return (double)this.spawnOffset.y;
}
public double getDepthShot() {
return (double)this.spawnOffset.z;
}
public boolean isPitchAdjustShot() {
return true;
}
public Map<InteractionType, String> getInteractions() {
return this.interactions;
}
public int getLaunchWorldSoundEventIndex() {
return this.launchWorldSoundEventIndex;
}
public int getProjectileSoundEventIndex() {
return this.projectileSoundEventIndex;
}
@Nonnull
public Vector3f getSpawnOffset() {
return this.spawnOffset;
}
@Nonnull
public Direction getSpawnRotationOffset() {
return this.spawnRotationOffset;
}
@Nonnull
public Vector3d getCalculatedOffset(float pitch, float yaw) {
Vector3d offset = new Vector3d((double)this.spawnOffset.x, (double)this.spawnOffset.y, (double)this.spawnOffset.z);
offset.rotateX(pitch);
offset.rotateY(yaw);
return offset;
}
@Nonnull
public com.hypixel.hytale.protocol.ProjectileConfig toPacket() {
com.hypixel.hytale.protocol.ProjectileConfig config = new com.hypixel.hytale.protocol.ProjectileConfig();
config.physicsConfig = (com.hypixel.hytale.protocol.PhysicsConfig)this.physicsConfig.toPacket();
config.model = this.getModel().toPacket();
config.launchForce = this.launchForce;
config.spawnOffset = this.spawnOffset;
config.rotationOffset = this.spawnRotationOffset;
config.launchLocalSoundEventIndex = this.launchLocalSoundEventIndex;
config.projectileSoundEventIndex = this.projectileSoundEventIndex;
config.interactions = new EnumMap(InteractionType.class);
for(Map.Entry<InteractionType, String> e : this.interactions.entrySet()) {
config.interactions.put((InteractionType)e.getKey(), RootInteraction.getRootInteractionIdOrUnknown((String)e.getValue()));
}
return config;
}
static {
CODEC = ((AssetBuilderCodec.Builder)((AssetBuilderCodec.Builder)((AssetBuilderCodec.Builder)((AssetBuilderCodec.Builder)((AssetBuilderCodec.Builder)((AssetBuilderCodec.Builder)((AssetBuilderCodec.Builder)((AssetBuilderCodec.Builder)((AssetBuilderCodec.Builder)((AssetBuilderCodec.Builder)AssetBuilderCodec.builder(ProjectileConfig.class, ProjectileConfig::new, Codec.STRING, (config, s) -> config.id = s, (config) -> config.id, (asset, data) -> asset.data = data, (asset) -> asset.data).appendInherited(new KeyedCodec("Physics", PhysicsConfig.CODEC), (o, i) -> o.physicsConfig = i, (o) -> o.physicsConfig, (o, p) -> o.physicsConfig = p.physicsConfig).add()).appendInherited(new KeyedCodec("Model", Codec.STRING), (o, i) -> o.model = i, (o) -> o.model, (o, p) -> o.model = p.model).addValidator(Validators.nonNull()).addValidator(ModelAsset.VALIDATOR_CACHE.getValidator()).add()).appendInherited(new KeyedCodec("LaunchForce", Codec.DOUBLE), (o, i) -> o.launchForce = i, (o) -> o.launchForce, (o, p) -> o.launchForce = p.launchForce).add()).appendInherited(new KeyedCodec("SpawnOffset", ProtocolCodecs.VECTOR3F), (o, i) -> o.spawnOffset = i, (o) -> o.spawnOffset, (o, p) -> o.spawnOffset = p.spawnOffset).addValidator(Validators.nonNull()).add()).appendInherited(new KeyedCodec("SpawnRotationOffset", ProtocolCodecs.DIRECTION), (o, i) -> {
o.spawnRotationOffset = i;
Direction var10000 = o.spawnRotationOffset;
var10000.yaw *= 0.017453292F;
var10000 = o.spawnRotationOffset;
var10000.pitch *= 0.017453292F;
var10000 = o.spawnRotationOffset;
var10000.roll *= 0.017453292F;
}, (o) -> o.spawnRotationOffset, (o, p) -> o.spawnRotationOffset = p.spawnRotationOffset).addValidator(Validators.nonNull()).add()).appendInherited(new KeyedCodec("Interactions", new EnumMapCodec(InteractionType.class, RootInteraction.CHILD_ASSET_CODEC)), (o, i) -> o.interactions = i, (o) -> o.interactions, (o, p) -> o.interactions = p.interactions).addValidatorLate(() -> RootInteraction.VALIDATOR_CACHE.getMapValueValidator().late()).addValidator(Validators.nonNull()).add()).appendInherited(new KeyedCodec("LaunchLocalSoundEventId", Codec.STRING), (o, i) -> o.launchLocalSoundEventId = i, (o) -> o.launchLocalSoundEventId, (o, p) -> o.launchLocalSoundEventId = p.launchLocalSoundEventId).addValidator(SoundEventValidators.ONESHOT).documentation("The sound event played to the throwing player when the projectile is spawned/launched").add()).appendInherited(new KeyedCodec("LaunchWorldSoundEventId", Codec.STRING), (o, i) -> o.launchWorldSoundEventId = i, (o) -> o.launchWorldSoundEventId, (o, p) -> o.launchWorldSoundEventId = p.launchWorldSoundEventId).addValidator(SoundEventValidators.MONO).addValidator(SoundEventValidators.ONESHOT).documentation("The positioned sound event played to surrounding players when the projectile is spawned/launched").add()).appendInherited(new KeyedCodec("ProjectileSoundEventId", Codec.STRING), (o, i) -> o.projectileSoundEventId = i, (o) -> o.projectileSoundEventId, (o, p) -> o.projectileSoundEventId = p.projectileSoundEventId).addValidator(SoundEventValidators.LOOPING).addValidator(SoundEventValidators.MONO).documentation("The looping sound event to attach to the projectile.").add()).afterDecode(ProjectileConfig::processConfig)).build();
VALIDATOR_CACHE = new ValidatorCache<String>(new AssetKeyValidator(ProjectileConfig::getAssetStore));
}
}