Renderer/src/main/java/electrosphere/entity/ClientEntityUtils.java
austin 90a88bbd8b
Some checks reported errors
studiorailgun/Renderer/pipeline/head Something is wrong with the build of this commit
break out interaction into dedicated collision eng
2025-04-03 16:35:01 -04:00

86 lines
2.9 KiB
Java

package electrosphere.entity;
import java.util.List;
import org.joml.Quaterniond;
import org.joml.Vector3d;
import electrosphere.client.interact.ClientInteractionEngine;
import electrosphere.engine.Globals;
import electrosphere.entity.state.attach.AttachUtils;
import electrosphere.entity.state.hitbox.HitboxCollectionState;
import electrosphere.entity.types.collision.CollisionObjUtils;
import electrosphere.renderer.actor.ActorUtils;
import electrosphere.renderer.actor.instance.TextureInstancedActor;
/**
* Client only entity utility functions
*/
public class ClientEntityUtils {
/**
* Called when the creature is first spawned to serialize to all people in its initial chunk
* @param entity
* @param position
*/
public static void initiallyPositionEntity(Entity entity, Vector3d position, Quaterniond rotation){
//reposition entity
CollisionObjUtils.clientPositionCharacter(entity, position, rotation);
}
/**
* Destroys an entity on the client
* @param entity the entity to destroy
*/
public static void destroyEntity(Entity entity){
if(entity != null){
//
//destroy the child entities, too
if(AttachUtils.hasChildren(entity)){
List<Entity> children = AttachUtils.getChildrenList(entity);
for(Entity child : children){
ClientEntityUtils.destroyEntity(child);
}
}
//delete unique model if present
if(entity.containsKey(EntityDataStrings.HAS_UNIQUE_MODEL)){
ActorUtils.queueActorForDeletion(entity);
}
//check for client-specific stuff
Globals.renderingEngine.getLightManager().destroyPointLight(entity);
//deregister all behavior trees
EntityUtils.cleanUpEntity(entity);
//instanced actor
if(TextureInstancedActor.getTextureInstancedActor(entity) != null){
TextureInstancedActor actor = TextureInstancedActor.getTextureInstancedActor(entity);
actor.free();
}
if(Globals.clientSceneWrapper != null){
Globals.clientSceneWrapper.getScene().deregisterEntity(entity);
Globals.clientSceneWrapper.deregisterTranslationMapping(entity);
if(Globals.clientSceneWrapper.getCollisionEngine() != null){
Globals.clientSceneWrapper.getCollisionEngine().destroyPhysics(entity);
}
}
if(Globals.clientScene != null){
Globals.clientScene.deregisterEntity(entity);
}
HitboxCollectionState.destroyHitboxState(entity,false);
ClientInteractionEngine.destroyCollidableTemplate(entity);
if(entity == Globals.playerEntity && Globals.firstPersonEntity != null){
ClientEntityUtils.destroyEntity(Globals.firstPersonEntity);
}
}
}
}