From 868b4aade332d3e6a06633e429fc3ecdfbb4a69a Mon Sep 17 00:00:00 2001 From: IntegratedQuantum Date: Sat, 1 Mar 2025 15:23:05 +0100 Subject: [PATCH] Keep crafting more when holding left click in inventory crafting. fixes #1051 --- src/gui/gui.zig | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/gui/gui.zig b/src/gui/gui.zig index 04ff1806..1357b1e6 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -587,6 +587,11 @@ pub const inventory = struct { // MARK: inventory var leftClickSlots: List(*ItemSlot) = undefined; var rightClickSlots: List(*ItemSlot) = undefined; var initialized: bool = false; + const minCraftingCooldown = 20; + const maxCraftingCooldown = 400; + var nextCraftingAction: i64 = undefined; + var craftingCooldown: u63 = undefined; + var startedCrafting: bool = false; pub fn init() void { carried = Inventory.init(main.globalAllocator, 1, .normal, .{.hand = main.game.Player.id}); @@ -595,6 +600,7 @@ pub const inventory = struct { // MARK: inventory carriedItemSlot = ItemSlot.init(.{0, 0}, carried, 0, .default, .normal); carriedItemSlot.renderFrame = false; initialized = true; + startedCrafting = false; } pub fn deinit() void { @@ -630,6 +636,22 @@ pub const inventory = struct { // MARK: inventory fn update() void { if(!initialized) return; if(hoveredItemSlot) |itemSlot| { + if(itemSlot.inventory.type == .crafting and itemSlot.mode == .takeOnly) { + if(main.KeyBoard.key("mainGuiButton").pressed) { + const time = std.time.milliTimestamp(); + if(!startedCrafting) { + startedCrafting = true; + craftingCooldown = maxCraftingCooldown; + nextCraftingAction = time; + } + while(time -% nextCraftingAction >= 0) { + nextCraftingAction +%= craftingCooldown; + craftingCooldown -= (craftingCooldown - minCraftingCooldown)*craftingCooldown/1000; + itemSlot.inventory.depositOrSwap(itemSlot.itemSlot, carried); + } + return; + } + } if(itemSlot.mode != .normal) return; if(carried.getAmount(0) == 0) return; @@ -658,6 +680,10 @@ pub const inventory = struct { // MARK: inventory if(!initialized) return; if(main.game.world == null) return; if(leftClick) { + if(startedCrafting) { + startedCrafting = false; + return; + } if(leftClickSlots.items.len != 0) { const targetInventories = main.stackAllocator.alloc(Inventory, leftClickSlots.items.len); defer main.stackAllocator.free(targetInventories);