diff options
author | ubq323 <ubq323@ubq323.website> | 2023-01-05 05:29:34 +0000 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2023-01-05 05:29:34 +0000 |
commit | f707f4dc34d3a48ad2ebaaa4130c777a9a219f47 (patch) | |
tree | 0f5376585ab0ed6d0ef1be09d9634cf462bb7e23 | |
parent | 3b5db556ebc7b7328094cbba67fa89efa5bf87be (diff) |
shop2
-rw-r--r-- | shop2.lua | 35 |
1 files changed, 19 insertions, 16 deletions
@@ -41,7 +41,14 @@ local function parsemeta(m) return out end -local chest = peripheral.wrap"back" +local chest +for _,name in ipairs(peripheral.getNames()) do + if name:match("chest") then chest = peripheral.wrap(name) break end +end +assert(chest,"couldn't find chest") +-- might not work if there are multiple modems but why would you do that +local localname = peripheral.find("modem").getNameLocal() + local function take_stock() -- if you do this in parallel, you avoid having to wait 1 tick for each -- slot of the chest. which is probably good. @@ -71,23 +78,19 @@ local function stock_amt(stockinfo,idesc) return total end -local si = take_stock() -pp(si) - -for iadr,itm in pairs(ITEMS) do - print(iadr,itm.hname,stock_amt(si,itm)) - -end - --- XXX -local function give(amt) +local function give(stockinfo,idesc,amt) amt = amt or 1 -- assumes that we have at least amt in stock already - for i=1,16 do - local x = turtle.getItemDetail(i) - if x and x.name == ITEM then - local a = math.min(amt,x.count) - turtle.select(i) + -- actually no, might as well double check this anyway + assert(stock_amt(stockinfo,idesc) >= amt) + assert(amt>0) + -- make sure current turtle inv slot is empty + assert(turtle.getItemCount() == 0) + + for slotidx,idtl in pairs(stockinfo) do + if item_desc_matches(idesc,idtl) then + local a = math.min(amt,idtl.count) + chest.pushItems(localname, slotidx, a, 1) turtle.drop(a) amt = amt - a if amt <= 0 then break end |