macro structure rotation fix
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2025-05-28 15:13:35 -04:00
parent e7d2bf42c1
commit e9beaba539
3 changed files with 88 additions and 77 deletions

View File

@ -2022,6 +2022,7 @@ Fix foundation generation for structures in chunkgen
Body synchronization includes enabled state Body synchronization includes enabled state
Fix upright tree continuously re-enabling bodies Fix upright tree continuously re-enabling bodies
Fix server collision resolution never triggering for second body Fix server collision resolution never triggering for second body
Fix macro structure rotation generation

View File

@ -246,66 +246,66 @@ public class ClientInteractionEngine {
InteractionTargetMenu.setInteractionTargetString(text); InteractionTargetMenu.setInteractionTargetString(text);
set = true; set = true;
} }
if(!set){ // if(!set){
target = Globals.clientState.clientSceneWrapper.getCollisionEngine().rayCast(new Vector3d(centerPos), new Vector3d(eyePos).mul(-1), CollisionEngine.DEFAULT_INTERACT_DISTANCE); // target = Globals.clientState.clientSceneWrapper.getCollisionEngine().rayCast(new Vector3d(centerPos), new Vector3d(eyePos).mul(-1), CollisionEngine.DEFAULT_INTERACT_DISTANCE);
if(target != null){ // if(target != null){
EntityType type = CommonEntityUtils.getEntityType(target); // EntityType type = CommonEntityUtils.getEntityType(target);
if(type == null){ // if(type == null){
throw new Error("Entity does not have a type defined!"); // throw new Error("Entity does not have a type defined!");
} // }
switch(type){ // switch(type){
case CREATURE: { // case CREATURE: {
InteractionTargetMenu.setInteractionTargetString(CommonEntityUtils.getEntitySubtype(target)); // InteractionTargetMenu.setInteractionTargetString(CommonEntityUtils.getEntitySubtype(target));
set = true; // set = true;
} break; // } break;
case ITEM: { // case ITEM: {
InteractionTargetMenu.setInteractionTargetString(CommonEntityUtils.getEntitySubtype(target)); // InteractionTargetMenu.setInteractionTargetString(CommonEntityUtils.getEntitySubtype(target));
set = true; // set = true;
} break; // } break;
case FOLIAGE: { // case FOLIAGE: {
InteractionTargetMenu.setInteractionTargetString(CommonEntityUtils.getEntitySubtype(target)); // InteractionTargetMenu.setInteractionTargetString(CommonEntityUtils.getEntitySubtype(target));
set = true; // set = true;
} break; // } break;
default: { // default: {
//silently ignore // //silently ignore
} break; // } break;
} // }
} // }
} // }
if(!set){ // if(!set){
Vector3d collisionPosition = Globals.clientState.clientSceneWrapper.getCollisionEngine().rayCastPosition(centerPos, new Vector3d(eyePos).mul(-1), CollisionEngine.DEFAULT_INTERACT_DISTANCE); // Vector3d collisionPosition = Globals.clientState.clientSceneWrapper.getCollisionEngine().rayCastPosition(centerPos, new Vector3d(eyePos).mul(-1), CollisionEngine.DEFAULT_INTERACT_DISTANCE);
if( // if(
collisionPosition != null && // collisionPosition != null &&
collisionPosition.distance(centerPos) < CollisionEngine.DEFAULT_INTERACT_DISTANCE && // collisionPosition.distance(centerPos) < CollisionEngine.DEFAULT_INTERACT_DISTANCE &&
collisionPosition.x >= 0 && collisionPosition.y >= 0 && collisionPosition.z >= 0 // collisionPosition.x >= 0 && collisionPosition.y >= 0 && collisionPosition.z >= 0
){ // ){
//grab block at point // //grab block at point
BlockChunkData blockChunkData = Globals.clientState.clientBlockManager.getChunkDataAtWorldPoint(Globals.clientState.clientWorldData.convertRealToWorldSpace(collisionPosition), 0); // BlockChunkData blockChunkData = Globals.clientState.clientBlockManager.getChunkDataAtWorldPoint(Globals.clientState.clientWorldData.convertRealToWorldSpace(collisionPosition), 0);
if(blockChunkData != null){ // if(blockChunkData != null){
Vector3i blockPos = ClientWorldData.convertRealToLocalBlockSpace(new Vector3d(collisionPosition).add(new Vector3d(eyePos).mul(-BlockChunkData.BLOCK_SIZE_MULTIPLIER / 2.0f))); // 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)){ // if(!blockChunkData.isEmpty(blockPos.x, blockPos.y, blockPos.z)){
short type = blockChunkData.getType(blockPos.x, blockPos.y, blockPos.z); // short type = blockChunkData.getType(blockPos.x, blockPos.y, blockPos.z);
String text = Globals.gameConfigCurrent.getBlockData().getTypeFromId(type).getName(); // String text = Globals.gameConfigCurrent.getBlockData().getTypeFromId(type).getName();
InteractionTargetMenu.setInteractionTargetString(text); // InteractionTargetMenu.setInteractionTargetString(text);
Globals.cursorState.hintShowBlockCursor(); // Globals.cursorState.hintShowBlockCursor();
Globals.cursorState.hintClampToExistingBlock(); // Globals.cursorState.hintClampToExistingBlock();
set = true; // set = true;
} // }
} // }
//if we didn't find a block type, try terrain // //if we didn't find a block type, try terrain
if(!set){ // if(!set){
ChunkData chunkData = Globals.clientState.clientTerrainManager.getChunkDataAtWorldPoint(Globals.clientState.clientWorldData.convertRealToWorldSpace(collisionPosition), 0); // ChunkData chunkData = Globals.clientState.clientTerrainManager.getChunkDataAtWorldPoint(Globals.clientState.clientWorldData.convertRealToWorldSpace(collisionPosition), 0);
if(chunkData != null){ // if(chunkData != null){
int voxelType = chunkData.getType(ClientWorldData.convertRealToVoxelSpace(new Vector3d(collisionPosition).add(new Vector3d(ServerTerrainChunk.VOXEL_SIZE / 2.0f)))); // int voxelType = chunkData.getType(ClientWorldData.convertRealToVoxelSpace(new Vector3d(collisionPosition).add(new Vector3d(ServerTerrainChunk.VOXEL_SIZE / 2.0f))));
if(voxelType != ServerTerrainChunk.VOXEL_TYPE_AIR){ // if(voxelType != ServerTerrainChunk.VOXEL_TYPE_AIR){
String text = Globals.gameConfigCurrent.getVoxelData().getTypeFromId(voxelType).getName(); // String text = Globals.gameConfigCurrent.getVoxelData().getTypeFromId(voxelType).getName();
InteractionTargetMenu.setInteractionTargetString(text); // InteractionTargetMenu.setInteractionTargetString(text);
set = true; // set = true;
} // }
} // }
} // }
} // }
} // }
if(!set){ if(!set){
InteractionTargetMenu.setInteractionTargetString(""); InteractionTargetMenu.setInteractionTargetString("");
} }

