Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.05 KB | None | 0 0
  1. -- Botania Altar Automation with Logistic piper
  2. --
  3. -- Turtle has
  4. --  an open crate in front
  5. --  vacuum chest below (auto extract to LP network)
  6. --  work chest above
  7. --  orderer/request pipe on the back
  8. --  analog redstone input from altar comparator on the right
  9. --  left side free
  10. --  
  11. -- Turtle job is to keep stock of items that it knows how to manufacture
  12.  
  13.  
  14. -- This particular turtle knows how to manufacture using Botania Altar only
  15. -- If item ca
  16. -- Manufacture may be external (output at the front) list is as follows:
  17.  
  18.  
  19. Stock = {}
  20.  
  21. Stock["minecraft:pick"] = {keep=10, --actual=0,
  22.         BOM = {{"plank",3,grid={1,2,3}}, {"stick",2,grid={5,8}}}}
  23.  
  24. Stock["RuneOfWater"] = {keep=10, --actual=0,
  25.         BOM = {{"manasteel", 1},{"manadust",1},{"bonemeal",1},
  26.                             {"Fishingrod",1,ns=true},{"manastone",1,end=true}}}
  27. Parts = {} -- unique parts that are needed for all the recipes
  28. for i,v in pairs(Stock) do
  29.     Stock[i].actual = 0
  30.     for j,k in pairs(Stock[i].BOM) do
  31.         Parts[k[1]] = {id=nil, actual=0}
  32.     end
  33. end
  34.  
  35.  
  36.  
  37. --grid - where to put items in crafting grid
  38. --ns -nonstacking item, will store extra in work chest and craft one by one
  39. --end -item will be consumed at the end of crafting process
  40.  
  41. lp = peripheral.wrap("back")
  42.  
  43. --[
  44. local function easyRequest( itemID, amount )
  45.   local result = lp.getLP().getItemIdentifierBuilder()
  46.   result.setItemID( itemID )
  47.   lp.makeRequest( result.build(), amount )
  48. end
  49. easyRequest( "minecraft:stone", 1 )
  50.  
  51. --]
  52.  
  53.  
  54.  
  55. while true do
  56.     sleep(10)
  57.     Items = lp.getAvailableItems()
  58.     for k,v in pairs(Items) do
  59.       id=v.getValue1()
  60. --    f.write("ID: "..id.getId().."\n")
  61. --    f.write("Unlocalized Name: "..id.getName().."\n")
  62. --    f.write("Mod Name: "..id.getModName().."\n")
  63. --    f.write("Meta: "..id.getData().."/"..id.getUndamaged().getData().."\n")
  64. --    f.write("Count: "..m.getItemAmount(id).."\n\n")
  65.       if Stock[id.getId()] then
  66.         Stock[id.getId()].actual= lp.getItemAmount(id)
  67.      
  68.       for i,p in pairs(Parts) do
  69.         if like(i,Stock[id.getId()]) then
  70.             amount=lp.getItemAmount(id)
  71.             if Parts[i].actual < amount then --chose the item we have the most of
  72.                 Parts[i].id=id
  73.                 Parts[i].actual=lp.getItemAmount(id)
  74.             end
  75.         end
  76.       end
  77.     end
  78. --Now our stock is updated with actual values and all parts needed for crafting also have
  79. -- first we need to try to make stuff that we have the least of
  80.  
  81.     for k,v in pairs(Stock) do
  82.  
  83.  
  84.     end
  85.  
  86.     for k,v in pairs(Items) do      
  87.         local id=v.getValue1()
  88.         local amt=m.getItemAmount(id)
  89.         if checkCount and amt<=itemThreshold then
  90.           Count=request(id,amt,Count)
  91.         end
  92.  
  93.         -- it has EVERY item in the network.
  94.  
  95.  
  96.         for i=1,#nameList do
  97.           if nameWhitelist and id.getName()==nameList[i] then
  98.             Count=request(id,amt,Count)
  99.           elseif not nameWhitelist and id.getName()~=nameList[i] then
  100.             Count=request(id,amt,Count)
  101.           end
  102.         end
  103.  
  104.         for i=1,#idList do
  105.           findColon,findColonEnd=string.find(idList[i],":")
  106.           if findColon then
  107.             if idWhitelist and id.getId()==string.sub(idList[i],1,findColon-1) and id.getData()==string.sub(idList[i],findColon+1) then
  108.               Count=request(id,amt,Count)
  109.             elseif not idWhitelist and id.getId()~=idList[i] then
  110.               Count=request(id,amt,Count)
  111.             end
  112.           else
  113.             if idWhitelist and id.getId()==idList[i] then
  114.               Count=request(id,amt,Count)
  115.             elseif not idWhitelist and id.getId()~=idList[i] then
  116.               Count=request(id,amt,Count)
  117.             end
  118.           end
  119.         end
  120.         for i=1,#modList do
  121.           if modWhitelist and id.getModName()==modList[i] then
  122.             Count=request(id,amt,Count)
  123.           elseif not modWhitelist and id.getModName()~=modList[i] then
  124.             Count=request(id,amt,Count)
  125.           end
  126.         end
  127.         if checkDurability and id.isDamageable() and id.getData()/id.getUndamaged().getData()<=durabilityPercentThreshold/100 then
  128.           Count=request(id,amt,Count)
  129.         end
  130.         if k%itemsPerTick==0 then
  131.           searchTime=searchTime+.05
  132.           sleep(0.05)
  133.         end
  134.       end      
  135. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement