diff --git a/assets/cubyz/biomes/rainbow_forest.zig.zon b/assets/cubyz/biomes/rainbow_forest.zig.zon index 4c6d200b..31821874 100644 --- a/assets/cubyz/biomes/rainbow_forest.zig.zon +++ b/assets/cubyz/biomes/rainbow_forest.zig.zon @@ -21,7 +21,7 @@ .structures = .{ .{ .id = "cubyz:simple_tree", - .leaves = "cubyz:non_degradable_oak_leaves", + .leaves = "cubyz:oak_leaves", .log = "cubyz:oak_log", .top = "cubyz:oak_top", .chance = 0.48, @@ -40,6 +40,7 @@ .height_variation = 0, .leafRadius = 16, .leafRadius_variation = 3, + .priority = 0.1, }, .{ .id = "cubyz:simple_tree", @@ -52,6 +53,7 @@ .height_variation = 0, .leafRadius = 16, .leafRadius_variation = 3, + .priority = 0.1, }, .{ .id = "cubyz:simple_tree", @@ -64,6 +66,7 @@ .height_variation = 0, .leafRadius = 16, .leafRadius_variation = 3, + .priority = 0.1, }, .{ .id = "cubyz:simple_tree", @@ -76,6 +79,7 @@ .height_variation = 0, .leafRadius = 16, .leafRadius_variation = 3, + .priority = 0.1, }, .{ .id = "cubyz:simple_tree", @@ -88,6 +92,7 @@ .height_variation = 0, .leafRadius = 16, .leafRadius_variation = 3, + .priority = 0.1, }, .{ .id = "cubyz:simple_tree", @@ -100,6 +105,7 @@ .height_variation = 0, .leafRadius = 16, .leafRadius_variation = 3, + .priority = 0.1, }, }, } diff --git a/assets/cubyz/blocks/non_degradable_oak_leaves.zig.zon b/assets/cubyz/blocks/non_degradable_oak_leaves.zig.zon deleted file mode 100644 index bfc0f7cb..00000000 --- a/assets/cubyz/blocks/non_degradable_oak_leaves.zig.zon +++ /dev/null @@ -1,14 +0,0 @@ -.{ - .class = .leaf, - .hasItem = false, - .hardness = 0.4, - .drops = .{ - "cubyz:oak_leaves", - "0.1 cubyz:apple", - }, - .degradable = false, - .alwaysViewThrough = true, - .absorbedLight = 0x121012, - .model = "cubyz:cube", - .texture = "cubyz:oak_leaves", -} diff --git a/src/server/terrain/StructureMap.zig b/src/server/terrain/StructureMap.zig index a5f6a041..f0925e30 100644 --- a/src/server/terrain/StructureMap.zig +++ b/src/server/terrain/StructureMap.zig @@ -16,10 +16,15 @@ const TerrainGenerationProfile = terrain.TerrainGenerationProfile; pub const Structure = struct { generateFn: *const fn(self: *const anyopaque, chunk: *ServerChunk, caveMap: terrain.CaveMap.CaveMapView) void, data: *const anyopaque, + priority: f32, pub fn generate(self: Structure, chunk: *ServerChunk, caveMap: terrain.CaveMap.CaveMapView) void { self.generateFn(self.data, chunk, caveMap); } + + fn lessThan(_: void, lhs: Structure, rhs: Structure) bool { + return lhs.priority < rhs.priority; + } }; pub const StructureMapFragment = struct { @@ -54,6 +59,12 @@ pub const StructureMapFragment = struct { main.globalAllocator.destroy(self); } + fn finishGeneration(self: *StructureMapFragment) void { + for(&self.data) |list| { + std.sort.insertion(Structure, list.items, {}, Structure.lessThan); + } + } + fn getIndex(self: *const StructureMapFragment, x: i32, y: i32, z: i32) usize { std.debug.assert(x >= 0 and x < size*self.pos.voxelSize and y >= 0 and y < size*self.pos.voxelSize and z >= 0 and z < size*self.pos.voxelSize); // Coordinates out of range. return @intCast(((x >> main.chunk.chunkShift+self.voxelShift)*chunkedSize + (y >> main.chunk.chunkShift+self.voxelShift))*chunkedSize + (z >> main.chunk.chunkShift+self.voxelShift)); @@ -151,6 +162,7 @@ fn cacheInit(pos: ChunkPosition) *StructureMapFragment { for(profile.structureMapGenerators) |generator| { generator.generate(mapFragment, profile.seed ^ generator.generatorSeed); } + mapFragment.finishGeneration(); _ = @atomicRmw(u16, &mapFragment.refCount.raw, .Add, 1, .monotonic); return mapFragment; } diff --git a/src/server/terrain/biomes.zig b/src/server/terrain/biomes.zig index c4feefff..c0278d94 100644 --- a/src/server/terrain/biomes.zig +++ b/src/server/terrain/biomes.zig @@ -28,6 +28,7 @@ pub const SimpleStructureModel = struct { // MARK: SimpleStructureModel vtable: VTable, data: *anyopaque, chance: f32, + priority: f32, generationMode: GenerationMode, pub fn initModel(parameters: ZonElement) ?SimpleStructureModel { @@ -40,6 +41,7 @@ pub const SimpleStructureModel = struct { // MARK: SimpleStructureModel .vtable = vtable, .data = vtable.loadModel(arena.allocator(), parameters), .chance = parameters.get(f32, "chance", 0.1), + .priority = parameters.get(f32, "priority", 1), .generationMode = std.meta.stringToEnum(GenerationMode, parameters.get([]const u8, "generationMode", "")) orelse vtable.generationMode, }; } diff --git a/src/server/terrain/structuremapgen/SimpleStructureGen.zig b/src/server/terrain/structuremapgen/SimpleStructureGen.zig index ea1b4140..8db697df 100644 --- a/src/server/terrain/structuremapgen/SimpleStructureGen.zig +++ b/src/server/terrain/structuremapgen/SimpleStructureGen.zig @@ -64,6 +64,7 @@ pub fn generate(map: *StructureMapFragment, worldSeed: u64) void { map.addStructure(.{ .data = @ptrCast(data), .generateFn = &SimpleStructure.generate, + .priority = model.priority, }, .{px -% margin, py -% margin, relZ -% margin -% 15}, .{px +% margin, py +% margin, relZ +% margin +% 15}); break; } else { @@ -102,6 +103,7 @@ pub fn generate(map: *StructureMapFragment, worldSeed: u64) void { map.addStructure(.{ .data = @ptrCast(data), .generateFn = &SimpleStructure.generate, + .priority = model.priority, }, .{px -% margin, py -% margin, relZ -% margin -% 15}, .{px +% margin, py +% margin, relZ +% margin +% 15}); break; } else {