mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-09-10 12:58:21 -04:00
Keep crafting more when holding left click in inventory crafting.
fixes #1051
This commit is contained in:
parent
ead00272cc
commit
868b4aade3
@ -587,6 +587,11 @@ pub const inventory = struct { // MARK: inventory
|
|||||||
var leftClickSlots: List(*ItemSlot) = undefined;
|
var leftClickSlots: List(*ItemSlot) = undefined;
|
||||||
var rightClickSlots: List(*ItemSlot) = undefined;
|
var rightClickSlots: List(*ItemSlot) = undefined;
|
||||||
var initialized: bool = false;
|
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 {
|
pub fn init() void {
|
||||||
carried = Inventory.init(main.globalAllocator, 1, .normal, .{.hand = main.game.Player.id});
|
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 = ItemSlot.init(.{0, 0}, carried, 0, .default, .normal);
|
||||||
carriedItemSlot.renderFrame = false;
|
carriedItemSlot.renderFrame = false;
|
||||||
initialized = true;
|
initialized = true;
|
||||||
|
startedCrafting = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit() void {
|
pub fn deinit() void {
|
||||||
@ -630,6 +636,22 @@ pub const inventory = struct { // MARK: inventory
|
|||||||
fn update() void {
|
fn update() void {
|
||||||
if(!initialized) return;
|
if(!initialized) return;
|
||||||
if(hoveredItemSlot) |itemSlot| {
|
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(itemSlot.mode != .normal) return;
|
||||||
|
|
||||||
if(carried.getAmount(0) == 0) return;
|
if(carried.getAmount(0) == 0) return;
|
||||||
@ -658,6 +680,10 @@ pub const inventory = struct { // MARK: inventory
|
|||||||
if(!initialized) return;
|
if(!initialized) return;
|
||||||
if(main.game.world == null) return;
|
if(main.game.world == null) return;
|
||||||
if(leftClick) {
|
if(leftClick) {
|
||||||
|
if(startedCrafting) {
|
||||||
|
startedCrafting = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
if(leftClickSlots.items.len != 0) {
|
if(leftClickSlots.items.len != 0) {
|
||||||
const targetInventories = main.stackAllocator.alloc(Inventory, leftClickSlots.items.len);
|
const targetInventories = main.stackAllocator.alloc(Inventory, leftClickSlots.items.len);
|
||||||
defer main.stackAllocator.free(targetInventories);
|
defer main.stackAllocator.free(targetInventories);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user