hornedcommando

getInfo

Apr 16th, 2024
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.43 KB | Gaming | 0 0
  1. --Simple aggregation of function for ease of testing functions or quickly getting block info
  2. --by hornedcommando
  3.  
  4. local tTurtle = require("TrackingTurtle")
  5.  
  6. local myTurtle = tTurtle.create()
  7.  
  8. -- Select the first slot in the inventory
  9. turtle.select(1)
  10.  
  11. -- Function to check information about the item in the selected slot
  12. local function checkItem()
  13. -- Get information about the item in the selected slot
  14. local itemDetail = turtle.getItemDetail()
  15.  
  16. -- Check if an item is present in the selected slot
  17. if itemDetail then
  18. -- Print information about the item
  19. print("All Item Detail Fields:")
  20. for key, value in pairs(itemDetail) do
  21. print(key .. ": " .. tostring(value))
  22. end
  23. else
  24. print("No item in the selected slot.")
  25. end
  26. end
  27.  
  28. -- Function to check the block in front of the turtle
  29. local function checkBlock()
  30. -- Get information about the block in front of the turtle
  31. local success, block = turtle.inspect()
  32. if success then
  33. -- Print information about the block
  34. print("Item Name:".. block.name)
  35. print("State Table:")
  36. for key, value in pairs(block.state) do
  37. print(key .. ": " .. tostring(value))
  38. end
  39. else
  40. print("No item in the selected slot.")
  41. end
  42. end
  43.  
  44. -- Function to show the fuel level of the turtle
  45. local function showFuelLevel()
  46. -- Get the fuel level of the turtle
  47. local fuelLevel = turtle.getFuelLevel()
  48.  
  49. if fuelLevel then
  50. print("Fuel Level: ".. fuelLevel)
  51. else
  52. print("Unable to retrieve fuel level.")
  53. end
  54. end
  55.  
  56. local function showdetect()
  57. local success, block = turtle.detect()
  58. if success then
  59. print("Detect returns true")
  60. else
  61. print("Detect returns false")
  62. end
  63. end
  64.  
  65. local function myPosition()
  66. local x, y, z = myTurtle.getPosition()
  67. if x then
  68. print("Position: x=".. x)
  69. else
  70. print("Position is not available.")
  71. end
  72. end
  73.  
  74. local function myFacing()
  75. local facing = myTurtle.getFacing()
  76. if facing then
  77. print("Facing: ".. facing)
  78. else
  79. print("Facing is not available.")
  80. end
  81. end
  82.  
  83. local fuelValues = {
  84. ["minecraft:coal"] = 80,
  85. ["minecraft:charcoal"] = 80,
  86. ["minecraft:lava_bucket"] = 1000,
  87. ["minecraft:blaze_rod"] = 120,
  88. ["minecraft:dried_kelp_block"] = 4000,
  89. ["minecraft:coal_block"] = 800,
  90. ["minecraft:planks"] = 15,
  91. ["minecraft:stick"] = 5,
  92. ["minecraft:wooden_slab"] = 15,
  93. ["minecraft:note_block"] = 15,
  94. ["minecraft:jukebox"] = 15,
  95. ["minecraft:lectern"] = 15,
  96. ["minecraft:bookshelf"] = 15,
  97. ["minecraft:crafting_table"] = 15,
  98. ["minecraft:cartography_table"] = 15,
  99. ["minecraft:fletching_table"] = 15,
  100. ["minecraft:smithing_table"] = 15,
  101. ["minecraft:looms"] = 15,
  102. ["minecraft:loom"] = 15,
  103. ["minecraft:composter"] = 15,
  104. ["minecraft:barrel"] = 15,
  105. ["minecraft:smoker"] = 15,
  106. }
  107.  
  108. local function howMuchFuel()
  109. local fuelLevel = turtle.getFuelLevel()
  110. local item = turtle.getItemDetail()
  111. turtle.refuel(1)
  112. local newfuelLevel = turtle.getFuelLevel()
  113. print("Fuel Level: ".. newfuelLevel)
  114. local itemfuel = newfuelLevel - fuelLevel
  115. print("Name: ".. item.name .. " gives ".. itemfuel .. " fuel.")
  116. end
  117.  
  118. --Moving forward 1 block costs 1 fuel
  119. local function movementCost()
  120. local fuelLevel = turtle.getFuelLevel()
  121. myTurtle.forward()
  122. local newfuelLevel = turtle.getFuelLevel()
  123. local moveCost = newfuelLevel - fuelLevel
  124. print("Moving forward costs: ".. moveCost .. " fuel.")
  125.  
  126. end
  127.  
  128. local function stackWheat()
  129. print("Checking inventory")
  130. for slot = 1, 16 do
  131. if turtle.getItemDetail(slot) then
  132. local item = turtle.getItemDetail(slot)
  133. print("Slot: " .. slot .. " Item: " .. item.name)
  134. if item.name ~= "minecraft:wheat" then
  135. print("this is not wheat")
  136. turtle.select(slot)
  137. turtle.drop()
  138. else
  139. print("Wheat found in slot " .. slot)
  140. end
  141. else
  142. print("Slot: " .. slot .. " is empty")
  143. end
  144. end
  145. end
  146.  
  147. -- Suck everything below so long as 1. below is not empty and 2. the turtle can drop the item
  148. local function suckWhile()
  149. while turtle.suckDown() do
  150. if not turtle.suckDown() then
  151. break
  152. end
  153. end
  154. end
  155.  
  156. local function isItem(itemName)
  157. local item = turtle.getItemDetail()
  158. if item and item.name == itemName then
  159. return true
  160. else
  161. return false
  162. end
  163. end
  164.  
  165. local function findEmptySlot()
  166. for i = 1, 16 do
  167. if turtle.getItemCount(i) == 0 then
  168. return i
  169. end
  170. end
  171. return false
  172. end
  173.  
  174. local function countInventory()
  175. local count = 0
  176. for i = 1, 16 do
  177. count = count + turtle.getItemCount(i)
  178. end
  179. return count
  180. end
  181.  
  182.  
  183.  
  184. --Function to pull items from chest below, keep matching items, and drop non matches
  185. local function sort(itemName)
  186. local sortChestFull = false
  187. local pullChestEmpty = false
  188. local inventoryFull = false
  189.  
  190.  
  191.  
  192. while not inventoryFull do
  193. local emptySlot = findEmptySlot()
  194. if not emptySlot then
  195. print("Inventory full")
  196. inventoryFull = true
  197. break
  198. end
  199.  
  200. if not sortChestFull then
  201. print("Checking chest below")
  202. local count = countInventory()
  203. suckWhile()
  204. local newCount = countInventory()
  205. if count == newCount then
  206. print("No more items in the chest below.")
  207. pullChestEmpty = true
  208. end
  209.  
  210. for i = 1, 16 do
  211. turtle.select(i)
  212. local item = turtle.getItemDetail(i)
  213. if item and item.name == itemName then
  214. print("Match found in slot " .. i)
  215. else
  216. print("Non-matching item in slot " .. i .. ", dumping...")
  217. if not turtle.drop() then
  218. print("Chest is full, waiting...")
  219. sortChestFull = true
  220. break
  221. end
  222. end
  223. end
  224. end
  225. end
  226. end
  227.  
  228.  
  229. local function fillAndStack(itemName)
  230. while true do
  231. local foundMatch = false
  232. local emptySlot = false
  233.  
  234. if not emptySlot then
  235. print("Inventory full")
  236. break -- Exit the loop if inventory is full
  237. end
  238.  
  239. -- Pull items from the chest until the inventory is full
  240. for i = 1, 16 do
  241. turtle.select(i)
  242. if turtle.getItemCount(i) == 0 then
  243. if turtle.suckDown() then
  244. print("Pulled items from the chest below into slot " .. i)
  245. local item = turtle.getItemDetail(i)
  246. if item and item.name == itemName then
  247. foundMatch = true
  248. print("Match found in slot " .. i)
  249. break -- Exit the loop if a match is found
  250. else
  251. print("Non-matching item in slot " .. i .. ", dumping...")
  252. turtle.drop()
  253. end
  254. else
  255. print("No more items in the chest below.")
  256. break -- Exit the loop if no more items
  257. end
  258. end
  259. end
  260.  
  261. if not foundMatch then
  262. print("No match found in current inventory slots.")
  263. sleep(1) -- Wait for a moment before trying again
  264. end
  265. end
  266. end
  267.  
  268. local junk = {
  269. "minecraft:dirt",
  270. "minecraft:cobblestone",
  271. "create:dolomite_cobblestone",
  272. "create:limestone_cobblestone",
  273. "create:gabbro_cobblestone",
  274. "create:granite_cobblestone",
  275. "forbidden_arcanus:darkstone",
  276. "extcaves:sedimentstone",
  277. "extcaves:lavastone",
  278. "extcaves:pebble_sedimentstone",
  279. "create:andesite_cobblestone",
  280. "create:diorite_cobblestone",
  281. "minecraft:gravel",
  282. "occultism:datura_seeds",
  283. "minecraft:wheat_seeds",
  284. "extcaves:pebble_stone",
  285. "minecraft:stone",
  286. "minecraft:granite",
  287. "minecraft:diorite",
  288. "minecraft:andesite",
  289. "minecraft:gravel",
  290. "minecraft:deepslate",
  291. "railcraft:quarried_stone",
  292. "minecraft:cobbled_deepslate",
  293. "minecraft:tuff",
  294. "minecraft:basalt",
  295. "minecraft:blackstone",
  296. "minecraft:calcite"
  297. -- Add more junk items as needed
  298. }
  299.  
  300. --Function to check if a block is junk
  301. local function isJunk(blockName)
  302. for _, junkBlock in ipairs(junk) do
  303. if blockName == junkBlock then
  304. return true
  305. end
  306. end
  307. return false
  308. end
  309.  
  310. --Function to drop junk from inventory
  311. local function dropJunk()
  312. print("Dropping junk")
  313. for slot = 1, 16 do
  314. turtle.select(slot)
  315. local itemDetail = turtle.getItemDetail()
  316. if itemDetail and isJunk(itemDetail.name) then
  317. turtle.drop()
  318. end
  319. end
  320. end
  321.  
  322. local function isForbiddenBlock(blockName)
  323. local forbiddenBlocks = {
  324. "forbidden_arcanus:stella_arcanum",
  325. "minecraft:bedrock"
  326. }
  327. for _, forbiddenBlock in ipairs(forbiddenBlocks) do
  328. if blockName == forbiddenBlock then
  329. return true
  330. end
  331. end
  332. return false
  333. end
  334.  
  335. -- Function to keep as many vauluables as possible, while dropping junk
  336. local function junkShuffle()
  337. myTurtle.face(0)
  338. local success, block = turtle.inspect()
  339. if isForbiddenBlock(block.name) then
  340. print("Detected block is forbidden")
  341. else
  342. turtle.dig()
  343. dropJunk()
  344. while turtle.suckUp() do
  345. turtle.suckUp()
  346. dropJunk()
  347. end
  348. isJunkShuffle = true
  349. end
  350. end
  351.  
  352. --Mining Test
  353. function miningTest()
  354. for i = 1, 4 do
  355. local success, block = turtle.inspect()
  356. if isForbiddenBlock(block.name) or isJunk(block.name) then
  357. myTurtle.turnRight()
  358. else
  359. turtle.dig()
  360. myTurtle.turnRight()
  361. end
  362. end
  363. end
  364.  
  365.  
  366.  
  367.  
  368.  
  369. -- Call the functions to check item, block, and fuel level
  370. checkItem()
  371. --showFuelLevel()
  372. --showdetect()
  373. --checkBlock()
  374. --myPosition()
  375. --myFacing()
  376. --howMuchFuel()
  377. --movementCost()
  378. --sort("minecraft:wheat")
  379. --junkShuffle()
  380. --miningTest()
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
Add Comment
Please, Sign In to add comment