Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- args = { ... }
- garbage = {
- "minecraft:cobblestone",
- "minecraft:dirt",
- "minecraft:gravel",
- "chisel:diorite",
- "chisel:andesite",
- "chisel:granite",
- "chisel:marble",
- "chisel:limestone",
- }
- function digForward()
- while turtle.detect() do
- turtle.dig()
- end
- end
- function digUp()
- while turtle.detectUp() do
- turtle.digUp()
- end
- end
- function digDown()
- while turtle.detectDown() do
- turtle.digDown()
- end
- end
- local px = 0; local py = 0; local pz = 0
- local facing = 0
- function back(count)
- for i = 1, count do
- if not turtle.back() then
- turnLeft(2)
- forward(1)
- turnLeft(2)
- else
- if facing == 0 then px = px - 1
- elseif facing == 1 then py = py - 1
- elseif facing == 2 then px = px + 1
- elseif facing == 3 then py = py + 1
- end
- end
- end
- end
- function forward(count)
- for i = 1, count do
- digForward(1)
- while not turtle.forward() do
- if not digForward(1) then
- turtle.attack()
- end
- end
- end
- if facing == 0 then px = px + count
- elseif facing == 1 then py = py + count
- elseif facing == 2 then px = px - count
- elseif facing == 3 then py = py - count
- end
- end
- function up(count)
- for i = 1, count do
- digUp(1)
- while not turtle.up() do
- if not digUp(1) then
- turtle.attackUp()
- end
- end
- end
- pz = pz + count
- end
- function down(count)
- for i = 1, count do
- digDown(1)
- while not turtle.down() do
- if not digDown(1) then
- turtle.attackDown()
- end
- end
- end
- pz = pz - count
- end
- function turnLeft(count)
- for i = 1, count do
- turtle.turnLeft()
- end
- facing = facing - count
- while facing < 0 do facing = facing + 4 end
- end
- function turnRight(count)
- for i = 1, count do
- turtle.turnRight()
- end
- facing = facing + count
- while facing > 3 do facing = facing - 4 end
- end
- function dig3xXInFront(height)
- forward(1)
- turnLeft(1)
- for i = 1, height - 1 do
- digForward(1)
- up(1)
- end
- checkForFilled()
- digForward(1)
- turnRight(2)
- for i = 1, height - 1 do
- digForward(1)
- down(1)
- end
- checkForFilled()
- digForward(1)
- turnLeft(1)
- end
- function checkForFilled()
- if turtle.getItemCount(10) > 0 then
- checkForAndDropGarbage()
- local pos = getLocationData()
- moveToPos({ 0, 0, 0, 0 })
- checkForAndDropGarbage()
- turnLeft(1)
- dropAll()
- moveToPos(pos)
- end
- end
- function isGarbage(val)
- for index, value in ipairs(garbage) do
- if value == val then
- return true
- end
- end
- return false
- end
- function checkForAndDropGarbage()
- for i = 1, 16 do
- local data = turtle.getItemDetail(i)
- if data then
- if isGarbage(data.name) then
- turtle.select(i)
- turtle.drop()
- end
- end
- end
- turtle.select(1)
- end
- function getLocationData()
- return { px, py, pz, facing }
- end
- function moveToPos(pos)
- local lpx = pos[1]
- local lpy = pos[2]
- local lpz = pos[3]
- local lfacing = pos[4]
- if lpx ~= px then
- if lpx > px then
- setFacing(0)
- forward(lpx - px)
- else
- setFacing(2)
- forward(px - lpx)
- end
- end
- if lpy ~= py then
- if lpy > py then
- setFacing(1)
- forward(lpy - py)
- else
- setFacing(3)
- forward(py - lpy)
- end
- end
- if lpz ~= pz then
- if lpz > pz then
- up(lpz - pz)
- else
- down(pz - lpz)
- end
- end
- setFacing(lfacing)
- end
- function setFacing(lfacing)
- while lfacing ~= facing do
- turnLeft(1)
- end
- end
- function digLoop(length, height)
- for i = 1, length do
- dig3xXInFront(height)
- end
- --checkForAndDropGarbage()
- back(1)
- turnRight(1)
- forward(1)
- dig3xXInFront(height)
- dig3xXInFront(height)
- dig3xXInFront(height)
- back(1)
- turnRight(1)
- forward(1)
- for i = 1, length do
- dig3xXInFront(height)
- end
- --checkForAndDropGarbage()
- back(1)
- turnLeft(1)
- forward(1)
- dig3xXInFront(height)
- dig3xXInFront(height)
- dig3xXInFront(height)
- back(1)
- turnLeft(1)
- forward(1)
- end
- function refuel()
- for i = 1, 16 do
- turtle.select(i);
- turtle.refuel()
- end
- end
- function dropAll()
- for i = 1, 16 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.select(1)
- end
- if table.getn(args) ~= 3 then
- print("arguments 'width', 'depth' and 'height' expected (width is not 100% accourate)")
- else
- local x = tonumber(args[1]) / 6
- if tonumber(args[1]) % 6 ~= 0 then x = x + 1 end
- local y = tonumber(args[2]) - 2
- local z = tonumber(args[3])
- for j = 1, x do
- digLoop(y, z)
- refuel()
- end
- checkForAndDropGarbage()
- moveToPos({ 0, 0, 0, 3 })
- dropAll()
- turnRight(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement