Advertisement
gustav9797

woodchopper

Jan 6th, 2013
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.64 KB | None | 0 0
  1. map = {}
  2.  
  3. X = 0
  4. Y = 0
  5. Z = 0
  6. angle = 0
  7.  
  8. function setmapblock(x,y,solid)
  9. if map[x] == nil then
  10. map[x] = {}
  11. end
  12. map[x][y] = solid
  13. end
  14.  
  15. function getmapblock(x,y)
  16. if map[x] == nil then
  17. return nil
  18. elseif map[x][y] == nil then
  19. return nil
  20. end
  21. return map[x][y]
  22. end
  23.  
  24. function drawmap()
  25. --location = gps.locate(1, false)
  26. term.clear()
  27. term.setCursorPos(1,1)
  28. print(location)
  29. for y = Y-8, Y+16 do
  30. term.setCursorPos(1,y-Y+5)
  31. for x = X-6,X+12 do
  32. block = getmapblock(x,y)
  33. if x-X == 0 and y-Y == 0 then
  34. term.write("@")
  35. elseif block == nil then
  36. term.write("o")
  37. elseif block == 1 then
  38. term.write("#")
  39. else--block == 0
  40. term.write("_")
  41. -- term.setTextColor(colors.gray)
  42. -- term.write("x")
  43. end
  44. end
  45. term.write("/n")
  46. end
  47. end
  48.  
  49. function chop()
  50. shell.run("note-ai","happy")
  51. turtle.select(1)
  52. while turtle.detect() do
  53. updatefuel()
  54. turtle.dig()
  55. turtle.digUp()
  56. turtle.up()
  57. end
  58. while not turtle.detectDown() do
  59. updatefuel()
  60. turtle.down()
  61. end
  62. if turtle.getItemCount(3) > 1 then
  63. turtle.select(3)
  64. turtle.place()
  65. rotate()
  66. end
  67. end
  68.  
  69. function rotate()
  70. if math.random(0,1) == 1 then
  71. turtle.turnLeft()
  72. angle = angle + 1
  73. else
  74. turtle.turnRight()
  75. angle = angle - 1
  76. end
  77. if angle > 3 then angle = angle - 4
  78. elseif angle < 0 then angle = angle + 4 end
  79. end
  80.  
  81. function updatefuel()
  82. if turtle.getFuelLevel() == 0 then
  83. turtle.select(1)
  84. turtle.refuel(1)
  85. happyness = happyness + 2.5
  86. sleep(1)
  87. end
  88. end
  89.  
  90. happyness = 10
  91.  
  92. while true do
  93. happyness = happyness - 0.125
  94. if happyness <= 0 then
  95. for i=1,4 do
  96. shell.run("note-ai", "angry")
  97. sleep(5)
  98. end
  99. happyness = 5
  100. elseif happyness > 10 then
  101. happyness = 10
  102. end
  103.  
  104. updatefuel()
  105.  
  106. xx = 0
  107. yy = 0
  108.  
  109. if angle == 0 or angle == 2 then
  110. xx = 1-angle
  111. elseif angle == 1 or angle == 3 then
  112. yy = 1-angle+1
  113. end
  114.  
  115. turtle.select(3)
  116. if turtle.suck() or turtle.suckUp() or turtle.suckDown() then
  117. shell.run("note-ai","happy")
  118. happyness = happyness + 1
  119. end
  120.  
  121. if turtle.getItemCount(3) > 2 and math.random(0,3) == 0 then
  122. shell.run("note-ai","happy")
  123. happyness = happyness + 1
  124. turtle.place()
  125. rotate()
  126. end
  127.  
  128. if turtle.detect() then
  129. issolid = false
  130. turtle.select(2)
  131. issolid = turtle.compare()
  132. turtle.select(3)
  133. issolid = issolid or turtle.compare()
  134. if not issolid then
  135. happyness = happyness + 2
  136. chop()
  137. else
  138. happyness = happyness - 0.1
  139. setmapblock(X+xx,Y+yy, 1)
  140. rotate()
  141. end
  142. elseif not turtle.detectDown() then
  143. setmapblock(X,Y, 1)
  144. turtle.back()
  145. rotate()
  146. else
  147. setmapblock(X+xx,Y+yy, 0)
  148. turtle.forward()
  149. X = X + xx
  150. Y = Y + yy
  151.  
  152. if math.random(0,3) == 1 then
  153. rotate()
  154. end
  155. end
  156. drawmap()
  157. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement