Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- computercraft surface felling
- args={...}
- x=0
- y=0
- x1= tonumber(args[1])
- y1= tonumber(args[2])
- x2= tonumber(args[3])
- y2= tonumber(args[4])
- if x1==nil or y1==nil then
- print("Usage: fell [x1] [y1] {[x2] [y2]}")
- return
- end
- if x2==nil or y2==nil then
- x2=0
- y2=0
- end
- w=math.abs(x1-x2)
- h=math.abs(y1-y2)
- print("Requested felling a "..w.."x"..h.." area.")
- print("Checking fuel...")
- reqFuel=w*h + (w + h)*3
- if turtle.getFuelLevel() < reqFuel then
- print("I do not have enough fuel.")
- print("I have "..turtle.getFuelLevel().." fuel. But I need "..reqFuel.." fuel.")
- if turtle.getFuelLimit() < reqFuel then
- print("And I can only carry "..turtle.getFuelLimit().." fuel.")
- end
- return
- end
- print("Finding start...")
- function fellDown()
- while turtle.down() do
- end
- end
- function fell()
- while true do
- r,t = turtle.inspectUp()
- if r and (string.find(t.name, "Wood") or string.find(t.name, "log") or string.find(t.name, "leaves")) then
- turtle.digUp()
- turtle.up()
- else
- fellDown()
- return
- end
- end
- end
- function selectItem(t)
- for i=16,1,-1 do
- turtle.select(i)
- item=turtle.getItemDetail()
- if item~=nil and (item.name == t.name and item.damage == t.metadata) then
- return true
- end
- end
- return false
- end
- function tryForward()
- r,t = turtle.inspect()
- if r then
- if string.find(t.name, "Wood") or string.find(t.name, "log") then
- turtle.dig()
- turtle.forward()
- fell()
- else
- if not turtle.up() then
- print("Error: ceiling detected!")
- fellDown()
- print("So now I'mma break yo shit!")
- turtle.dig()
- turtle.forward()
- if selectItem(t) then turtle.drop() end
- else
- tryForward()
- end
- end
- else
- turtle.forward()
- fellDown()
- end
- return true
- end
- function findLoc(a,b)
- if a<x then
- turtle.turnRight()
- turtle.turnRight()
- for i=x-1,a,-1 do
- tryForward()
- x=x-1
- end
- turtle.turnRight()
- turtle.turnRight()
- elseif a>x then
- for i=x+1,a do
- tryForward()
- x=x+1
- end
- end
- if b<y then
- turtle.turnLeft()
- for i=y-1,b,-1 do
- tryForward()
- y=y-1
- end
- turtle.turnRight()
- elseif b>y then
- turtle.turnRight()
- for i=y+1,b do
- tryForward()
- y=y+1
- end
- turtle.turnLeft()
- end
- end
- print(" "..x2.." "..y2)
- findLoc(x2,y2)
- print(":"..x.." "..y)
- it=1
- if y2-y1>0 then it=-2 else it=2 end
- for yi=y2,y1-it,it do
- print(" "..x1.." "..yi)
- findLoc(x1,yi)
- print(":"..x.." "..y)
- findLoc(x1,yi+it/2)
- print(" "..x2.." "..(yi+it))
- findLoc(x2,yi+it/2)
- print(":"..x.." "..y)
- findLoc(x2,yi+it)
- end
- print(" ".."0".." ".."0")
- findLoc(0,0)
- print(":"..x.." "..y)
- print("Done!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement