Skip to content

Commit

Permalink
Merge pull request #157 from BenjaTK/air-layer
Browse files Browse the repository at this point in the history
Fix bug with HeightmapGenerator3D and standardize how air layer works
  • Loading branch information
BenjaTK authored Aug 15, 2024
2 parents ad7937a + 99e920c commit 7f41358
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func _set_grid() -> void:
for x in range(settings.world_length):
max_height = maxi(
floor(settings.noise.get_noise_1d(x) * settings.height_intensity + settings.height_offset), max_height
)
) + 1

var area := Rect2i(
# starting point
Expand All @@ -102,10 +102,9 @@ func _set_grid_area(area: Rect2i) -> void:

var height = floor(settings.noise.get_noise_1d(x) * settings.height_intensity + settings.height_offset)
for y in range(area.position.y, area.end.y):
if y > -height and y <= -settings.min_height:
if y >= -height and y <= -settings.min_height:
grid.set_valuexy(x, y, settings.tile)

if y == -height and settings.air_layer:
elif y == -height - 1 and settings.air_layer:
grid.set_valuexy(x, y, null)


2 changes: 1 addition & 1 deletion addons/gaea/generators/3D/grid_3d.gd
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func erasexyz(x: int, y: int, z: int, layer: int) -> void:
## Returns [code]true[/code] if the cell at the given position has a non-existing neighbor. Doesn't include diagonals.
func has_empty_neighbor(pos: Vector3i, layer: int) -> bool:
for neighbor in NEIGHBORS:
if not has_cell(pos + neighbor, layer):
if not has_cell(pos + neighbor, layer) or get_value(pos + neighbor, layer) == null:
return true

return false
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func _set_grid() -> void:
max_height = maxi(
floor(settings.noise.get_noise_2d(x, z) * settings.height_intensity + settings.height_offset),
max_height
)
) + 1

var area := AABB(
# starting point
Expand Down Expand Up @@ -114,5 +114,5 @@ func _set_grid_area(area: AABB) -> void:
if y <= height and y >= settings.min_height:
grid.set_valuexyz(x, y, z, settings.tile)

if y == height and settings.air_layer:
elif y == height + 1 and settings.air_layer:
grid.set_valuexyz(x, y, z, null)
2 changes: 1 addition & 1 deletion addons/gaea/renderers/3D/gridmap_gaea_renderer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func _draw_area(area: AABB) -> void:
if erase_empty_tiles:
var has_cell: bool = false
for layer in range(generator.grid.get_layer_count()):
if generator.grid.has_cell(cell, layer):
if generator.grid.has_cell(cell, layer) and generator.grid.get_value(cell, layer) != null:
has_cell = true
break

Expand Down

0 comments on commit 7f41358

Please sign in to comment.