Advertisement
BombBloke

Hive Maintenance Turtle v2 (OpenPeripheral)

Jan 27th, 2014
443
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 42.21 KB | None | 0 0
  1. -- Hive Maintenance
  2. -- ----------------------------------------------------------
  3.  
  4. -- Tries to keep my barrels stocked with "real" resources, so's
  5. -- I don't have to worry about converting combs etc myself.
  6.  
  7. -- ----------------------------------------------------------
  8.  
  9. -- Initialise important values:
  10.  
  11. -- ----------------------------------------------------------
  12.  
  13. -- Number of inventory servers (that should be) online:
  14. local invServerCount = 2
  15.  
  16. -- Job timer IDs. [1] = furnace, [2] = centrifuge, [3] = pulveriser, [4] = casings, [5] = panels, [6] = pearls, [7] = magma.
  17. local worktimer = {}
  18. for i=1,7 do worktimer[i] = 0 end
  19.  
  20. -- Misc stuff.
  21. local facing = {"north","east","south","west"}
  22. local invServer, job = {}, {}
  23. local direction, curnode, x, y, z, pathList, report
  24.  
  25. -- First three indexes are co-ords. All thereafter are linked nodes.
  26. local node = {{241,422,58,   2,3},       --   1, barrel central.
  27.     {244,422,57,   1,3,4},  --   2, processed resource dropoff.
  28.     {244,419,57,   1,2},    --   3, machine central.
  29.     {242,430,57,   2}}      --   4, chopper programming point.
  30.  
  31. -- Basic machine tasks.
  32. local machine  = {
  33.     -- Centrifuge: 
  34.     {["waypoint"] = {{245,417,58}}, ["time"] = 5.25, ["task"] = "centrifuge",
  35.     {"Simmering Comb (13360:2)",{"Phosphor (13324:0)","Refractory Wax (13325:0)"}},
  36.     {"Seedy Comb (8776:9)",{"Honey Drop (13283:0)","Nutdew (8786:7)"}},
  37.     {"Dripping Comb (13360:5)",{"Honey Drop (13283:0)","Honeydew (13289:0)"}},
  38.     {"Earthy Comb (26090:14)",{"Magic Wax (26091:0)","Clay (337:0)"}},
  39.     {"Energetic Comb (8776:12)",{"Honey Drop (13283:0)","Beeswax (13285:0)","Redstone (331:0)"}},
  40.     {"Mysterious Comb (13360:8)",{"Honey Drop (13283:0)","Pulsating Propolis (13287:2)"}},
  41.     {"Iron Comb (8776:15)",{"Honey Drop (13283:0)","Beeswax (13285:0)","Iron Grains (8829:6)"}},
  42.     {"Copper Comb (8776:17)",{"Honey Drop (13283:0)","Beeswax (13285:0)","Copper Grains (8829:10)"}},
  43.     {"Tin Comb (8776:18)",{"Honey Drop (13283:0)","Beeswax (13285:0)","Tin Grains (8829:11)"}},
  44.     {"Golden Comb (8776:16)",{"Honey Drop (13283:0)","Beeswax (13285:0)","Gold Grains (8829:7)"}},
  45.     {"Lapis Comb (8776:46)",{"Honey Drop (13283:0)","Beeswax (13285:0)","Lapis Lazuli (351:4)"}},
  46.     {"Diamond Comb (8776:56)",{"Honey Drop (13283:0)","Beeswax (13285:0)","Diamond Fragment (8829:1)"}},
  47.     {"Emerald Comb (8776:52)",{"Honey Drop (13283:0)","Beeswax (13285:0)","Emerald Fragment (8829:2)"}},
  48.     {"Uranium Comb (8776:21)",{"Honey Drop (13283:0)","Beeswax (13285:0)","ic2.itemCrushedUranOre (30064:4)"}},
  49.     {"Mellow Comb (13360:16)",{"Honeydew (13289:0)","Beeswax (13285:0)","Nether Quartz (406:0)"}}},
  50.    
  51.     -- Furnace:
  52.     {["waypoint"] = {{246,417,58}}, ["time"] = 4, ["task"] = "furnace",
  53.     {"ic2.itemDustIron (30066:5)","Iron Ingot (265:0)"},
  54.     {"ic2.itemDustCopper (30066:3)","Copper Ingot (20264:64)"},
  55.     {"ic2.itemDustTin (30066:7)","Tin Ingot (20264:65)"},
  56.     {"ic2.itemDustGold (30066:4)","Gold Ingot (266:0)"},
  57.     {"Block of Quartz (155:0)","tile.extrautils:decorativeBlock1.2.name (2523:2)"},
  58.     {"Wheat Flour (12660:2)","Bread (297:0)"},
  59.     {"Sand (12:0)","Glass (20:0)"},
  60.     {"Clay (337:0)","Brick (336:0)"},
  61.     {"Clay (82:0)","Hardened Clay (172:0)"}},
  62.  
  63.     -- Pulverisor:
  64.     {["waypoint"] = {{249,418,58},{249,417,58}}, ["time"] = 4, ["task"] = "pulverise",
  65.     {"Cobblestone (4:0)",{"Sand (12:0)","Gravel (13:0)"}}}}
  66.  
  67. for i=1,#machine do machine[i].current = 1 end
  68.  
  69. -- Carpenter specifics.
  70. local carpenter = {
  71.     {["making"] = "Impregnated Casing (13380:0)", ["max"] = 4096,
  72.     ["sX"] = 247, ["sY"] = 418, ["sZ"] = 57, ["sContent"] = {"Seeds (295:0)","Nutdew (8786:7)"},
  73.     ["cX"] = 248, ["cY"] = 418, ["cZ"] = 57, ["cContent"] =
  74.     {"Oak Wood (17:0)","Oak Wood (17:0)","Oak Wood (17:0)","Oak Wood (17:0)",
  75.     "Oak Wood (17:0)","Oak Wood (17:0)","Oak Wood (17:0)","Oak Wood (17:0)",
  76.     "Oak Wood (17:0)","Oak Wood (17:0)","Oak Wood (17:0)","Oak Wood (17:0)",
  77.     "Oak Wood (17:0)","Oak Wood (17:0)","Oak Wood (17:0)","Oak Wood (17:0)"}},
  78.    
  79.     {["making"] = "Scented Paneling (13354:6)", ["max"] = 4096,
  80.     ["sX"] = 250, ["sY"] = 418, ["sZ"] = 57, ["sContent"] = {"Honey Drop (13283:0)","Honeydew (13289:0)"},
  81.     ["cX"] = 251, ["cY"] = 418, ["cZ"] = 57, ["cContent"] =
  82.     {"Jungle Wood Planks (5:3)","Jungle Wood Planks (5:3)","Jungle Wood Planks (5:3)",
  83.     "Jungle Wood Planks (5:3)","Jungle Wood Planks (5:3)","Jungle Wood Planks (5:3)",
  84.     "Beeswax (13285:0)","Beeswax (13285:0)","Beeswax (13285:0)","Beeswax (13285:0)",
  85.     "Pollen (13286:0)","Pollen (13286:0)","Royal Jelly (13288:0)","Royal Jelly (13288:0)"}},
  86.    
  87.     {["making"] = "Ender Pearl (368:0)", ["max"] = 1024,
  88.     ["cX"] = 252, ["cY"] = 418, ["cZ"] = 57, ["cContent"] =
  89.     {"Pulsating Mesh (13354:1)","Pulsating Mesh (13354:1)","Pulsating Mesh (13354:1)","Pulsating Mesh (13354:1)",
  90.     "Pulsating Mesh (13354:1)","Pulsating Mesh (13354:1)","Pulsating Mesh (13354:1)","Pulsating Mesh (13354:1)",
  91.     "Pulsating Mesh (13354:1)","Pulsating Mesh (13354:1)","Pulsating Mesh (13354:1)","Pulsating Mesh (13354:1)",
  92.     "Pulsating Mesh (13354:1)","Pulsating Mesh (13354:1)","Pulsating Mesh (13354:1)","Pulsating Mesh (13354:1)"}}}
  93.  
  94. -- Stuff to craft.
  95. local craft = {["current"] = 1,
  96.     {"tile.alveary.0 (1382:0)",
  97.     {{"Scented Paneling (13354:6)","Scented Paneling (13354:6)","Scented Paneling (13354:6)"},
  98.     {"Scented Paneling (13354:6)","Impregnated Casing (13380:0)","Scented Paneling (13354:6)"},
  99.     {"Scented Paneling (13354:6)","Scented Paneling (13354:6)","Scented Paneling (13354:6)"}}},
  100.    
  101.     {"Wheat Flour (12660:2)",
  102.     {{"Wheat (296:0)"}}},
  103.    
  104.     {"Block of Redstone (152:0)",
  105.     {{"Redstone (331:0)","Redstone (331:0)","Redstone (331:0)"},
  106.     {"Redstone (331:0)","Redstone (331:0)","Redstone (331:0)"},
  107.     {"Redstone (331:0)","Redstone (331:0)","Redstone (331:0)"}}},
  108.    
  109.     {"Glowstone (89:0)",
  110.     {{"Glowstone Dust (348:0)","Glowstone Dust (348:0)"},
  111.     {"Glowstone Dust (348:0)","Glowstone Dust (348:0)"}}},
  112.    
  113.     {"ic2.itemDustIron (30066:5)",
  114.     {{"Iron Grains (8829:6)","Iron Grains (8829:6)"},
  115.     {"Iron Grains (8829:6)","Iron Grains (8829:6)"}}},
  116.    
  117.     {"ic2.itemDustCopper (30066:3)",
  118.     {{"Copper Grains (8829:10)","Copper Grains (8829:10)"},
  119.     {"Copper Grains (8829:10)","Copper Grains (8829:10)"}}},
  120.    
  121.     {"ic2.itemDustTin (30066:7)",
  122.     {{"Tin Grains (8829:11)","Tin Grains (8829:11)"},
  123.     {"Tin Grains (8829:11)","Tin Grains (8829:11)"}}},
  124.    
  125.     {"ic2.itemDustGold (30066:4)",
  126.     {{"Gold Grains (8829:7)","Gold Grains (8829:7)"},
  127.     {"Gold Grains (8829:7)","Gold Grains (8829:7)"}}},
  128.    
  129.     {"Lapis Lazuli Block (22:0)",
  130.     {{"Lapis Lazuli (351:4)","Lapis Lazuli (351:4)","Lapis Lazuli (351:4)"},
  131.     {"Lapis Lazuli (351:4)","Lapis Lazuli (351:4)","Lapis Lazuli (351:4)"},
  132.     {"Lapis Lazuli (351:4)","Lapis Lazuli (351:4)","Lapis Lazuli (351:4)"}}},
  133.    
  134.     {"Emerald (388:0)",
  135.     {{"Emerald Fragment (8829:2)","Emerald Fragment (8829:2)","Emerald Fragment (8829:2)"},
  136.     {"Emerald Fragment (8829:2)","Emerald Fragment (8829:2)","Emerald Fragment (8829:2)"},
  137.     {"Emerald Fragment (8829:2)","Emerald Fragment (8829:2)","Emerald Fragment (8829:2)"}}},
  138.    
  139.     {"Apatite",
  140.     {{"Apatite Shard (26120:7)","Apatite Shard (26120:7)","Apatite Shard (26120:7)"},
  141.     {"Apatite Shard (26120:7)","Apatite Shard (26120:7)","Apatite Shard (26120:7)"},
  142.     {"Apatite Shard (26120:7)","Apatite Shard (26120:7)","Apatite Shard (26120:7)"}}},
  143.    
  144.     {"Block of Quartz (155:0)",
  145.     {{"Nether Quartz (406:0)","Nether Quartz (406:0)"},
  146.     {"Nether Quartz (406:0)","Nether Quartz (406:0)"}}},
  147.    
  148.     {"Smokey Quartz (22406:0)",
  149.     {{"Nether Quartz (406:0)","Nether Quartz (406:0)","Nether Quartz (406:0)"},
  150.     {"Nether Quartz (406:0)","Charcoal (263:1)","Nether Quartz (406:0)"},
  151.     {"Nether Quartz (406:0)","Nether Quartz (406:0)","Nether Quartz (406:0)"}},8},
  152.    
  153.     {"Block of Smokey Quartz (2615:0)",
  154.     {{"Smokey Quartz (22406:0)","Smokey Quartz (22406:0)"},
  155.     {"Smokey Quartz (22406:0)","Smokey Quartz (22406:0)"}}},
  156.    
  157.     {"ic2.itemPartIndustrialDiamond (30135:0)",
  158.     {{"Diamond Fragment (8829:1)","Diamond Fragment (8829:1)","Diamond Fragment (8829:1)"},
  159.     {"Diamond Fragment (8829:1)","Diamond Fragment (8829:1)","Diamond Fragment (8829:1)"},
  160.     {"Diamond Fragment (8829:1)","Diamond Fragment (8829:1)","Diamond Fragment (8829:1)"}}},
  161.    
  162.     {"Diamond (264:0)",
  163.     {{"ic2.itemPartIndustrialDiamond (30135:0)"}}},
  164.    
  165.     {"Stone Bricks (98:0)",
  166.     {{"Stone (1:0)","Stone (1:0)"},
  167.     {"Stone (1:0)","Stone (1:0)"}},4},
  168.    
  169.     {"Chiseled Stone Bricks (98:3)",
  170.     {{"Stone Bricks (98:0)","Stone Bricks (98:0)"},
  171.     {"Stone Bricks (98:0)","Stone Bricks (98:0)"}}},
  172.    
  173.     {"Stone Slab (44:0)",
  174.     {{"Stone (1:0)","Stone (1:0)","Stone (1:0)"}},6},
  175.    
  176.     {"Stone Slab (43:0)",
  177.     {{"Stone Slab (44:0)"},
  178.     {"Stone Slab (44:0)"}}},
  179.    
  180.     {"Stone Slab (43:8)",
  181.     {{"Stone Slab (43:0)","Stone Slab (43:0)"},
  182.     {"Stone Slab (43:0)","Stone Slab (43:0)"}},4},
  183.    
  184.     {"tile.extrautils:decorativeBlock1.0.name (2523:0)",
  185.     {{"Stone (1:0)","Stone Bricks (98:0)","Stone (1:0)"},
  186.     {"Stone Bricks (98:0)","Stone Bricks (98:0)","Stone Bricks (98:0)"},
  187.     {"Stone (1:0)","Stone Bricks (98:0)","Stone (1:0)"}},9},
  188.    
  189.     {"tile.extrautils:decorativeBlock1.4.name (2523:4)",
  190.     {{"tile.extrautils:decorativeBlock1.0.name (2523:0)","tile.extrautils:decorativeBlock1.0.name (2523:0)"},
  191.     {"tile.extrautils:decorativeBlock1.0.name (2523:0)","tile.extrautils:decorativeBlock1.0.name (2523:0)"}},4},
  192.    
  193.     {"tile.extrautils:decorativeBlock1.7.name (2523:7)",
  194.     {{"tile.extrautils:decorativeBlock1.4.name (2523:4)","tile.extrautils:decorativeBlock1.4.name (2523:4)"},
  195.     {"tile.extrautils:decorativeBlock1.4.name (2523:4)","tile.extrautils:decorativeBlock1.4.name (2523:4)"}},4},
  196.    
  197.     {"Pillar Quartz Block (155:2)",
  198.     {{"Block of Quartz (155:0)"},
  199.     {"Block of Quartz (155:0)"}},2},
  200.    
  201.     {"Quartz Slab (44:7)",
  202.     {{"Block of Quartz (155:0)","Block of Quartz (155:0)","Block of Quartz (155:0)"}},6},
  203.    
  204.     {"Chiseled Quartz Block (155:1)",
  205.     {{"Quartz Slab (44:7)"},
  206.     {"Quartz Slab (44:7)"}}},
  207.    
  208.     {"Pillar Smokey Quartz Block (2615:2)",
  209.     {{"Block of Smokey Quartz (2615:0)"},
  210.     {"Block of Smokey Quartz (2615:0)"}},2},
  211.    
  212.     {"Smokey Quartz Slab (2616:0)",
  213.     {{"Block of Smokey Quartz (2615:0)","Block of Smokey Quartz (2615:0)","Block of Smokey Quartz (2615:0)"}},6},
  214.    
  215.     {"Chiseled Smokey Quartz Block (2615:1)",
  216.     {{"Smokey Quartz Slab (2616:0)"},
  217.     {"Smokey Quartz Slab (2616:0)"}}},
  218.    
  219.     {"Wax Capsule (13290:0)",
  220.     {{"Beeswax (13285:0)","Beeswax (13285:0)","Beeswax (13285:0)"}},4},
  221.    
  222.     {"Ambrosia (13293:0)",
  223.     {{"Honeydew (13289:0)","Wax Capsule (13290:0)","Honeydew (13289:0)"},
  224.     {"Royal Jelly (13288:0)","Royal Jelly (13288:0)","Royal Jelly (13288:0)"},
  225.     {"Honeydew (13289:0)","Honeydew (13289:0)","Honeydew (13289:0)"}}},
  226.    
  227.     {"Honeyed Slice (13291:0)",
  228.     {{"Honey Drop (13283:0)","Honey Drop (13283:0)","Honey Drop (13283:0)"},
  229.     {"Honey Drop (13283:0)","Bread (297:0)","Honey Drop (13283:0)"},
  230.     {"Honey Drop (13283:0)","Honey Drop (13283:0)","Honey Drop (13283:0)"}},4},
  231.    
  232.     {"ic2.itemFuelPlantBall (30224:0)",
  233.     {{"Wheat (296:0)","Wheat (296:0)","Wheat (296:0)"},
  234.     {"Wheat (296:0)","","Wheat (296:0)"},
  235.     {"Wheat (296:0)","Wheat (296:0)","Wheat (296:0)"}},4},
  236.    
  237.     {"Oak Wood Planks (5:0)",
  238.     {{"Oak Wood (17:0)"}},4},
  239.    
  240.     {"Oak Wood Slab (126:0)",
  241.     {{"Oak Wood Planks (5:0)","Oak Wood Planks (5:0)","Oak Wood Planks (5:0)"}},6},
  242.    
  243.     {"Jungle Wood Planks (5:3)",
  244.     {{"tile.mfr.rubberwood.log.name (3122:0)"}},3},
  245.    
  246.     {"Jungle Wood Slab (126:3)",
  247.     {{"Jungle Wood Planks (5:3)","Jungle Wood Planks (5:3)","Jungle Wood Planks (5:3)"}},6},
  248.    
  249.     {"Cherry Wood Planks (1947:1)",
  250.     {{"Cherry Wood (1933:1)"}},4},
  251.    
  252.     {"Cherry Wood Slab (1949:1)",
  253.     {{"Cherry Wood Planks (1947:1)","Cherry Wood Planks (1947:1)","Cherry Wood Planks (1947:1)"}},6},
  254.    
  255.     {"Stick (280:0)",
  256.     {{"Cherry Wood Planks (1947:1)"},
  257.     {"Cherry Wood Planks (1947:1)"}},4},
  258.    
  259.     {"Fence (85:0)",
  260.     {{"Stick (280:0)","Stick (280:0)","Stick (280:0)"},
  261.     {"Stick (280:0)","Stick (280:0)","Stick (280:0)"}},2},
  262.    
  263.     {"Ladder (65:0)",
  264.     {{"Stick (280:0)","","Stick (280:0)"},
  265.     {"Stick (280:0)","Stick (280:0)","Stick (280:0)"},
  266.     {"Stick (280:0)","","Stick (280:0)"}},3},
  267.    
  268.     {"Glass Pane (102:0)",
  269.     {{"Glass (20:0)","Glass (20:0)","Glass (20:0)"},
  270.     {"Glass (20:0)","Glass (20:0)","Glass (20:0)"}},16},
  271.    
  272.     {"Sandstone (24:0)",
  273.     {{"Sand (12:0)","Sand (12:0)"},
  274.     {"Sand (12:0)","Sand (12:0)"}}},
  275.    
  276.     {"Smooth Sandstone (24:2)",
  277.     {{"Sandstone (24:0)","Sandstone (24:0)"},
  278.     {"Sandstone (24:0)","Sandstone (24:0)"}},4},
  279.    
  280.     {"Sandstone Slab (44:1)",
  281.     {{"Sandstone (24:0)","Sandstone (24:0)","Sandstone (24:0)"}},6},
  282.    
  283.     {"Chiseled Sandstone (24:1)",
  284.     {{"Sandstone Slab (44:1)"},
  285.     {"Sandstone Slab (44:1)"}}},
  286.    
  287.     {"Stone Bricks Slab (44:5)",
  288.     {{"Stone Bricks (98:0)","Stone Bricks (98:0)","Stone Bricks (98:0)"}},6},
  289.    
  290.     {"tile.extrautils:decorativeBlock1.6.name (2523:6)",
  291.     {{"Gravel (13:0)","Gravel (13:0)"},
  292.     {"Gravel (13:0)","Gravel (13:0)"}}},
  293.    
  294.     {"tile.extrautils:decorativeBlock1.10.name (2523:10)",
  295.     {{"Stone Bricks Slab (44:5)","tile.extrautils:decorativeBlock1.6.name (2523:6)","Stone Bricks Slab (44:5)"},
  296.     {"tile.extrautils:decorativeBlock1.6.name (2523:6)","tile.extrautils:decorativeBlock1.6.name (2523:6)","tile.extrautils:decorativeBlock1.6.name (2523:6)"},
  297.     {"Stone Bricks Slab (44:5)","tile.extrautils:decorativeBlock1.6.name (2523:6)","Stone Bricks Slab (44:5)"}},8},
  298.    
  299.     {"Pulsating Mesh (13354:1)",
  300.     {{"Pulsating Propolis (13287:2)","","Pulsating Propolis (13287:2)"},
  301.     {"","Pulsating Propolis (13287:2)",""},
  302.     {"Pulsating Propolis (13287:2)","","Pulsating Propolis (13287:2)"}}},
  303.    
  304.     {"item.ccwirelessmodem.name (1226:1)",
  305.     {{"Stone (1:0)","Stone (1:0)","Stone (1:0)"},
  306.     {"Stone (1:0)","Ender Pearl (368:0)","Stone (1:0)"},
  307.     {"Stone (1:0)","Stone (1:0)","Stone (1:0)"}}},
  308.    
  309.     {"Chest (54:0)",
  310.     {{"Oak Wood Planks (5:0)","Oak Wood Planks (5:0)","Oak Wood Planks (5:0)"},
  311.     {"Oak Wood Planks (5:0)","","Oak Wood Planks (5:0)"},
  312.     {"Oak Wood Planks (5:0)","Oak Wood Planks (5:0)","Oak Wood Planks (5:0)"}}},
  313.    
  314.     {"item.computer.name (1225:0)",
  315.     {{"Stone (1:0)","Stone (1:0)","Stone (1:0)"},
  316.     {"Stone (1:0)","Redstone (331:0)","Stone (1:0)"},
  317.     {"Stone (1:0)","Glass Pane (102:0)","Stone (1:0)"}}},
  318.    
  319.     {"Turtle (1227:0)",
  320.     {{"Iron Ingot (265:0)","Iron Ingot (265:0)","Iron Ingot (265:0)"},
  321.     {"Iron Ingot (265:0)","item.computer.name (1225:0)","Iron Ingot (265:0)"},
  322.     {"Iron Ingot (265:0)","Chest (54:0)","Iron Ingot (265:0)"}}},
  323.    
  324.     {"Stone Tool Rod (14277:1)",
  325.     {{"Stone (1:0)"},
  326.     {"Stone (1:0)"}},4},
  327.    
  328.     {"Torch (1484:0)",
  329.     {{"item.mfr.rubber.raw.name (12258:0)"},
  330.     {"Stone Tool Rod (14277:1)"}},4},
  331.    
  332.     {"Clay (82:0)",
  333.     {{"Clay (337:0)","Clay (337:0)"},
  334.     {"Clay (337:0)","Clay (337:0)"}}},
  335.    
  336.     {"Bricks (45:0)",
  337.     {{"Brick (336:0)","Brick (336:0)"},
  338.     {"Brick (336:0)","Brick (336:0)"}}},
  339.    
  340.     {"tile.mfr.decorativebrick.pavedstone.name (3133:4)",
  341.     {{"Stone Slab (44:0)","","Stone Slab (44:0)"},
  342.     {"","Bricks (45:0)",""},
  343.     {"Stone Slab (44:0)","","Stone Slab (44:0)"}},8},
  344.    
  345.     {"tile.mfr.decorativebrick.glowstone.name (3133:1)",
  346.     {{"Glowstone (89:0)","","Glowstone (89:0)"},
  347.     {"","Bricks (45:0)",""},
  348.     {"Glowstone (89:0)","","Glowstone (89:0)"}},8}}
  349.    
  350. local barrel = {
  351.     ["Honey Drop (13283:0)"] = {["x"] = 239, ["y"] = 427, ["z"] = 58},
  352.     ["Honeydew (13289:0)"] = {["x"] = 238, ["y"] = 427, ["z"] = 58},
  353.     ["Beeswax (13285:0)"] = {["x"] = 237, ["y"] = 427, ["z"] = 58},
  354.     ["Royal Jelly (13288:0)"] = {["x"] = 236, ["y"] = 427, ["z"] = 58},
  355.     ["Pollen (13286:0)"] = {["x"] = 235, ["y"] = 427, ["z"] = 58},
  356.     ["Glowstone Dust (348:0)"] = {["x"] = 234, ["y"] = 427, ["z"] = 58},
  357.     ["Glowstone (89:0)"] = {["x"] = 233, ["y"] = 427, ["z"] = 58},
  358.     ["Refractory Wax (13325:0)"] = {["x"] = 232, ["y"] = 427, ["z"] = 58},
  359.     ["ic2.itemCrushedUranOre (30064:4)"] = {["x"] = 231, ["y"] = 427, ["z"] = 58},
  360.     ["Redstone (331:0)"] = {["x"] = 230, ["y"] = 427, ["z"] = 58},
  361.     ["Block of Redstone (152:0)"] = {["x"] = 229, ["y"] = 427, ["z"] = 58},
  362.     ["Propolis (13287:0)"] = {["x"] = 228, ["y"] = 427, ["z"] = 58},
  363.     ["Iron Grains (8829:6)"] = {["x"] = 227, ["y"] = 427, ["z"] = 58},
  364.     ["ic2.itemDustIron (30066:5)"] = {["x"] = 226, ["y"] = 427, ["z"] = 58},
  365.     ["Iron Ingot (265:0)"] = {["x"] = 225, ["y"] = 427, ["z"] = 58},
  366.     ["Copper Grains (8829:10)"] = {["x"] = 224, ["y"] = 427, ["z"] = 58},
  367.     ["ic2.itemDustCopper (30066:3)"] = {["x"] = 223, ["y"] = 427, ["z"] = 58},
  368.     ["Copper Ingot (20264:64)"] = {["x"] = 222, ["y"] = 427, ["z"] = 58},
  369.     ["Tin Grains (8829:11)"] = {["x"] = 221, ["y"] = 427, ["z"] = 58},
  370.     ["ic2.itemDustTin (30066:7)"] = {["x"] = 220, ["y"] = 427, ["z"] = 58},
  371.     ["Tin Ingot (20264:65)"] = {["x"] = 219, ["y"] = 427, ["z"] = 58},
  372.     ["Gold Grains (8829:7)"] = {["x"] = 218, ["y"] = 427, ["z"] = 58},
  373.     ["ic2.itemDustGold (30066:4)"] = {["x"] = 217, ["y"] = 427, ["z"] = 58},
  374.     ["Gold Ingot (266:0)"] = {["x"] = 216, ["y"] = 427, ["z"] = 58},
  375.     ["Lapis Lazuli (351:4)"] = {["x"] = 215, ["y"] = 427, ["z"] = 58},
  376.     ["Lapis Lazuli Block (22:0)"] = {["x"] = 214, ["y"] = 427, ["z"] = 58},
  377.     ["Emerald Fragment (8829:2)"] = {["x"] = 213, ["y"] = 427, ["z"] = 58},
  378.     ["Emerald (388:0)"] = {["x"] = 212, ["y"] = 427, ["z"] = 58},
  379.     ["Apatite Shard (26120:7)"] = {["x"] = 211, ["y"] = 427, ["z"] = 58},
  380.     ["Nether Quartz (406:0)"] = {["x"] = 210, ["y"] = 427, ["z"] = 58},
  381.     ["Diamond Fragment (8829:1)"] = {["x"] = 209, ["y"] = 427, ["z"] = 58},
  382.     ["ic2.itemPartIndustrialDiamond (30135:0)"] = {["x"] = 208, ["y"] = 427, ["z"] = 58},
  383.     ["Diamond (264:0)"] = {["x"] = 208, ["y"] = 427, ["z"] = 60},
  384.     ["Ender Pearl (368:0)"] = {["x"] = 209, ["y"] = 427, ["z"] = 60},
  385.     ["Pulsating Mesh (13354:1)"] = {["x"] = 210, ["y"] = 427, ["z"] = 60},
  386.     ["Pulsating Propolis (13287:2)"] = {["x"] = 211, ["y"] = 427, ["z"] = 60},
  387.     ["Chest (54:0)"] = {["x"] = 212, ["y"] = 427, ["z"] = 60},
  388.     ["item.ccwirelessmodem.name (1226:1)"] = {["x"] = 213, ["y"] = 427, ["z"] = 60},
  389.     ["Turtle (1227:0)"] = {["x"] = 214, ["y"] = 427, ["z"] = 60},
  390.     ["item.computer.name (1225:0)"] = {["x"] = 215, ["y"] = 427, ["z"] = 60},
  391.     ["Nutdew (8786:7)"] = {["x"] = 216, ["y"] = 427, ["z"] = 60},
  392.     ["tile.mfr.decorativebrick.glowstone.name (3133:1)"] = {["x"] = 217, ["y"] = 427, ["z"] = 60},
  393.     ["tile.mfr.decorativebrick.pavedstone.name (3133:4)"] = {["x"] = 218, ["y"] = 427, ["z"] = 60},
  394.     ["Bricks (45:0)"] = {["x"] = 219, ["y"] = 427, ["z"] = 60},
  395.     ["Brick (336:0)"] = {["x"] = 220, ["y"] = 427, ["z"] = 60},
  396.     ["Hardened Clay (172:0)"] = {["x"] = 221, ["y"] = 427, ["z"] = 60},
  397.     ["Clay (82:0)"] = {["x"] = 222, ["y"] = 427, ["z"] = 60},
  398.     ["Clay (337:0)"] = {["x"] = 223, ["y"] = 427, ["z"] = 60},
  399.     ["Magic Wax (26091:0)"] = {["x"] = 224, ["y"] = 427, ["z"] = 60},
  400.     ["Mellow Comb (13360:16)"] = {["x"] = 225, ["y"] = 427, ["z"] = 60},
  401.     ["Uranium Comb (8776:21)"] = {["x"] = 226, ["y"] = 427, ["z"] = 60},
  402.     ["Emerald Comb (8776:52)"] = {["x"] = 227, ["y"] = 427, ["z"] = 60},
  403.     ["Diamond Comb (8776:56)"] = {["x"] = 228, ["y"] = 427, ["z"] = 60},
  404.     ["Lapis Comb (8776:46)"] = {["x"] = 229, ["y"] = 427, ["z"] = 60},
  405.     ["Golden Comb (8776:16)"] = {["x"] = 230, ["y"] = 427, ["z"] = 60},
  406.     ["Tin Comb (8776:18)"] = {["x"] = 231, ["y"] = 427, ["z"] = 60},
  407.     ["Copper Comb (8776:17)"] = {["x"] = 232, ["y"] = 427, ["z"] = 60},
  408.     ["Iron Comb (8776:15)"] = {["x"] = 233, ["y"] = 427, ["z"] = 60},
  409.     ["Mysterious Comb (13360:8)"] = {["x"] = 234, ["y"] = 427, ["z"] = 60},
  410.     ["Energetic Comb (8776:12)"] = {["x"] = 235, ["y"] = 427, ["z"] = 60},
  411.     ["Simmering Comb (13360:2)"] = {["x"] = 236, ["y"] = 427, ["z"] = 60},
  412.     ["Earthy Comb (26090:14)"] = {["x"] = 237, ["y"] = 427, ["z"] = 60},
  413.     ["Dripping Comb (13360:5)"] = {["x"] = 238, ["y"] = 427, ["z"] = 60},
  414.     ["Seedy Comb (8776:9)"] = {["x"] = 239, ["y"] = 427, ["z"] = 60},
  415.     ["Cobblestone (4:0)"] = {["x"] = 239, ["y"] = 420, ["z"] = 60},
  416.     ["Stone (1:0)"] = {["x"] = 238, ["y"] = 420, ["z"] = 60},
  417.     ["Stone Bricks (98:0)"] = {["x"] = 237, ["y"] = 420, ["z"] = 60},
  418.     ["Chiseled Stone Bricks (98:3)"] = {["x"] = 236, ["y"] = 420, ["z"] = 60},
  419.     ["Stone Slab (44:0)"] = {["x"] = 235, ["y"] = 420, ["z"] = 60},
  420.     ["Stone Slab (43:0)"] = {["x"] = 234, ["y"] = 420, ["z"] = 60},
  421.     ["Stone Slab (43:8)"] = {["x"] = 233, ["y"] = 420, ["z"] = 60},
  422.     ["tile.extrautils:decorativeBlock1.0.name (2523:0)"] = {["x"] = 232, ["y"] = 420, ["z"] = 60},
  423.     ["tile.extrautils:decorativeBlock1.4.name (2523:4)"] = {["x"] = 231, ["y"] = 420, ["z"] = 60},
  424.     ["tile.extrautils:decorativeBlock1.7.name (2523:7)"] = {["x"] = 230, ["y"] = 420, ["z"] = 60},
  425.     ["tile.extrautils:decorativeBlock1.2.name (2523:2)"] = {["x"] = 229, ["y"] = 420, ["z"] = 60},
  426.     ["Block of Quartz (155:0)"] = {["x"] = 228, ["y"] = 420, ["z"] = 60},
  427.     ["Pillar Quartz Block (155:2)"] = {["x"] = 227, ["y"] = 420, ["z"] = 60},
  428.     ["Quartz Slab (44:7)"] = {["x"] = 226, ["y"] = 420, ["z"] = 60},
  429.     ["Chiseled Quartz Block (155:1)"] = {["x"] = 225, ["y"] = 420, ["z"] = 60},
  430.     ["Block of Smokey Quartz (2615:0)"] = {["x"] = 224, ["y"] = 420, ["z"] = 60},
  431.     ["Pillar Smokey Quartz Block (2615:2)"] = {["x"] = 223, ["y"] = 420, ["z"] = 60},
  432.     ["Smokey Quartz Slab (2616:0)"] = {["x"] = 222, ["y"] = 420, ["z"] = 60},
  433.     ["Chiseled Smokey Quartz Block (2615:1)"] = {["x"] = 221, ["y"] = 420, ["z"] = 60},
  434.     ["Smokey Quartz (22406:0)"] = {["x"] = 220, ["y"] = 420, ["z"] = 60},
  435.     ["tile.alveary.0 (1382:0)"] = {["x"] = 219, ["y"] = 420, ["z"] = 60},
  436.     ["Scented Paneling (13354:6)"] = {["x"] = 218, ["y"] = 420, ["z"] = 60},
  437.     ["Impregnated Casing (13380:0)"] = {["x"] = 217, ["y"] = 420, ["z"] = 60},
  438.     ["ic2.itemFuelPlantBall (30224:0)"] = {["x"] = 216, ["y"] = 420, ["z"] = 60},
  439.     ["Apple (260:0)"] = {["x"] = 215, ["y"] = 420, ["z"] = 60},
  440.     ["Ambrosia (13293:0)"] = {["x"] = 214, ["y"] = 420, ["z"] = 60},
  441.     ["Wax Capsule (13290:0)"] = {["x"] = 213, ["y"] = 420, ["z"] = 60},
  442.     ["Honeyed Slice (13291:0)"] = {["x"] = 212, ["y"] = 420, ["z"] = 60},
  443.     ["Bread (297:0)"] = {["x"] = 211, ["y"] = 420, ["z"] = 60},
  444.     ["Wheat Flour (12660:2)"] = {["x"] = 210, ["y"] = 420, ["z"] = 60},
  445.     ["Wheat (296:0)"] = {["x"] = 209, ["y"] = 420, ["z"] = 60},
  446.     ["Seeds (295:0)"] = {["x"] = 208, ["y"] = 420, ["z"] = 60},
  447.     ["Oak Sapling (6:0)"] = {["x"] = 208, ["y"] = 420, ["z"] = 58},
  448.     ["Oak Wood (17:0)"] = {["x"] = 209, ["y"] = 420, ["z"] = 58},
  449.     ["Oak Wood Planks (5:0)"] = {["x"] = 210, ["y"] = 420, ["z"] = 58},
  450.     ["Oak Wood Slab (126:0)"] = {["x"] = 211, ["y"] = 420, ["z"] = 58},
  451.     ["tile.mfr.rubberwood.sapling.name (3124:0)"] = {["x"] = 212, ["y"] = 420, ["z"] = 58},
  452.     ["tile.mfr.rubberwood.log.name (3122:0)"] = {["x"] = 213, ["y"] = 420, ["z"] = 58},
  453.     ["Jungle Wood Planks (5:3)"] = {["x"] = 214, ["y"] = 420, ["z"] = 58},
  454.     ["Jungle Wood Slab (126:3)"] = {["x"] = 215, ["y"] = 420, ["z"] = 58},
  455.     ["Pink Cherry Sapling (1937:10)"] = {["x"] = 216, ["y"] = 420, ["z"] = 58},
  456.     ["Cherry Wood (1933:1)"] = {["x"] = 217, ["y"] = 420, ["z"] = 58},
  457.     ["Cherry Wood Planks (1947:1)"] = {["x"] = 218, ["y"] = 420, ["z"] = 58},
  458.     ["Cherry Wood Slab (1949:1)"] = {["x"] = 219, ["y"] = 420, ["z"] = 58},
  459.     ["Stick (280:0)"] = {["x"] = 220, ["y"] = 420, ["z"] = 58},
  460.     ["item.mfr.rubber.raw.name (12258:0)"] = {["x"] = 221, ["y"] = 420, ["z"] = 58},
  461.     ["Charcoal (263:1)"] = {["x"] = 222, ["y"] = 420, ["z"] = 58},
  462.     ["Ladder (65:0)"] = {["x"] = 223, ["y"] = 420, ["z"] = 58},
  463.     ["Fence (85:0)"] = {["x"] = 224, ["y"] = 420, ["z"] = 58},
  464.     ["Stone Tool Rod (14277:1)"] = {["x"] = 225, ["y"] = 420, ["z"] = 58},
  465.     ["Torch (1484:0)"] = {["x"] = 226, ["y"] = 420, ["z"] = 58},
  466.     ["Glass Pane (102:0)"] = {["x"] = 227, ["y"] = 420, ["z"] = 58},
  467.     ["Glass (20:0)"] = {["x"] = 228, ["y"] = 420, ["z"] = 58},
  468.     ["Chiseled Sandstone (24:1)"] = {["x"] = 229, ["y"] = 420, ["z"] = 58},
  469.     ["Smooth Sandstone (24:2)"] = {["x"] = 230, ["y"] = 420, ["z"] = 58},
  470.     ["Sandstone Slab (44:1)"] = {["x"] = 231, ["y"] = 420, ["z"] = 58},
  471.     ["Sandstone (24:0)"] = {["x"] = 232, ["y"] = 420, ["z"] = 58},
  472.     ["Sand (12:0)"] = {["x"] = 233, ["y"] = 420, ["z"] = 58},
  473.     ["Stone Bricks Slab (44:5)"] = {["x"] = 234, ["y"] = 420, ["z"] = 58},
  474.     ["tile.extrautils:decorativeBlock1.10.name (2523:10)"] = {["x"] = 235, ["y"] = 420, ["z"] = 58},
  475.     ["tile.extrautils:decorativeBlock1.6.name (2523:6)"] = {["x"] = 236, ["y"] = 420, ["z"] = 58},
  476.     ["Gravel (13:0)"] = {["x"] = 237, ["y"] = 420, ["z"] = 58},
  477.     ["Dirt (3:0)"] = {["x"] = 238, ["y"] = 420, ["z"] = 58},
  478.     ["Phosphor (13324:0)"] = {["x"] = 239, ["y"] = 420, ["z"] = 58}}
  479.  
  480. -- ----------------------------------------------------------
  481.  
  482. -- Functions and stuff:
  483.  
  484. -- ----------------------------------------------------------
  485.  
  486. -- Tell the turtle server I'm alive.
  487. local function doTurtleServerReport()
  488.     rednet.send(report,{"Hello TurtleServer",os.getComputerLabel()})
  489.     report = nil
  490. end
  491.  
  492. -- Returns true if the turtle is carrying anything.
  493. local function carrying()
  494.     for i=1,16 do if turtle.getItemCount(i) ~= 0 then return true end end
  495.     return false
  496. end
  497.  
  498. -- Poll the inventory servers re a given barrel.
  499. local function getAmountOf(barreltype)
  500.     local myMessage
  501.     for i=1,3 do
  502.         for i=1,invServerCount do rednet.send(invServer[i],barreltype) end
  503.         myMessage = {rednet.receive(3)}
  504.         if myMessage and tonumber(myMessage[2]) then break end
  505.     end
  506.    
  507.     if not tonumber(myMessage[2]) then
  508.         print("Warning: Could not get reading for amount of "..barreltype..".")
  509.         return 0
  510.     else return tonumber(myMessage[2]) end
  511. end
  512.  
  513. -- Returns true if the turtle is at the specified node.
  514. local function atNode(tnode) return (x == node[tnode][1] and y == node[tnode][2] and z == node[tnode][3]) end
  515.  
  516. -- Accepts strings representing compass-facings to turn the turtle.
  517. local function faceDirection(targetdirection)
  518.     local tardir
  519.     for i=1,4 do if targetdirection == facing[i] then
  520.         tardir = i
  521.         break
  522.     end end
  523.    
  524.     if tardir < direction then
  525.         if tardir == 1 and direction == 4 then while not turtle.turnRight() do end
  526.         else for i=1,direction-tardir do while not turtle.turnLeft() do end end end
  527.     elseif tardir > direction then
  528.         if tardir == 4 and direction == 1 then while not turtle.turnLeft() do end
  529.         else for i=1,tardir-direction do while not turtle.turnRight() do end end end
  530.     end
  531.    
  532.     direction = tardir
  533. end
  534.  
  535. -- Travel to a co-ordinate.
  536. local function goToPos(targetx,targety,targetz)
  537.     while x ~= targetx or y ~= targety or z ~= targetz do
  538.         if z > targetz then if turtle.down() then z = z - 1 end
  539.         elseif z < targetz then if turtle.up() then z = z + 1 end end
  540.        
  541.         if x > targetx then
  542.             if direction ~= 4 then faceDirection("west") end
  543.             if turtle.forward() then x = x - 1 end
  544.         elseif x < targetx then
  545.             if direction ~= 2 then faceDirection("east") end
  546.             if turtle.forward() then x = x + 1 end
  547.         end
  548.        
  549.         if y > targety then
  550.             if direction ~= 1 then faceDirection("north") end
  551.             if turtle.forward() then y = y - 1 end
  552.         elseif y < targety then
  553.             if direction ~= 3 then faceDirection("south") end
  554.             if turtle.forward() then y = y + 1 end
  555.         end
  556.     end
  557. end
  558.  
  559. -- Travel directly to a node and update the node tracker.
  560. local function goToNode(desnode)
  561.     goToPos(node[desnode][1],node[desnode][2],node[desnode][3])
  562.     curnode = desnode
  563. end
  564.  
  565. -- Used by the next function to determine the cheapest route to a given destination.
  566. local function checkNode(thisNode, desnode)
  567.     -- Do a quick search in case the target is right next to us:
  568.     for i=1,#node[thisNode]-3 do if node[thisNode][i+3] == desnode then
  569.         return math.abs(node[thisNode][1] - node[desnode][1]) + math.abs(node[thisNode][2] - node[desnode][2]) + math.abs(node[thisNode][3] - node[desnode][3])
  570.     end end
  571.    
  572.     -- Do a long search, checking the validity of all attached nodes:
  573.     local linkedNodes = {}
  574.     for i=1,#node[thisNode]-3 do
  575.         local alreadyChecked = false
  576.         for j=1,#pathList do if pathList[j] == node[thisNode][i+3] then
  577.             alreadyChecked = true
  578.             break
  579.         end end
  580.         if not alreadyChecked then linkedNodes[#linkedNodes+1] = node[thisNode][i+3] end
  581.     end
  582.    
  583.     -- This is a dead end:
  584.     if #linkedNodes == 0 then return 3000 end
  585.    
  586.     -- Tracking can continue from this point:
  587.     local maxDistance, checkingNode, bestNode = 2000
  588.     pathList[#pathList+1] = thisNode
  589.     for i=1,#linkedNodes do
  590.         checkingNode = checkNode(linkedNodes[i],desnode)
  591.         if checkingNode < maxDistance then
  592.             maxDistance = checkingNode
  593.             bestNode = linkedNodes[i]
  594.         end
  595.     end
  596.     pathList[#pathList] = nil
  597.    
  598.     return maxDistance + math.abs(node[thisNode][1] - node[bestNode][1]) + math.abs(node[thisNode][2] - node[bestNode][2]) + math.abs(node[thisNode][3] - node[bestNode][3])   
  599. end
  600.  
  601. -- Travels to a given node, pathing from the current node.
  602. local function pathToNode(desnode)
  603.     if report then doTurtleServerReport() end
  604.    
  605.     goToNode(curnode)
  606.    
  607.     while true do
  608.         -- Quick checks:
  609.         for i=1,#node[curnode]-3 do if node[curnode][i+3] == desnode then
  610.             goToNode(desnode)
  611.             return
  612.         end end
  613.  
  614.         -- Long check:
  615.         local bestNode, maxDistance, checkingNode = {}, 2000   
  616.         pathList = {curnode}
  617.         for i=1,#node[curnode]-3 do
  618.             checkingNode = checkNode(node[curnode][3+i],desnode)
  619.             if checkingNode < maxDistance then
  620.                 maxDistance = checkingNode
  621.                 bestNode = node[curnode][3+i]
  622.             end
  623.         end
  624.  
  625.         goToNode(bestNode)
  626.     end
  627. end
  628.  
  629. -- Collect a given number of items from a barrel into a given turtle slot.
  630. local function fetch(item, slot, amount)
  631.     if not amount then amount = 64 end
  632.     turtle.select(slot)
  633.    
  634.     if x > 239 or x < 208 or y > 427 or y < 420 or z > 60 or z < 58 then
  635.         pathToNode(1)
  636.     elseif barrel[item].z ~= z then
  637.         if y==427 then goToPos(x, 426, z)
  638.         elseif y==420 then goToPos(x, 421, z) end
  639.     end
  640.    
  641.     if not (x == barrel[item].x and y == barrel[item].y and z == barrel[item].z) then
  642.         goToPos(barrel[item].x,barrel[item].y,barrel[item].z)
  643.         faceDirection(y==427 and "south" or "north")
  644.         sleep(1)
  645.     elseif (y==427 and direction~=3) or (y==420 and direction~=1) then
  646.         faceDirection(y==427 and "south" or "north")
  647.         sleep(1)
  648.     end
  649.    
  650.     peripheral.call("front", "pushItemIntoSlot", y==427 and "north" or "south", 2, amount, slot)
  651. end
  652.  
  653. -- Refuel the turtle itself.
  654. local function goGetFuel()
  655.     print("I'm hungry. Off to eat some EU...")
  656.     fetch("Charcoal (263:1)",1)
  657.     print("OMNOMNOM")
  658.     turtle.refuel()
  659.     print("Ah, that hit the spot!")
  660.     print("")
  661. end
  662.  
  663. -- Dumps the turtle's inventory into the dropoff chest.
  664. local function dropOff()
  665.     print("Dropping off loot...")
  666.     pathToNode(2)
  667.     for i=1,16 do if turtle.getItemCount(i) ~= 0 then
  668.         turtle.select(i)
  669.         turtle.dropDown()
  670.     end end
  671.     turtle.select(1)
  672.     print("")
  673. end
  674.  
  675. local function fuelMagmaticEngines()
  676.     print("Let's check the magma boiler.")
  677.    
  678.     if getAmountOf("Phosphor (13324:0)") < 2 then
  679.         print("Hey, we're out of phosphor!!")
  680.         print("")
  681.         curcombbarrel = 1
  682.         return
  683.     end
  684.    
  685.     pathToNode(3)
  686.     goToPos(244,418,57)
  687.     faceDirection("north")
  688.     sleep(1)
  689.    
  690.     local magmaTable,needsMore,inSqueezer = {},false
  691.     for i=1,9 do
  692.         inSqueezer = peripheral.call("front", "getStackInSlot", i)
  693.         magmaTable[i] = 64 - (inSqueezer and inSqueezer.qty or 0)
  694.         if magmaTable[i] > 0 then needsMore = true end
  695.     end
  696.    
  697.     if not needsMore then
  698.         print("Looks like she's already filled to the brim.")
  699.         worktimer[7] = os.startTimer(480)
  700.         return
  701.     end
  702.    
  703.     for i=1,6 do if magmaTable[i] > 0 then fetch("Phosphor (13324:0)",i,magmaTable[i]) end end
  704.     for i=7,9 do if magmaTable[i] > 0 then fetch("Cobblestone (4:0)",i,magmaTable[i]) end end
  705.    
  706.     pathToNode(3)
  707.     goToPos(244,418,57)
  708.     faceDirection("north")
  709.     sleep(1)
  710.  
  711.     for i=1,9 do peripheral.call("front", "pullItemIntoSlot", "south", i, turtle.getItemCount(i), i) end
  712.    
  713.     print("Lava production restocked.")
  714.     if carrying() then dropOff() else print("") end
  715.     worktimer[7] = os.startTimer(480)
  716. end
  717.  
  718. -- Clump things together.
  719. local function craftStuff()
  720.     local thiscraft = craft.current
  721.     craft.current = craft.current + 1
  722.     if craft.current > #craft then craft.current = 1 end   
  723.    
  724.     if barrel[craft[thiscraft][1]] and getAmountOf(craft[thiscraft][1]) == 4096 then return false end
  725.    
  726.     -- Check we have the required ingredients on hand:
  727.     local needed = {}
  728.     for i=1,#craft[thiscraft][2] do for j=1,#craft[thiscraft][2][1] do if needed[craft[thiscraft][2][i][j]] then
  729.         needed[craft[thiscraft][2][i][j]] = needed[craft[thiscraft][2][i][j]] + 1
  730.     elseif craft[thiscraft][2][i][j] ~= "" then needed[craft[thiscraft][2][i][j]] = 1 end end end
  731.        
  732.     for thing,required in pairs(needed) do if getAmountOf(thing) < required then return false end end
  733.    
  734.     -- Looks like we're all set, go get some resources.
  735.     for thing,required in pairs(needed) do
  736.         local slotx,sloty,gotten,slot,maxPerSlot = 0,1,0,{},craft[thiscraft][3] and math.floor(64/craft[thiscraft][3]) or 64
  737.         for i=1,required do
  738.             repeat
  739.                 slotx = slotx + 1
  740.                 if slotx > #craft[thiscraft][2][sloty] then
  741.                     slotx = 1
  742.                     sloty = sloty + 1
  743.                 end
  744.             until craft[thiscraft][2][sloty][slotx] == thing
  745.            
  746.             slot[i] = (sloty-1)*4+slotx
  747.             fetch(craft[thiscraft][2][sloty][slotx],slot[i],maxPerSlot)
  748.             gotten = gotten + turtle.getItemCount(slot[i])
  749.         end
  750.                
  751.         -- We should've had enough, but somehow don't?
  752.         if gotten < required then
  753.             dropOff()
  754.             return false
  755.         end
  756.                
  757.         -- We got enough, now divide it between the relevant slots evenly.
  758.         local perSlot = math.floor(gotten / required)
  759.         for i=required,1,-1 do if turtle.getItemCount(slot[i]) < perSlot then for j=1,required do if turtle.getItemCount(slot[j]) - perSlot > 0 then
  760.             turtle.select(slot[j])
  761.             turtle.transferTo(slot[i],math.min(perSlot - turtle.getItemCount(slot[i]),turtle.getItemCount(slot[j]) - perSlot))
  762.             if turtle.getItemCount(slot[i]) >= perSlot then break end
  763.         end end end end
  764.     end
  765.            
  766.     turtle.craft()
  767.     print("Crafted "..craft[thiscraft][1].."!")
  768.     dropOff()
  769.     return true
  770. end
  771.  
  772. -- Relay stuff to a basic resource processing machine.
  773. local function feedMachine(curmachine)
  774.     local thisresource = machine[curmachine].current
  775.     machine[curmachine].current = machine[curmachine].current + 1
  776.     if machine[curmachine].current > #machine[curmachine] then machine[curmachine].current = 1 end
  777.    
  778.     -- Skip this stack if the input barrel is too low on resources...
  779.     if getAmountOf(machine[curmachine][thisresource][1]) < 64 then return false end
  780.    
  781.     -- ... or if all the output barrels are full.
  782.     if type(machine[curmachine][thisresource][2]) == "table" then
  783.         local barrelsFull = true
  784.         for i=1,#machine[curmachine][thisresource][2] do if getAmountOf(machine[curmachine][thisresource][2][i]) < 4096 then
  785.             barrelsFull = false
  786.             break
  787.         end end
  788.         if barrelsFull then return false end
  789.     elseif barrel[machine[curmachine][thisresource][2]] and getAmountOf(machine[curmachine][thisresource][2]) == 4096 then return false end
  790.        
  791.     fetch(machine[curmachine][thisresource][1],1)
  792.     pathToNode(3)
  793.     for i=1,#machine[curmachine].waypoint do goToPos(machine[curmachine].waypoint[i][1],machine[curmachine].waypoint[i][2],machine[curmachine].waypoint[i][3]) end
  794.     sleep(1)
  795.     if peripheral.call("bottom", "getStackInSlot", 1) then peripheral.call("bottom", "pushItemIntoSlot", "up", 1, 64, 2) end
  796.     worktimer[curmachine] = os.startTimer(turtle.getItemCount(1) * machine[curmachine].time)
  797.     turtle.dropDown()
  798.     print("Processing "..machine[curmachine][thisresource][1].." in progress.")
  799.     if carrying() then dropOff() end
  800.    
  801.     return true
  802. end
  803.  
  804. -- Restock the carpenters and their attached squeezers:
  805. local function feedCarpenter(curcarpenter)
  806.     print("Let's check on "..carpenter[curcarpenter].making.." production.")
  807.    
  808.     pathToNode(3)
  809.     if carpenter[curcarpenter].sX then
  810.         goToPos(carpenter[curcarpenter].sX,carpenter[curcarpenter].sY,carpenter[curcarpenter].sZ)
  811.         faceDirection("north")
  812.         sleep(1)
  813.  
  814.         local curFluidResource, bestFluidResource, thisFluidResource = 0
  815.         for i=1,#carpenter[curcarpenter].sContent do
  816.             thisFluidResource = getAmountOf(carpenter[curcarpenter].sContent[i])
  817.             if thisFluidResource > curFluidResource then
  818.                 curFluidResource = thisFluidResource
  819.                 bestFluidResource = carpenter[curcarpenter].sContent[i]
  820.             end
  821.         end
  822.  
  823.         if bestFluidResource then
  824.             local squeezerTable,needsMore,inSqueezer = {},false
  825.             for i=1,9 do
  826.                 inSqueezer = peripheral.call("front", "getStackInSlot", i)
  827.                 if inSqueezer then squeezerTable[i] = {64 - inSqueezer.qty, inSqueezer.name.." ("..inSqueezer.id..":"..inSqueezer.dmg..")"}
  828.                 else squeezerTable[i] = {64, bestFluidResource} end
  829.                 if squeezerTable[i][1] > 0 then needsMore = true end
  830.             end
  831.  
  832.             if needsMore then
  833.                 for i=1,9 do if squeezerTable[i][1] > 0 then fetch(squeezerTable[i][2],i,squeezerTable[i][1]) end end
  834.  
  835.                 pathToNode(3)
  836.                 goToPos(carpenter[curcarpenter].sX,carpenter[curcarpenter].sY,carpenter[curcarpenter].sZ)
  837.                 faceDirection("north")
  838.                 sleep(1)
  839.  
  840.                 for i=1,9 do peripheral.call("front", "pullItemIntoSlot", "south", i, turtle.getItemCount(i), i) end
  841.  
  842.                 print("Squeezer restocked.")
  843.             else print("Looks like the squeezer's full.") end
  844.         else print("Warning: We're out of squeezables for this carpenter.") end
  845.  
  846.         if carrying() then
  847.             dropOff()
  848.             pathToNode(3)
  849.         end
  850.     end
  851.    
  852.     goToPos(carpenter[curcarpenter].cX,carpenter[curcarpenter].cY,carpenter[curcarpenter].cZ)
  853.     faceDirection("north")
  854.     sleep(1)
  855.    
  856.     local carpenterTable,needsMore,inCarpenter = {}, false
  857.     for i=1,#carpenter[curcarpenter].cContent do
  858.         inCarpenter = peripheral.call("front", "getStackInSlot", 12+i)
  859.         carpenterTable[i] = 64 - (inCarpenter and inCarpenter.qty or 0)
  860.         if carpenterTable[i] > 0 then needsMore = true end
  861.     end
  862.  
  863.     if needsMore then
  864.         for i=1,#carpenter[curcarpenter].cContent do if carpenterTable[i] > 0 then fetch(carpenter[curcarpenter].cContent[i],i,carpenterTable[i]) end end
  865.            
  866.         pathToNode(3)
  867.         goToPos(carpenter[curcarpenter].cX,carpenter[curcarpenter].cY,carpenter[curcarpenter].cZ)
  868.         faceDirection("north")
  869.         sleep(1)
  870.  
  871.         for i=1,#carpenter[curcarpenter].cContent do peripheral.call("front", "pullItemIntoSlot", "south", i, turtle.getItemCount(i), 12+i) end
  872.  
  873.         print("Carpenter restocked.")
  874.     else print("Looks like the carpenter's full.") end
  875.    
  876.     if carrying() then dropOff() else print("") end
  877. end
  878.  
  879. -- Perform a server-assigned task.
  880. local function doJob()
  881.     if job[1][1] == "New turtle" then
  882.         print("Seems I need to replace "..job[1][2]..".")
  883.         if getAmountOf("Diamond (264:0)") < 3 or getAmountOf("Stick (280:0)") < 2 or getAmountOf("Turtle (1227:0)") < 1 or getAmountOf("item.ccwirelessmodem.name (1226:1)") < 1 then
  884.             print("... but I don't have the parts. Maybe some other time.")
  885.             print("")
  886.             table.remove(job,1)
  887.             return
  888.         end
  889.        
  890.         fetch("Diamond (264:0)",1,1)
  891.         fetch("Diamond (264:0)",2,1)
  892.         fetch("Diamond (264:0)",5,1)
  893.         fetch("Stick (280:0)",6,1)
  894.         fetch("Stick (280:0)",10,1)
  895.         turtle.craft()
  896.  
  897.         for i=1,16 do if turtle.getItemCount(i) > 0 then
  898.             turtle.select(i)
  899.             turtle.transferTo(1)
  900.             break
  901.         end end
  902.  
  903.         fetch("Turtle (1227:0)",2,1)
  904.         fetch("item.ccwirelessmodem.name (1226:1)",3,1)
  905.         turtle.craft()
  906.        
  907.         for i=1,16 do if turtle.getItemCount(i) > 0 then
  908.             turtle.select(i)
  909.             turtle.transferTo(1)
  910.             break
  911.         end end
  912.        
  913.         fetch("Charcoal (263:1)",2)
  914.        
  915.         pathToNode(4)
  916.         faceDirection("west")
  917.    
  918.         sleep(1)
  919.         local myFile = fs.open("\\disk\\id","w")
  920.         myFile.writeLine(job[1][2]:sub(10))
  921.         myFile.close()
  922.        
  923.         while not turtle.back() do end
  924.         turtle.select(1)
  925.         while not turtle.place() do end
  926.         turtle.select(2)
  927.         turtle.drop()
  928.        
  929.         peripheral.call("front","turnOn")
  930.        
  931.         while not turtle.forward() do end
  932.         table.remove(job,1)
  933.         print("Success!")
  934.         print("")
  935.     end -- More tasks to go here.
  936. end
  937.    
  938. -- ----------------------------------------------------------
  939.  
  940. -- Primary functions:
  941.  
  942. -- ----------------------------------------------------------
  943.  
  944. -- Deal with timers and rednet.
  945. local function catchTimers()
  946.     local turtleServerTimeOut, myEvent = os.startTimer(0)
  947.     while true do
  948.         myEvent = {os.pullEvent()}
  949.         if myEvent[1] == "timer" then
  950.             if myEvent[2] == turtleServerTimeOut then
  951.                 report = 65535
  952.                 turtleServerTimeOut = os.startTimer(600)
  953.             else for i=1,table.getn(worktimer) do if worktimer[i] == myEvent[2] then
  954.                 worktimer[i] = 0
  955.                 break
  956.             end end end
  957.         elseif myEvent[1] == "rednet_message" and myEvent[3] == "Hey, you still there?" then
  958.             report = myEvent[2]
  959.             turtleServerTimeOut = os.startTimer(600)
  960.         elseif myEvent[1] == "rednet_message" and type(myEvent[3]) == "table" then
  961.             if myEvent[3][1] == "We need a new turtle." then
  962.                 job[#job+1] = {"New turtle",myEvent[3][2]}
  963.             end -- More tasks to go here later.
  964.         end
  965.     end
  966. end
  967.  
  968. -- Primary work loop.
  969. local function main()
  970.     while true do
  971.         if turtle.getFuelLevel() < 1000 then goGetFuel() end
  972.         if carrying() then dropOff() end
  973.         if worktimer[7] == 0 then fuelMagmaticEngines() end
  974.        
  975.         while #job > 0 do doJob() end
  976.        
  977.         print("Let's try to craft something!")
  978.         local firstDo = craft.current
  979.         repeat until craftStuff() or firstDo == craft.current
  980.         print("")
  981.        
  982.         while #job > 0 do doJob() end
  983.            
  984.         for i=1,#machine do if worktimer[i] == 0 then
  985.             print("Checking for resources to "..machine[i].task.."...")
  986.             firstDo = machine[i].current
  987.             repeat until feedMachine(i) or firstDo == machine[i].current
  988.             print("")
  989.         end end
  990.        
  991.         while #job > 0 do doJob() end
  992.        
  993.         for i=1,#carpenter do if worktimer[3+i] == 0 then
  994.             if getAmountOf(carpenter[i].making) < carpenter[i].max then feedCarpenter(i) end
  995.             worktimer[3+i] = os.startTimer(600)
  996.         end end
  997.        
  998.         while #job > 0 do doJob() end
  999.     end
  1000. end
  1001.  
  1002. -- ----------------------------------------------------------
  1003.  
  1004. -- I've just booted up. Where am I? Who am I? etc...
  1005.  
  1006. -- ----------------------------------------------------------
  1007.  
  1008. -- Ping the GPS servers until I get a valid reading, then determine the nearest node:
  1009. do
  1010.     local tempx, tempy, tempz
  1011.     while tempx == nil or tempy == nil or tempz == nil do
  1012.         tempx, tempy, tempz = gps.locate(5)
  1013.         sleep(5)
  1014.     end
  1015.    
  1016.     while not turtle.forward() do while not turtle.turnLeft() do end end
  1017.     x,y,z = gps.locate(5)
  1018.  
  1019.     if x < tempx then direction = 4
  1020.     elseif x > tempx then direction = 2
  1021.     elseif y < tempy then direction = 1
  1022.     else direction = 3 end
  1023.    
  1024.     local temp1, temp2 = 255, 0
  1025.     for i=1,table.getn(node) do
  1026.         temp2 = math.sqrt(math.pow(x - node[i][1],2) + math.pow(y - node[i][2],2))
  1027.         temp2 = math.sqrt(math.pow(temp2,2) + math.pow(z - node[i][3],2))
  1028.         if temp2 < temp1 then
  1029.             temp1 = temp2
  1030.             curnode = i
  1031.         end
  1032.     end
  1033. end
  1034.  
  1035. -- Broadcast until all inventory servers are identified.
  1036. rednet.open("right")
  1037. while #invServer < invServerCount do
  1038.     rednet.broadcast("Hello InvServer")
  1039.     local myTimer = os.startTimer(5)
  1040.     while true do
  1041.         local myEvent = {os.pullEvent()}
  1042.         if myEvent[1] == "timer" and myEvent[2] == myTimer then
  1043.             break
  1044.         elseif myEvent[1] == "rednet_message" and myEvent[3] == "Hello, InvServerClient!" then
  1045.             invServer[#invServer+1] = myEvent[2]
  1046.             for i=1,#invServer-1 do if invServer[i] == invServer[#invServer] then invServer[#invServer] = nil end end
  1047.             if #invServer == invServerCount then break end
  1048.         end
  1049.     end
  1050. end
  1051.  
  1052. print("I'm at "..x..","..y..","..z..", I have "..turtle.getFuelLevel().." fuel and I'm facing "..facing[direction]..".")
  1053. print("")
  1054.  
  1055. parallel.waitForAny(main, catchTimers)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement