Advertisement
SenpaiJody

Mob Farm Controller

Oct 28th, 2022 (edited)
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.22 KB | None | 0 0
  1. os.loadAPI("button")
  2.  
  3. term.clear()
  4.  
  5. local s_mode -- 0 = solo; 1 = do
  6. local s_auto -- 0 = nonlethal; 1 = slaughter; 2 = crusher
  7.  
  8. function loadData()
  9.     local file = io.open("savedata","r")
  10.     local info = file:read()
  11.     s_mode = tonumber(info:sub(1,1))
  12.     s_auto = tonumber(info:sub(2,2))
  13.     file:close()
  14.     end
  15. function saveData()
  16.     local file = io.open("savedata","w")
  17.     file:write(s_mode..s_auto)
  18.     file:close()
  19.     end
  20. function fillTable()
  21.    button.setTable("Toggle Mode", mode, 12,24,11,13)
  22.    button.setTable("Switch Auto", auto, 27,41,11,13)
  23.    button.screen()
  24. end
  25. function getClick()
  26.    event,side,x,y = os.pullEvent("mouse_click")
  27.    button.checkxy(x,y)
  28. end
  29.  
  30. function update()
  31.     term.setCursorPos(16,4)
  32.     if s_mode == 0 then --solo mode
  33.         term.write("Solo")
  34.     else
  35.         term.write("Duo ")
  36.         end
  37.     term.setCursorPos(22,6)
  38.     if s_auto == 0 then -- nonlethal
  39.         term.setTextColor(colors.red)
  40.         term.write("Disabled          ")
  41.     elseif s_auto == 1 then
  42.         term.setTextColor(colors.green)
  43.         term.write("Slaughterer (Meat)")
  44.     elseif s_auto == 2 then
  45.         term.setTextColor(colors.green)
  46.         term.write("Crusher      (XP) ")
  47.         end
  48.     term.setTextColor(colors.white)
  49.     end
  50.  
  51. function pulse(strength)
  52.     redstone.setAnalogOutput("bottom",strength)
  53.     os.sleep(0.2)
  54.     redstone.setAnalogOutput("bottom",0)
  55.     end
  56.  
  57. function mode()
  58.     button.flash("Toggle Mode")
  59.     pulse(5)
  60.     if s_mode == 1 then s_mode = 0 else s_mode = 1 end
  61.     saveData()
  62.     update()
  63. end
  64. function auto()
  65.     button.flash("Switch Auto")
  66.     if s_auto == 0 then --if disabled
  67.         s_auto = 1
  68.         pulse(6) --turn on slaughterer
  69.     elseif s_auto == 1 then --if slaughtere
  70.         s_auto = 2
  71.         pulse(6) -- turn off slaughterer
  72.         os.sleep(0.3)
  73.         pulse(7) -- turn on crusher
  74.     elseif s_auto == 2 then --if crusher
  75.         s_auto = 0
  76.         pulse(7) --turn off crusher
  77.         end
  78.     saveData()
  79.     update()
  80. end
  81.  
  82.  
  83. loadData()
  84. fillTable()
  85. update()
  86. button.heading("Mob Grinder Controller")
  87. term.setCursorPos(10,4)
  88. term.write("Mode:")
  89. term.setCursorPos(10,6)
  90. term.write("Autokiller:")
  91.  
  92.  
  93.  
  94. while true do
  95.    getClick()
  96. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement