Tribble1991

Spawner Control

Jul 31st, 2014
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Variables --
  2. mouseWidth = 0
  3. mouseHeight = 0
  4.  
  5. currentMob = "None"
  6. currentSpawnerStatus = "Off "
  7.  
  8. --Set turtle connection --
  9. rednet.open("left")
  10. Turtle = 2
  11.  
  12.  
  13. --Set monitor properties
  14. monitor = peripheral.wrap("top")
  15. monitor.setBackgroundColor(colors.black)
  16. monitor.clear()
  17.  
  18. --Write spawner status data --
  19.  
  20. monitor.setCursorPos(2,2)
  21. monitor.setBackgroundColor((colors.blue))
  22. monitor.write(" Spawner Control ")
  23.  
  24. monitor.setCursorPos(2,4)
  25. monitor.setBackgroundColor((colors.blue))
  26. monitor.write(" Status ")
  27.  
  28. function setCurrentSpawnerStatusData()
  29.     if currentSpawnerStatus == "On  " then
  30.         monitor.setCursorPos(11,4)
  31.         monitor.setBackgroundColor((colors.green))
  32.         monitor.write(currentSpawnerStatus)
  33.     elseif currentSpawnerStatus == "Off " then
  34.         monitor.setCursorPos(11,4)
  35.         monitor.setBackgroundColor((colors.red))
  36.         monitor.write(currentSpawnerStatus)
  37.     end
  38.    
  39. end
  40.  
  41. function changeSpawnerStatus()
  42.     --Clicked Status --
  43.     if(currentSpawnerStatus == "On  ") then
  44.         currentSpawnerStatus = "Off "
  45.         rednet.send(Turtle, "Off") 
  46.     elseif(currentSpawnerStatus == "Off ") then
  47.         currentSpawnerStatus = "On  "
  48.         rednet.send(Turtle, "On")  
  49.     end
  50.     setCurrentSpawnerStatusData()
  51. end
  52.  
  53. function setCurrentMobData()
  54.     --Write first list of mobs
  55.     monitor.setCursorPos(2,6)
  56.     if currentMob == "Enderman" then
  57.         monitor.setBackgroundColor((colors.green))
  58.     else
  59.         monitor.setBackgroundColor((colors.red))
  60.     end
  61.     monitor.write("  Enderman  ")
  62.  
  63.     monitor.setCursorPos(2,8)
  64.     if currentMob == "Skeleton" then
  65.         monitor.setBackgroundColor((colors.green))
  66.     else
  67.         monitor.setBackgroundColor((colors.red))
  68.     end
  69.     monitor.write("  Skeleton  ")
  70.  
  71.     monitor.setCursorPos(2,10)
  72.     if currentMob == "Blaze" then
  73.         monitor.setBackgroundColor((colors.green))
  74.         else
  75.         monitor.setBackgroundColor((colors.red))
  76.     end
  77.     monitor.write("  Blaze     ")
  78.  
  79.     monitor.setCursorPos(2,12)
  80.     if currentMob == "Wisp" then
  81.         monitor.setBackgroundColor((colors.green))
  82.         else
  83.         monitor.setBackgroundColor((colors.red))
  84.     end
  85.     monitor.write("  Wisp     ")
  86.  
  87.     monitor.setCursorPos(2,14)
  88.     if currentMob == "Cow" then
  89.         monitor.setBackgroundColor((colors.green))
  90.         else
  91.         monitor.setBackgroundColor((colors.red))
  92.     end
  93.     monitor.write("  Cow       ")
  94.  
  95.     --Write second list of mobs
  96.     monitor.setCursorPos(16,6)
  97.     if currentMob == "Ghast" then
  98.         monitor.setBackgroundColor((colors.green))
  99.         else
  100.         monitor.setBackgroundColor((colors.red))
  101.     end
  102.     monitor.write("  Ghast     ")
  103.  
  104.     monitor.setCursorPos(16,8)
  105.     if currentMob == "Chicken" then
  106.         monitor.setBackgroundColor((colors.green))
  107.     else
  108.         monitor.setBackgroundColor((colors.red))
  109.     end
  110.     monitor.write("  Chicken   ")
  111.  
  112.     monitor.setCursorPos(16,10)
  113.     if currentMob == "Sheep" then
  114.         monitor.setBackgroundColor((colors.green))
  115.     else
  116.         monitor.setBackgroundColor((colors.red))
  117.     end
  118.     monitor.write("  Sheep     ")
  119.  
  120.     monitor.setCursorPos(16,12)
  121.     if currentMob == "None" then
  122.         monitor.setBackgroundColor((colors.green))
  123.     else
  124.         monitor.setBackgroundColor((colors.red))
  125.     end
  126.     monitor.write("  None      ")
  127.  
  128.     monitor.setCursorPos(16,14)
  129.     if currentMob == "None" then
  130.         monitor.setBackgroundColor((colors.green))
  131.     else
  132.         monitor.setBackgroundColor((colors.red))
  133.     end
  134.     monitor.write("  None      ")
  135. end
  136.  
  137. -- Perform clicked action --
  138. function checkClickPosition()
  139.     --SpawnerStatus --
  140.     if(mouseWidth > 10 and mouseWidth < 15 and mouseHeight == 4) then
  141.         changeSpawnerStatus()
  142.     end
  143.     -- 1st Row --
  144.     if(mouseWidth > 1 and mouseWidth < 13 and mouseHeight == 6) then
  145.         --Clicked Enderman --
  146.         currentMob = "Enderman"
  147.         setCurrentMobData()    
  148.         rednet.send(Turtle, 1) 
  149.     elseif(mouseWidth > 15 and mouseWidth < 27 and mouseHeight == 6) then
  150.         --Clicked Ghast--
  151.         currentMob = "Ghast"
  152.         setCurrentMobData()
  153.     rednet.send(Turtle, 6) 
  154.     -- 2nd Row --
  155.     elseif(mouseWidth > 1 and mouseWidth < 13 and mouseHeight == 8) then
  156.         --Clicked Skeleton --
  157.         currentMob = "Skeleton"
  158.         setCurrentMobData()
  159.         rednet.send(Turtle, 2)     
  160.     elseif(mouseWidth > 15 and mouseWidth < 27 and mouseHeight == 8) then
  161.         --Clicked Chicken --
  162.         currentMob = "Chicken"
  163.         setCurrentMobData()
  164.         rednet.send(Turtle, 7) 
  165.     -- 3rd Row --
  166.     elseif(mouseWidth > 1 and mouseWidth < 13 and mouseHeight == 10) then
  167.         --Clicked Blaze
  168.         currentMob = "Blaze"
  169.         setCurrentMobData()
  170.         rednet.send(Turtle, 3) 
  171.     elseif(mouseWidth > 15 and mouseWidth < 27 and mouseHeight == 10) then
  172.         --Clicked None --
  173.         currentMob = "Sheep"
  174.         setCurrentMobData()
  175.         rednet.send(Turtle, 8)     
  176.  
  177.     -- 4th Row --
  178.     elseif(mouseWidth > 1 and mouseWidth < 13 and mouseHeight == 12) then
  179.         --Clicked Whisp --
  180.         currentMob = "Whisp"
  181.         setCurrentMobData()
  182.         rednet.send(Turtle, 4) 
  183.     elseif(mouseWidth > 15 and mouseWidth < 27 and mouseHeight == 12) then
  184.         --Clicked None --
  185.         currentMob = "None"
  186.         setCurrentMobData()
  187.         rednet.send(Turtle, "Stop")
  188.  
  189.     -- 5th Row --
  190.     elseif(mouseWidth > 1 and mouseWidth < 13 and mouseHeight == 14) then
  191.         --Clicked Cow --
  192.         currentMob = "Cow"
  193.         setCurrentMobData()
  194.         rednet.send(Turtle, 5)     
  195.     elseif(mouseWidth > 15 and mouseWidth < 27 and mouseHeight == 14) then
  196.         --Clicked None --
  197.         currentMob = "None"
  198.         setCurrentMobData()
  199.         rednet.send(Turtle, "Stop")
  200.     end
  201. end
  202.  
  203. --First time data setup --
  204. setCurrentSpawnerStatusData()
  205. setCurrentMobData()
  206.  
  207. repeat
  208.     event,p1,p2,p3 = os.pullEvent()
  209.  
  210.     if event == "monitor_touch" then
  211.         mouseWidth = p2
  212.         mouseHeight = p3
  213.         checkClickPosition()
  214.     end
  215. until event=="char" and p1==("x")
Advertisement
Add Comment
Please, Sign In to add comment