View File

@ -7,13 +7,11 @@ import java.util.function.Consumer;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.joml.AABBd; import org.joml.AABBd;
import org.joml.Quaterniond;
import org.joml.Vector3d; import org.joml.Vector3d;
import org.joml.Vector3i; import org.joml.Vector3i;
import electrosphere.client.block.BlockChunkCache; import electrosphere.client.block.BlockChunkCache;
import electrosphere.client.block.BlockChunkData; import electrosphere.client.block.BlockChunkData;
import electrosphere.controls.cursor.CursorState;
import electrosphere.engine.Globals; import electrosphere.engine.Globals;
import electrosphere.logger.LoggerInterface; import electrosphere.logger.LoggerInterface;
import electrosphere.server.datacell.ServerWorldData; import electrosphere.server.datacell.ServerWorldData;
@ -227,7 +225,6 @@ public class ServerBlockChunkGenerationThread implements Runnable {
Vector3d chunkRealPos = ServerWorldData.convertChunkToRealSpace(chunkPos); Vector3d chunkRealPos = ServerWorldData.convertChunkToRealSpace(chunkPos);
Vector3d localBlockPos = new Vector3d(); Vector3d localBlockPos = new Vector3d();
Vector3d currRealPos = new Vector3d(chunkRealPos); Vector3d currRealPos = new Vector3d(chunkRealPos);
Vector3d dimVec = new Vector3d();
//contains at least one structure //contains at least one structure
for(int x = 0; x < BlockChunkData.CHUNK_DATA_WIDTH; x++){ for(int x = 0; x < BlockChunkData.CHUNK_DATA_WIDTH; x++){
for(int y = 0; y < BlockChunkData.CHUNK_DATA_WIDTH; y++){ 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) 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 finalX = Math.round((float)localBlockPos.x);
int finalY = Math.round((float)localBlockPos.y); int finalY = Math.round((float)localBlockPos.y);
int finalZ = Math.round((float)localBlockPos.z); 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 //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( if(
finalX >= 0 && finalX >= 0 &&