Advertisement
MrReps

Ars element automation

May 1st, 2023
842
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.90 KB | Gaming | 0 0
  1. -- Script need BUTTON API by DIREWOLF20 !
  2.  
  3. --Chargement API
  4. os.loadAPI("button")
  5.  
  6. --Variable Global
  7. nbToCraft = 0
  8. nbToPrint = "0"
  9. selectedCraft = ""
  10. doingCrafting = false
  11.  
  12. local craftingTable = {}
  13. craftingTable["Water"] = {"minecraft:water_bucket", "minecraft:kelp", "minecraft:snow_block"}
  14. craftingTable["Manip"] = {"minecraft:stone_button", "minecraft:clock", "minecraft:redstone"}
  15. craftingTable["Fire"] = {"minecraft:flint_and_steel", "minecraft:gunpowder", "minecraft:torch"}
  16. craftingTable["Earth"] = {"minecraft:dirt", "minecraft:iron_ingot", "minecraft:wheat_seeds"}
  17. craftingTable["Air"] = {"minecraft:feather", "minecraft:arrow", "ars_nouveau:wilden_wing"}
  18. craftingTable["Conju"] = {"minecraft:book", "ars_nouveau:wilden_horn", "ars_nouveau:starbuncle_shards"}
  19. craftingTable["Abjur"] = {"minecraft:milk_bucket", "minecraft:fermented_spider_eye", "minecraft:sugar"}
  20.  
  21. local reactStore = "minecraft:barrel_1"
  22. local inOut = "minecraft:barrel_0"
  23. local imbuer = "ars_nouveau:imbuement_chamber_1"
  24. local pedest0 = "ars_nouveau:arcane_pedestal_3"
  25. local pedest1 = "ars_nouveau:arcane_pedestal_4"
  26. local pedest2 = "ars_nouveau:arcane_pedestal_5"
  27.  
  28. local pedestTab = {pedest0, pedest1, pedest2}
  29.  
  30. local reactStoreW = peripheral.wrap(reactStore)
  31. local imbuerW = peripheral.wrap(imbuer)
  32. local inOutW = peripheral.wrap(inOut)
  33.  
  34. local pedest0W = peripheral.wrap(pedest0)
  35. local pedest1W = peripheral.wrap(pedest1)
  36. local pedest2W = peripheral.wrap(pedest2)
  37.  
  38. local pedestWTab = {pedest0W, pedest1W, pedest2W}
  39. --math.floor(nbToCraft)
  40.  
  41. --Prog:
  42. m = peripheral.wrap("back")
  43.  
  44. function fillTable()
  45.  button.setTable("Water",selector,"Water",2,8,2,4)
  46.  button.setTable("Manip",selector,"Manip",11,18,2,4)
  47.  button.setTable("Fire",selector,"Fire",21,28,2,4)
  48.  button.setTable("Earth",selector,"Earth",2,8,6,8)
  49.  button.setTable("Air",selector,"Air",11,18,6,8)
  50.  button.setTable("Conju",selector,"Conju",21,28,6,8)
  51.  button.setTable("Abjur",selector,"Abjur",11,18,10,12)
  52.  
  53.  button.setTable("--",subMultiple,"",2,5,16,18)
  54.  button.setTable("-",subSimple,"",7,9,16,18)
  55.  button.setTable("+",addSimple,"",21,23,16,18)
  56.  button.setTable("++",addMultiple,"",25,28,16,18)
  57.  
  58.  button.setTable(nbToPrint,crafting,"",11,18,16,18)
  59.  button.screen()
  60. end
  61.  
  62. function getClic()
  63.  event,side,x,y = os.pullEvent("monitor_touch")
  64.  button.checkxy(x,y)
  65. end
  66.  
  67. function suckAll()
  68.  print("Empty Pedest")
  69.  for _, pedestW in pairs(pedestWTab) do
  70.   if pedestW.getItemDetail(1) ~= nil then
  71.    pedestW.pushItems(reactStore, 1)
  72.   end
  73.  end
  74. end
  75.  
  76. function nbConv()
  77.  -- updating craft button
  78.  if doingCrafting then
  79.   button.toggleButton(nbToPrint)
  80.  end
  81.  nbToPrint = tostring(nbToCraft)
  82.  -- updating selected craft
  83.  if selectedCraft ~= "" then
  84.   button.toggleButton(selectedCraft)
  85.  end
  86.  button.clearTable()
  87.  fillTable()
  88.  if selectedCraft ~= "" then
  89.   button.toggleButton(selectedCraft)
  90.  end
  91.  -- updating the craft if craft there is
  92.  if doingCrafting then
  93.   button.toggleButton(nbToPrint)
  94.  end
  95.  
  96.  button.screen()
  97. end
  98.  
  99. function crafting()
  100.  print("craft")
  101.  button.toggleButton(nbToPrint)
  102.  -- empty imbueur in case
  103.  if imbuerW.getItemDetail(1) ~= nil then
  104.   imbuerW.pushItems(inOut,1)
  105.  end
  106.  
  107.  doingCrafting = true
  108.  
  109.  --keeping the name of the input
  110.  local craftInput = "ars_nouveau:source_gem"
  111.  
  112.  --making gems
  113.  while doingCrafting and nbToCraft ~= 0 do
  114.   --cheking for the slot of gems
  115.   local found = false
  116.   local list = inOutW.list()
  117.   local slot = 1
  118.   while not found and slot <= #list do
  119.    if list[slot]["name"] == craftInput then
  120.     print("item found")
  121.     found = true
  122.    else
  123.     slot = slot + 1
  124.    end
  125.   end
  126.   -- making sure to have a gem
  127.   if not found then
  128.    print("no catalyser found")
  129.    doingCrafting = false
  130.    nbToCraft = nbToCraft + 1 --compense le -1 qui n'a pas lieux dans ce casd
  131.   else
  132.    -- puting gem in imbuer
  133.    print("putting the item")
  134.    print(inOutW.getItemDetail(slot)["name"])
  135.    inOutW.pushItems(imbuer, slot)
  136.   end
  137.   while doingCrafting and imbuerW.getItemDetail(1)["name"] == craftInput do
  138.    print("checking for craft")
  139.    -- waiting for craft or cancel
  140.    os.startTimer(3)
  141.    local event = os.pullEvent()
  142.    if event ~= "timer" then
  143.     -- stoping  craft
  144.     print("crafting have been stoped")
  145.     doingCrafting = false
  146.     os.reboot()
  147.    end
  148.   end
  149.   imbuerW.pushItems(inOut, 1)
  150.   nbToCraft = nbToCraft - 1
  151.   nbConv()
  152.  end
  153.  print("end crafting")
  154.  doingCrafting = false
  155.  button.toggleButton(nbToPrint)
  156. end
  157.  
  158. function addSimple()
  159.  print("+")
  160.  button.flash("+")
  161.  nbToCraft = nbToCraft + 1
  162.  nbConv()
  163. end
  164.  
  165. function addMultiple()
  166.  print("++")
  167.  button.flash("++")
  168.  nbToCraft = nbToCraft + 5
  169.  nbConv()
  170. end
  171.  
  172. function selector(input)
  173.  -- Affichage
  174.  print(input)
  175.  if selectedCraft == input then
  176.   button.toggleButton(selectedCraft)
  177.   selectedCraft = ""
  178.   suckAll()
  179.  else
  180.   if selectedCraft ~= "" then
  181.    button.toggleButton(selectedCraft)
  182.   end
  183.   selectedCraft = input
  184.   button.toggleButton(selectedCraft)
  185.   -- Item Move
  186.   suckAll()
  187.  
  188.   local listItem = reactStoreW.list()
  189.   local found = false
  190.  
  191.   for number, item in pairs(craftingTable[selectedCraft]) do
  192.    found = false
  193.    for slot, stored in ipairs(listItem) do
  194.     if stored["name"] == item then
  195.      reactStoreW.pushItems(pedestTab[number], slot)
  196.      print("pushing "..item)
  197.      found = true
  198.     end
  199.    end
  200.    if not found then
  201.     print("item "..item.." hasn't been found")
  202.    end
  203.   end
  204.  end
  205. end
  206.  
  207. function subSimple()
  208.  print("-")
  209.  button.flash("-")
  210.  if nbToCraft >= 1 then
  211.   nbToCraft = nbToCraft - 1
  212.  end
  213.  nbConv()
  214. end
  215.  
  216. function subMultiple()
  217.  print("--")
  218.  button.flash("--")
  219.  if nbToCraft >= 5 then
  220.   nbToCraft = nbToCraft - 5
  221.  else
  222.   nbToCraft = 0
  223.  end
  224.  nbConv()
  225. end
  226.  
  227. --Prog actif:
  228. if imbuerW.getItemDetail(1) ~= nil then
  229.  imbuerW.pushItems(inOut, 1)
  230. end
  231. button.clearTable()
  232. fillTable()
  233. button.heading("Essence Crafting")
  234. --button.label(1,4,"Tutoriel")
  235.  
  236. while true do
  237.  getClic()
  238. end
  239.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement