Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Automate Spectrum Potion Workshop for liquid crystal;
- needs to insert bucket ebfore everything else, or other stuff
- will be put into the container slot
- ]]
- local RUN_EVERY_SEC = 0.5
- local GET_ITEMS_EVERY_ITERS = 1
- -- Config these two depending on sides
- local DropFunction = turtle.dropDown
- local SuckFunction = turtle.suck
- local Items = {
- MERMAIDS = "spectrum:mermaids_gem",
- YELLOW_P = "spectrum:yellow_pigment",
- PINK_P = "spectrum:pink_pigment",
- SHIMMERSTONE = "spectrum:sparklestone_gem",
- BUCKET = "minecraft:bucket",
- }
- local MAX_SLOT = 16
- local function getItemsAndCheck(suckFun, dropFun)
- local done = false
- repeat
- local success = suckFun(64)
- done = not success
- until done
- for slot = 1, MAX_SLOT do
- local data = turtle.getItemDetail(slot)
- if data
- and not includes(Items, data.name) then
- turtle.select(slot)
- dropFun(64)
- end
- end
- end
- local function hasItem(itemId)
- local currentRecipe
- local recipeSlots
- for slot = 1, MAX_SLOT do
- local data = turtle.getItemDetail(slot)
- if data and data.name == itemId then
- return true
- end
- end
- return false
- end
- local function dropItem(dropFun, itemId, num)
- for slot = 1, MAX_SLOT do
- local data = turtle.getItemDetail(slot)
- if data and data.name == itemId then
- turtle.select(slot)
- dropFun(num)
- end
- end
- end
- local function main()
- print("Spectrum Crystal automation: starting!")
- local iters = 0
- while true do
- if iters == 0 then
- getItemsAndCheck(SuckFunction, DropFunction)
- end
- if hasItem(Items.BUCKET) then
- print("Has bucket! Transferring items...")
- dropItem(DropFunction, Items.BUCKET, 1)
- dropItem(DropFunction, Items.SHIMMERSTONE, 32)
- dropItem(DropFunction, Items.PINK_P, 32)
- dropItem(DropFunction, Items.YELLOW_P, 32)
- dropItem(DropFunction, Items.MERMAIDS, 4)
- end
- iters = (iters + 1) % GET_ITEMS_EVERY_ITERS
- ---@diagnostic disable-next-line: undefined-field
- os.sleep(RUN_EVERY_SEC)
- end
- end
- -- library stuff
- function includes(tbl, val)
- for k, v in pairs(tbl) do
- if v == val then
- return true
- end
- end
- return false
- end
- function indexOf(list, val)
- for i, v in ipairs(list) do
- if v == val then
- return i
- end
- end
- end
- -- If the tables have the same items,
- -- with eventually different order
- function matches(tbl1, tbl2)
- local tbl2copy = {}
- for k2, v2 in pairs(tbl2) do
- tbl2copy[k2] = v2
- end
- for k1, v1 in pairs(tbl1) do
- local found = false
- for k2, v2 in pairs(tbl2copy) do
- if v2 == v1 then
- found = true
- tbl2copy[k2] = nil
- break
- end
- end
- if not found then
- return false
- end
- end
- return true
- end
- function dump(o)
- if type(o) == 'table' then
- local s = '{ '
- for k,v in pairs(o) do
- if type(k) ~= 'number' then k = '"'..k..'"' end
- s = s .. '['..k..'] = ' .. dump(v) .. ','
- end
- return s .. '} '
- else
- return tostring(o)
- end
- end
- -- Actually run
- main()
Advertisement
Add Comment
Please, Sign In to add comment