Add selection wand (#1298)

* Add selection wand

* Update zon file extension

* Apply review change requests

* Simplify receive logic for worldEditPos

* Convert isServerSide to method
This commit is contained in:
Krzysztof Wiśniewski 2025-04-25 20:49:37 +02:00 committed by GitHub
parent f41504f684
commit fde5a69cdc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 43 additions and 14 deletions

View File

@ -0,0 +1,4 @@
.{
.texture = "selection_wand.png",
.stackSize = 1,
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

View File

@ -973,19 +973,28 @@ pub const Protocols = struct {
}, },
.worldEditPos => { .worldEditPos => {
const typ = try reader.readEnum(WorldEditPosition); const typ = try reader.readEnum(WorldEditPosition);
switch(typ) { const pos: ?Vec3i = switch(typ) {
.selectedPos1, .selectedPos2 => { .selectedPos1, .selectedPos2 => try reader.readVec(Vec3i),
const pos = try reader.readVec(Vec3i); .clear => null,
switch(typ) { };
.selectedPos1 => game.Player.selectionPosition1 = pos, if(conn.isServerSide()) {
.selectedPos2 => game.Player.selectionPosition2 = pos, switch(typ) {
else => unreachable, .selectedPos1 => conn.user.?.worldEditData.selectionPosition1 = pos.?,
} .selectedPos2 => conn.user.?.worldEditData.selectionPosition2 = pos.?,
}, .clear => {
.clear => { conn.user.?.worldEditData.selectionPosition1 = null;
game.Player.selectionPosition1 = null; conn.user.?.worldEditData.selectionPosition2 = null;
game.Player.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 => { .timeAndBiome => {
@ -1789,6 +1798,10 @@ pub const Connection = struct { // MARK: Connection
return self.connectionState.load(.unordered) == .connected; return self.connectionState.load(.unordered) == .connected;
} }
fn isServerSide(conn: *Connection) bool {
return conn.user != null;
}
fn handlePacketLoss(self: *Connection, loss: LossStatus) void { fn handlePacketLoss(self: *Connection, loss: LossStatus) void {
if(loss == .noLoss) return; if(loss == .noLoss) return;
self.slowStart = false; self.slowStart = false;

View File

@ -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 => |tool| {
_ = tool; // TODO: Tools might change existing blocks. _ = 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 { pub fn breakBlock(inventory: main.items.Inventory, slot: u32, deltaTime: f64) void {
if(selectedBlockPos) |selectedPos| { 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)) { if(@reduce(.Or, lastSelectedBlockPos != selectedPos)) {
mesh_storage.removeBreakingAnimation(lastSelectedBlockPos); mesh_storage.removeBreakingAnimation(lastSelectedBlockPos);
lastSelectedBlockPos = selectedPos; lastSelectedBlockPos = selectedPos;
@ -863,7 +876,6 @@ pub const MeshSelection = struct { // MARK: MeshSelection
main.items.Inventory.Sync.ClientSide.mutex.lock(); main.items.Inventory.Sync.ClientSide.mutex.lock();
if(!game.Player.isCreative()) { if(!game.Player.isCreative()) {
const stack = inventory.getStack(slot);
var damage: f32 = 1; var damage: f32 = 1;
const isTool = stack.item != null and stack.item.? == .tool; const isTool = stack.item != null and stack.item.? == .tool;
if(isTool) { if(isTool) {