Advertisement
Guest User

rune

a guest
Oct 17th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.19 KB | None | 0 0
  1. local component = require('component')
  2. local sides = require('sides')
  3. local serialize = require('serialization')
  4.  
  5. local xnet = component.xnet
  6.  
  7. local endpoints = {}
  8.  
  9. local args = {...}
  10. print("Making " .. args[1] .. " rune")
  11.  
  12. function addReq(rune, item, amount)
  13.    table.insert(rune, {["item"] = item, ["amount"] = amount})
  14.    return rune
  15. end
  16.  
  17. function baseRune()
  18.   local rune = {
  19.     {["item"] = "botania:manaresource:23", ["amount"] = 1},
  20.     {["item"] = "botania:manaresource", ["amount"] = 1},
  21.   }
  22.   return rune
  23. end
  24.  
  25. local air = baseRune()
  26. air = addReq(air, "minecraft:string", 1)
  27. air = addReq(air, "minecraft:feather", 1)
  28. air = addReq(air, "minecraft:carpet", 1)
  29.  
  30. local water = baseRune()
  31. water = addReq(water, "minecraft:fishing_rod", 1)
  32. water = addReq(water, "minecraft:reeds", 1)
  33. water = addReq(water, "minecraft:dye:15", 1)
  34.  
  35. local earth = baseRune()
  36. earth = addReq(earth, "minecraft:brown_mushroom", 1)
  37. earth = addReq(earth, "minecraft:coal_block", 1)
  38. earth = addReq(earth, "minecraft:stone", 1)
  39.  
  40. local fire = baseRune()
  41. fire = addReq(fire, "minecraft:nether_wart", 1)
  42. fire = addReq(fire, "minecraft:gunpowder", 1)
  43. fire = addReq(fire, "minecraft:netherbrick", 1)
  44.  
  45. runes = {}
  46. runes["air"] = air
  47. runes["water"] = water
  48. runes["earth"] = earth
  49. runes["fire"] = fire
  50.  
  51. for i,block in ipairs(xnet.getConnectedBlocks()) do
  52.   endpoints[block.connector] = block  
  53. end
  54.  
  55. function parseItems(items)
  56.   local assocTable = {}
  57.   for i,item in ipairs(items) do
  58.     if (item.name ~= "minecraft:air") then
  59.        local name = item.name
  60.        if item.damage ~= 0 then
  61.          name = name .. ":" .. item.damage
  62.        end
  63.        assocTable[name] = item
  64.        assocTable[name].slot = i
  65.     end
  66.   end
  67.   return assocTable
  68. end
  69.  
  70. function getItems(name)
  71.   local items = parseItems(xnet.getItems(endpoints[name].pos))
  72.   return items
  73. end  
  74.  
  75. function moveItem(from, to, item, amount)
  76.   local fromPos = endpoints[from].pos
  77.   local toPos = endpoints[to].pos
  78.   local items = getItems(from)
  79.   missing = true
  80.   for key,v in pairs(items) do
  81.     if (key == item) then
  82.       missing = false
  83.     end
  84.   end
  85.   if (missing) then
  86.     error("Missing " .. item)
  87.   end    
  88.   xnet.transferItem(fromPos, items[item].slot, amount, toPos)
  89.   return
  90. end
  91.  
  92. function checkReqs(from, reqs)
  93.   local items = getItems(from)
  94.   local missing = {}
  95.   for rKey, rV in ipairs(reqs) do
  96.     isMissing = true  
  97.     for key,v in pairs(items) do
  98.       if (rV.item == key) then
  99.         isMissing = false
  100.       end
  101.     end
  102.     if (isMissing) then
  103.       table.insert(missing, rV.item)
  104.     end
  105.   end
  106.   return missing
  107. end
  108.  
  109.  
  110. local missingItems = checkReqs("Rune Materials", runes[args[1]])
  111. if (missingItems[1] ~= nil) then
  112.   error("Missing items: " .. serialize.serialize(missingItems))
  113. end
  114.  
  115. print("Inputting Items...")
  116. for i,requirement in ipairs(runes[args[1]]) do
  117.   moveItem("Rune Materials", "Rune Input", requirement.item, requirement.amount)
  118. end
  119. print("Waiting for ritual to finish...")
  120. while (component.redstone.getInput(sides.left) ~= 2) do
  121.   os.sleep(0.01)
  122. end
  123. print("Ritual charged. Dropping Rock")
  124. moveItem("Rune Materials", "Rune Input", "botania:livingrock", 1)
  125. os.sleep(1)
  126. print("Firing Wand")
  127. component.redstone.setOutput(sides.back, 15)
  128. os.sleep(0.2)
  129. component.redstone.setOutput(sides.back, 0)
  130. print("Finished.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement