mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-08-03 11:17:05 -04:00
Integrate void block with commands (#1333)
* Integrate void block with paste * Update src/blueprint.zig Co-authored-by: IntegratedQuantum <43880493+IntegratedQuantum@users.noreply.github.com> * Add -v flag description to /paste command description * Swap conditions in paste --------- Co-authored-by: IntegratedQuantum <43880493+IntegratedQuantum@users.noreply.github.com>
This commit is contained in:
parent
386ff63903
commit
af65b7c7fb
@ -20,6 +20,7 @@ const Entity = main.server.Entity;
|
||||
const entity_data = @import("entity_data.zig");
|
||||
const EntityDataClass = entity_data.EntityDataClass;
|
||||
const sbb = main.server.terrain.structure_building_blocks;
|
||||
const blueprint = main.blueprint;
|
||||
|
||||
var arena = main.heap.NeverFailingArenaAllocator.init(main.globalAllocator);
|
||||
const allocator = arena.allocator();
|
||||
@ -207,6 +208,7 @@ pub fn finishBlocks(zonElements: std.StringHashMap(ZonElement)) void {
|
||||
registerLodReplacement(i, zonElements.get(_id[i]) orelse continue);
|
||||
registerOpaqueVariant(i, zonElements.get(_id[i]) orelse continue);
|
||||
}
|
||||
blueprint.registerVoidBlock(parseBlock("cubyz:void"));
|
||||
}
|
||||
|
||||
pub fn reset() void {
|
||||
|
@ -21,6 +21,7 @@ const BinaryWriter = main.utils.BinaryWriter;
|
||||
const BinaryReader = main.utils.BinaryReader;
|
||||
|
||||
pub const blueprintVersion = 0;
|
||||
var voidType: ?u16 = null;
|
||||
|
||||
pub const BlueprintCompression = enum(u16) {
|
||||
deflate,
|
||||
@ -104,7 +105,10 @@ pub const Blueprint = struct {
|
||||
}
|
||||
return .{.success = self};
|
||||
}
|
||||
pub fn paste(self: Blueprint, pos: Vec3i) void {
|
||||
pub const PasteFlags = struct {
|
||||
preserveVoid: bool = false,
|
||||
};
|
||||
pub fn paste(self: Blueprint, pos: Vec3i, flags: PasteFlags) void {
|
||||
const startX = pos[0];
|
||||
const startY = pos[1];
|
||||
const startZ = pos[2];
|
||||
@ -119,7 +123,8 @@ pub const Blueprint = struct {
|
||||
const worldZ = startZ +% @as(i32, @intCast(z));
|
||||
|
||||
const block = self.blocks.get(x, y, z);
|
||||
_ = main.server.world.?.updateBlock(worldX, worldY, worldZ, block);
|
||||
if(block.typ != voidType or flags.preserveVoid)
|
||||
_ = main.server.world.?.updateBlock(worldX, worldY, worldZ, block);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -270,3 +275,8 @@ pub const Blueprint = struct {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
pub fn registerVoidBlock(block: Block) void {
|
||||
voidType = block.typ;
|
||||
std.debug.assert(voidType != 0);
|
||||
}
|
||||
|
@ -10,13 +10,22 @@ const copy = @import("copy.zig");
|
||||
const Block = main.blocks.Block;
|
||||
const Blueprint = main.blueprint.Blueprint;
|
||||
|
||||
pub const description = "Paste clipboard content to current player position.";
|
||||
pub const usage = "/paste";
|
||||
pub const description =
|
||||
\\Paste clipboard content to current player position.
|
||||
\\'-v' - Enable preserving void blocks. By default, void blocks are not preserved.
|
||||
;
|
||||
pub const usage = "/paste [-v]";
|
||||
|
||||
pub fn execute(args: []const u8, source: *User) void {
|
||||
var flags = Blueprint.PasteFlags{};
|
||||
|
||||
if(args.len != 0) {
|
||||
source.sendMessage("#ff0000Too many arguments for command /paste. Expected no arguments.", .{});
|
||||
return;
|
||||
if(std.mem.eql(u8, args, "-v")) {
|
||||
flags.preserveVoid = true;
|
||||
} else {
|
||||
source.sendMessage("#ff0000Argument(s) '{s}' not recognized.", .{args});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(source.worldEditData.clipboard) |clipboard| {
|
||||
@ -38,7 +47,7 @@ pub fn execute(args: []const u8, source: *User) void {
|
||||
},
|
||||
}
|
||||
|
||||
clipboard.paste(pos);
|
||||
clipboard.paste(pos, flags);
|
||||
} else {
|
||||
source.sendMessage("#ff0000Error: No clipboard content to paste.", .{});
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ pub fn execute(args: []const u8, source: *User) void {
|
||||
action.position[1] + @as(i32, @intCast(action.blueprint.blocks.depth)) - 1,
|
||||
action.position[2] + @as(i32, @intCast(action.blueprint.blocks.height)) - 1,
|
||||
});
|
||||
action.blueprint.paste(action.position);
|
||||
action.blueprint.paste(action.position, .{.preserveVoid = true});
|
||||
|
||||
switch(undo) {
|
||||
.success => |blueprint| {
|
||||
|
@ -20,7 +20,7 @@ pub fn execute(args: []const u8, source: *User) void {
|
||||
action.position[1] + @as(i32, @intCast(action.blueprint.blocks.depth)) - 1,
|
||||
action.position[2] + @as(i32, @intCast(action.blueprint.blocks.height)) - 1,
|
||||
});
|
||||
action.blueprint.paste(action.position);
|
||||
action.blueprint.paste(action.position, .{.preserveVoid = true});
|
||||
|
||||
switch(redo) {
|
||||
.success => |blueprint| {
|
||||
|
Loading…
x
Reference in New Issue
Block a user