From e9beaba539f0f5407ec490cad4b4275b5c397230 Mon Sep 17 00:00:00 2001 From: austin Date: Wed, 28 May 2025 15:13:35 -0400 Subject: [PATCH] macro structure rotation fix --- docs/src/progress/renderertodo.md | 1 + .../interact/ClientInteractionEngine.java | 120 +++++++++--------- .../ServerBlockChunkGenerationThread.java | 44 ++++--- 3 files changed, 88 insertions(+), 77 deletions(-) diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index 61339cca..09a68d93 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -2022,6 +2022,7 @@ Fix foundation generation for structures in chunkgen Body synchronization includes enabled state Fix upright tree continuously re-enabling bodies Fix server collision resolution never triggering for second body +Fix macro structure rotation generation diff --git a/src/main/java/electrosphere/client/interact/ClientInteractionEngine.java b/src/main/java/electrosphere/client/interact/ClientInteractionEngine.java index b0fd0723..a97ac295 100644 --- a/src/main/java/electrosphere/client/interact/ClientInteractionEngine.java +++ b/src/main/java/electrosphere/client/interact/ClientInteractionEngine.java @@ -246,66 +246,66 @@ public class ClientInteractionEngine { InteractionTargetMenu.setInteractionTargetString(text); set = true; } - if(!set){ - target = Globals.clientState.clientSceneWrapper.getCollisionEngine().rayCast(new Vector3d(centerPos), new Vector3d(eyePos).mul(-1), CollisionEngine.DEFAULT_INTERACT_DISTANCE); - if(target != null){ - EntityType type = CommonEntityUtils.getEntityType(target); - if(type == null){ - throw new Error("Entity does not have a type defined!"); - } - switch(type){ - case CREATURE: { - InteractionTargetMenu.setInteractionTargetString(CommonEntityUtils.getEntitySubtype(target)); - set = true; - } break; - case ITEM: { - InteractionTargetMenu.setInteractionTargetString(CommonEntityUtils.getEntitySubtype(target)); - set = true; - } break; - case FOLIAGE: { - InteractionTargetMenu.setInteractionTargetString(CommonEntityUtils.getEntitySubtype(target)); - set = true; - } break; - default: { - //silently ignore - } break; - } - } - } - if(!set){ - Vector3d collisionPosition = Globals.clientState.clientSceneWrapper.getCollisionEngine().rayCastPosition(centerPos, new Vector3d(eyePos).mul(-1), CollisionEngine.DEFAULT_INTERACT_DISTANCE); - if( - collisionPosition != null && - collisionPosition.distance(centerPos) < CollisionEngine.DEFAULT_INTERACT_DISTANCE && - collisionPosition.x >= 0 && collisionPosition.y >= 0 && collisionPosition.z >= 0 - ){ - //grab block at point - BlockChunkData blockChunkData = Globals.clientState.clientBlockManager.getChunkDataAtWorldPoint(Globals.clientState.clientWorldData.convertRealToWorldSpace(collisionPosition), 0); - if(blockChunkData != null){ - Vector3i blockPos = ClientWorldData.convertRealToLocalBlockSpace(new Vector3d(collisionPosition).add(new Vector3d(eyePos).mul(-BlockChunkData.BLOCK_SIZE_MULTIPLIER / 2.0f))); - if(!blockChunkData.isEmpty(blockPos.x, blockPos.y, blockPos.z)){ - short type = blockChunkData.getType(blockPos.x, blockPos.y, blockPos.z); - String text = Globals.gameConfigCurrent.getBlockData().getTypeFromId(type).getName(); - InteractionTargetMenu.setInteractionTargetString(text); - Globals.cursorState.hintShowBlockCursor(); - Globals.cursorState.hintClampToExistingBlock(); - set = true; - } - } - //if we didn't find a block type, try terrain - if(!set){ - ChunkData chunkData = Globals.clientState.clientTerrainManager.getChunkDataAtWorldPoint(Globals.clientState.clientWorldData.convertRealToWorldSpace(collisionPosition), 0); - if(chunkData != null){ - int voxelType = chunkData.getType(ClientWorldData.convertRealToVoxelSpace(new Vector3d(collisionPosition).add(new Vector3d(ServerTerrainChunk.VOXEL_SIZE / 2.0f)))); - if(voxelType != ServerTerrainChunk.VOXEL_TYPE_AIR){ - String text = Globals.gameConfigCurrent.getVoxelData().getTypeFromId(voxelType).getName(); - InteractionTargetMenu.setInteractionTargetString(text); - set = true; - } - } - } - } - } + // if(!set){ + // target = Globals.clientState.clientSceneWrapper.getCollisionEngine().rayCast(new Vector3d(centerPos), new Vector3d(eyePos).mul(-1), CollisionEngine.DEFAULT_INTERACT_DISTANCE); + // if(target != null){ + // EntityType type = CommonEntityUtils.getEntityType(target); + // if(type == null){ + // throw new Error("Entity does not have a type defined!"); + // } + // switch(type){ + // case CREATURE: { + // InteractionTargetMenu.setInteractionTargetString(CommonEntityUtils.getEntitySubtype(target)); + // set = true; + // } break; + // case ITEM: { + // InteractionTargetMenu.setInteractionTargetString(CommonEntityUtils.getEntitySubtype(target)); + // set = true; + // } break; + // case FOLIAGE: { + // InteractionTargetMenu.setInteractionTargetString(CommonEntityUtils.getEntitySubtype(target)); + // set = true; + // } break; + // default: { + // //silently ignore + // } break; + // } + // } + // } + // if(!set){ + // Vector3d collisionPosition = Globals.clientState.clientSceneWrapper.getCollisionEngine().rayCastPosition(centerPos, new Vector3d(eyePos).mul(-1), CollisionEngine.DEFAULT_INTERACT_DISTANCE); + // if( + // collisionPosition != null && + // collisionPosition.distance(centerPos) < CollisionEngine.DEFAULT_INTERACT_DISTANCE && + // collisionPosition.x >= 0 && collisionPosition.y >= 0 && collisionPosition.z >= 0 + // ){ + // //grab block at point + // BlockChunkData blockChunkData = Globals.clientState.clientBlockManager.getChunkDataAtWorldPoint(Globals.clientState.clientWorldData.convertRealToWorldSpace(collisionPosition), 0); + // if(blockChunkData != null){ + // Vector3i blockPos = ClientWorldData.convertRealToLocalBlockSpace(new Vector3d(collisionPosition).add(new Vector3d(eyePos).mul(-BlockChunkData.BLOCK_SIZE_MULTIPLIER / 2.0f))); + // if(!blockChunkData.isEmpty(blockPos.x, blockPos.y, blockPos.z)){ + // short type = blockChunkData.getType(blockPos.x, blockPos.y, blockPos.z); + // String text = Globals.gameConfigCurrent.getBlockData().getTypeFromId(type).getName(); + // InteractionTargetMenu.setInteractionTargetString(text); + // Globals.cursorState.hintShowBlockCursor(); + // Globals.cursorState.hintClampToExistingBlock(); + // set = true; + // } + // } + // //if we didn't find a block type, try terrain + // if(!set){ + // ChunkData chunkData = Globals.clientState.clientTerrainManager.getChunkDataAtWorldPoint(Globals.clientState.clientWorldData.convertRealToWorldSpace(collisionPosition), 0); + // if(chunkData != null){ + // int voxelType = chunkData.getType(ClientWorldData.convertRealToVoxelSpace(new Vector3d(collisionPosition).add(new Vector3d(ServerTerrainChunk.VOXEL_SIZE / 2.0f)))); + // if(voxelType != ServerTerrainChunk.VOXEL_TYPE_AIR){ + // String text = Globals.gameConfigCurrent.getVoxelData().getTypeFromId(voxelType).getName(); + // InteractionTargetMenu.setInteractionTargetString(text); + // set = true; + // } + // } + // } + // } + // } if(!set){ InteractionTargetMenu.setInteractionTargetString(""); } diff --git a/src/main/java/electrosphere/server/physics/block/manager/ServerBlockChunkGenerationThread.java b/src/main/java/electrosphere/server/physics/block/manager/ServerBlockChunkGenerationThread.java index fe141da4..471e5cb0 100644 --- a/src/main/java/electrosphere/server/physics/block/manager/ServerBlockChunkGenerationThread.java +++ b/src/main/java/electrosphere/server/physics/block/manager/ServerBlockChunkGenerationThread.java @@ -7,13 +7,11 @@ import java.util.function.Consumer; import java.util.stream.Collectors; import org.joml.AABBd; -import org.joml.Quaterniond; import org.joml.Vector3d; import org.joml.Vector3i; import electrosphere.client.block.BlockChunkCache; import electrosphere.client.block.BlockChunkData; -import electrosphere.controls.cursor.CursorState; import electrosphere.engine.Globals; import electrosphere.logger.LoggerInterface; import electrosphere.server.datacell.ServerWorldData; @@ -227,7 +225,6 @@ public class ServerBlockChunkGenerationThread implements Runnable { Vector3d chunkRealPos = ServerWorldData.convertChunkToRealSpace(chunkPos); Vector3d localBlockPos = new Vector3d(); Vector3d currRealPos = new Vector3d(chunkRealPos); - Vector3d dimVec = new Vector3d(); //contains at least one structure for(int x = 0; x < BlockChunkData.CHUNK_DATA_WIDTH; x++){ for(int y = 0; y < BlockChunkData.CHUNK_DATA_WIDTH; y++){ @@ -249,23 +246,36 @@ public class ServerBlockChunkGenerationThread implements Runnable { Math.round((currRealPos.z - aabb.minZ) / BlockChunkData.BLOCK_SIZE_MULTIPLIER) ); - Quaterniond rotationQuat = CursorState.getBlockRotation(struct.getRotation()); - rotationQuat.transform(localBlockPos); - dimVec.set(struct.getFab().getDimensions()); - rotationQuat.transform(dimVec); - dimVec.absolute(); - if(localBlockPos.x < 0){ - localBlockPos.x = dimVec.x + localBlockPos.x; - } - if(localBlockPos.y < 0){ - localBlockPos.y = dimVec.y + localBlockPos.y; - } - if(localBlockPos.z < 0){ - localBlockPos.z = dimVec.z + localBlockPos.z; - } int finalX = Math.round((float)localBlockPos.x); int finalY = Math.round((float)localBlockPos.y); int finalZ = Math.round((float)localBlockPos.z); + + int intermediateX = finalX; + int intermediateZ = finalZ; + + int dimX = (int)Math.round((struct.getAABB().maxX - struct.getAABB().minX) / BlockChunkData.BLOCK_SIZE_MULTIPLIER); + int dimZ = (int)Math.round((struct.getAABB().maxZ - struct.getAABB().minZ) / BlockChunkData.BLOCK_SIZE_MULTIPLIER); + + switch(struct.getRotation()){ + case 0: { + } break; + case 1: { + finalX = intermediateZ; + finalZ = dimZ - intermediateX; + } break; + case 2: { + finalX = dimX - intermediateX; + finalZ = dimZ - intermediateZ; + } break; + case 3: { + finalX = dimX - intermediateZ; + finalZ = intermediateX; + } break; + default: { + throw new Error("Unsupported rotation value " + struct.getRotation()); + } + } + //structure file might have dimensions larger than fab, so need to make sure we're inbounds on fab file to draw data from fab file if( finalX >= 0 &&