-
-
Notifications
You must be signed in to change notification settings - Fork 232
Saplings and Seeds #2585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Saplings and Seeds #2585
Changes from all commits
f86bb94
4f5bebb
4e0de58
9ad5b0a
14d97e8
e216b62
bdb0cb2
10c3836
08ecb24
5b68a8d
c74e085
8896218
cffc575
f33d3a8
dbb2147
ceb16b0
cc0b6de
bcf99eb
a1d3e42
fbd777c
6293562
1b61a67
a2ddebc
702b6f1
70bda9c
bac9af6
75a9972
190cd6a
b82be53
f8c6724
a3dd604
0f426e4
e944aa3
4ba14be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| .{ | ||
| .tags = .{.cuttable}, | ||
| .blockHealth = 0.2, | ||
| .drops = .{ | ||
| .{.items = .{.auto}}, | ||
| }, | ||
| .onTick = .{.type = .sapling, .sbb = .{ | ||
| .structure = "cubyz:cactus/saguaro", | ||
| .placeMode = .degradable, | ||
| .chance = 0.01, | ||
| }}, | ||
| .degradable = true, | ||
| .collide = false, | ||
| .alwaysViewThrough = true, | ||
| .absorbedLight = 0x121012, | ||
| .model = "cubyz:cactus_flower", | ||
| .rotation = "cubyz:direction", | ||
| .texture = "cubyz:cactus_flower", | ||
| .texture_top = "cubyz:cactus_flower_top", | ||
| .texture_bottom = "cubyz:cactus_flower_top", | ||
| .item = .{ | ||
| .texture = "cactus_flower.png", | ||
| }, | ||
| .lodReplacement = "cubyz:air", | ||
| .onTouch = .{ | ||
| .type = .hurt, | ||
| .dps = 0.2, | ||
| .damageType = .spiky, | ||
| }, | ||
| .onUpdate = .{ | ||
| .type = .checkSupportBlocks, | ||
| }, | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| .{ | ||
| .tags = .{.cuttable}, | ||
| .blockHealth = 0.2, | ||
| .drops = .{ | ||
| .{.items = .{.auto}}, | ||
| }, | ||
| .onTick = .{ | ||
| .type = .sapling, | ||
| .sbb = .{ | ||
| .structure = "cubyz:tree/oak/white", | ||
| .placeMode = .degradable, | ||
| .chance = 0.03, | ||
| }, | ||
| }, | ||
| .degradable = true, | ||
| .collide = false, | ||
| .alwaysViewThrough = true, | ||
| .absorbedLight = 0x121012, | ||
| .model = "cubyz:cactus_flower", | ||
| .rotation = "cubyz:direction", | ||
| .texture = "cubyz:cactus_flower", | ||
| .texture_top = "cubyz:cactus_flower_top", | ||
| .texture_bottom = "cubyz:cactus_flower_top", | ||
| .item = .{ | ||
| .texture = "cactus_flower.png", | ||
| }, | ||
| .lodReplacement = "cubyz:air", | ||
| .onTouch = .{ | ||
| .type = .hurt, | ||
| .dps = 0.2, | ||
| .damageType = .spiky, | ||
| }, | ||
| .onUpdate = .{ | ||
| .type = .checkSupportBlocks, | ||
| }, | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| const std = @import("std"); | ||
|
|
||
| const main = @import("main"); | ||
| const Vec3i = main.vec.Vec3i; | ||
| const sbbGen = main.server.terrain.structures.simple_structures.SbbGen; | ||
| const SimpleStructureModel = main.server.terrain.biomes.SimpleStructureModel; | ||
|
|
||
| sbb: *sbbGen.SbbGen, | ||
| chance: f32, | ||
|
|
||
| pub fn init(zon: main.ZonElement, _: main.callbacks.Creator) ?*@This() { | ||
| const result = main.worldArena.create(@This()); | ||
|
|
||
| const vtableModel = sbbGen.loadModel(zon.getChild("sbb")) orelse { | ||
| std.log.err("Error occurred while loading structure for saplings", .{}); | ||
| return null; | ||
| }; | ||
| result.sbb = vtableModel; | ||
| result.chance = zon.get(f32, "chance", 0.1); | ||
| return result; | ||
| } | ||
|
|
||
| pub fn run(self: *@This(), params: main.callbacks.ServerBlockCallback.Params) main.callbacks.Result { | ||
|
|
||
| // copied from SimpleStructureGen.generate. | ||
| const randomValue = main.random.nextFloat(&main.seed); | ||
| if (randomValue < self.chance) { | ||
| self.sbb.placeSbb(self.sbb.structureRef, Vec3i{params.blockPos.x, params.blockPos.y, params.blockPos.z}, null, self.sbb.rotation.getInitialRotation(&main.seed), params.chunk, &main.seed, false); | ||
| } | ||
|
|
||
| return .handled; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,7 @@ const NeverFailingAllocator = main.heap.NeverFailingAllocator; | |
| pub const id = "cubyz:sbb"; | ||
| pub const generationMode = .floor; | ||
|
|
||
| const SbbGen = @This(); | ||
| pub const SbbGen = @This(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It makes no sense to make this public |
||
|
|
||
| structureRef: *const sbb.StructureBuildingBlock, | ||
| placeMode: Blueprint.PasteMode, | ||
|
|
@@ -53,10 +53,10 @@ pub fn loadModel(parameters: ZonElement) ?*SbbGen { | |
| } | ||
|
|
||
| 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}, null, self.rotation.getInitialRotation(seed), chunk, seed); | ||
| placeSbb(self, self.structureRef, Vec3i{x, y, z}, null, self.rotation.getInitialRotation(seed), chunk, seed, true); | ||
| } | ||
|
|
||
| fn placeSbb(self: *SbbGen, structure: *const sbb.StructureBuildingBlock, placementPosition: Vec3i, placementDirection: ?Neighbor, rotation: sbb.Rotation, chunk: *ServerChunk, seed: *u64) void { | ||
| pub fn placeSbb(self: *SbbGen, structure: *const sbb.StructureBuildingBlock, placementPosition: Vec3i, placementDirection: ?Neighbor, rotation: sbb.Rotation, chunk: *ServerChunk, seed: *u64, comptime duringWorldGeneration: bool) void { | ||
| const blueprints = &(structure.getBlueprints(seed).* orelse return); | ||
|
|
||
| const origin = blueprints[0].originBlock; | ||
|
|
@@ -68,12 +68,20 @@ fn placeSbb(self: *SbbGen, structure: *const sbb.StructureBuildingBlock, placeme | |
| const rotatedOrigin = rotated.originBlock.pos(); | ||
| const pastePosition = placementPosition - rotatedOrigin - (placementDirection orelse origin.direction()).relPos(); | ||
|
|
||
| rotated.blueprint.pasteInGeneration(pastePosition, chunk, self.placeMode); | ||
| if (duringWorldGeneration) { | ||
| rotated.blueprint.pasteInGeneration(pastePosition, chunk, self.placeMode); | ||
| } else { | ||
| var pos = Vec3i{0, 0, 0}; | ||
| pos[0] = chunk.super.pos.wx + pastePosition[0]; | ||
| pos[1] = chunk.super.pos.wy + pastePosition[1]; | ||
| pos[2] = chunk.super.pos.wz + pastePosition[2]; | ||
|
|
||
| rotated.blueprint.paste(pos, .{.replaceUndegradable = false}); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be configurable via self.placeMode, like when placed in generation. |
||
| } | ||
| for (rotated.childBlocks) |childBlock| { | ||
| const child = structure.getChildStructure(childBlock) orelse continue; | ||
| const childRotation = blueprintRotation.getChildRotation(seed, child.rotation, childBlock.direction()); | ||
| placeSbb(self, child, pastePosition + childBlock.pos(), childBlock.direction(), childRotation, chunk, seed); | ||
| placeSbb(self, child, pastePosition + childBlock.pos(), childBlock.direction(), childRotation, chunk, seed, duringWorldGeneration); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1231,7 +1231,7 @@ pub const ServerWorld = struct { // MARK: ServerWorld | |
| } | ||
|
|
||
| /// Returns the actual block on failure | ||
| pub fn cmpxchgBlock(self: *ServerWorld, wx: i32, wy: i32, wz: i32, oldBlock: ?Block, _newBlock: Block) ?Block { | ||
| pub fn cmpxchgBlock(self: *ServerWorld, wx: i32, wy: i32, wz: i32, oldBlock: ?Block, _newBlock: Block, comptime noUpdate: bool) ?Block { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use an enum to improve reasability at the callsite |
||
| main.sync.threadContext.assertCorrectContext(.server); | ||
| const baseChunk = ChunkManager.getOrGenerateChunkAndIncreaseRefCount(.{.wx = wx & ~@as(i32, chunk.chunkMask), .wy = wy & ~@as(i32, chunk.chunkMask), .wz = wz & ~@as(i32, chunk.chunkMask), .voxelSize = 1}); | ||
| defer baseChunk.decreaseRefCount(); | ||
|
|
@@ -1291,6 +1291,7 @@ pub const ServerWorld = struct { // MARK: ServerWorld | |
| for (userList) |user| { | ||
| main.network.protocols.blockUpdate.send(user.conn, &.{.{.pos = .{wx, wy, wz}, .newBlock = newBlock, .blockEntityData = &.{}}}); | ||
| } | ||
|
|
||
| // onBreak event | ||
|
tillpp marked this conversation as resolved.
|
||
| if (oldBlock) |block| { | ||
| if (block.typ != newBlock.typ) { | ||
|
|
@@ -1301,7 +1302,9 @@ pub const ServerWorld = struct { // MARK: ServerWorld | |
| }); | ||
| } | ||
| } | ||
| self.triggerNeighborBlockUpdates(wx, wy, wz); | ||
| if (!noUpdate) { | ||
| self.triggerNeighborBlockUpdates(wx, wy, wz); | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
@@ -1324,8 +1327,8 @@ pub const ServerWorld = struct { // MARK: ServerWorld | |
| } | ||
| } | ||
|
|
||
| pub fn updateBlock(self: *ServerWorld, wx: i32, wy: i32, wz: i32, newBlock: Block) void { | ||
| _ = self.cmpxchgBlock(wx, wy, wz, null, newBlock); | ||
| pub fn updateBlock(self: *ServerWorld, wx: i32, wy: i32, wz: i32, newBlock: Block, comptime noUpdate: bool) void { | ||
| _ = self.cmpxchgBlock(wx, wy, wz, null, newBlock, noUpdate); | ||
| } | ||
|
|
||
| pub fn queueChunkUpdateAndDecreaseRefCount(self: *ServerWorld, ch: *ServerChunk) void { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How many leaf blocks are there in a tree?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably less then 1000
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to have those numbers, I think for all saplings the number of saplings per tree should be consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feel free to count them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also the amount of leaves varies because of the generation