Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/blocks.zig
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ pub const Ore = struct {
maxHeight: i32,
minHeight: i32,

targetTags: []const Tag,

blockType: u16,
seed: u64,
};
Expand Down Expand Up @@ -214,13 +216,16 @@ pub fn register(_: []const u8, id: []const u8, zon: ZonElement) u16 {
std.log.err("Ore must have rotation mode \"cubyz:ore\"!", .{});
break :blk;
}
const targetBlockTags = Tag.loadTagsFromZon(main.stackAllocator, oreProperties.getChild("targetTags"));
defer main.stackAllocator.free(targetBlockTags);
ores.append(main.worldArena, .{
.veins = oreProperties.get(f32, "veins") orelse 0,
.size = oreProperties.get(f32, "size") orelse 0,
.maxHeight = oreProperties.get(i32, "maxHeight") orelse std.math.maxInt(i32),
.minHeight = oreProperties.get(i32, "minHeight") orelse std.math.minInt(i32),
.density = oreProperties.get(f32, "density") orelse 0.5,
.blockType = @intCast(size),
.targetTags = targetBlockTags,
.seed = std.hash.Wyhash.hash(0, id),
});
}
Expand Down
19 changes: 12 additions & 7 deletions src/server/terrain/chunkgen/OreGenerator.zig
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,20 @@ fn considerCoordinates(ore: *const main.blocks.Ore, relX: f32, relY: f32, relZ:
while (curZ < zMax) : (curZ += 1) {
const distToCenterZ = (@as(f32, @floatFromInt(curZ)) - veinRelZ)/radius;
const distSqr = xyDistSqr + distToCenterZ*distToCenterZ;
if (distSqr < 1) {
// Add some roughness. The ore density gets smaller at the edges:
if ((1 - distSqr)*ore.density >= random.nextFloat(&veinSeed)) {
const stoneBlock = chunk.getBlock(curX, curY, curZ);
if (chunk.getBlock(curX, curY, curZ).allowOres()) {
chunk.updateBlockInGeneration(curX, curY, curZ, .{.typ = ore.blockType, .data = stoneBlock.typ});
}
if (distSqr >= 1) continue;
// Add some roughness. The ore density gets smaller at the edges:
if ((1 - distSqr)*ore.density < random.nextFloat(&veinSeed)) continue;
const stoneBlock = chunk.getBlock(curX, curY, curZ);
if (!stoneBlock.allowOres()) continue;
var hasCorrectTags: bool = true;
for (ore.targetTags) |tag| {
if (!stoneBlock.hasTag(tag)) {
hasCorrectTags = false;
break;
Comment thread
Crepestrom marked this conversation as resolved.
Outdated
}
}
if (!hasCorrectTags) continue;
chunk.updateBlockInGeneration(curX, curY, curZ, .{.typ = ore.blockType, .data = stoneBlock.typ});
}
}
}
Expand Down
Loading