mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-08-03 11:17:05 -04:00
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:
parent
f41504f684
commit
fde5a69cdc
4
assets/cubyz/items/selection_wand.zig.zon
Normal file
4
assets/cubyz/items/selection_wand.zig.zon
Normal file
@ -0,0 +1,4 @@
|
||||
.{
|
||||
.texture = "selection_wand.png",
|
||||
.stackSize = 1,
|
||||
}
|
BIN
assets/cubyz/items/textures/selection_wand.png
Normal file
BIN
assets/cubyz/items/textures/selection_wand.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.3 KiB |
@ -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;
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user