Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- Program : wood farming
- --- Author : LightKnight51
- --- Last modification : 13/04/2023
- --- Variables
- local fuel = 0
- local bExit = false
- local UseChest = true
- --- Utils API
- os.loadAPI("MarquitoLuaUtils")
- --- Functions
- -- Depose the chest
- function DeposeChest()
- if MarquitoLuaUtils.BlockDetection("down", false) == "minecraft:bedrock" then
- MarquitoLuaUtils.error("minecraft:bedrock")
- elseif string.find(MarquitoLuaUtils.BlockDetection("down", false),"chest") then
- print("Chest already in place")
- MarquitoLuaUtils.Log("INFO", "Chest already in place")
- turtle.select(1)
- else
- turtle.digDown()
- chestId = MarquitoLuaUtils.FindIDContains("chest", false)
- if chestId ~= nil then
- turtle.select(chestId)
- turtle.placeDown()
- print("Chest has been placed")
- MarquitoLuaUtils.Log("INFO", "Chest has been placed")
- end
- turtle.select(1)
- end
- end
- -- Dig wood and return in init prosition properly
- function FarmWood()
- countHeight = 0
- while string.find(MarquitoLuaUtils.BlockDetection("front", false), "log") do
- turtle.dig()
- turtle.digUp()
- turtle.up()
- countHeight = countHeight + 1
- end
- if countHeight > 0 then
- for i = 1, countHeight do
- turtle.down()
- end
- end
- end
- -- Use bone meal if we have to grow tree
- function UseBoneMeal()
- boneMealId = MarquitoLuaUtils.FindIDContains("bone_meal", false)
- if boneMealId ~= nil then
- turtle.select(boneMealId)
- turtle.place()
- end
- end
- -- Launch wood farming
- function InitWoodFarming()
- print("Launch wood farming program")
- MarquitoLuaUtils.Log(MarquitoLuaUtils.LogLevel.INFO, "Launch wood farming program")
- -- Set if we want to use chest
- UseChest = tostring(MarquitoLuaUtils.GetConfValue("use_chest")) == "true"
- --UseChest
- while UseChest == nil do
- print("Use chest for store wood ? (yes or no)")
- UseChest = tostring(read()) == "yes"
- end
- if UseChest then
- MarquitoLuaUtils.SetConfValue("use_chest", "true")
- else
- MarquitoLuaUtils.SetConfValue("use_chest", "false")
- end
- -- Depose the chest
- if UseChest then
- DeposeChest()
- end
- while true do
- if string.find(MarquitoLuaUtils.BlockDetection("front", false), "log") then
- -- Get wood
- FarmWood()
- -- Store items in chest
- local excludingItems = {"sapling", "coal", "blaze_rod", "bone_meal"}
- if UseChest then
- MarquitoLuaUtils.DropAllItemsInChest(true, excludingItems)
- else
- MarquitoLuaUtils.DropAllItems(true, excludingItems)
- end
- elseif string.find(MarquitoLuaUtils.BlockDetection("front", false), "sapling") then
- UseBoneMeal()
- elseif MarquitoLuaUtils.BlockDetection("front", true) then
- local idSapling = MarquitoLuaUtils.FindIDContains("sapling")
- if idSapling ~= nil then
- turtle.select(idSapling)
- turtle.place()
- end
- end
- os.sleep(0.3)
- end
- MarquitoLuaUtils.EndLog()
- end
- parallel.waitForAny(InitWoodFarming, MarquitoLuaUtils.Refuel)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement