From 24fd4791da2e9e738977ff198dac3657dc19d1f0 Mon Sep 17 00:00:00 2001 From: austin Date: Wed, 30 Apr 2025 12:34:58 -0400 Subject: [PATCH] voxel placement improvements --- assets/Data/entity/items/fabs/floors.json | 2 +- docs/src/progress/renderertodo.md | 2 ++ .../electrosphere/controls/cursor/CursorState.java | 1 + .../entity/state/item/ServerChargeState.java | 10 ++++++---- .../physics/block/editing/ServerBlockEditing.java | 13 +++++++++++-- 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/assets/Data/entity/items/fabs/floors.json b/assets/Data/entity/items/fabs/floors.json index dc57f383..9aa062aa 100644 --- a/assets/Data/entity/items/fabs/floors.json +++ b/assets/Data/entity/items/fabs/floors.json @@ -1,7 +1,7 @@ { "items" : [ { - "id" : "woodfloor", + "id" : "fab:woodfloor", "tokens" : [ "GRAVITY", "TARGETABLE" diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index 99e44dc6..47607425 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -1607,6 +1607,8 @@ Items keep charge state UI renders charge state Item stacking +(04/20/2025) +Voxel placement improvements diff --git a/src/main/java/electrosphere/controls/cursor/CursorState.java b/src/main/java/electrosphere/controls/cursor/CursorState.java index 9343788a..c2ff9fcd 100644 --- a/src/main/java/electrosphere/controls/cursor/CursorState.java +++ b/src/main/java/electrosphere/controls/cursor/CursorState.java @@ -173,6 +173,7 @@ public class CursorState { } cursorPos.set(this.clampPositionToNearestBlock(cursorPos)); EntityUtils.getPosition(Globals.playerBlockCursor).set(cursorPos); + cursorPos.sub(BlockChunkData.BLOCK_SIZE_MULTIPLIER / 2.0,BlockChunkData.BLOCK_SIZE_MULTIPLIER / 2.0,BlockChunkData.BLOCK_SIZE_MULTIPLIER / 2.0); EntityUtils.getPosition(CursorState.playerFabCursor).set(cursorPos); } } diff --git a/src/main/java/electrosphere/entity/state/item/ServerChargeState.java b/src/main/java/electrosphere/entity/state/item/ServerChargeState.java index f877000a..3c5641f9 100644 --- a/src/main/java/electrosphere/entity/state/item/ServerChargeState.java +++ b/src/main/java/electrosphere/entity/state/item/ServerChargeState.java @@ -62,10 +62,12 @@ public class ServerChargeState implements BehaviorTree { Entity inventoryItem = serverToolbarState.getInInventoryItem(); if(inventoryItem != null){ ServerChargeState serverChargeState = ServerChargeState.getServerChargeState(inventoryItem); - if(serverChargeState.getCharges() - charges > 0){ - serverChargeState.setCharges(serverChargeState.getCharges() - charges); - } else { - throw new Error("Undefined! " + charges + serverChargeState.getCharges()); + if(serverChargeState != null){ + if(serverChargeState.getCharges() - charges > 0){ + serverChargeState.setCharges(serverChargeState.getCharges() - charges); + } else { + throw new Error("Undefined! " + charges + serverChargeState.getCharges()); + } } } } diff --git a/src/main/java/electrosphere/server/physics/block/editing/ServerBlockEditing.java b/src/main/java/electrosphere/server/physics/block/editing/ServerBlockEditing.java index a01a8101..07e29978 100644 --- a/src/main/java/electrosphere/server/physics/block/editing/ServerBlockEditing.java +++ b/src/main/java/electrosphere/server/physics/block/editing/ServerBlockEditing.java @@ -93,14 +93,23 @@ public class ServerBlockEditing { Quaterniond rotationQuatd = CursorState.getBlockRotation(rotation); Quaternionf rotationQuatf = new Quaternionf((float)rotationQuatd.x,(float)rotationQuatd.y,(float)rotationQuatd.z,(float)rotationQuatd.w); Matrix4f rotMat = new Matrix4f().rotate(rotationQuatf); - Vector4f rotationHolder = new Vector4f(); + Vector4f rotationHolder = new Vector4f(1,1,1,1); + rotMat.transform(rotationHolder); + + //if the cursor is not the default rotation, we want to actually place blocks one position LOWER than the cursor depending on the rotation + //this is because we want the final vertex to end on the block (ie we must place at final vertex-1) + Vector3i offsetFromRot = new Vector3i( + Math.round(Math.min(0,rotationHolder.x)), + Math.round(Math.min(0,rotationHolder.y)), + Math.round(Math.min(0,rotationHolder.z)) + ); for(int x = 0; x < dims.x; x++){ for(int y = 0; y < dims.y; y++){ for(int z = 0; z < dims.z; z++){ rotationHolder.set(x,y,z,1); rotMat.transform(rotationHolder); - currVoxelPos.set(voxelPos).add(Math.round(rotationHolder.x),Math.round(rotationHolder.y),Math.round(rotationHolder.z)); + currVoxelPos.set(voxelPos).add(Math.round(rotationHolder.x),Math.round(rotationHolder.y),Math.round(rotationHolder.z)).add(offsetFromRot); currChunkPos.set(chunkPos).add(