Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- local width = tonumber(args[1]) or 12
- local height = tonumber(args[2]) or width
- local start = turtle.loc
- local function makeItem(name, metadata)
- return { name=name, metadata=metadata }
- end
- local treeType = 0 -- Oak
- local trunk = makeItem("minecraft:log", treeType)
- local sapling = makeItem("minecraft:sapling", treeType)
- local leaves = makeItem("minecraft:leaves", 4 + treeType)
- local function isMatch(a, b)
- return a.name == b.name and a.metadata == b.metadata
- end
- local function chopAndPlantOne()
- -- Done if this is outside the planting area
- local x = turtle.loc.x - start.x + 1
- local z = turtle.loc.z - start.z + 1
- if x <= 2 or x + 2 > width or z <= 2 or z + 2 > height then
- return
- end
- -- Done if there is already a sapling planted
- local _, down = turtle.inspectDown()
- if isMatch(down, sapling) then
- return
- end
- -- Not a sapling, so dig it out
- turtle.digDown()
- -- Replant if we have extra saplings
- if turtle.getItemCount(1) > 1 then
- turtle.select(1)
- turtle.placeDown()
- end
- end
- local function chopAndPlant(n)
- for i=1,n do
- turtle.digUp()
- chopAndPlantOne()
- turtle.suckDown()
- turtle.dig()
- turtle.forward()
- end
- end
- local function chopAll(n)
- for i=1,n do
- turtle.digUp()
- turtle.digDown()
- turtle.dig()
- turtle.forward()
- end
- end
- local layerCount = 0
- local function chopLayer()
- local turnParity = layerCount + width;
- local layer = (turtle.loc.y - 1 - start.y)/3
- if layer > 0 then
- layerCount = layerCount + 1
- else
- layerCount = 0
- end
- -- Chop and plant on the first layer, otherwise just shop
- local chop = layer == 0 and chopAndPlant or chopAll
- for i=1,width do
- local turn = (i + turnParity) % 2 == 0 and turtle.lt or turtle.rt
- if i > 1 then
- turn()
- chop(1)
- turn()
- end
- chop(height-1)
- end
- -- About face
- turtle.rt()
- turtle.rt()
- end
- local function chopUp(n)
- for i=1,n do
- turtle.digUp()
- turtle.up()
- end
- end
- local function chopDown(n)
- for i=1,n do
- turtle.digDown()
- turtle.down()
- end
- end
- ----------
- -- Main --
- ----------
- local requiredFuel = width*height*2 + 6
- chopUp(1)
- while true do
- -- TODO: inventory stuff
- -- Check fuel
- if turtle.getFuelLevel() < requiredFuel then
- print "Not enough fuel"
- -- TODO: refuel
- break
- end
- chopUp(3)
- chopLayer()
- chopDown(3)
- chopLayer()
- -- stop after one pass for now
- break
- end
- chopDown(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement