Advertisement
CaptainSpaceCat

Godforger

May 31st, 2022 (edited)
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.17 KB | None | 0 0
  1.  
  2. local Buffer = require "lib/buffer"
  3. local List = require "lib/list"
  4. local Recipe = require "lib/recipe"
  5.  
  6. local buf = Buffer("bottom", "front")
  7.  
  8. local all_shards = List({
  9.     List({
  10.         "atum:anput_godshard",
  11.         "atum:anubis_godshard",
  12.         "atum:horus_godshard",
  13.         "atum:montu_godshard",
  14.         "atum:ptah_godshard",
  15.     }),
  16.     List({
  17.         "atum:atem_godshard",
  18.         "atum:geb_godshard",
  19.         "atum:ra_godshard",
  20.         "atum:shu_godshard",
  21.         "atum:tefnut_godshard",
  22.     }),
  23.     List({
  24.         "atum:isis_godshard",
  25.         "atum:nepthys_godshard",
  26.         "atum:nuit_godshard",
  27.         "atum:osiris_godshard",
  28.         "atum:seth_godshard",
  29.     }),
  30. })
  31.  
  32. local scaling_factor = {8, 4, 1}
  33.  
  34. function getLeastPriorityShard()
  35.     local scores = List()
  36.     local m = 1
  37.     for level in all_shards() do
  38.         for shard in level() do
  39.             local entry = {}
  40.             entry.score = buf:count(shard) * scaling_factor[m]
  41.             entry.name = shard
  42.             scores:append(entry)
  43.         end
  44.         m = m + 1
  45.     end
  46.     maxScore = 0
  47.     maxName = ""
  48.     for entry in scores() do
  49.         if entry.score > maxScore then
  50.             maxScore = entry.score
  51.             maxName = entry.name
  52.         end
  53.     end
  54.     return maxName ~= "" and maxName
  55. end
  56.  
  57. function getRecipe(shardtype)
  58.   local r = Recipe("atum:godforged_block", 1)
  59.   r:add("atum:nebu_ingot", {1,3,7,9})
  60.   r:add("resourcefulbees:dusty_mummbee_honeycomb", {2,5,8})
  61.   r:add(shardtype, {4,6})
  62.   return r
  63. end
  64.  
  65. function craft()
  66.   local shard = getLeastPriorityShard()
  67.   if not shard then return false end
  68.   local recipe = getRecipe(shard)
  69.   if shard == nil then
  70.       return false
  71.   end
  72.   buf:craft(recipe)
  73.  
  74.   -- place the godforged block somewhere to be broken automatically
  75.   turtle.turnLeft()
  76.   local success = false
  77.   for i = 1, 120 do
  78.     if turtle.place() then
  79.       success = true
  80.       break
  81.     end
  82.     sleep(1)
  83.   end
  84.   if not success then
  85.     turtle.turnRight()
  86.     print("Failed to place godforged block, terminating...")
  87.     return false
  88.   end
  89.   turtle.turnRight()
  90.   return true
  91. end
  92.  
  93. while craft() do
  94.     sleep(30)
  95. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement