Skip to content

Commit

Permalink
Blocks drop items in survival mode.
Browse files Browse the repository at this point in the history
fixes #645

also fixes an issue where the torch couldn't be broken in survival mode.
  • Loading branch information
IntegratedQuantum committed Dec 31, 2024
1 parent 9f3c63e commit a40a854
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/Inventory.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1270,12 +1270,29 @@ pub const Command = struct { // MARK: Command
}}, side);
},
.yes_dropsItems => |amount| {
if(side == .server) {
// TODO: Drop block items
_ = amount;
if(side == .server and gamemode != .creative) {
for(0..amount) |_| {
for(self.newBlock.blockDrops()) |drop| {
if(drop.chance == 1 or main.random.nextFloat(&main.seed) < drop.chance) {
for(drop.items) |itemStack| {
main.server.world.?.drop(itemStack.clone(), @as(vec.Vec3d, @floatFromInt(self.pos)) + vec.Vec3d{0.5, 0.5, 0.5}, main.random.nextFloatVectorSigned(3, &main.seed), main.random.nextFloat(&main.seed)*20);
}
}
}
}
}
},
}

if(side == .server and gamemode != .creative and self.oldBlock.typ != self.newBlock.typ) {
for(self.oldBlock.blockDrops()) |drop| {
if(drop.chance == 1 or main.random.nextFloat(&main.seed) < drop.chance) {
for(drop.items) |itemStack| {
main.server.world.?.drop(itemStack.clone(), @as(vec.Vec3d, @floatFromInt(self.pos)) + vec.Vec3d{0.5, 0.5, 0.5}, main.random.nextFloatVectorSigned(3, &main.seed), main.random.nextFloat(&main.seed)*20);
}
}
}
}
}

fn serialize(self: UpdateBlock, data: *main.List(u8)) void {
Expand Down
3 changes: 3 additions & 0 deletions src/rotation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ pub const RotationMode = struct { // MARK: RotationMode
}
}
}
if(newBlock.typ == 0) {
return .yes;
}
}
return .no;
}
Expand Down

0 comments on commit a40a854

Please sign in to comment.