Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
27 changes: 27 additions & 0 deletions assets/cubyz/biomes/silly.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.{
.properties = .{},
.minHeightLimit = 7,
.minHeight = 22,
.maxHeight = 40,
.maxHeightLimit = 50,
.smoothBeaches = true,
.minRadius = 256,
.maxRadius = 320,
.roughness = 1,
.hills = 5,
.chance = 100000,
.music = "cubyz:sunrise",
.validPlayerSpawn = true,
.ground_structure = .{
"cubyz:grass",
"2 to 3 cubyz:soil",
},
.structures = .{
.{
.id = "cubyz:sbb",
.structure = "cubyz:village/origin",
.placeMode = .all,
.chance = 0.0005,
},
},
}
7 changes: 7 additions & 0 deletions assets/cubyz/sbb/village/house/any.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.{
.blueprints = .{
.{.id = "cubyz:village/house/house", .chance = 0.2},
.{.id = null, .chance = 0.8},
},
.snapping = .bottom,
}
Binary file added assets/cubyz/sbb/village/house/house.blp
Binary file not shown.
Binary file added assets/cubyz/sbb/village/origin.blp
Binary file not shown.
9 changes: 9 additions & 0 deletions assets/cubyz/sbb/village/origin.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.{
.blueprints = .{
.{.id = "cubyz:village/origin"},
},
.originOffset = .{0, 0, -1},
.children = .{
.green = "cubyz:village/path/always_path",
},
}
11 changes: 11 additions & 0 deletions assets/cubyz/sbb/village/path/always_path.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.{
.blueprints = .{
.{.id = "cubyz:village/path/path_left", .chance = 0.5},
.{.id = "cubyz:village/path/path_right", .chance = 0.5},
},
.children = .{
.red = "cubyz:village/path/path_block",
.green = "cubyz:village/path/path",
.yellow = "cubyz:village/house/any",
},
}
12 changes: 12 additions & 0 deletions assets/cubyz/sbb/village/path/path.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.{
.blueprints = .{
.{.id = "cubyz:village/path/path_left", .chance = 0.35},
.{.id = "cubyz:village/path/path_right", .chance = 0.35},
.{.id = null, .chance = 0.3},
},
.children = .{
.red = "cubyz:village/path/path_block",
.green = "cubyz:village/path/path",
.yellow = "cubyz:village/house/any",
},
}
Binary file added assets/cubyz/sbb/village/path/path_block.blp
Binary file not shown.
8 changes: 8 additions & 0 deletions assets/cubyz/sbb/village/path/path_block.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.{
.blueprints = .{
.{.id = "cubyz:village/path/path_block", .chance = 0.6},
.{.id = null, .chance = 0.4},
},
.snapping = .bottom,
.originOffset = .{0, 0, -1},
}
Binary file added assets/cubyz/sbb/village/path/path_left.blp
Binary file not shown.
Binary file added assets/cubyz/sbb/village/path/path_right.blp
Binary file not shown.
37 changes: 32 additions & 5 deletions src/server/terrain/simple_structures/SbbGen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ pub fn loadModel(arena: NeverFailingAllocator, parameters: ZonElement) *SbbGen {
return self;
}

