Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Autocrafting da UU Matter, by youtube.com/Keledan75
- -- Impara a programmare con Minecraft Episodi 55-59
- -- http://www.youtube.com/watch?v=WSEmYOA6nE0
- -- Uso: metti una crafty turtle sopra uno scrigno pieno di UU matter; la turtle scarica gli oggetti prodotti in uno scrigno sopra di essa
- shallICraft = true
- ordered = 10
- maxUUperRecipe = 192
- max = 4
- strErrorQuantity = "Quantita' di UU Matter insufficiente per la ricetta"
- strUnloading = "Scaricando Oggetti..."
- strQuantityOK = "Quantita' corretta"
- strWelcome = "\nScegli tua ricetta, X per uscire \n"
- strRecipe = ""
- strRequiredItem = ""
- strMessage = ""
- intNumeroOggetti = 0
- intMinQty = 0
- slots = {5,6,7,9,10,11,13,14,15}
- craftingInterval = 1
- oggettiOrdinati = 1
- recipes = {redstone= {0, 0, 0, 0, 1, 0, 1, 1, 1, 4, 24, "r"},
- copper = {0, 0, 1, 1, 0, 1, 0, 0, 0, 3, 10, "c"},
- tin = {0, 0, 0, 1, 0, 1, 0, 0, 1, 3, 10, "t"},
- gold = {0, 1, 0, 1, 1, 1, 0, 1, 0, 5, 2, "g"},
- diamond = {1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 1, "d"},
- rubber = {1, 0, 1, 0, 0, 0, 1, 0, 1, 4, 21, "u"},
- glass = {0, 1, 0, 1, 0, 1, 0, 1, 0, 4, 32, "v"},
- iridium = {1, 1, 1, 0, 1, 0, 1, 1, 1, 7, 1, "i"},
- wood = {0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 8, "w"},
- stone = {0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 16, "s"},
- obsidian = {1, 0, 1, 1, 0, 1, 0, 0, 0, 4, 12, "o"},
- flint = {0, 1, 0, 1, 1, 0, 1, 1, 0, 5, 32, "f"},
- coal = {0, 0, 1, 1, 0, 0, 0, 0, 1, 3, 20, "b"},
- glowstone = {0, 1, 0, 1, 0, 1, 1, 1, 1, 6, 8, "l"},
- iron = {1, 0, 1, 0, 1, 0, 1, 0, 1, 5, 2, "e"},
- clay = {1, 1, 0, 1, 0, 0, 1, 1, 0, 5, 48, "a"}
- }
- -- se la lettera è quella nella tabella recipes ritorna vero, altrimenti false
- -- attribuisce alle variabili i valori di quantità minima e oggetto richiesto
- function checkKey(key)
- for i in pairs(recipes) do
- if recipes[i][12] == key then
- -- print (recipes[i][12] .. " - ")
- intMinQty = recipes[i][11]
- strRequiredItem = i
- return true
- end
- end
- return false
- end
- -- Fetches the needed UU, sucks up to max times to get it. May fail if the first slots of a chest has small stacks
- function fetchUU(needed, max)
- UUAmount = 0
- for i = 1, max do
- turtle.select(1)
- turtle.suckDown()
- UUAmount = UUAmount + turtle.getItemCount(1)
- if UUAmount >= needed then break end
- end
- return UUAmount
- end
- -- unloads up to the max slot - scarica fino allo slot max
- local function unload(side, max)
- unloaded = 0
- print( strUnloading )
- for n=1,max do
- unloaded = unloaded + turtle.getItemCount(n)
- turtle.select(n)
- if side == "up" then turtle.dropUp() else turtle.dropDown() end
- end
- turtle.select(1)
- return unloaded
- end
- -- Accorpa i primi 3 slot e trasferisci negli slot secondo la ricetta
- function prepareForCrafting(UUperSlot, UUNeeded, recipe)
- for i = 1, 9 do
- if recipes[recipe][i] > 0 then
- turtle.select(1)
- turtle.transferTo(slots[i], UUperSlot)
- end
- if UUNeeded > 64 and UUNeeded < 128 then
- turtle.select(2)
- turtle.transferTo(1, 64)
- elseif UUNeeded > 128 then
- turtle.select(2)
- turtle.transferTo(1, 64)
- turtle.select(3)
- turtle.transferTo(2, 64)
- end
- end
- end
- -- Gives back the unused UU
- -- Restituisce la UU non usata
- function returnUU()
- for i = 1, max do
- turtle.select(i)
- turtle.dropDown()
- end
- turtle.select(1)
- end
- -- Craft the required items
- -- Produce gli oggetti richiesti
- function crafting()
- finito = false
- -- se non ha finito il crafting o se lo slot 4 è ancora libero, continua il crafting
- while not finito or turtle.getItemCount(4) > 0 do
- if turtle.craft() then
- -- scarica materiale già craftato ed esegue ancora crafting
- unload ("up", 3)
- else
- finito = true
- end
- end
- end
- function executeCrafting (recipe, ordered)
- -- Execution - Esecuzione
- requiredCrafting = math.ceil (ordered / recipes[recipe][11])
- UUNeeded = recipes[recipe][10] * requiredCrafting
- -- If more than maxUUperRecipe asked, reset to maxUUPerRecipe, recalculates the requiredcrafting
- if UUNeeded > maxUUperRecipe then
- UUNeeded = maxUUperRecipe
- requiredCrafting = math.floor (maxUUperRecipe / recipes[recipe][10])
- end
- finalAmount = recipes[recipe][11] * requiredCrafting
- if shallICraft then
- print ("UU richiesta: " .. UUNeeded)
- strMessage = "Oggetti prodotti: " .. finalAmount .. " di " .. recipe
- fetchUU(UUNeeded, max)
- prepareForCrafting(requiredCrafting, UUNeeded, recipe)
- returnUU()
- crafting()
- --clean the whole table
- unload("down", 16)
- end
- sleep (craftingInterval)
- end
- -- print on screen the recipe list and specifies the key for each recipe
- function elencoRicette()
- local strKey = ""
- local strRecipe = ""
- local strMenu = ""
- local n = 0
- for i in pairs(recipes) do
- n = n + 1
- -- mette in maiuscolo la lettera iniziale della ricetta
- strRecipe = i:gsub("^%l", string.upper)
- strKey = recipes[i][12]
- -- alle righe pari vado a capo
- if (n % 2 == 0) then
- strMenu = strMenu .. " - " .. strRecipe ..": '" .. strKey .. "' "
- print (strMenu)
- strMenu = ""
- else
- strMenu = strRecipe ..": '" .. strKey .. "' "
- end
- end
- end
- -- esegue la routine principale - executes the main routine
- function routine ()
- -- faccio apparire un messaggio di benvenuto
- -- ripulisco lo schermo
- term.clear()
- print (strMessage)
- print (strWelcome)
- -- Descrivo i comandi disponibili
- elencoRicette()
- -- accetto input da tastiera per il tipo di crafting richiesto
- tipoEvento, tipoOggetti = os.pullEvent("char")
- -- controllo se ho premuto un tasto corretto
- if tipoEvento == "char" then
- print ("Hai premuto il tasto: " .. tipoOggetti)
- if checkKey(tipoOggetti) then
- -- richiedo il numero di oggetti da produrre
- print ("Crafting minimo: " .. intMinQty .. " - Invio per minimo")
- intNumeroOggetti = tonumber(read())
- -- se si preme invio allora si fabbrica la qtà minima
- if intNumeroOggetti == nil then intNumeroOggetti = intMinQty end
- -- piazza un controllo e verifica se ho passato un valore numerico maggiore di 0 e inferiore di un massimo che decideremo
- print ("Hai ordinato " .. strRequiredItem .. " in quantità : " .. intNumeroOggetti)
- -- lancio execute crafting con i parametri: tipo di oggetto ordinato; la quantità minima ordinabile oppure la quantità ordinata se è superiore al minimo.
- if intNumeroOggetti < intMinQty then intNumeroOggetti = intMinQty end
- executeCrafting(strRequiredItem, intNumeroOggetti)
- elseif (tipoOggetti == "x" or tipoOggetti == "X") then
- print ("Termino il programma")
- shallICraft = false
- else
- strMessage = "Il tasto premuto non corrisponde a una ricetta valida"
- end
- end
- end
- while shallICraft do
- routine()
- end
Advertisement
Add Comment
Please, Sign In to add comment