From 4c6c30db0f16b1d85c701f213ea0d7e99e251ba7 Mon Sep 17 00:00:00 2001 From: austin Date: Tue, 29 Apr 2025 11:51:49 -0400 Subject: [PATCH] fix door tree physics --- docs/src/progress/renderertodo.md | 3 +++ .../electrosphere/collision/PhysicsEntityUtils.java | 9 +++++++++ .../entity/state/furniture/ClientDoorState.java | 12 ++++++++++-- .../entity/state/furniture/ServerDoorState.java | 10 ++++++++-- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index bc90f793..2cdcccd0 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -1579,6 +1579,9 @@ Area selection utility RoomTool item Grid alignment actually aligns entity to grid +(04/29/2025) +Fix door tree physics + diff --git a/src/main/java/electrosphere/collision/PhysicsEntityUtils.java b/src/main/java/electrosphere/collision/PhysicsEntityUtils.java index 92667215..d6a91e00 100644 --- a/src/main/java/electrosphere/collision/PhysicsEntityUtils.java +++ b/src/main/java/electrosphere/collision/PhysicsEntityUtils.java @@ -676,5 +676,14 @@ public class PhysicsEntityUtils { PhysicsUtils.disableBody(collisionEngine, body); } } + + /** + * Gets the physics template for the entity + * @param entity The entity + * @return The template + */ + public static CollidableTemplate getPhysicsTemplate(Entity entity){ + return (CollidableTemplate)entity.getData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE); + } } diff --git a/src/main/java/electrosphere/entity/state/furniture/ClientDoorState.java b/src/main/java/electrosphere/entity/state/furniture/ClientDoorState.java index 10265007..78394b72 100644 --- a/src/main/java/electrosphere/entity/state/furniture/ClientDoorState.java +++ b/src/main/java/electrosphere/entity/state/furniture/ClientDoorState.java @@ -1,14 +1,19 @@ package electrosphere.entity.state.furniture; +import org.joml.Quaterniond; +import org.joml.Vector3d; + import electrosphere.collision.PhysicsEntityUtils; import electrosphere.engine.Globals; import electrosphere.entity.EntityDataStrings; +import electrosphere.entity.EntityUtils; import electrosphere.net.synchronization.enums.BehaviorTreeIdEnums; import electrosphere.entity.Entity; import electrosphere.entity.btree.BehaviorTree; import electrosphere.entity.btree.StateTransitionUtil; import electrosphere.entity.btree.StateTransitionUtil.StateTransitionUtilItem; +import electrosphere.entity.types.collision.CollisionObjUtils; import electrosphere.game.data.furniture.DoorData; import electrosphere.net.synchronization.annotation.SyncedField; import electrosphere.net.synchronization.annotation.SynchronizableEnum; @@ -87,7 +92,7 @@ public class ClientDoorState implements BehaviorTree { doorData.getOpening(), () -> { this.setState(DoorState.OPEN); - PhysicsEntityUtils.disableBody(Globals.clientSceneWrapper.getCollisionEngine(), this.parent); + Globals.clientSceneWrapper.getCollisionEngine().destroyPhysics(this.parent); } ), StateTransitionUtilItem.create( @@ -100,7 +105,10 @@ public class ClientDoorState implements BehaviorTree { doorData.getClosing(), () -> { this.setState(DoorState.CLOSED); - PhysicsEntityUtils.enableBody(Globals.clientSceneWrapper.getCollisionEngine(), this.parent); + Vector3d pos = EntityUtils.getPosition(this.parent); + Quaterniond rot = EntityUtils.getRotation(this.parent); + PhysicsEntityUtils.clientAttachCollidableTemplate(this.parent, PhysicsEntityUtils.getPhysicsTemplate(this.parent)); + CollisionObjUtils.clientPositionCharacter(this.parent, pos, rot); } ), }); diff --git a/src/main/java/electrosphere/entity/state/furniture/ServerDoorState.java b/src/main/java/electrosphere/entity/state/furniture/ServerDoorState.java index aa8d8d49..9063937a 100644 --- a/src/main/java/electrosphere/entity/state/furniture/ServerDoorState.java +++ b/src/main/java/electrosphere/entity/state/furniture/ServerDoorState.java @@ -1,9 +1,13 @@ package electrosphere.entity.state.furniture; +import org.joml.Vector3d; + import electrosphere.collision.PhysicsEntityUtils; import electrosphere.engine.Globals; import electrosphere.entity.EntityDataStrings; +import electrosphere.entity.EntityUtils; +import electrosphere.entity.ServerEntityUtils; import electrosphere.net.synchronization.enums.FieldIdEnums; import electrosphere.server.datacell.Realm; import electrosphere.server.datacell.utils.DataCellSearchUtils; @@ -67,7 +71,7 @@ public class ServerDoorState implements BehaviorTree { () -> { this.setState(DoorState.OPEN); Realm parentRealm = Globals.realmManager.getEntityRealm(this.parent); - PhysicsEntityUtils.disableBody(parentRealm.getCollisionEngine(), this.parent); + parentRealm.getCollisionEngine().destroyPhysics(this.parent); } ), StateTransitionUtilItem.create( @@ -81,7 +85,9 @@ public class ServerDoorState implements BehaviorTree { () -> { this.setState(DoorState.CLOSED); Realm parentRealm = Globals.realmManager.getEntityRealm(this.parent); - PhysicsEntityUtils.enableBody(parentRealm.getCollisionEngine(), this.parent); + Vector3d pos = EntityUtils.getPosition(this.parent); + PhysicsEntityUtils.serverAttachCollidableTemplate(parentRealm, this.parent, PhysicsEntityUtils.getPhysicsTemplate(this.parent)); + ServerEntityUtils.repositionEntity(this.parent, pos); } ), });