From fde5a69cdce14b8dc8fe230d107e5e2015be8bda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Wi=C5=9Bniewski?= Date: Fri, 25 Apr 2025 20:49:37 +0200 Subject: [PATCH] Add selection wand (#1298) * Add selection wand * Update zon file extension * Apply review change requests * Simplify receive logic for worldEditPos * Convert isServerSide to method --- assets/cubyz/items/selection_wand.zig.zon | 4 ++ .../cubyz/items/textures/selection_wand.png | Bin 0 -> 4440 bytes src/network.zig | 39 ++++++++++++------ src/renderer.zig | 14 ++++++- 4 files changed, 43 insertions(+), 14 deletions(-) create mode 100644 assets/cubyz/items/selection_wand.zig.zon create mode 100644 assets/cubyz/items/textures/selection_wand.png diff --git a/assets/cubyz/items/selection_wand.zig.zon b/assets/cubyz/items/selection_wand.zig.zon new file mode 100644 index 00000000..0ab5a685 --- /dev/null +++ b/assets/cubyz/items/selection_wand.zig.zon @@ -0,0 +1,4 @@ +.{ + .texture = "selection_wand.png", + .stackSize = 1, +} diff --git a/assets/cubyz/items/textures/selection_wand.png b/assets/cubyz/items/textures/selection_wand.png new file mode 100644 index 0000000000000000000000000000000000000000..6032041c453cf44d9d9db7fd17606ad40a42340d GIT binary patch literal 4440 zcmeHLeNYo;8ec2Qmz;PNq_xU+brfqi`;pDpLd5VPL>q~KO6SD7+1-%6d~8e>66l<8 z9*!b@^x$e8t6;0;D4wS{ioK&YRYqI!a`kRR?K$<7sx2y5t2cgedhaGcb;g++{<*n7 zNG8d?Pkztud7j_%yzk6zjd@{CT+GWc5Cp{;bF=cnZ@m188VkOY?>u23XwdmcYmwP9c@TjlU~2>!|24O_}23odk-#}u%PC{sIeIvE-n6~orvVl z?VsG*I?*vEcJqnmH5(7LCAO`G{Z;2cW-&Q56!DF@* zySwWrI9;m@_KH{M&JI>b^)$V|`LAzGZ%&YU)G1@X%h zr!L2?B;1N#8{E(^an6f<-Yct*ji0aS>~GN)TN*pZrPkcv>Mkl;aBlyi4(o~5>b2GF z^;^&fpZ$rPnINX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mV?d00001 diff --git a/src/network.zig b/src/network.zig index 24cfa80e..9fcb3990 100644 --- a/src/network.zig +++ b/src/network.zig @@ -973,19 +973,28 @@ pub const Protocols = struct { }, .worldEditPos => { const typ = try reader.readEnum(WorldEditPosition); - switch(typ) { - .selectedPos1, .selectedPos2 => { - const pos = try reader.readVec(Vec3i); - switch(typ) { - .selectedPos1 => game.Player.selectionPosition1 = pos, - .selectedPos2 => game.Player.selectionPosition2 = pos, - else => unreachable, - } - }, - .clear => { - game.Player.selectionPosition1 = null; - game.Player.selectionPosition2 = null; - }, + const pos: ?Vec3i = switch(typ) { + .selectedPos1, .selectedPos2 => try reader.readVec(Vec3i), + .clear => null, + }; + if(conn.isServerSide()) { + switch(typ) { + .selectedPos1 => conn.user.?.worldEditData.selectionPosition1 = pos.?, + .selectedPos2 => conn.user.?.worldEditData.selectionPosition2 = pos.?, + .clear => { + conn.user.?.worldEditData.selectionPosition1 = null; + conn.user.?.worldEditData.selectionPosition2 = null; + }, + } + } else { + switch(typ) { + .selectedPos1 => game.Player.selectionPosition1 = pos, + .selectedPos2 => game.Player.selectionPosition2 = pos, + .clear => { + game.Player.selectionPosition1 = null; + game.Player.selectionPosition2 = null; + }, + } } }, .timeAndBiome => { @@ -1789,6 +1798,10 @@ pub const Connection = struct { // MARK: Connection return self.connectionState.load(.unordered) == .connected; } + fn isServerSide(conn: *Connection) bool { + return conn.user != null; + } + fn handlePacketLoss(self: *Connection, loss: LossStatus) void { if(loss == .noLoss) return; self.slowStart = false; diff --git a/src/renderer.zig b/src/renderer.zig index eeedcf60..490173a1 100644 --- a/src/renderer.zig +++ b/src/renderer.zig @@ -840,6 +840,11 @@ pub const MeshSelection = struct { // MARK: MeshSelection } } } + if(std.mem.eql(u8, baseItem.id, "cubyz:selection_wand")) { + game.Player.selectionPosition2 = selectedPos; + main.network.Protocols.genericUpdate.sendWorldEditPos(main.game.world.?.conn, .selectedPos2, selectedPos); + return; + } }, .tool => |tool| { _ = tool; // TODO: Tools might change existing blocks. @@ -851,6 +856,14 @@ pub const MeshSelection = struct { // MARK: MeshSelection pub fn breakBlock(inventory: main.items.Inventory, slot: u32, deltaTime: f64) void { if(selectedBlockPos) |selectedPos| { + const stack = inventory.getStack(slot); + const isSelectionWand = stack.item != null and stack.item.? == .baseItem and std.mem.eql(u8, stack.item.?.baseItem.id, "cubyz:selection_wand"); + if(isSelectionWand) { + game.Player.selectionPosition1 = selectedPos; + main.network.Protocols.genericUpdate.sendWorldEditPos(main.game.world.?.conn, .selectedPos1, selectedPos); + return; + } + if(@reduce(.Or, lastSelectedBlockPos != selectedPos)) { mesh_storage.removeBreakingAnimation(lastSelectedBlockPos); lastSelectedBlockPos = selectedPos; @@ -863,7 +876,6 @@ pub const MeshSelection = struct { // MARK: MeshSelection main.items.Inventory.Sync.ClientSide.mutex.lock(); if(!game.Player.isCreative()) { - const stack = inventory.getStack(slot); var damage: f32 = 1; const isTool = stack.item != null and stack.item.? == .tool; if(isTool) {