Advertisement
Wickwire

botania

Dec 2nd, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.24 KB | None | 0 0
  1. tArgs = { ... }
  2. if #tArgs ~= 1 then
  3.    print("Usage: botania <type>");
  4.    print("<type> is one of: wood, stone");
  5.    return;
  6. end
  7.  
  8. pos = 1;
  9. runMe = 1;
  10. empty = 0;
  11. napTime = 10;
  12. waitTime = 2;
  13. findType = "";
  14. output = "";
  15.  
  16. function nextPos()
  17.    pos = pos + 1;
  18.    if pos > 16 then
  19.       pos = 1;
  20.    end
  21. end
  22.  
  23. function findBlock(findName)
  24.    local lpos = pos;
  25.    local tryNext = 0;
  26.    turtle.select(lpos);
  27.    if turtle.getItemCount(lpos) > 0 then
  28.       local itemData = turtle.getItemDetail();
  29. --print("Slot "..lpos..": "..itemData.name);
  30.       if itemData.name == findName then
  31.          empty = 0;
  32.          return true;
  33.       else
  34.          tryNext = 1;
  35.       end
  36.    else
  37.       if empty == 16 then
  38.          return false;
  39.       else
  40.          tryNext = 1;
  41.       end
  42.    end
  43.    if tryNext then
  44.       tryNext = 0;
  45.       empty = empty + 1;
  46.       nextPos();
  47.       return findBlock(findName);
  48.    end
  49. end
  50.  
  51. function placeBlock(placeName)
  52.    if findBlock(placeName) == false then
  53.       return false;
  54.    end
  55.    local count = turtle.getItemCount();
  56.    while count > 0 do
  57.       if turtle.placeDown() then
  58.          return true;
  59.       else
  60.          sleep(waitTime);
  61.       end
  62.       if findBlock(placeName) == false then
  63.          return false;
  64.       end
  65.       count = turtle.getItemCount();
  66.    end
  67. end
  68.  
  69. function getTypeName(shortName)
  70.    local types = {
  71.       ["wood"] = "minecraft:log",
  72.       ["stone"] = "minecraft:stone"
  73.    }
  74.    if types[shortName] then
  75.       if shortName == "wood" then
  76.          output = "Botania:livingwood";
  77.       else
  78.          output = "Botania:livingrock";
  79.       end
  80.       return types[shortName];
  81.    else
  82.       return false;
  83.    end
  84. end
  85.  
  86. function stopMe()
  87.    runMe = 0;
  88. end
  89.  
  90. --Main Loop Below
  91. local typeName = getTypeName(tArgs[1]);
  92. if typeName == false then
  93.    return;
  94. end
  95. while runMe == 1 do
  96.    if placeBlock(typeName) then
  97.       while turtle.detectDown() do
  98.          sleep(napTime);
  99.          local success, data = turtle.inspectDown();
  100.          if success then
  101.             if data.name == output then
  102.                turtle.digDown();
  103.             end
  104.          end
  105.       end
  106.    else
  107.       print("Sleeping for "..napTime.." seconds.");
  108.       empty = 0;
  109.       sleep(napTime);
  110.    end
  111. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement