Advertisement
acool

self replicating turtles test

May 1st, 2025 (edited)
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.65 KB | None | 0 0
  1. -- IMPLEMENTED LATER
  2. local maxDistance = 100 -- the amount of blocks the turtle can move away from its first position X,Y not
  3. -- pastebin get S67j7heg colony
  4. -- use maxDistance if you wanna limit turtle to only move in a certain area
  5. local position = {0,0,0} -- X is forward based on turtles original orientation
  6. local orientation = 1 -- forward,right,backward,left
  7.  
  8. local currentItemDetail = {name="hello",count=1}
  9. local currentFuel = 0
  10. local desiredFuel = 800
  11. -- 1 coal = 80 fuel
  12. -- 1 fuel = 1 move block
  13. function turnRight()
  14.     turtle.turnRight()
  15.    orientation=orientation+1
  16.     if orientation >4 then orientation = 1 end
  17. end
  18.  
  19. function turnLeft()
  20.     turtle.turnLeft()
  21.    orientation=orientation-1
  22.     if orientation <1 then orientation = 4 end
  23. end
  24. function turn(direction)
  25.    while orientation~=direction do turnRight() end
  26. end
  27. function getFromChest(name)
  28.     turtle.drop()
  29.     local adsa,asdasd = turtle.suck()
  30.     repeat      
  31.         adsa,asdasd = turtle.suck()
  32.         currentItemDetail = turtle.getItemDetail()
  33.         if currentItemDetail and currentItemDetail.name==name then
  34.             return
  35.         else
  36.            turtle.dropUp()
  37.         end
  38.     until adsa==false
  39.     repeat      
  40.         adsa,asdasd = turtle.suckUp()
  41.         turtle.drop()
  42.     until adsa==false
  43.    
  44. end
  45. function forward()
  46.     turtle.select(4)
  47.     turtle.dig("right")
  48.     turtle.dropDown()
  49.     turtle.forward()
  50.    if orientation==1 then
  51.          position[1]=position[1]+1
  52.    elseif orientation==2 then
  53.         position[3]=position[3]+1
  54.    elseif orientation==3 then
  55.         position[1]=position[1]-1
  56.    elseif orientation==4 then
  57.         position[3]=position[3]-1
  58.    end
  59.     turtle.select(1)
  60. end
  61. function dropAll()
  62.    for i=1,16 do
  63.       turtle.select(i)
  64.        turtle.drop()
  65.    end
  66.     turtle.select(1)
  67. end
  68. function digMove(direction)
  69.    if direction=="up" then
  70.         turtle.digUp()
  71.         turtle.up()
  72.        position[2]=position[2]+1
  73.    elseif direction=="down" then
  74.         turtle.digDown()
  75.         turtle.down()
  76.         position[2]=position[2]-1
  77.    else
  78.       turn(direction)
  79.         turtle.dig("right")
  80.         forward()
  81.    end
  82. end
  83. print("Turtle Self-replication")
  84. print("Please insert 10 coal into slot")
  85. turtle.turnRight()
  86. -- wait for user to input fuel
  87. while currentFuel < desiredFuel do
  88.     turtle.refuel(desiredFuel/80)
  89.     currentFuel = turtle.getFuelLevel()
  90.     print("Fuel : "..currentFuel.." / "..desiredFuel)
  91.     sleep(1)
  92. end
  93. print("done insert fuel, remove any items in slot")
  94. -- walk forward to disperse
  95. for i=1,5 do
  96.     forward()
  97.     sleep(0)
  98.     position={0,0,0}
  99. end
  100.  
  101. -- get a chest for craft organization
  102. print("Need a chest in selected slot ONLY 1")
  103. repeat
  104.     currentItemDetail = turtle.getItemDetail()
  105.     sleep(1)
  106. until currentItemDetail and currentItemDetail.name == "minecraft:chest" and currentItemDetail.count == 1
  107.  
  108. print("Setting up base... Digging down 8 blocks to make furnace.. make sure to check that below block is stone")
  109. turtle.place() -- place chest
  110. sleep(1)
  111. -- dig until 8 cobblestone
  112. repeat
  113.     digMove("down")
  114.     currentItemDetail = turtle.getItemDetail()
  115. until currentItemDetail.name == "minecraft:cobblestone" and currentItemDetail.count >= 8
  116. -- go back to base
  117. repeat
  118.        turtle.up()
  119.        position[2]=position[2]+1
  120. until position[2]==0
  121. -- drop all into chest
  122. dropAll()
  123. turtle.select(16)
  124. dropAll()
  125. getFromChest("minecraft:cobblestone")
  126. turtle.transferTo(1,1)
  127. turtle.transferTo(2,1)
  128. turtle.transferTo(3,1)
  129. turtle.transferTo(5,1)
  130. turtle.transferTo(7,1)
  131. turtle.transferTo(9,1)
  132. turtle.transferTo(10,1)
  133. turtle.transferTo(11,1)
  134. turtle.drop()
  135. turtle.craft(1)
  136. turtle.select(1)
  137. turtle.placeUp()
Tags: ccTweaked
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement