fix: center ground under chunks and align player spawn with chunk grid
checkpoint / checkpoint (push) Successful in 5m56s

This commit is contained in:
2026-09-17 13:36:59 +00:00
parent bbd9ffc46f
commit 7c77c0b447
4 changed files with 253 additions and 3 deletions
+61
View File
@@ -213,6 +213,12 @@ func _try_load_real_content() -> Node:
marker.position = spawn_pos
var entries: Array = (index_result.data as Dictionary).get("chunks", [])
var min_cx := 0
var max_cx := 0
var min_cy := 0
var max_cy := 0
var found_spawn_obj: Variant = null
for entry in entries:
var cx: int = int(entry["cx"])
var cy: int = int(entry["cy"])
@@ -229,6 +235,61 @@ func _try_load_real_content() -> Node:
_build_chunk_collision(world_root, Vector3i(cx, cy, cz), decoded)
_chunks_loaded += 1
if _chunks_loaded == 1:
min_cx = cx
max_cx = cx
min_cy = cy
max_cy = cy
else:
min_cx = mini(min_cx, cx)
max_cx = maxi(max_cx, cx)
min_cy = mini(min_cy, cy)
max_cy = maxi(max_cy, cy)
if found_spawn_obj == null:
var chunk_origin := Vector3(
float(cx * Chunk.CHUNK_SIZE_X),
float(cz * Chunk.CHUNK_SIZE_Z),
float(cy * Chunk.CHUNK_SIZE_Y)
)
for obj in decoded.objects:
if obj.type == "spawn_point" or str(obj.properties.get("catalog_id", "")) == "spawn_point":
found_spawn_obj = chunk_origin + Vector3(obj.position.x, 1.5, obj.position.y)
break
if _chunks_loaded > 0:
var props := world_root.find_child("Props", true, false)
if props != null:
props.queue_free()
var chest := world_root.find_child("ScriptedChest", true, false)
if chest != null:
chest.queue_free()
var min_x := float(min_cx * Chunk.CHUNK_SIZE_X)
var max_x := float((max_cx + 1) * Chunk.CHUNK_SIZE_X)
var min_z := float(min_cy * Chunk.CHUNK_SIZE_Y)
var max_z := float((max_cy + 1) * Chunk.CHUNK_SIZE_Y)
var center_x := (min_x + max_x) * 0.5
var center_z := (min_z + max_z) * 0.5
var size_x := maxf(40.0, (max_x - min_x) + 8.0)
var size_z := maxf(40.0, (max_z - min_z) + 8.0)
var ground: StaticBody3D = world_root.find_child("Ground", true, false) as StaticBody3D
if ground != null:
ground.position = Vector3(center_x, -0.5, center_z)
var shape_node := ground.find_child("CollisionShape3D", true, false) as CollisionShape3D
if shape_node != null:
var box := BoxShape3D.new()
box.size = Vector3(size_x, 1.0, size_z)
shape_node.shape = box
if found_spawn_obj != null:
spawn_pos = found_spawn_obj
elif not (room.get("spawn") is Dictionary and (room.get("spawn") as Dictionary).has("pos")):
spawn_pos = Vector3(16.0, 1.5, 16.0)
marker.position = spawn_pos
return world_root