Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.24 KB | None | 0 0
  1. ]]--
  2.  
  3. --[[
  4. emptyInventory:
  5. Arguments:
  6. forceEmpty (Boolean) - If true, forces the turtle to empty its inventory
  7.  
  8. Does:
  9. Empties Turtle's inventory except the first slot(seeds) and second slot(bonemeal)
  10. ]]--
  11. function emptyInventory(forceEmpty)
  12.  
  13. -- Check if the turtle's inventory is full or the emptying should be forced
  14. if (turtle.getItemCount(16) > 0 or forceEmpty == true) then
  15.  
  16. -- Refill seeds in slot#1
  17. refillSeeds(true)
  18.  
  19. -- Loop to check each slot, 3 through 16, of the turtle's inventory
  20. for n = 3, 16, 1 do
  21.  
  22. -- check if there's items in the slot
  23. if (turtle.getItemCount(n) > 0) then
  24.  
  25. -- select the turtle's inventory slot, and 'dropUp()' (Place in the inventory above the turtle)
  26. turtle.select(n)
  27. turtle.dropUp()
  28. end
  29. end
  30.  
  31. -- Otherwise, refillSeeds
  32. else
  33. refillSeeds(false)
  34. end
  35. end
  36.  
  37. --[[
  38. refillSeeds:
  39. Arguments:
  40. forceRefill (boolean) - If true, forces the turtle to refill seeds
  41.  
  42. Does:
  43. Refills the first slot of the turtle with seeds from else where in the turtle's inventory
  44. ]]--
  45. function refillSeeds(forceRefill)
  46.  
  47. --[[ Variables:
  48. seedCount: number of seeds in slot#1
  49. refillCount: number of seeds required to refill slot#1 ]]
  50. local seedCount, refillCount = turtle.getItemCount(1), 0
  51. refillCount = 64 - seedCount
  52.  
  53. -- Check if there's no seeds in slot #1
  54. if (seedCount == 0) then
  55.  
  56. -- Print the turtle is out of seeds
  57. print("Out of seeds: place seeds in first slot to continue")
  58.  
  59. -- Wait for seeds
  60. repeat
  61. sleep(1)
  62. until (turtle.getItemCount(1) > 0)
  63.  
  64. -- Check if the turtle needs to refill seeds or the 'forceRefill' argument is true
  65. elseif (seedCount < 16) or (forceRefill == true and seedCount < 64) then
  66.  
  67. -- select the first slot
  68. turtle.select(1)
  69.  
  70. -- loop over slots #3 through #16
  71. for n = 3, 16, 1 do
  72.  
  73. -- check if the slot looped over contains seeds
  74. if (turtle.compareTo(n) == true) then
  75.  
  76. -- Select the looped over slot
  77. turtle.select(n)
  78.  
  79. -- If there's not enough seeds to completely refill slot#1
  80. if (refillCount > turtle.getItemCount(n)) then
  81.  
  82. -- transfer the seeds to slot one
  83. turtle.transferTo(1, turtle.getItemCount(n))
  84.  
  85. -- Adjust refillCount
  86. refillCount = 64 - turtle.getItemCount(1)
  87.  
  88. -- If there's more than enough seeds in the looped over slot to refill slot#1
  89. else
  90.  
  91. -- transfer enough seeds to fill slot#1 then exit the loop
  92. turtle.transferTo(1, refillCount)
  93. break
  94. end
  95.  
  96. -- select slot#1 for the next literation of the loop
  97. turtle.select(1)
  98. end
  99. end
  100. end
  101. end
  102.  
  103. --[[
  104. getBoneMeal
  105. Arguments:
  106. none
  107. Usage:
  108. Refills slot#2 with bone meal from an inventory directly below the turtle
  109. ]]
  110. function getBoneMeal()
  111.  
  112. -- select the turtle's second inventory slot
  113. turtle.select(2)
  114.  
  115. -- Check to see if the turtle needs more bonemeal
  116. if (turtle.getItemCount(2) <= 8) then
  117.  
  118. -- Attempt to retrieve bone meal from inventory below the turtle
  119. if (turtle.suckDown() == false) then
  120.  
  121. -- Print the turtle is out of bone meal and waiting
  122. print("Out of bonemeal, waiting...")
  123.  
  124. -- Wait for bone meal to be placed in inventory below the turtle
  125. repeat
  126. sleep(1)
  127. until (turtle.suckDown() == true)
  128. end
  129.  
  130. -- loop over the turtle's inventory slots #3 through 16
  131. for n = 3, 16, 1 do
  132.  
  133. -- if the slot has bone meal(extra) place it in the inventory above
  134. if (turtle.compareTo(n) == true) then
  135. turtle.select(n)
  136. turtle.dropUp()
  137. turtle.select(2)
  138. end
  139. end
  140. end
  141. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement