Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function logMsg(text) print("[" .. os.date("%T") .. "] " .. text) end
- local function selectItem(id)
- -- match exact
- for i = 1, 16 do
- local data = turtle.getItemDetail(i)
- if data and data.name == id then
- turtle.select(i)
- return true
- end
- end
- -- match by tags
- for i = 1, 16 do
- local data = turtle.getItemDetail(i, true)
- if data then
- for tag, _ in pairs(data.tags) do
- if tag == id then
- turtle.select(i)
- return true
- end
- end
- end
- end
- -- no match
- return false
- end
- local function nKeys(t)
- local i = 0
- for _, _ in pairs(t) do i = i + 1 end
- return i
- end
- local crystallizer
- local QUALITY_NONE = 0
- local QUALITY_CRUDE = 1
- local QUALITY_FINE = 2
- local QUALITY_PRISTINE = 3
- local qualityEnumToName = {
- [0] = "NONE",
- [1] = "CRUDE",
- [2] = "FINE",
- [3] = "PRISTINE"
- }
- local function getCrystalState()
- for _, item in pairs(crystallizer.list()) do
- if item and item.name then
- if item.name:find("pristine") then
- return QUALITY_PRISTINE
- elseif item.name:find("fine") then
- return QUALITY_FINE
- elseif item.name:find("crude") then
- return QUALITY_CRUDE
- end
- end
- end
- return QUALITY_NONE
- end
- local function isCrystalDone() return nKeys(crystallizer.list()) == 1 end
- local function processCrystal()
- if not selectItem("elementalcraft:shards") then
- turtle.suckUp() -- shards above on a pedestal
- end
- for shard = 1, 10 do
- while not selectItem("elementalcraft:shards") do
- turtle.suckUp() -- shards above on a pedestal
- os.sleep(1)
- end
- turtle.drop(1) -- crystallizer in front
- end
- logMsg("Shards placed!")
- if not selectItem("elementalcraft:crystals") then
- turtle.suckDown(1) -- crystals below on a pedestal
- end
- while not selectItem("elementalcraft:crystals") do
- turtle.suckDown(1) -- crystals below on a pedestal
- os.sleep(1)
- end
- turtle.drop(1) -- crystallizer in front
- logMsg("Crystal placed!")
- while not isCrystalDone() do os.sleep(1) end
- local quality = getCrystalState()
- logMsg("Got gem of quality " .. qualityEnumToName[quality] .. "!")
- if quality < QUALITY_PRISTINE then
- logMsg("Gem not quality enough!")
- return processCrystal()
- else
- logMsg("Gem is correct quality!")
- turtle.suck() -- gem will be imported from turtle inventory
- return nil
- end
- end
- local function mainLoop()
- crystallizer = peripheral.find("elementalcraft:crystallizer")
- while selectItem("minecraft:diamond") do
- logMsg("Gem requested!")
- turtle.drop(1) -- crystallizer in front
- processCrystal()
- end
- os.sleep(1)
- end
- local function errorHandler(error) logMsg("internal error: " .. error) end
- logMsg("Elemental gem crafter started up.")
- while true do
- -- xpcall(mainLoop, errorHandler)
- mainLoop() -- for debugging
- end
Advertisement
Add Comment
Please, Sign In to add comment