From 9a0c584cbac73215a0ab43fc085267a5f980b288 Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Sun, 14 May 2017 00:53:59 -0400 Subject: [PATCH] throttlee --- apps/builder.lua | 6 ++---- apps/scripts/obsidian | 12 +++++++++++- sys/apis/util.lua | 10 +++++++--- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/apps/builder.lua b/apps/builder.lua index 4e3c327..1d16c19 100644 --- a/apps/builder.lua +++ b/apps/builder.lua @@ -541,9 +541,7 @@ function Builder:getGenericSupplyList(blockIndex) end function Builder:substituteBlocks() - local spinner = UI.Spinner({ - spinSymbols = { '' } - }) + local throttle = Util.throttle() for _,b in pairs(schematic.blocks) do @@ -560,7 +558,7 @@ function Builder:substituteBlocks() b.dmg = sub.sdmg end - spinner:spin() + throttle() end end diff --git a/apps/scripts/obsidian b/apps/scripts/obsidian index 84e28f8..48da893 100644 --- a/apps/scripts/obsidian +++ b/apps/scripts/obsidian @@ -27,15 +27,24 @@ local function findObsidian() local _,b = turtle.inspectDown() if b and (b.name == 'minecraft:lava' or b.name == 'minecraft:flowing_lava') then if turtle.selectSlot('minecraft:water_bucket') then - turtle.up() + while not turtle.up() do + print('stuck') + end turtle.placeDown() os.sleep(2) turtle.placeDown() turtle.down() + turtle.select(1) _, b = turtle.inspectDown() end end + if turtle.getCount(16) > 0 then + print('Inventory full') + print('Enter to continue...') + read() + end + if b and b.name == 'minecraft:obsidian' then turtle.digDown() addNode(node) @@ -78,6 +87,7 @@ local s, m = turtle.run(function() os.sleep(2) turtle.placeDown() turtle.down() + turtle.select(1) until turtle.abort end) turtle.goto(0, 0, 0, 0) diff --git a/sys/apis/util.lua b/sys/apis/util.lua index 387ca28..951701c 100644 --- a/sys/apis/util.lua +++ b/sys/apis/util.lua @@ -21,13 +21,17 @@ function Util.tryTimes(attempts, f, ...) return unpack(result) end -function Util.throttle() +function Util.throttle(fn) local ts = os.time() - return function() + local timeout = .095 + return function(...) local nts = os.time() - if nts ~= ts then + if nts > ts + timeout then ts = nts os.sleep(0) + if fn then + fn(...) + end end end end