From: Olav Bakke Svendsen Date: Tue, 14 May 2024 04:58:17 +0000 (+0200) Subject: vines/turtle.lua: inventory utils X-Git-Tag: skystone~20 X-Git-Url: http://git.olavbs.no/?a=commitdiff_plain;h=a8172f60e1c12a03c796b0d386eeb1ae60be3a9c;p=cc.git vines/turtle.lua: inventory utils --- diff --git a/vines/turtle.lua b/vines/turtle.lua new file mode 100644 index 0000000..d0b37bc --- /dev/null +++ b/vines/turtle.lua @@ -0,0 +1,80 @@ +-- setup: +-- equip weak automata +-- place in front of coal/shear chest, facing it + +-- refuel, grab shears (keep two at all times) +-- harvest +-- offload +-- index +-- repeat + +local shears = + { "alloyed:steel_shears" + , "minecraft:shears" + } + +-- return positions of shears in inventory +-- might not be useful if countShears and selectShears is implemented +-- local locateShears = function() +-- local t = {} +-- for i = 1, 16 do +-- local item = turtle.getItemDetail(i) +-- if item then +-- for _,name in pairs(shears) do +-- if item.name == name then +-- table.insert(t, i) +-- end +-- end +-- end +-- end +-- end + +-- find : list of item names -> index | nil +-- returns the first inventory index containing an item from list t +-- if no item is found, returns nil +local find = function(t) + for i = 1, 16 do + print("looking in", i) + local item = turtle.getItemDetail(i) + if item then + for _,name in pairs(t) do + print("comparing", name, item.name) + if item.name == name then + return i + end + end + end + end + return nil +end + +-- count : list of item names -> count +local count = function(t) + local c = 0 + for i = 1, 16 do + local item = turtle.getItemDetail(i) + if item then + for _, name in pairs(t) do + if item.name == name then + count = count + 1 + break + end + end + end + end +end + +-- select shears in inventory if not already selected. +-- returns bool. false means no shears in inventory. +-- local selectShears = function() +-- if not turtle.getItemDetail() then +-- for i = 1, 16 do +-- if item and (item.name == "minecraft:shears" or item.name == "alloyed:steel_shears") +-- (and item + + + +-- local shear = function() +-- selectShears() +-- local collect = function() +-- a