Advertisement
melzneni

Turti Std turtle adapter

Aug 14th, 2023 (edited)
1,915
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.77 KB | None | 0 0
  1. turtleAdapter = {
  2.     forward = function()
  3.         while not turtle.forward() do
  4.             if not turtle.dig() then
  5.                 turtle.attack()
  6.             end
  7.         end
  8.  
  9.         if test then
  10.             if storageData.direction == 0 then
  11.                 storageData.pos[1] = storageData.pos[1] + 1
  12.             elseif storageData.direction == 1 then
  13.                 storageData.pos[3] = storageData.pos[3] + 1
  14.             elseif storageData.direction == 2 then
  15.                 storageData.pos[1] = storageData.pos[1] - 1
  16.             elseif storageData.direction == 3 then
  17.                 storageData.pos[3] = storageData.pos[3] - 1
  18.             end
  19.             state = true
  20.         end
  21.         return true
  22.     end,
  23.     up = function()
  24.         while not turtle.up() do
  25.             if not turtle.digUp() then
  26.                 turtle.attackUp()
  27.             end
  28.         end
  29.         if test then
  30.             storageData.pos[2] = storageData.pos[2] + 1
  31.         end
  32.         return true
  33.     end,
  34.     down = function()
  35.         while not turtle.down() do
  36.             if not turtle.digDown() then
  37.                 turtle.attackDown()
  38.             end
  39.         end
  40.         if test then
  41.             storageData.pos[2] = storageData.pos[2] - 1
  42.         end
  43.         return true
  44.     end,
  45.     turnLeft = function()
  46.         local state = turtle.turnLeft()
  47.         storageData.direction = storageData.direction - 1
  48.         if storageData.direction < 0 then
  49.             storageData.direction = storageData.direction + 4
  50.         end
  51.         return state
  52.     end,
  53.     turnRight = function()
  54.         local state = turtle.turnRight()
  55.         storageData.direction = storageData.direction + 1
  56.         if storageData.direction > 3 then
  57.             storageData.direction = storageData.direction - 4
  58.         end
  59.         return state
  60.     end,
  61.     detect = function()
  62.         return turtle.detect()
  63.     end,
  64.     detectUp = function()
  65.         return turtle.detectUp()
  66.     end,
  67.     detectDown = function()
  68.         return turtle.detectDown()
  69.     end,
  70.     select = function(id)
  71.         return turtle.select(id)
  72.     end,
  73.     place = function()
  74.         local state = turtle.place()
  75.         if state then
  76.             sleep(0.1)
  77.         end
  78.         return state
  79.     end,
  80.     placeUp = function()
  81.         local state = turtle.placeUp()
  82.         if state then
  83.             sleep(0.1)
  84.         end
  85.         return state
  86.     end,
  87.     placeDown = function()
  88.         local state = turtle.placeDown()
  89.         if state then
  90.             sleep(0.1)
  91.         end
  92.         return state
  93.     end,
  94.     dig = function()
  95.         local digged = false;
  96.         while (turtle.detect()) do
  97.             if not turtle.dig() then
  98.                 break ;
  99.             end
  100.             digged = true;
  101.         end
  102.         return digged
  103.     end,
  104.     digUp = function()
  105.         local digged = false;
  106.         while (turtle.detectUp()) do
  107.             if not turtle.digUp() then
  108.                 break ;
  109.             end
  110.             digged = true;
  111.         end
  112.         return digged
  113.     end,
  114.     digDown = function()
  115.         local digged = false;
  116.         while (turtle.detectDown()) do
  117.             if not turtle.digDown() then
  118.                 break ;
  119.             end
  120.             digged = true;
  121.         end
  122.         return digged
  123.     end,
  124.     attack = function()
  125.         return turtle.attack()
  126.     end,
  127.     attackUp = function()
  128.         return turtle.attackUp()
  129.     end,
  130.     attackDown = function()
  131.         return turtle.attackDown()
  132.     end,
  133.     getItemName = function(id)
  134.         local name = turtle.getItemDetail(id)
  135.         if name == nil then
  136.             return nil
  137.         end
  138.         return name.name
  139.     end,
  140.     getItemCount = function(id)
  141.         if id == nil then
  142.             return turtle.getItemCount()
  143.         end
  144.         return turtle.getItemCount(id)
  145.     end,
  146.     getItemSpace = function(id)
  147.         if id == nil then
  148.             return turtle.getItemSpace()
  149.         end
  150.         return turtle.getItemSpace(id)
  151.     end,
  152.     drop = function(cnt)
  153.         return turtle.drop(cnt)
  154.     end,
  155.     dropUp = function(cnt)
  156.         return turtle.dropUp(cnt)
  157.     end,
  158.     dropDown = function(cnt)
  159.         return turtle.dropDown(cnt)
  160.     end,
  161.     suck = function(cnt)
  162.         return turtle.suck(cnt)
  163.     end,
  164.     suckUp = function(cnt)
  165.         return turtle.suckUp(cnt)
  166.     end,
  167.     suckDown = function(cnt)
  168.         return turtle.suckDown(cnt)
  169.     end,
  170.     refuel = function()
  171.         return turtle.refuel()
  172.     end,
  173.     getFuelLevel = function()
  174.         return turtle.getFuelLevel()
  175.     end
  176. }
  177.  
  178. function setStorageData(sD)
  179.     storageData = sD
  180. end
  181.  
  182. return {
  183.     turtleAdapter = turtleAdapter, setStorageData = setStorageData,
  184.     setTest = function(t)
  185.         test = t
  186.     end
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement