Skip to content

Commit b74ba74

Browse files
committed
allow for reach to be changed in creative
1 parent 146ed64 commit b74ba74

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/gui/windows/advanced_controls.zig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,20 @@ fn speedFormatter(allocator: main.heap.NeverFailingAllocator, value: f32) []cons
3838
return std.fmt.allocPrint(allocator.allocator, "#ffffffPlace/Break Speed: {d:.0} ms", .{value/1.0e6}) catch unreachable;
3939
}
4040

41+
fn reachCallback(newValue: f32) void {
42+
settings.creativeReach = @min(@max(1, @round(newValue/6)), 40)*6;
43+
settings.save();
44+
}
45+
46+
fn reachFormatter(allocator: main.heap.NeverFailingAllocator, value: f32) []const u8 {
47+
return std.fmt.allocPrint(allocator.allocator, "#ffffffCreative Reach: {d:.0} blocks", .{@round(value/6)*6}) catch unreachable;
48+
}
49+
4150
pub fn onOpen() void {
4251
const list = VerticalList.init(.{padding, 16 + padding}, 300, 16);
4352
list.add(ContinuousSlider.init(.{0, 0}, 128, 1.0e6, 1.0e9, @floatFromInt(settings.updateRepeatDelay.nanoseconds), &delayCallback, &delayFormatter));
4453
list.add(ContinuousSlider.init(.{0, 0}, 128, 1.0e6, 0.5e9, @floatFromInt(settings.updateRepeatSpeed.nanoseconds), &speedCallback, &speedFormatter));
54+
list.add(ContinuousSlider.init(.{0, 0}, 128, 6.0, 240.0, settings.creativeReach, &reachCallback, &reachFormatter));
4555
list.finish(.center);
4656
window.rootComponent = list.toComponent();
4757
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @as(Vec2f, @splat(padding));

src/renderer.zig

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,10 @@ pub const MeshSelection = struct { // MARK: MeshSelection
905905
lastDir = _dir;
906906

907907
// Test blocks:
908-
const closestDistance: f64 = 6.0; // selection now limited
908+
var closestDistance: f64 = 6.0; // selection now limited
909+
if (game.Player.isCreative()) {
910+
closestDistance = @as(f64, settings.creativeReach);
911+
}
909912
// Implementation of "A Fast Voxel Traversal Algorithm for Ray Tracing" http://www.cse.yorku.ca/~amana/research/grid.pdf
910913
const step: Vec3i = @intFromFloat(std.math.sign(dir));
911914
const invDir = @as(Vec3d, @splat(1))/dir;

src/settings.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ pub var updateRepeatSpeed: std.Io.Duration = .fromMilliseconds(200);
6767

6868
pub var updateRepeatDelay: std.Io.Duration = .fromMilliseconds(500);
6969

70+
pub var creativeReach: f32 = 6.0;
71+
7072
pub var controllerAxisDeadzone: f32 = 0.2;
7173

7274
const settingsFile = if (builtin.mode == .Debug) "debug_settings.zig.zon" else "settings.zig.zon";

0 commit comments

Comments
 (0)