class_name GeneratorSimple extends RefCounted const NAME := "simple" var noise := FastNoiseLite.new() var array := PackedByteArray() var bias_air := 0.0 # Above this, always air var bias_solid := 64.0 # Below this, always solid func _init() -> void: noise.seed = randi() noise.noise_type = FastNoiseLite.TYPE_SIMPLEX noise.fractal_gain = 0.75 noise.fractal_lacunarity = 2.5 noise.fractal_octaves = 3 array.resize((Chunk.SIZE + 4) * (Chunk.SIZE + 4)) func generate(world: World, chunk: Chunk) -> void: const THRESHOLD := 0.5 var region := chunk.region.extend(2) var i := 0 for pos in region: var bias := (pos.y - bias_air) / (bias_solid - bias_air) array[i] = int((noise.get_noise_2dv(Vector2(pos)) + bias) >= THRESHOLD) i += 1 var matter: Matter.Layer = chunk.get_or_create_layer(Matter) var shapes: Shape.Layer = chunk.get_or_create_layer(Shape) for pos in BlockRegion.LOCAL_CHUNK: var shape: Shape var a := array const W := (Chunk.SIZE + 4) i = (pos.x + 2) + (pos.y + 2) * W var values: Array[int] = [ a[i-2-W*2], a[i-1-W*2], a[i-W*2], a[i+1-W*2], a[i+2-W*2], a[i-2-W ], a[i-1-W ], a[i-W ], a[i+1-W ], a[i+2-W ], a[i-2 ], a[i-1 ], a[i ], a[i+1 ], a[i+2 ], a[i-2+W ], a[i-1+W ], a[i+W ], a[i+1+W ], a[i+2+W ], a[i-2+W*2], a[i-1+W*2], a[i+W*2], a[i+1+W*2], a[i+2+W*2], ] # TODO: Implement custom pattern matching that can handle rotation and mirroring. # var x := -1 # var pattern: Array[int] = [ # x, x, x, x, x, # x, x, 0, 0, 0, # x, 0, 0, 1, 1, # x, 1, 1, 1, x, # x, x, x, x, x, # ] match values: # HALF_SLOPE (non-mirrored) [ _, _, _, _, _, _, _, 0, 0, 0, _, 0, 0, 1, 1, _, 1, 1, 1, _, _, _, _, _, _, ]: shape = Shape.Base.HALF_SLOPE.variants[0] [ _, 0, 1, _, _, _, 0, 1, 1, _, _, 0, 0, 1, _, _, _, 0, 1, _, _, _, _, _, _, ]: shape = Shape.Base.HALF_SLOPE.variants[1] [ _, _, _, _, _, _, 1, 1, 1, _, 1, 1, 0, 0, _, 0, 0, 0, _, _, _, _, _, _, _, ]: shape = Shape.Base.HALF_SLOPE.variants[2] [ _, _, _, _, _, _, 1, 0, _, _, _, 1, 0, 0, _, _, 1, 1, 0, _, _, _, 1, 0, _, ]: shape = Shape.Base.HALF_SLOPE.variants[3] [ _, _, _, _, _, _, 0, 0, 0, _, 0, 0, 1, 1, _, 1, 1, 1, _, _, _, _, _, _, _, ]: shape = Shape.Base.HALF_SLOPE_BIG.variants[0] [ _, _, _, _, _, _, 0, 1, _, _, _, 0, 1, 1, _, _, 0, 0, 1, _, _, _, 0, 1, _, ]: shape = Shape.Base.HALF_SLOPE_BIG.variants[1] [ _, _, _, _, _, _, _, 1, 1, 1, _, 1, 1, 0, 0, _, 0, 0, 0, _, _, _, _, _, _, ]: shape = Shape.Base.HALF_SLOPE_BIG.variants[2] [ _, 1, 0, _, _, _, 1, 0, 0, _, _, 1, 1, 0, _, _, _, 1, 0, _, _, _, _, _, _, ]: shape = Shape.Base.HALF_SLOPE_BIG.variants[3] # HALF_SLOPE (mirrored) [ _, _, _, _, _, 0, 0, 0, _, _, 1, 1, 0, 0, _, _, 1, 1, 1, _, _, _, _, _, _, ]: shape = Shape.Base.HALF_SLOPE.variants[4] [ _, _, _, _, _, _, _, 0, 1, _, _, 0, 0, 1, _, _, 0, 1, 1, _, _, 0, 1, _, _, ]: shape = Shape.Base.HALF_SLOPE.variants[5] [ _, _, _, _, _, _, 1, 1, 1, _, _, 0, 0, 1, 1, _, _, 0, 0, 0, _, _, _, _, _, ]: shape = Shape.Base.HALF_SLOPE.variants[6] [ _, _, 1, 0, _, _, 1, 1, 0, _, _, 1, 0, 0, _, _, 1, 0, _, _, _, _, _, _, _, ]: shape = Shape.Base.HALF_SLOPE.variants[7] [ _, _, _, _, _, _, 0, 0, 0, _, _, 1, 1, 0, 0, _, _, 1, 1, 1, _, _, _, _, _, ]: shape = Shape.Base.HALF_SLOPE_BIG.variants[4] [ _, _, 0, 1, _, _, 0, 0, 1, _, _, 0, 1, 1, _, _, 0, 1, _, _, _, _, _, _, _, ]: shape = Shape.Base.HALF_SLOPE_BIG.variants[5] [ _, _, _, _, _, 1, 1, 1, _, _, 0, 0, 1, 1, _, _, 0, 0, 0, _, _, _, _, _, _, ]: shape = Shape.Base.HALF_SLOPE_BIG.variants[6] [ _, _, _, _, _, _, _, 1, 0, _, _, 1, 1, 0, _, _, 1, 0, 0, _, _, 1, 0, _, _, ]: shape = Shape.Base.HALF_SLOPE_BIG.variants[7] # SLOPE [ _, _, _, _, _, _, _, 0, _, _, _, 0, 0, 1, _, _, _, 1, _, _, _, _, _, _, _, ]: shape = Shape.Base.SLOPE.variants[0] [ _, _, _, _, _, _, _, 1, _, _, _, 0, 0, 1, _, _, _, 0, _, _, _, _, _, _, _, ]: shape = Shape.Base.SLOPE.variants[1] [ _, _, _, _, _, _, _, 1, _, _, _, 1, 0, 0, _, _, _, 0, _, _, _, _, _, _, _, ]: shape = Shape.Base.SLOPE.variants[2] [ _, _, _, _, _, _, _, 0, _, _, _, 1, 0, 0, _, _, _, 1, _, _, _, _, _, _, _, ]: shape = Shape.Base.SLOPE.variants[3] # FULL [ _, _, _, _, _, _, _, _, _, _, _, _, 1, _, _, _, _, _, _, _, _, _, _, _, _, ]: shape = Shape.FULL if shape: matter.set_at(pos, Matter.PLASTIC) shapes.set_at(pos, shape)