Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module(...)
- local U = require "utils"
- local T = require "turtle"
- local lastCleared = "back"
- function clearCube(X, Y, Z, vertDir, horDir)
- vertDir = vertDir or "down"
- horDir = horDir or "right"
- turtle.select(16)
- for y = 1, Y, 1 do
- for x = 1, X, 1 do
- for z = 1, Z - 1, 1 do
- forward()
- invFull()
- end
- T.turn(horDir)
- if not (x == X) then
- forward()
- end
- T.turn(horDir)
- if not (x == X) then
- horDir = T.swapRowDir(horDir)
- end
- end
- if vertDir == "up" then
- up()
- elseif vertDir == "down" then
- down()
- end
- invFull()
- end
- end
- function invFull(placeChestDir, excludeSlots)
- placeChestDir = placeChestDir or lastCleared
- excludeSlots = excludeSlots or 1
- if turtle.getItemCount(16 - excludeSlots) > 0 then
- if placeChestDir == "back" then
- T.turn("right", 2)
- dropAll("front", 1, 16 - excludeSlots)
- T.turn("right", 2)
- elseif placeChestDir == "top" then
- dropAll("top", 1, 16 - excludeSlots)
- elseif placeChestDir == "bottom" then
- dropAll("bottom", 1, 16 - excludeSlots)
- elseif placeChestDir == "front" then
- dropAll("front", 1, 16 - excludeSlots)
- elseif placeChestDir == "right" then
- T.turn("right")
- dropAll("front", 1, 16 - excludeSlots)
- T.turn("left")
- elseif placeChestDir == "left" then
- T.turn("left")
- dropAll("front", 1, 16 - excludeSlots)
- T.turn("right")
- end
- end
- end
- function dropAll(dir, startSlot, endSlot)
- dir = dir or "front"
- startSlot = startSlot or 1
- endSlot = endSlot or 16
- turtle.select(16)
- if dir == "front" then
- turtle.place()
- elseif dir == "top" then
- turtle.placeUp()
- elseif dir == "bottom" then
- turtle.placeDown()
- end
- for i = startSlot, endSlot, 1 do
- local drop = true
- turtle.select(i)
- for j = endSlot + 1, 16, 1 do
- if turtle.compareTo(j) then
- drop = false
- break
- end
- end
- if drop then
- if dir == "front" then
- turtle.drop()
- elseif dir == "top" then
- turtle.dropUp()
- elseif dir == "bottom" then
- turtle.dropDown()
- end
- end
- end
- turtle.select(16)
- if dir == "front" then
- turtle.dig()
- elseif dir == "top" then
- turtle.digUp()
- elseif dir == "bottom" then
- turtle.digDown()
- end
- end
- function dig()
- 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
- function forward(times)
- times = times or 1
- for i = 1, times, 1 do
- local done = false
- while not done do
- dig()
- done = turtle.forward()
- end
- end
- lastCleared = "back"
- end
- function up(times)
- times = times or 1
- for i = 1, times, 1 do
- done = false
- while not done do
- digUp()
- done = turtle.up()
- end
- end
- lastCleared = "bottom"
- end
- function down(times)
- times = times or 1
- for i = 1, times, 1 do
- done = false
- while not done do
- digDown()
- done = turtle.down()
- end
- end
- lastCleared = "top"
- end
Advertisement
Add Comment
Please, Sign In to add comment