--- trades_seller.lua --- Library for automated selling items in /trades in Minecraft/SkyBlock ---@class crafter local lib = {} local player = require("player") ---@type number|nil local schedule = nil ---@type number local currentIndex = 0 ---@type number local tickDelay = 2 ---@type number local tickCounter = 0 ---@type fun(slot: number)|nil local doneCallback = nil ---@type fun()|nil local timeoutCallback = nil ---@type number local craftStartTick = nil local function calculateTimeout() if not schedule or #schedule == 0 then return 10 end return #schedule * tickDelay + 10 end registerClientTick(function() if schedule then if craftStartTick and (os.clock() - craftStartTick) * 20 > calculateTimeout() then schedule = nil currentIndex = 0 if timeoutCallback then timeoutCallback() end return end local isOpen = player.inventory.isAnyScreenOpened() if isOpen then local containerSlots = player.inventory.getContainerSlots() if containerSlots and containerSlots > 34 then tickCounter = tickCounter + 1 if tickCounter >= tickDelay then tickCounter = 0 currentIndex = currentIndex + 1 local t = schedule[currentIndex] if t then local from = t + 45 if t >= 54 then from = t end if from >= 54 then player.inventory.shiftLeftClick(from) end end if currentIndex > #schedule then if currentIndex >= #schedule + 10 then schedule = nil currentIndex = 0 if doneCallback then doneCallback() end end end end end end end end) --- Crafts items from specified slots ---@param task number[] Array of selling slots ---@param delay number? Delay between each craft action in ticks (default: 2) ---@param callback fun(slot: number)|nil Callback function when crafting is complete, receives empty slot number ---@param timeout fun(closed: boolean)|nil Callback function when crafting fails (timeout or empty slot) function lib.sell(task, delay, callback, timeout) doneCallback = callback timeoutCallback = timeout schedule = task currentIndex = 0 if delay then tickDelay = delay else tickDelay = 2 end tickCounter = tickDelay - 1 craftStartTick = os.clock() end return lib