Advertisement
TechManDylan

LogStripper1.1

Oct 25th, 2023 (edited)
713
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.46 KB | None | 0 0
  1. -- List of Minecraft log types to strip
  2. local logTypes = {
  3.     "minecraft:oak_log",
  4.     "minecraft:spruce_log",
  5.     "minecraft:birch_log",
  6.     "minecraft:jungle_log",
  7.     "minecraft:acacia_log",
  8.     "minecraft:dark_oak_log",
  9. }
  10.  
  11. -- Check for Minecraft logs in turtle inventory
  12. function checkInventoryForLogs()
  13.     for slot = 1, 16 do
  14.         local item = turtle.getItemDetail(slot)
  15.         if item and isLog(item.name) then
  16.             return slot
  17.         end
  18.     end
  19.     return nil
  20. end
  21.  
  22. -- Check if a given item name is a log
  23. function isLog(itemName)
  24.     for _, logType in ipairs(logTypes) do
  25.         if itemName == logType then
  26.             return true
  27.         end
  28.     end
  29.     return false
  30. end
  31.  
  32. -- Check if the block in front of the turtle is a stripped log and break it
  33. function checkAndBreakBlock()
  34.     local success, block = turtle.inspect()
  35.     if success and isStrippedLog(block.name) then
  36.         turtle.dig()
  37.         while turtle.detect() do
  38.             sleep(0.1)
  39.         end
  40.     end
  41. end
  42.  
  43. -- Check if a given item name is a stripped log
  44. function isStrippedLog(blockName)
  45.     return blockName:match("^minecraft:stripped_")
  46. end
  47.  
  48. -- Place a stripped log in front of the turtle
  49. function placeLog()
  50.     local slot = checkInventoryForLogs()
  51.     if slot then
  52.         turtle.select(slot)
  53.         turtle.place()
  54.         sleep(0.1)
  55.     end
  56. end
  57.  
  58. -- Main loop
  59. while true do
  60.     placeLog()
  61.     checkAndBreakBlock()
  62.     sleep(0.1)
  63. end
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement