ProjectileModule.java
package com.hypixel.hytale.server.core.modules.projectile;
import com.hypixel.hytale.common.plugin.PluginManifest;
import com.hypixel.hytale.component.AddReason;
import com.hypixel.hytale.component.CommandBuffer;
import com.hypixel.hytale.component.ComponentRegistryProxy;
import com.hypixel.hytale.component.ComponentType;
import com.hypixel.hytale.component.Holder;
import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.component.Store;
import com.hypixel.hytale.math.vector.Vector3d;
import com.hypixel.hytale.math.vector.Vector3f;
import com.hypixel.hytale.protocol.Direction;
import com.hypixel.hytale.protocol.InteractionType;
import com.hypixel.hytale.protocol.SoundCategory;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.asset.type.model.config.Model;
import com.hypixel.hytale.server.core.entity.Entity;
import com.hypixel.hytale.server.core.entity.EntityUtils;
import com.hypixel.hytale.server.core.entity.InteractionChain;
import com.hypixel.hytale.server.core.entity.InteractionContext;
import com.hypixel.hytale.server.core.entity.InteractionManager;
import com.hypixel.hytale.server.core.entity.LivingEntity;
import com.hypixel.hytale.server.core.entity.UUIDComponent;
import com.hypixel.hytale.server.core.modules.collision.CollisionModule;
import com.hypixel.hytale.server.core.modules.entity.DespawnComponent;
import com.hypixel.hytale.server.core.modules.entity.EntityModule;
com.hypixel.hytale.server.core.modules.entity.component.AudioComponent;
com.hypixel.hytale.server.core.modules.entity.component.BoundingBox;
com.hypixel.hytale.server.core.modules.entity.component.HeadRotation;
com.hypixel.hytale.server.core.modules.entity.component.ModelComponent;
com.hypixel.hytale.server.core.modules.entity.component.PersistentModel;
com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
com.hypixel.hytale.server.core.modules.entity.tracker.NetworkId;
com.hypixel.hytale.server.core.modules.interaction.InteractionModule;
com.hypixel.hytale.server.core.modules.interaction.Interactions;
com.hypixel.hytale.server.core.modules.interaction.interaction.config.Interaction;
com.hypixel.hytale.server.core.modules.interaction.interaction.config.RootInteraction;
com.hypixel.hytale.server.core.modules.physics.component.Velocity;
com.hypixel.hytale.server.core.modules.physics.util.PhysicsMath;
com.hypixel.hytale.server.core.modules.projectile.component.PredictedProjectile;
com.hypixel.hytale.server.core.modules.projectile.component.Projectile;
com.hypixel.hytale.server.core.modules.projectile.config.PhysicsConfig;
com.hypixel.hytale.server.core.modules.projectile.config.ProjectileConfig;
com.hypixel.hytale.server.core.modules.projectile.config.StandardPhysicsConfig;
com.hypixel.hytale.server.core.modules.projectile.config.StandardPhysicsProvider;
com.hypixel.hytale.server.core.modules.projectile.interaction.ProjectileInteraction;
com.hypixel.hytale.server.core.modules.projectile.system.PredictedProjectileSystems;
com.hypixel.hytale.server.core.modules.projectile.system.StandardPhysicsTickSystem;
com.hypixel.hytale.server.core.modules.time.TimeResource;
com.hypixel.hytale.server.core.plugin.JavaPlugin;
com.hypixel.hytale.server.core.plugin.JavaPluginInit;
com.hypixel.hytale.server.core.universe.world.SoundUtil;
com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
java.time.Duration;
java.util.UUID;
javax.annotation.Nonnull;
javax.annotation.Nullable;
{
PluginManifest.corePlugin(ProjectileModule.class).description().depends(CollisionModule.class).depends(EntityModule.class).build();
Message.translation();
ProjectileModule instance;
ComponentType<EntityStore, Projectile> projectileComponentType;
ComponentType<EntityStore, StandardPhysicsProvider> standardPhysicsProviderComponentType;
ComponentType<EntityStore, PredictedProjectile> predictedProjectileComponentType;
ProjectileModule {
instance;
}
{
(init);
instance = ;
}
{
ComponentRegistryProxy<EntityStore> entityStoreRegistry = .getEntityStoreRegistry();
.getCodecRegistry(Interaction.CODEC).register(, ProjectileInteraction.class, ProjectileInteraction.CODEC);
.projectileComponentType = entityStoreRegistry.registerComponent(Projectile.class, , Projectile.CODEC);
.predictedProjectileComponentType = entityStoreRegistry.registerComponent(PredictedProjectile.class, () -> {
();
});
.standardPhysicsProviderComponentType = entityStoreRegistry.registerComponent(StandardPhysicsProvider.class, () -> {
();
});
entityStoreRegistry.registerSystem( ());
entityStoreRegistry.registerSystem( .EntityTrackerUpdate());
.getCodecRegistry(PhysicsConfig.CODEC).register(, StandardPhysicsConfig.class, StandardPhysicsConfig.CODEC);
}
Ref<EntityStore> {
.spawnProjectile((UUID), creatorRef, commandBuffer, config, position, direction);
}
Ref<EntityStore> {
Holder<EntityStore> holder = EntityStore.REGISTRY.newHolder();
();
config.getSpawnRotationOffset();
rotation.setYaw(PhysicsMath.normalizeTurnAngle(PhysicsMath.headingFromDirection(direction.x, direction.z)));
rotation.setPitch(PhysicsMath.pitchFromDirection(direction.x, direction.y, direction.z));
rotation.add(rotationOffset.pitch, rotationOffset.yaw, rotationOffset.roll);
PhysicsMath.vectorFromAngles(rotation.getYaw(), rotation.getPitch(), direction);
config.getCalculatedOffset(rotation.getPitch(), rotation.getYaw());
position.add(offset);
holder.addComponent(TransformComponent.getComponentType(), (position, rotation));
holder.addComponent(HeadRotation.getComponentType(), (rotation));
(predictionId != ) {
holder.addComponent(UUIDComponent.getComponentType(), (predictionId));
}
holder.addComponent(Interactions.getComponentType(), (config.getInteractions()));
config.getModel();
holder.addComponent(ModelComponent.getComponentType(), (model));
holder.addComponent(PersistentModel.getComponentType(), (model.toReference()));
holder.addComponent(BoundingBox.getComponentType(), (model.getBoundingBox()));
holder.addComponent(NetworkId.getComponentType(), (((EntityStore)commandBuffer.getExternalData()).takeNextNetworkId()));
holder.ensureComponent(Projectile.getComponentType());
(predictionId != ) {
holder.addComponent(PredictedProjectile.getComponentType(), (predictionId));
}
holder.addComponent(Velocity.getComponentType(), ());
config.getPhysicsConfig().apply(holder, creatorRef, direction.clone().scale(config.getLaunchForce()), commandBuffer, predictionId != );
holder.ensureComponent(EntityStore.REGISTRY.getNonSerializedComponentType());
holder.addComponent(DespawnComponent.getComponentType(), (((TimeResource)commandBuffer.getResource(TimeResource.getResourceType())).getNow().plus(Duration.ofSeconds())));
config.getLaunchWorldSoundEventIndex();
(launchWorldSoundEventIndex != ) {
SoundUtil.playSoundEvent3d(launchWorldSoundEventIndex, SoundCategory.SFX, position.x, position.y, position.z, (targetRef) -> !targetRef.equals(creatorRef), commandBuffer);
}
config.getProjectileSoundEventIndex();
(projectileSoundEventIndex != ) {
();
audioComponent.addSound(projectileSoundEventIndex);
holder.addComponent(AudioComponent.getComponentType(), audioComponent);
}
Ref<EntityStore> projectileRef = commandBuffer.addEntity(holder, AddReason.SPAWN);
(predictionId == && creatorRef != ) {
commandBuffer.run((store) -> onProjectileSpawnInteraction(projectileRef, creatorRef, store));
}
projectileRef;
}
{
(InteractionManager)store.getComponent(creatorRef, InteractionModule.get().getInteractionManagerComponent());
(interactionManagerComponent != ) {
EntityUtils.getEntity(creatorRef, store);
(var5 LivingEntity) {
(LivingEntity)var5;
InteractionContext.forProxyEntity(interactionManagerComponent, livingEntity, ref);
context.getRootInteractionId(InteractionType.ProjectileSpawn);
(rootInteractionId != ) {
RootInteraction.getRootInteractionOrUnknown(rootInteractionId);
(rootInteraction != ) {
interactionManagerComponent.initChain(InteractionType.ProjectileSpawn, context, rootInteraction, );
interactionManagerComponent.queueExecuteChain(chain);
}
}
}
}
}
ComponentType<EntityStore, Projectile> {
.projectileComponentType;
}
ComponentType<EntityStore, StandardPhysicsProvider> {
.standardPhysicsProviderComponentType;
}
ComponentType<EntityStore, PredictedProjectile> {
.predictedProjectileComponentType;
}
}