throttlee

This commit is contained in:
kepler155c@gmail.com 2017-05-14 00:53:59 -04:00
parent c34b46699b
commit 9a0c584cba
3 changed files with 20 additions and 8 deletions

View File

@ -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

View File

@ -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)

View File

@ -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