pub fn generate(self: *SbbGen, _: GenerationMode, x: i32, y: i32, z: i32, chunk: *ServerChunk, _: CaveMapView, _: CaveBiomeMapView, seed: *u64, _: bool) void {
placeSbb(self, self.structureRef, Vec3i{x, y, z}, Neighbor.dirUp, self.rotation.getInitialRotation(seed), chunk, seed);
pub fn generate(self: *SbbGen, _: GenerationMode, x: i32, y: i32, z: i32, chunk: *ServerChunk, caveMap: CaveMapView, _: CaveBiomeMapView, seed: *u64, _: bool) void {
placeSbb(self, self.structureRef, Vec3i{x, y, z}, Neighbor.dirUp, self.rotation.getInitialRotation(seed), chunk, caveMap, seed, 5);
}

fn placeSbb(self: *SbbGen, structure: *const sbb.StructureBuildingBlock, placementPosition: Vec3i, placementDirection: Neighbor, rotation: sbb.Rotation, chunk: *ServerChunk, seed: *u64) void {
fn placeSbb(self: *SbbGen, structure: *const sbb.StructureBuildingBlock, placementPosition: Vec3i, placementDirection: Neighbor, rotation: sbb.Rotation, chunk: *ServerChunk, caveMap: CaveMapView, seed: *u64, iterationsLeft: usize) void {
const blueprints = &(structure.getBlueprints(seed).* orelse return);

const origin = blueprints[0].originBlock;
Expand All @@ -64,14 +64,41 @@ fn placeSbb(self: *SbbGen, structure: *const sbb.StructureBuildingBlock, placeme
});
const rotated = &blueprints[@intFromEnum(blueprintRotation)];
const rotatedOrigin = rotated.originBlock.pos();
const pastePosition = placementPosition - rotatedOrigin - placementDirection.relPos();
var pastePosition = placementPosition - rotatedOrigin - placementDirection.relPos();
pastePosition += structure.originOffset;

rotated.blueprint.pasteInGeneration(pastePosition, chunk, self.placeMode);

if(iterationsLeft == 0) return;
for(rotated.childBlocks) |childBlock| {
const child = structure.getChildStructure(childBlock) orelse continue;
const childRotation = rotation.getChildRotation(seed, child.rotation, childBlock.direction());
placeSbb(self, child, pastePosition + childBlock.pos(), childBlock.direction(), childRotation, chunk, seed);
var placementPos = pastePosition + childBlock.pos();
const oldZ = placementPos[2];
// std.debug.print("{d} {d}\n", .{placementPos[0], placementPos[1]});
if(placementPos[0] < 0 or placementPos[0] >= terrain.CaveMap.CaveMapFragment.width or placementPos[1] < 0 or placementPos[1] >= terrain.CaveMap.CaveMapFragment.width) {
return;
}
switch(child.snapping) {
.top => {
if(caveMap.isSolid(placementPos[0], placementPos[1], placementPos[2])) {
placementPos[2] = caveMap.findTerrainChangeBelow(placementPos[0], placementPos[1], placementPos[2]);
} else {
placementPos[2] = caveMap.findTerrainChangeAbove(placementPos[0], placementPos[1], placementPos[2]) + chunk.super.pos.voxelSize;
}
if(placementPos[2] & ~@as(i32, 31) != oldZ & ~@as(i32, 31)) return; // Too far from the surface.
},
.bottom => {
if(caveMap.isSolid(placementPos[0], placementPos[1], placementPos[2])) {
placementPos[2] = caveMap.findTerrainChangeAbove(placementPos[0], placementPos[1], placementPos[2]);
} else {
placementPos[2] = caveMap.findTerrainChangeBelow(placementPos[0], placementPos[1], placementPos[2]) + chunk.super.pos.voxelSize;
}
if(placementPos[2] & ~@as(i32, 31) != oldZ & ~@as(i32, 31)) return; // Too far from the surface.
},
.none => {},
}
placeSbb(self, child, placementPos, childBlock.direction(), childRotation, chunk, caveMap, seed, iterationsLeft - 1);
}
}

Expand Down
12 changes: 9 additions & 3 deletions src/server/terrain/structure_building_blocks.zig
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ const BlueprintEntry = struct {
childBlocks: []StructureBlock,

const StructureBlock = struct {
x: u16,
y: u16,
z: u16,
x: i16,
y: i16,
z: i16,
index: LocalBlockIndex,
data: u16,

Expand Down Expand Up @@ -225,11 +225,15 @@ pub const Rotation = union(RotationMode) {
}
};

const Snapping = enum {none, top, bottom};

pub const StructureBuildingBlock = struct {
id: []const u8,
children: []?*StructureBuildingBlock,
blueprints: AliasTable(Blueprints),
rotation: Rotation,
snapping: Snapping,
originOffset: Vec3i,

fn initFromZon(stringId: []const u8, zon: ZonElement) !StructureBuildingBlock {
const zonBlueprintsList = zon.getChild("blueprints");
Expand Down Expand Up @@ -285,6 +289,8 @@ pub const StructureBuildingBlock = struct {
.children = arenaAllocator.alloc(?*StructureBuildingBlock, childBlockName.items.len),
.blueprints = .init(arenaAllocator, blueprintArray),
.rotation = rotation,
.snapping = std.meta.stringToEnum(Snapping, zon.get([]const u8, "snapping", "none")) orelse .none,
.originOffset = zon.get(Vec3i, "originOffset", .{0, 0, 0}),
};
@memset(self.children, null);

Expand Down
Loading