mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-08-03 03:06:55 -04:00
[Structure Building Block] Allow specifying empty / sentinel children (#1388)
* Allow sentinel child declarations * Fix len check
This commit is contained in:
parent
1a1a503033
commit
e1fc8deef8
@ -56,7 +56,7 @@ fn placeSbb(self: *SbbGen, structure: *const sbb.StructureBuildingBlock, placeme
|
||||
rotated.blueprint.pasteInGeneration(pastePosition, chunk, self.placeMode);
|
||||
|
||||
for(rotated.childBlocks) |childBlock| {
|
||||
const child = structure.pickChild(childBlock, seed);
|
||||
const child = structure.pickChild(childBlock, seed) orelse continue;
|
||||
placeSbb(self, child, pastePosition + childBlock.pos(), childBlock.direction(), chunk, seed);
|
||||
}
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ pub const StructureBuildingBlock = struct {
|
||||
pub fn getBlueprint(self: StructureBuildingBlock, rotation: Degrees) *BlueprintEntry {
|
||||
return &self.blueprints[@intFromEnum(rotation)];
|
||||
}
|
||||
pub fn pickChild(self: StructureBuildingBlock, block: BlueprintEntry.StructureBlock, seed: *u64) *const StructureBuildingBlock {
|
||||
pub fn pickChild(self: StructureBuildingBlock, block: BlueprintEntry.StructureBlock, seed: *u64) ?*const StructureBuildingBlock {
|
||||
return self.children[block.index].sample(seed).structure;
|
||||
}
|
||||
};
|
||||
@ -160,18 +160,16 @@ fn initChildTableFromZon(parentId: []const u8, colorName: []const u8, colorIndex
|
||||
}
|
||||
|
||||
const Child = struct {
|
||||
structure: *StructureBuildingBlock,
|
||||
structure: ?*StructureBuildingBlock,
|
||||
chance: f32,
|
||||
|
||||
fn initFromZon(parentId: []const u8, colorName: []const u8, colorIndex: usize, childIndex: usize, zon: ZonElement) !Child {
|
||||
const structureId = zon.get([]const u8, "structure", "");
|
||||
if(structureId.len == 0) {
|
||||
std.log.err("['{s}'->'{s}'->'{d}'] Child node has empty structure field, parent structure will be discarded.", .{parentId, colorName, childIndex});
|
||||
return error.EmptyStructureId;
|
||||
const structureId = zon.get(?[]const u8, "structure", null);
|
||||
if(structureId != null and structureId.?.len != 0) {
|
||||
childrenToResolve.append(.{.parentId = parentId, .colorName = colorName, .colorIndex = colorIndex, .childIndex = childIndex, .structureId = structureId.?});
|
||||
}
|
||||
childrenToResolve.append(.{.parentId = parentId, .colorName = colorName, .colorIndex = colorIndex, .childIndex = childIndex, .structureId = structureId});
|
||||
return .{
|
||||
.structure = undefined,
|
||||
.structure = null,
|
||||
.chance = zon.get(f32, "chance", 1.0),
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user