knayvik

OC Mob Duplicator

Jul 10th, 2022 (edited)
537
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.66 KB | None | 0 0
  1. local component = require("component")
  2. local sides = require("sides")
  3. local term = require("term")
  4.  
  5. local transposer = component.transposer
  6. local gpu = component.gpu
  7.  
  8. local mobCount = 2
  9. local chestSide = sides.down
  10. local duplicatorSide = sides.up
  11.  
  12. local mobList = {
  13.     witherSkeleton = 1,
  14.     ghast = 2,
  15. }
  16.  
  17. local abbr = {
  18.     witherSkeleton = {"witherSkeleton", "ws", "wither skeleton"},
  19.     ghast = {"ghast", "gh"},
  20. }
  21.  
  22. function init()
  23.     gpu.setResolution(60, 20)
  24. end
  25.  
  26. function findEmpty()
  27.     for i = 1, mobCount do
  28.         if (transposer.getSlotStackSize(chestSide, i) == 0) then
  29.             return i
  30.         end
  31.     end
  32. end
  33.  
  34. function returnPokeball()
  35.     transposer.transferItem(duplicatorSide, chestSide, 1, 7, findEmpty())
  36.     print("Retrieving Mob...")
  37.     os.sleep(1/2)
  38. end
  39.  
  40. function sendPokeball(mob)
  41.     returnPokeball()
  42.     transposer.transferItem(chestSide, duplicatorSide, 1, mobList[mob], 7)
  43.     print("Sending Mob...")
  44.     os.sleep(1/2)
  45. end
  46.  
  47. function readInput(input)
  48.     if (input == "stop" or input == "STOP") then
  49.         return "stop"
  50.     end
  51.     for k,v in pairs(abbr) do
  52.         for _,n in ipairs(v) do
  53.             if (n == input) then
  54.                 return v[1]
  55.             end
  56.         end
  57.     end
  58. end
  59.  
  60. init()
  61. while true do
  62.     term.clear()
  63.    
  64.     print("Avaliable Mobs: ")
  65.    
  66.     for k, v in pairs(abbr) do
  67.         io.write("\t"..v[1].." (")
  68.         for i,n in ipairs(v) do
  69.             if (i ~= #v) then
  70.                 io.write(n..", ")
  71.             else
  72.                 io.write(n)
  73.             end
  74.         end
  75.         io.write(")\n")
  76.     end
  77.    
  78.     local mobName = nil
  79.     repeat
  80.         print("Enter a mob (stop to stop): ")
  81.         input = readInput(io.read())
  82.     until(input ~= nil)
  83.     if (input == "stop") then
  84.         returnPokeball()
  85.         print("Process stopped.")
  86.     else
  87.         sendPokeball(input)
  88.     end
  89.    
  90.     os.sleep(1)
  91. end
Add Comment
Please, Sign In to add comment