Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- jmq quarry. Bit of a demonstrator of movement tracking without GPS.
- -- To use: Put a chest behind the turtle. If using flat bedrock, just
- -- run jmq [size], where size is how big you want the hole to be.
- -- If not using flat bedrock, run jmq x z y, where y is how deep you
- -- want the hole. Try feet pos - 6
- local t = turtle
- local NORTH, EAST, SOUTH, WEST= 0,1,2,3 -- if turtle placed facing NORTH
- local FORWARD, RIGHT, BACK, LEFT= 0,1,2,3 -- These are the actual ones used.
- local xoffs = { 0, 1, 0, -1}; -- Change in X moving forward for each facing.
- local zoffs = {-1, 0, 1, 0}; -- Change in Z moving forward for each facing.
- -- current facing and position - these are relative coords.
- local facing=FORWARD
- local pos={0,0,0}
- local X,Y,Z = 1,2,3 --array index
- --QUARRY SPECIFIC
- chestPos = {pos[X],pos[Y],pos[Z]}
- chestSide = BACK --Immediately behind turtle
- trashSide = LEFT
- function left()
- turtle.turnLeft()
- facing = (facing + 3) % 4
- end
- function turnRight()
- turtle.turnRight()
- facing = (facing + 1) % 4
- end
- function getOpposite(dir)
- return (dir + 2) % 4
- end
- function forward()
- if turtle.forward() then
- pos[1] = pos[1] + xoffs[facing+1]
- pos[3] = pos[3] + zoffs[facing+1]
- return true
- end
- return false
- end
- function back()
- if turtle.back() then
- pos[1] = pos[1] - xoffs[facing+1]
- pos[3] = pos[3] - zoffs[facing+1]
- return true
- end
- return false
- end
- function up()
- if turtle.up() then
- pos[2] = pos[2] + 1
- return true
- end
- return false
- end
- function down()
- if turtle.down() then
- pos[2] = pos[2] - 1
- return true
- end
- return false
- end
- function face(dir)
- dir = (facing - dir) % 4
- if dir == 0 then return
- elseif dir == 1 then left()
- elseif dir == 2 then left() left()
- elseif dir == 3 then turnRight()
- else print ("HUHHHHH??????"..dir)
- end
- end
- function go(dir)
- face(dir)
- return forward()
- end
- --This likely to be used with stored coords.
- function travel(coords, y, z)
- if y ~= nil then coords = {coords, y, z} end
- while pos[1] < coords[1] do while not go(RIGHT) do sleep(1) end end
- while pos[1] > coords[1] do while not go(LEFT) do sleep(1) end end
- while pos[2] < coords[2] do while not up() do sleep(1) end end
- while pos[2] > coords[2] do while not down() do sleep(1) end end
- while pos[3] < coords[3] do while not go(BACK) do sleep(1) end end
- while pos[3] > coords[3] do while not go(FORWARD) do sleep(1) end end
- end
- function ppos()
- print(pos[1]..", "..pos[2]..", "..pos[3]..", facing:"..facing)
- end
- function pfwd(tries)
- if tries == nil then tries = 1000 end
- for i=1,tries do
- if forward() then
- return true
- else
- if not t.dig() then
- sleep(0.3)
- print("Try "..i)
- end
- end
- end
- return false
- end
- function pdown(tries)
- if tries == nil then tries = 1000 end
- for i=1,tries do
- if down() then
- return true
- else
- if not t.digDown() then
- sleep(0.3)
- print("Try "..i)
- end
- end
- end
- return false
- end
- function pup(tries)
- if tries == nil then tries = 1000 end
- for i=1,tries do
- if up() then
- return true
- else
- if not t.digUp() then
- sleep(0.3)
- end
- end
- end
- return false
- end
- function pgo(dir, tries)
- face(dir)
- return pfwd(tries)
- end
- -- Best for starting new layer -
- -- if turtle gets stuck will be easier to find
- function ptravel(coords, y, z)
- if y ~= nil then coords = {coords, y, z} end
- while pos[1] < coords[1] do pgo(RIGHT) end
- while pos[1] > coords[1] do pgo(LEFT) end
- while pos[3] < coords[3] do pgo(BACK) end
- while pos[3] > coords[3] do pgo(FORWARD) end
- while pos[2] < coords[2] do pup() end
- while pos[2] > coords[2] do pdown() end
- end
- -- as above, but go forward/back first: Best for returning from dumping stuff
- -- as otherwise turtle will dig through anything sitting to the right of the start point
- function ptravelF(coords, y, z)
- if y ~= nil then coords = {coords, y, z} end
- while pos[3] < coords[3] do pgo(BACK) end
- while pos[3] > coords[3] do pgo(FORWARD) end
- while pos[1] < coords[1] do pgo(RIGHT) end
- while pos[1] > coords[1] do pgo(LEFT) end
- while pos[2] < coords[2] do pup() end
- while pos[2] > coords[2] do pdown() end
- end
- -- as above, but go up/down first: Best for dumping stuff
- -- as otherwise would likely dig through the wall/stairs.
- function ptravelV(coords, y, z)
- if y ~= nil then coords = {coords, y, z} end
- while pos[2] < coords[2] do pup() end
- while pos[2] > coords[2] do pdown() end
- while pos[1] < coords[1] do pgo(RIGHT) end
- while pos[1] > coords[1] do pgo(LEFT) end
- while pos[3] < coords[3] do pgo(BACK) end
- while pos[3] > coords[3] do pgo(FORWARD) end
- end
- function digTall()
- t.digUp()
- t.digDown()
- end
- function stairs(fwd, right,depth)
- if depth == nil then depth = 500 end
- digTall()
- while true do
- for i = 1,fwd-1 do
- print("Step "..i.." of "..fwd)
- if not pfwd(10) then return end
- digTall()
- if t.getItemCount(16) > 0 then
- dumpStuff()
- end
- print(depth)
- if not pdown(10) or depth < 1 then return end
- t.digDown()
- depth = depth - 1
- end
- turnRight()
- for i = 1,right-1 do
- print("Step "..i.." of "..right)
- if not pfwd(10) then return end
- digTall()
- if t.getItemCount(16) > 0 then
- dumpStuff()
- end
- if not pdown(10) or depth < 1 then return end
- t.digDown()
- depth = depth - 1
- end
- turnRight()
- end
- end
- function excavateColumn(length)
- digTall()
- for i = 1,length-1 do
- if not pfwd() then return false end
- digTall()
- if t.getItemCount(16) > 0 then
- dumpStuff()
- end
- end
- return true
- end
- function excavateLayer(rows, cols)
- f=facing
- right=(facing + 1) % 4 --relative to facing
- if not excavateColumn(cols) then return false end
- for i = 2,rows do
- pgo(right)
- f = getOpposite(f)
- face(f)
- if not excavateColumn(cols) then return false end
- end
- end
- function excavateUp(rows, cols, targetY)
- ppos()
- print("Excavate up to "..targetY)
- home = {pos[X], pos[Y], pos[Z]}
- while pos[Y] < targetY do
- ptravel(home)
- face(FORWARD)
- excavateLayer(rows, cols)
- home[Y] = home[Y] + 3
- end
- end
- function excavateDown(rows, cols, targetY)
- local home = {pos[X], pos[Y], pos[Z]}
- excavateLayer(rows, cols)
- while pos[Y] > targetY do
- home[Y] = home[Y] - 3
- ptravel(home)
- face(FORWARD)
- excavateLayer(rows, cols)
- end
- end
- function quarry(rows, cols, depth)
- t.select(1)
- local home = {pos[X], pos[Y], pos[Z]}
- homeFacing = facing
- dumpStuff()
- stairs(rows,cols,depth)
- turnRight()
- pfwd() -- move to inner part
- ptravel(home[X]+1, pos[Y], home[Z]-1)
- face(FORWARD)
- excavateUp(cols-2, rows-2, home[Y])
- ptravel(home)
- dumpStuff()
- face(homeFacing)
- end
- function inventoryContainsItems()
- for i=1,16 do
- if t.getItemCount(i) > 0 then
- return true
- end
- end
- return false
- end
- function dumpStuff()
- local home = {pos[X], pos[Y], pos[Z]}
- local homeFacing = facing
- ptravelV(chestPos) --up then across
- face(trashSide)
- local ok, meta = t.inspect();
- if ok and string.match(meta.name, 'rash') then -- Probably a trash can?
- print("Dump cobble")
- for i=1,16 do
- local block = t.getItemDetail(i)
- if (block and block.name == "minecraft:cobblestone") then
- t.select(i)
- if not t.drop() then
- print("Can't put item in trashcan.")
- while not t.drop() do
- sleep(1)
- end
- end
- end
- end
- end
- if inventoryContainsItems() then
- face(chestSide)
- if not t.inspect() then
- print("Please place a chest here")
- print("or clean out my inventory")
- while inventoryContainsItems() and not t.inspect() do
- sleep(1)
- end
- end
- for i=1,16 do
- if t.getItemCount(i) > 0 then
- t.select(i)
- if not t.drop() then
- print("Chest is full, please clear some space")
- while not t.drop() do
- sleep(1)
- end
- end
- end
- end
- end
- t.select(1)
- ptravelF(home) -- across then down
- face(homeFacing)
- end
- arg = {...}
- if arg[1] == nil then
- print("I dig a quarry forward and right.")
- print("use: jmq [fwd] [right] [deep]")
- print("or: jmq [size]")
- print("or: jmq help")
- print("")
- return
- end
- if arg[1] == 'help' then
- print("Put chest behind me")
- print("Trash can to left (optional)")
- print("")
- print("Use jmq[size] only with flat bedrock")
- print("Otherwise use jmq [fwd] [right] [deep]")
- print("[deep] = feet pos - bedrock height")
- print("")
- print("Example: jmq 8 8 8")
- return
- end
- local r, c, d = arg[1], arg[1], 200
- if arg[2] ~= nil then
- c = tonumber(arg[2])
- end
- if arg[3] ~= nil then
- d = tonumber(arg[3])
- end
- print (r)
- print (c)
- print (d)
- quarry(r, c, d)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement