From 22e6f80207123861efea1b5cdeb2a6aa852e8603 Mon Sep 17 00:00:00 2001 From: austin Date: Mon, 28 Apr 2025 13:23:21 -0400 Subject: [PATCH] grid-align work --- assets/Data/entity/objects/furniture.json | 5 +++++ docs/src/progress/renderertodo.md | 1 + .../java/electrosphere/entity/EntityTags.java | 5 +++++ .../types/common/CommonEntityUtils.java | 11 ++++++++++ .../game/data/grident/GridAlignedData.java | 12 +++++------ .../server/datacell/ServerWorldData.java | 21 +++++++++++++++++-- 6 files changed, 47 insertions(+), 8 deletions(-) diff --git a/assets/Data/entity/objects/furniture.json b/assets/Data/entity/objects/furniture.json index e073992f..7baae8e6 100644 --- a/assets/Data/entity/objects/furniture.json +++ b/assets/Data/entity/objects/furniture.json @@ -85,6 +85,11 @@ } } }, + "gridAlignedData" : { + "width" : 10, + "height" : 10, + "length" : 10 + }, "graphicsTemplate": { "model": { "path" : "Models/objects/furniture/workbench1.glb" diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index 37a1284c..bc90f793 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -1577,6 +1577,7 @@ Filter procedural worlds out of level select menu (04/28/2025) Area selection utility RoomTool item +Grid alignment actually aligns entity to grid diff --git a/src/main/java/electrosphere/entity/EntityTags.java b/src/main/java/electrosphere/entity/EntityTags.java index 48918a0b..2496abcc 100644 --- a/src/main/java/electrosphere/entity/EntityTags.java +++ b/src/main/java/electrosphere/entity/EntityTags.java @@ -30,4 +30,9 @@ public class EntityTags { public static final String DRAW_VOLUMETIC_SOLIDS_PASS = "drawVolumetricSolidsPass"; //draw in the non-volumetic phase of the volumetric pass public static final String DRAW_FOLIAGE_PASS = "drawFoliagePass"; //draw in the foliage pass + /** + * Entities that occupy block positions + */ + public static final String BLOCK_OCCUPANT = "blockOccupant"; + } diff --git a/src/main/java/electrosphere/entity/types/common/CommonEntityUtils.java b/src/main/java/electrosphere/entity/types/common/CommonEntityUtils.java index 3ba1369e..2ef0aaab 100644 --- a/src/main/java/electrosphere/entity/types/common/CommonEntityUtils.java +++ b/src/main/java/electrosphere/entity/types/common/CommonEntityUtils.java @@ -417,6 +417,10 @@ public class CommonEntityUtils { if(rawType.getBoneGroups() != null){ creatureActor.setBoneGroups(rawType.getBoneGroups()); } + //grid alignment + if(rawType.getGridAlignedData() != null){ + Globals.clientScene.registerEntityToTag(entity, EntityTags.BLOCK_OCCUPANT); + } //add health system if(rawType.getHealthSystem() != null){ ClientLifeTree.attachTree(entity,rawType.getHealthSystem()); @@ -721,6 +725,13 @@ public class CommonEntityUtils { creatureActor.setBoneGroups(rawType.getBoneGroups()); } + //grid alignment + if(rawType.getGridAlignedData() != null){ + position.set(realm.getServerWorldData().clampRealToBlock(position)); + Globals.clientScene.registerEntityToTag(entity, EntityTags.BLOCK_OCCUPANT); + //TODO: must register with all nearby scenes as well because it could possibly occupy other chunks + } + /// /// /// AI (This SHOULD only be applied on the server with the way AI architected currently) diff --git a/src/main/java/electrosphere/game/data/grident/GridAlignedData.java b/src/main/java/electrosphere/game/data/grident/GridAlignedData.java index 5b3ad8f0..ce0902b2 100644 --- a/src/main/java/electrosphere/game/data/grident/GridAlignedData.java +++ b/src/main/java/electrosphere/game/data/grident/GridAlignedData.java @@ -8,23 +8,23 @@ public class GridAlignedData { /** * The width in blocks to occupy on the block grid */ - int width; + Integer width; /** * The length in blocks to occupy on the block grid */ - int length; + Integer length; /** * The height in blocks to occupy on the block grid */ - int height; + Integer height; /** * Gets the height in blocks to occupy on the block grid * @return The height in blocks to occupy on the block grid */ - public int getWidth() { + public Integer getWidth() { return width; } @@ -32,7 +32,7 @@ public class GridAlignedData { * Gets the length in blocks to occupy on the block grid * @return The length in blocks to occupy on the block grid */ - public int getLength() { + public Integer getLength() { return length; } @@ -40,7 +40,7 @@ public class GridAlignedData { * Gets the width in blocks to occupy on the block grid * @return The width in blocks to occupy on the block grid */ - public int getHeight() { + public Integer getHeight() { return height; } diff --git a/src/main/java/electrosphere/server/datacell/ServerWorldData.java b/src/main/java/electrosphere/server/datacell/ServerWorldData.java index 61063e17..8c3e92d2 100644 --- a/src/main/java/electrosphere/server/datacell/ServerWorldData.java +++ b/src/main/java/electrosphere/server/datacell/ServerWorldData.java @@ -61,10 +61,14 @@ public class ServerWorldData { boolean isArena = false; - //terrain data + /** + * terrain data + */ private ServerTerrainManager serverTerrainManager; - //fluid data + /** + * fluid data + */ private ServerFluidManager serverFluidManager; /** @@ -345,6 +349,19 @@ public class ServerWorldData { public int clampWorldToMacro(int worldPos){ return (worldPos / this.serverTerrainManager.getModel().getMacroDataScale()) * this.serverTerrainManager.getModel().getMacroDataScale(); } + + /** + * Clamps a real space position to the closest block space position + * @param realPos The real space position + * @return The real space position that is clamped to the closest block space position + */ + public Vector3d clampRealToBlock(Vector3d realPos){ + return new Vector3d( + realPos.x - realPos.x % BlockChunkData.BLOCK_SIZE_MULTIPLIER, + realPos.y - realPos.y % BlockChunkData.BLOCK_SIZE_MULTIPLIER, + realPos.z - realPos.z % BlockChunkData.BLOCK_SIZE_MULTIPLIER + ); + } /** * Gets the terrain manager for this world