Advertisement
Guest User

Untitled

a guest
Oct 15th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.02 KB | None | 0 0
  1. function isCrafting(stor,itemStack)
  2. for i,task in ipairs(stor.getTasks()) do
  3. for j,outputs in ipairs(task.pattern.outputs) do
  4. if ((string.find(outputs.name,itemStack.name) ~= nil) and (tonumber(outputs.damage) == itemStack.damage)) then
  5. return(true)
  6. end
  7. end
  8. end
  9. return(false)
  10. end
  11.  
  12. local component = require("component")
  13. local os = require("os")
  14. stor = component.proxy(component.get("37a"))
  15.  
  16. items = {
  17. {label="Lapis Lazuli",max_quantity=700,min_quantity=500,name="dye",damage=4,block_name="lapis_block",block_damage=0,block_size=9},
  18. {label="Tin Ingot",max_quantity=300,min_quantity=100,name="thermalfoundation:material",damage=129,block_name="thermalfoundation:storage",block_damage=1,block_size=9},
  19. {label="Coal",max_quantity=700,min_quantity=500,name="coal",damage=0,block_name="coal_block",block_damage=0,block_size=9},
  20. {label="Redstone",max_quantity=1000,min_quantity=700,name="redstone",damage=0,block_name="redstone_block",block_damage=0,block_size=9},
  21. {label="Lead Ingot",max_quantity=300,min_quantity=100,name="thermalfoundation:material",damage=131,block_name="thermalfoundation:storage",block_damage=3,block_size=9},
  22. {label="Silver Ingot",max_quantity=300,min_quantity=100,name="thermalfoundation:material",damage=130,block_name="thermalfoundation:storage",block_damage=2,block_size=9},
  23. {label="Aluminum Ingot",max_quantity=300,min_quantity=100,name="thermalfoundation:material",damage=132,block_name="thermalfoundation:storage",block_damage=4,block_size=9},
  24. {label="Iron Ingot",max_quantity=700,min_quantity=500,name="iron_ingot",damage=0,block_name="iron_block",block_damage=0,block_size=9},
  25. {label="Copper Ingot",max_quantity=300,min_quantity=100,name="thermalfoundation:material",damage=128,block_name="thermalfoundation:storage",block_damage=0,block_size=9},
  26. {label="Gold Ingot",max_quantity=300,min_quantity=100,name="gold_ingot",damage=0,block_name="gold_block",block_damage=0,block_size=9},
  27. {label="Nickel Ingot",max_quantity=300,min_quantity=100,name="thermalfoundation:material",damage=133,block_name="thermalfoundation:storage",block_damage=5,block_size=9},
  28. {label="Diamond",max_quantity=700,min_quantity=500,name="minecraft:diamond",damage=0,block_name="minecraft:diamond_block",block_damage=0,block_size=9},
  29. {label="Emerald",max_quantity=300,min_quantity=100,name="minecraft:emerald",damage=0,block_name="minecraft:emerald_block",block_damage=0,block_size=9},
  30. {label="Draconium Ingot",max_quantity=700,min_quantity=500,name="draconicevolution:draconium_ingot",damage=0,block_name="draconicevolution:draconium_block",block_damage=0,block_size=9}
  31. }
  32.  
  33. while true do
  34. for i,item in ipairs(items) do
  35. itemStack = {name=item.name,damage=item.damage}
  36. blockStack = {name=item.block_name,damage=item.block_damage}
  37. quantityInStorage = stor.getItem(itemStack).size
  38. print("Checking: "..item.label)
  39.  
  40. if (quantityInStorage > item.max_quantity) then
  41. print(" "..quantityInStorage - item.max_quantity.." "..item.label.." to block")
  42. if (isCrafting(stor,blockStack) == false) then
  43. if (item.block_size == 0) then
  44. print(" Error: Spezify block size for item",item.name)
  45. else
  46. toCraft = math.floor((quantityInStorage - item.max_quantity) / item.block_size + 1)
  47. print(" Blocking: "..(toCraft * 9).." "..item.label)
  48. stor.scheduleTask(blockStack,toCraft)
  49. end
  50. end
  51. end
  52.  
  53. if (quantityInStorage < item.min_quantity) then
  54. toCraft = item.min_quantity - quantityInStorage
  55. print(toCraft.." " ..item.label.." to unblock")
  56. if (isCrafting(stor,itemStack) == false) then
  57. print(" Unblocking: ",(toCraft * 9).." "..item.label)
  58. stor.scheduleTask(itemStack,toCraft)
  59. end
  60. end
  61. end
  62.  
  63. print("\n\n")
  64. os.sleep(10)
  65. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement