Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
73 lines
3.2 KiB
Java
73 lines
3.2 KiB
Java
package electrosphere.entity;
|
|
|
|
import org.joml.Vector3d;
|
|
|
|
import electrosphere.engine.Globals;
|
|
import electrosphere.entity.types.collision.CollisionObjUtils;
|
|
import electrosphere.server.datacell.Realm;
|
|
import electrosphere.server.datacell.ServerDataCell;
|
|
import electrosphere.server.datacell.utils.DataCellSearchUtils;
|
|
import electrosphere.server.datacell.utils.ServerBehaviorTreeUtils;
|
|
|
|
/**
|
|
* Entity utilities specifically for the server side
|
|
*/
|
|
public class ServerEntityUtils {
|
|
|
|
/**
|
|
* Called when the creature is first spawned to serialize to all people in its initial chunk
|
|
* @param entity
|
|
* @param position
|
|
*/
|
|
public static void initiallyPositionEntity(Realm realm, Entity entity, Vector3d position){
|
|
Globals.realmManager.mapEntityToRealm(entity, realm);
|
|
//get current server data cell
|
|
ServerDataCell cell = realm.getDataCellManager().getDataCellAtPoint(position);
|
|
if(cell != null){
|
|
//initialize server datacell tracking of this entity
|
|
realm.initializeServerSideEntity(entity, cell);
|
|
} else {
|
|
//if it doesn't already exist, try creating it and if successfull move creature
|
|
cell = realm.getDataCellManager().tryCreateCellAtPoint(position);
|
|
//initialize server datacell tracking of this entity
|
|
realm.initializeServerSideEntity(entity, cell);
|
|
}
|
|
//reposition entity
|
|
CollisionObjUtils.positionCharacter(entity, position);
|
|
}
|
|
|
|
/**
|
|
* Called to reposition the creature
|
|
* @param entity
|
|
* @param position
|
|
*/
|
|
public static void repositionEntity(Entity entity, Vector3d position){
|
|
Realm realm = Globals.realmManager.getEntityRealm(entity);
|
|
//if server, get current server data cell
|
|
if(Globals.RUN_SERVER){
|
|
ServerDataCell oldDataCell = realm.getDataCellManager().getDataCellAtPoint(EntityUtils.getPosition(entity));
|
|
ServerDataCell newDataCell = realm.getDataCellManager().getDataCellAtPoint(position);
|
|
if(newDataCell != null){
|
|
ServerDataCell.moveEntityFromCellToCell(entity, oldDataCell, newDataCell);
|
|
ServerBehaviorTreeUtils.updateCell(entity, oldDataCell);
|
|
} else {
|
|
//if it doesn't already exist, try creating it and if successfull move creature
|
|
newDataCell = realm.getDataCellManager().tryCreateCellAtPoint(EntityUtils.getPosition(entity));
|
|
if(newDataCell != null){
|
|
ServerDataCell.moveEntityFromCellToCell(entity, oldDataCell, newDataCell);
|
|
ServerBehaviorTreeUtils.updateCell(entity, oldDataCell);
|
|
}
|
|
}
|
|
// //if the server is also a client, update the drawcell manager to know to pull new chunks
|
|
// if(Globals.RUN_CLIENT){
|
|
// Globals.drawCellManager.invalidateAllCells();
|
|
// Globals.drawCellManager.setCellX(Globals.clientPlayerData.getWorldPos().x);
|
|
// Globals.drawCellManager.setCellY(Globals.clientPlayerData.getWorldPos().z);
|
|
// }
|
|
}
|
|
//reposition entity
|
|
CollisionObjUtils.positionCharacter(entity, Globals.spawnPoint);
|
|
}
|
|
|
|
}
|