Guest User

spawner

a guest
Mar 27th, 2014
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.21 KB | None | 0 0
  1. spawner = peripheral.wrap("front")
  2. chest = peripheral.wrap("back")
  3. rednet.open("right")
  4. compId = 12
  5.  
  6. mobs = {}
  7. --Mobs in chest definition!
  8. mobs[0] = {name = "Empty", slot = 0}
  9. mobs[1] = {name = "Wither skeleton", slot = 1}
  10. mobs[2] = {name = "Blaze", slot = 2}
  11. mobs[3] = {name = "Zombie", slot = 3}
  12. mobs[4] = {name = "Enderman", slot = 4}
  13. mobs[5] = {name = "Villager", slot = 5}
  14. mobs[6] = {name = "Magma Cube", slot = 6}
  15. mobs[7] = {name = "Pigman", slot = 7}
  16. --End mobs definition
  17.  
  18. currentMob = mobs[0]
  19.  
  20. spawnerSide = "east"
  21. chestSide = "west"
  22.  
  23. spawnerSafarySlotNum = 1
  24. turtleTempSlotNum = 16
  25.  
  26. function getFromSpawner()
  27.   if (spawner.getStackInSlot(spawnerSafarySlotNum)) then
  28.     return spawner.pushItemIntoSlot(spawnerSide,spawnerSafarySlotNum,1,turtleTempSlotNum)
  29.   else
  30.     return false
  31.   end
  32. end
  33.  
  34. function getFromChest(mob)
  35.   if (chest.getStackInSlot(mob.slot)) then
  36.     return chest.pushItemIntoSlot(chestSide,mob.slot,1,turtleTempSlotNum)
  37.   else
  38.     return false
  39.   end
  40. --  currentMob = mob
  41. end
  42.  
  43. function putToSpawner()
  44.   if (spawner.getStackInSlot(spawnerSafarySlotNum) == nil) then
  45.     return spawner.pullItemIntoSlot(spawnerSide,turtleTempSlotNum,1,spawnerSafarySlotNum)
  46.   else
  47.     return false
  48.   end
  49. end
  50.  
  51. function putToChest()
  52.   return chest.pullItemIntoSlot(chestSide,turtleTempSlotNum,1,currentMob.slot)
  53. --  currentMob = mobs[0]
  54. end
  55.  
  56. function fromChestToSpawner(mob)
  57.   if (mob.slot ~= 0) then
  58.     if (getFromChest(mob)) then
  59.       currentMob = mob
  60.       if (putToSpawner()) then
  61.         return true
  62.       else
  63.         print ("Unable to put safary net to spawner!")
  64.         print ("Returning safary net to chest!")
  65.         putToChest()
  66.         currentMob = mobs[0]
  67.         return false
  68.       end
  69.     else
  70.       print ("Unable to take safary net from chest!")
  71.       return false
  72.     end
  73.   else
  74.     --print("Do something with empty request, maybe just emptying spawner")
  75.     fromSpawnerToChest()
  76.     return true
  77.   end
  78. end
  79.  
  80. function fromSpawnerToChest()
  81.   if (currentMob.slot ~= 0) then
  82.     if (getFromSpawner()) then
  83.       print ("Succes getting safary net from spawner")
  84.       putToChest()
  85.       currentMob = mobs[0]
  86.     else
  87.       print ("Cant get from spawner!")
  88.       return false
  89.     end
  90.   else
  91.     print ("Current Mob data not defined, dont know where to put safary net!")
  92.     return false
  93.   end  
  94. end
  95.  
  96. function response(mess)
  97.   rednet.send(compId,mess)
  98. end
  99. commands = {
  100.   getAllMobs = function() return mobs end,
  101.   getCurrentMob = function() return currentMob end,
  102.   fromChestToSpawner = function(args) return fromChestToSpawner(args[1]) end,
  103.   fromSpawnerToChest = function() return fromSpawnerToChest() end,
  104.   getSpawnExact = function() return spawner.getSpawnExact() end,
  105.   setSpawnExact = function(args) return spawner.setSpawnExact(args[1]) end,
  106.   getTankInfo = function() return spawner.getTankInfo("unknown")
  107. }
  108.  
  109. while true do
  110.   message = {}
  111.   message.sId, message.command, message.distance = rednet.receive()
  112.   if (message["command"]["cname"] == "Test") then
  113.     response(mobs)
  114.   else
  115.     print ("Executing "..message["command"]["cname"].." command with args ")
  116.     response(commands[message["command"]["cname"]](message["command"]["args"]))
  117.   end
  118. end
Advertisement
Add Comment
Please, Sign In to add comment