Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- shell.run("pastebin", "get", "jzpwtcvf", "dl")
- shell.run("dl", "ini")
- assert(os.loadAPI("ini"), "Couldn't download the INI api")
- function split(str,splitter)
- if not splitter then return end
- if not str then return end
- words = {}
- i=0
- for part in string.gmatch(str, "[^%"..splitter.."]+") do -- get each part
- i=i+1
- words[i] = part
- end
- return words
- end
- string.split = split
- function log2(n)
- return math.log(n)/math.log(2)
- end
- function log(n,base)
- return math.log(n)/math.log(base)
- end
- function dropTo(side)
- if side == "top" then
- return turtle.dropUp()
- elseif side == "bottom" then
- return turtle.dropDown()
- elseif side == "left" then
- turtle.turnLeft()
- ret = turtle.drop()
- turtle.turnRight()
- return ret
- elseif side == "right" then
- turtle.turnRight()
- ret = turtle.drop()
- turtle.turnLeft()
- return ret
- elseif side == "front" then
- return turtle.drop()
- elseif side == "back" then
- turtle.turnRight()
- turtle.turnRight()
- ret = turtle.drop()
- turtle.turnRight()
- turtle.turnRight()
- return ret
- else
- return false
- end
- end
- turtle.dropTo = dropTo
- -- Actual code
- settings = ini.open("settings")
- enderChest = peripheral.find("ender_chest")
- sides = peripheral.getNames()
- enderChestSide = sides[1]
- print("enderChest: "..enderChestSide)
- print("")
- if not enderChest then
- error("Usage: Put an ender chest in front, under or on top of the turtle.")
- end
- term.clear()
- term.setCursorPos(1,1)
- inputChest = settings.read("Main", "InputChest")
- if inputChest == false then
- inputChest = {}
- inputChest[1],inputChest[2],inputChest[3] = enderChest.getColors()
- settings.write("Main", "InputChest", table.concat(inputChest, ","))
- else
- inputChest = string.split(inputChest, ",")
- end
- print("Input: "..table.concat(inputChest, ","))
- setting = settings.read("Slots", "1")
- chestColors = {}
- if setting == false then
- base1, base2, base3 = enderChest.getColors()
- base1 = log2(base1)
- base2 = log2(base2)
- base3 = log2(base3)+1
- else
- chestColors[1] = string.split(setting, ",")
- base1 = chestColors[1][1]
- base2 = chestColors[1][2]
- base3 = chestColors[1][3]
- base1 = log2(base1)
- base2 = log2(base2)
- base3 = log2(base3)
- end
- slot = 1
- for i=base1,15 do
- for j=base2,15 do
- for k=base3,15 do
- if slot > 27 then
- i = 16
- j = 16
- k = 16
- break
- end
- chestColors[slot] = {}
- chestColors[slot][1] = 2^(i)
- chestColors[slot][2] = 2^(j)
- chestColors[slot][3] = 2^(k)
- --textutils.pagedTabulate(chestColors[slot])
- --sleep(0.25)
- slot = slot+1
- end
- end
- end
- for slot=1,27 do
- setting = settings.read("Slots", tostring(slot))
- if not setting then
- settings.write("Slots", tostring(slot), table.concat(chestColors[slot], ","))
- else
- chestColors[slot] = string.split(setting, ",")
- end
- end
- settings.close("settings")
- print("Settings done")
- enderChest.setColors(chestColors[1][1],chestColors[1][2],chestColors[1][3])
- while true do
- slots = enderChest.getAllStacks()
- for i,v in pairs(slots) do
- slots[i] = slots[i].all()
- if type(slots[i]) == "table" then
- -- print("Slot "..i..": "..slots[i].name)
- if i==1 then
- turtle.suck()
- else
- enderChest.swapStacks(1,i)
- turtle.suck()
- enderChest.swapStacks(1,i)
- end
- enderChest.setColors(chestColors[i][1],chestColors[i][2],chestColors[i][3])
- turtle.dropTo(enderChestSide)
- enderChest.setColors(inputChest[1],inputChest[2],inputChest[3])
- end
- end
- sleep()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement