subtixx

Untitled

Aug 30th, 2016
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.65 KB | None | 0 0
  1. local component = require("component")
  2. local colors = require("colors")
  3. local sides = require("sides")
  4. local gpu = component.gpu
  5. local event = require("event")
  6. local term = require("term")
  7. local buttonAPI = require("buttonAPI")
  8.  
  9. local redstone = component.redstone
  10. local filesystem = component.filesystem
  11.  
  12. local shardNBT = {}
  13. shardNBT["459290845737459ef043705871f76e04"] = "Skeleton"
  14. shardNBT["5601d9da3abb021e1d79fd88804a20c5"] = "Zombie"
  15. shardNBT["8d792d9a1d11e4732b3c5f3b106b606f"] = "Enderman"
  16.  
  17. function getClick()
  18.   local _, _, x, y = event.pull(1,touch)
  19.   if x == nil or y == nil then
  20.     local h, w = gpu.getResolution()
  21.     gpu.set(h, w, ".")
  22.     gpu.set(h, w, " ")
  23.   else
  24.     buttonAPI.checkxy(x,y)
  25.   end
  26. end
  27.  
  28. function buttonAPI.fillTable()
  29.   buttonAPI.setTable("Spawn Mobs (Shard)", spawnMobs, 10, 30, 5, 7)
  30.   buttonAPI.setTable("Place Shard", placeShard, 10, 30, 9, 11)
  31.   buttonAPI.setTable("Extract Shard", extractShard, 10, 30, 13, 15)
  32.  
  33.   buttonAPI.disableButton("Extract Shard")
  34.   buttonAPI.disableButton("Spawn Mobs (Shard)")
  35.  
  36.   buttonAPI.setTable("Reset System", reset, 50, 70, 21, 23)
  37.   buttonAPI.screen()
  38. end
  39.  
  40.  
  41. ---- Functions
  42. local spawning = false
  43. local hasShard = false
  44. local shardHash = ""
  45. local msgError = ""
  46.  
  47. function placeShard()
  48.   msgError = ""
  49.   if(hasShard) then return end
  50.   if(component.chest.getStackInSlot(1) == nil or component.chest.getStackInSlot(1).nbt_hash == nil) then msgError = "No shard found!" return end
  51.  
  52.   buttonAPI.toggleButton("Place Shard")
  53.  
  54.   shardHash = component.chest.getStackInSlot(1).nbt_hash
  55.   if(shardNBT[shardHash] == nil) then
  56.     --local file = filesystem.open("/usr/unknownshards.txt", "w")
  57.     --file.write(shardhash)
  58.     --file.close()
  59.   end
  60.  
  61.   redstone.setBundledOutput(sides.south, colors.brown, 255)  
  62.   os.sleep(1)
  63.   redstone.setBundledOutput(sides.south, colors.brown, 0)
  64.  
  65.   redstone.setBundledOutput(sides.south, colors.green, 255)
  66.   os.sleep(1)
  67.   redstone.setBundledOutput(sides.south, colors.green, 0)
  68.   hasShard = true
  69.   buttonAPI.toggleButton("Place Shard")
  70.  
  71.   buttonAPI.disableButton("Spawn Mobs (Shard)")
  72.   buttonAPI.disableButton("Extract Shard")
  73.   buttonAPI.disableButton("Place Shard")
  74. end
  75.  
  76. function reset()
  77.   msgError = ""
  78.   buttonAPI.disableButton("Spawn Mobs (Shard)", false)
  79.   buttonAPI.disableButton("Extract Shard", false)
  80.   buttonAPI.disableButton("Place Shard", false)
  81.  
  82.   buttonAPI.toggleButton("Reset System")
  83.  
  84.   redstone.setBundledOutput(sides.south, colors.brown, 0)
  85.   redstone.setBundledOutput(sides.south, colors.green, 0)
  86.   redstone.setBundledOutput(sides.south, colors.red, 0)
  87.   redstone.setBundledOutput(sides.top, colors.white, 0)
  88.  
  89.   hasShard = false
  90.   spawning = false
  91.  
  92.   redstone.setBundledOutput(sides.south, colors.red, 255)
  93.   os.sleep(1)
  94.   redstone.setBundledOutput(sides.south, colors.red, 0)
  95.  
  96.   buttonAPI.toggleButton("Reset System")
  97.  
  98.   buttonAPI.disableButton("Spawn Mobs (Shard)", false)
  99.   buttonAPI.disableButton("Extract Shard", false)
  100.   buttonAPI.disableButton("Place Shard", true)
  101. end
  102.  
  103. function extractShard()
  104.   msgError = ""
  105.   if(not hasShard) then return end
  106.    
  107.   buttonAPI.toggleButton("Extract Shard")
  108.  
  109.   buttonAPI.disableButton("Spawn Mobs (Shard)")
  110.   buttonAPI.disableButton("Place Shard")
  111.  
  112.   redstone.setBundledOutput(sides.south, colors.red, 255)
  113.   os.sleep(1)
  114.   redstone.setBundledOutput(sides.south, colors.red, 0)
  115.  
  116.   shardHash = ""
  117.   hasShard = false
  118.  
  119.   buttonAPI.toggleButton("Extract Shard")
  120.  
  121.   buttonAPI.disableButton("Extract Shard")
  122.   buttonAPI.disableButton("Place Shard", true)
  123. end
  124.  
  125. function spawnMobs()
  126.   msgError = ""
  127.   if(not hasShard) then return end
  128.   buttonAPI.toggleButton("Spawn Mobs (Shard)")
  129.  
  130.   spawning = not spawning
  131.   redstone.setBundledOutput(sides.top, colors.white, spawning and 255 or 0)
  132.  
  133.   buttonAPI.disableButton("Extract Shard", not spawning)
  134.   buttonAPI.disableButton("Place Shard", false)
  135. end
  136.  
  137. --useShard()
  138. --extractShard()
  139. --spawnMobs(false)
  140.  
  141. term.setCursorBlink(false)
  142. gpu.setResolution(80, 25)
  143. buttonAPI.clear()
  144. buttonAPI.fillTable()
  145. buttonAPI.heading("Soul Shard Spawner - By Subtixx")
  146.  
  147. while true do
  148.   if(hasShard) then
  149.     if (shardNBT[shardHash] ~= nil) then
  150.       buttonAPI.label(10, 3, "Active Shard: " .. tostring(shardNBT[shardHash]) .. "                ")
  151.     else
  152.       buttonAPI.label(10, 3, "Active Shard: " .. tostring(shardHash) .. "                ")
  153.     end
  154.   else
  155.     buttonAPI.label(10, 3, "Active Shard: No Shard                ")
  156.   end
  157.  
  158.   if(msgError ~= "") then
  159.     buttonAPI.label(40, 12, "ERROR: " .. msgError)
  160.   else
  161.     buttonAPI.label(40, 12, "                                         ")
  162.   end
  163.   getClick()
  164. end
Advertisement
Add Comment
Please, Sign In to add comment