Advertisement
enderpro100

WoodFarming

Nov 29th, 2020 (edited)
1,211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.30 KB | Gaming | 0 0
  1. --- Program : wood farming
  2. --- Author : LightKnight51
  3. --- Last modification : 13/04/2023
  4.  
  5.  
  6.  
  7. --- Variables
  8. local fuel = 0
  9. local bExit = false
  10. local UseChest = true
  11.  
  12. --- Utils API
  13. os.loadAPI("MarquitoLuaUtils")
  14.  
  15. --- Functions
  16.  
  17. -- Depose the chest
  18. function DeposeChest()
  19.     if MarquitoLuaUtils.BlockDetection("down", false) == "minecraft:bedrock" then
  20.         MarquitoLuaUtils.error("minecraft:bedrock")
  21.     elseif string.find(MarquitoLuaUtils.BlockDetection("down", false),"chest") then
  22.         print("Chest already in place")
  23.         MarquitoLuaUtils.Log("INFO", "Chest already in place")
  24.         turtle.select(1)
  25.     else
  26.         turtle.digDown()
  27.         chestId = MarquitoLuaUtils.FindIDContains("chest", false)
  28.         if chestId ~= nil then
  29.             turtle.select(chestId)
  30.             turtle.placeDown()
  31.             print("Chest has been placed")
  32.             MarquitoLuaUtils.Log("INFO", "Chest has been placed")
  33.         end
  34.         turtle.select(1)
  35.     end
  36. end
  37.  
  38. -- Dig wood and return in init prosition properly
  39. function FarmWood()
  40.     countHeight = 0
  41.     while string.find(MarquitoLuaUtils.BlockDetection("front", false), "log") do
  42.         turtle.dig()
  43.         turtle.digUp()
  44.         turtle.up()
  45.         countHeight = countHeight + 1
  46.     end
  47.     if countHeight > 0 then
  48.         for i = 1, countHeight do
  49.             turtle.down()
  50.         end
  51.     end
  52. end
  53.  
  54. -- Use bone meal if we have to grow tree
  55. function UseBoneMeal()
  56.     boneMealId = MarquitoLuaUtils.FindIDContains("bone_meal", false)
  57.     if boneMealId ~= nil then
  58.         turtle.select(boneMealId)
  59.         turtle.place()
  60.     end
  61. end
  62.  
  63. -- Launch wood farming
  64. function InitWoodFarming()
  65.     print("Launch wood farming program")
  66.     MarquitoLuaUtils.Log(MarquitoLuaUtils.LogLevel.INFO, "Launch wood farming program")
  67.  
  68.     -- Set if we want to use chest
  69.     UseChest = tostring(MarquitoLuaUtils.GetConfValue("use_chest")) == "true"
  70.     --UseChest
  71.     while UseChest == nil do
  72.         print("Use chest for store wood ? (yes or no)")
  73.         UseChest = tostring(read()) == "yes"
  74.     end
  75.     if UseChest then
  76.         MarquitoLuaUtils.SetConfValue("use_chest", "true")
  77.     else
  78.         MarquitoLuaUtils.SetConfValue("use_chest", "false")
  79.     end
  80.  
  81.     -- Depose the chest
  82.     if UseChest then
  83.         DeposeChest()
  84.     end
  85.  
  86.     while true do
  87.         if string.find(MarquitoLuaUtils.BlockDetection("front", false), "log") then
  88.             -- Get wood
  89.             FarmWood()
  90.             -- Store items in chest
  91.             local excludingItems = {"sapling", "coal", "blaze_rod", "bone_meal"}
  92.  
  93.             if UseChest then
  94.                 MarquitoLuaUtils.DropAllItemsInChest(true, excludingItems)
  95.             else
  96.                 MarquitoLuaUtils.DropAllItems(true, excludingItems)
  97.             end
  98.         elseif string.find(MarquitoLuaUtils.BlockDetection("front", false), "sapling") then
  99.             UseBoneMeal()
  100.         elseif MarquitoLuaUtils.BlockDetection("front", true) then
  101.             local idSapling = MarquitoLuaUtils.FindIDContains("sapling")
  102.             if idSapling ~= nil then
  103.                 turtle.select(idSapling)
  104.                 turtle.place()
  105.             end
  106.         end
  107.         os.sleep(0.3)
  108.     end
  109.     MarquitoLuaUtils.EndLog()
  110. end
  111.  
  112. parallel.waitForAny(InitWoodFarming, MarquitoLuaUtils.Refuel)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement