Advertisement
NanoBob

(old) bees

Dec 11th, 2015
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.00 KB | None | 0 0
  1. chest = peripheral.wrap("left")
  2. apiary = peripheral.wrap("powered_tile_1")
  3.  
  4.  
  5. function getBees()
  6.     local drones={}
  7.     local princesses={}
  8.     for id,data in pairs(chest.getAllStacks()) do
  9.         local name=string.lower(data.select().display_name)
  10.         if string.match(name,"drone")~=nil then
  11.             drones[ string.gsub(name," drone","") ] = true
  12.         elseif string.match(name,"princess")~=nil then
  13.             princesses[ string.gsub(name," princess","") ] = true
  14.         end
  15.     end
  16.     return drones,princesses
  17. end
  18.  
  19. function hasDrone(name)
  20.     local drones=getBees()
  21.     if drones[name]==true then
  22.         return true
  23.     end
  24.     return false
  25. end
  26.  
  27. function hasPrincess(name)
  28.     local _,princs=getBees()
  29.     if princs[name]==true then
  30.         return true
  31.     end
  32.     return false
  33. end
  34.  
  35. function getSlot(target)
  36.     for id,data in pairs(chest.getAllStacks()) do
  37.         local name=string.lower(data.select().display_name)
  38.         if name==target then
  39.             return id
  40.         end
  41.     end
  42.     return false
  43. end
  44.  
  45. function convert(array)
  46.     local comboTable={}
  47.     for id,combo in pairs(array) do
  48.         comboTable[id]={
  49.             combo.allele1.name,
  50.             combo.allele2.name,
  51.         }
  52.     end
  53.     return comboTable
  54. end
  55.  
  56. function startBreed(drone,princ)
  57.     local pSlot=getSlot(princ.." princess")
  58.     local dSlot=getSlot(drone.." drone")
  59.     if chest.pushItem("south",pSlot,1,1)~=1 then return false end
  60.     chest.pushItem("south",dSlot,1,2)
  61. end
  62.  
  63. function tryBreed(targetBee)
  64.     local combos=convert(apiary.getBeeParents(targetBee))
  65.     for i,combo in pairs( breeds[targetBee] ) do
  66.         if hasDrone(combo[1])==true and hasPrincess(combo[2])==true then
  67.             if startBreed(combo[1],combo[2])==false then break end
  68.             print(combo[1].."+"..combo[2].."="..targetBee)
  69.             break
  70.         elseif hasDrone(combo[2])==true and hasPrincess(combo[1])==true then
  71.             if startBreed(combo[2],combo[1])==false then break end
  72.             print(combo[2].."+"..combo[1].."="..targetBee)
  73.             break
  74.         end
  75.     end
  76. end
  77.  
  78. function breed(bee)
  79.     while true do
  80.         if getSlot("noble princess")==true then
  81.             return true
  82.         end
  83.         tryBreed("noble")
  84.         sleep(5)
  85.     end
  86. end
  87. breed(target)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement