Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function step(n)
- for i=1,n or 1 do
- while not turtle.forward() do
- if turtle.getFuelLevel() == 0 then
- turtle.refuel()
- elseif turtle.detect() then
- turtle.dig()
- else
- turtle.attack()
- end
- end
- end
- return true
- end
- local function stepUp(n)
- for i=1,n or 1 do
- while not turtle.up() do
- if turtle.getFuelLevel() == 0 then
- turtle.refuel()
- elseif turtle.detectUp() then
- turtle.digUp()
- else
- turtle.attackUp()
- end
- end
- end
- return true
- end
- local function stepDown(n)
- for i=1,n or 1 do
- while not turtle.down() do
- if turtle.getFuelLevel() == 0 then
- turtle.refuel()
- elseif turtle.detectDown() then
- turtle.digDown()
- else
- turtle.attackDown()
- end
- end
- end
- return true
- end
- local containers = {["minecraft:chest"]=true,
- ["minecraft:dispenser"]=true,
- ["minecraft:hopper"]=true,
- ["minecraft:dropper"]=true,
- ["minecraft:furnace"]=true,
- ["minecraft:lit_furnace"]=true,
- ["minecraft:ender_chest"]=true,
- ["EnderStorage:enderChest"]=true}
- local inspections = {turtle.inspectUp,turtle.inspect,turtle.inspectDown}
- local sideNames = {"top","front","bottom"}
- local function dropC(n)
- local d,b = turtle.inspectUp()
- if d and containers[b.name] then
- turtle.dropUp(n or 64)
- end
- d,b = turtle.inspectUp()
- if d and containers[b.name] then
- turtle.drop(n or 64)
- end
- d,b = turtle.inspectDown()
- if d and containers[b.name] then
- turtle.dropDown(n or 64)
- end
- end
- local function suckC(n)
- local d,b = turtle.inspectUp()
- if d and containers[b.name] then
- turtle.suckUp(n or 64)
- end
- d,b = turtle.inspect()
- if d and containers[b.name] then
- turtle.suck(n or 64)
- end
- d,b = turtle.inspectDown()
- if d and containers[b.name] then
- turtle.suckDown(n or 64)
- end
- end
- local movingDir = step
- local running = true
- local repeatSpot = false
- local function fuelFurnace(meta,side)
- if side == "front" then
- turtle.drop(8)
- turtle.turnRight()
- step()
- turtle.turnLeft()
- repeatSpot = true
- end
- end
- local actions = {
- ["minecraft:cobblestone"]=turtle.turnLeft,
- ["minecraft:planks"]=turtle.turnRight,
- ["minecraft:wool"]=function(color)
- turtle.select(color+1)
- end,
- ["minecraft:log"] = function()
- local h=0
- while turtle.detect() do
- turtle.dig()
- turtle.digUp()
- stepUp()
- h = h + 1
- end
- stepDown(h)
- step(2)
- local s = turtle.getSelectedSlot()
- for i=1,16 do
- if turtle.getItemCount(i) > 0 and turtle.getItemDetail(i).name =="minecraft:sapling" then
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.select(i)
- turtle.place()
- turtle.turnLeft()
- turtle.turnLeft()
- break
- end
- end
- repeatSpot = true
- turtle.select(s)
- end,
- ["minecraft:wooden_button"]=function()
- local s = turtle.getSelectedSlot()
- for i=1,16 do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- dropC()
- end
- end
- turtle.select(s)
- end,
- ["minecraft:sandstone"]=function(meta)
- if meta == 0 then
- local s = turtle.getSelectedSlot()
- for i=1,16 do
- if turtle.getItemCount(i) == 0 then
- turtle.select(i)
- break
- end
- end
- suckC(1)
- local tn = turtle.getItemDetail() and turtle.getItemDetail().name
- dropC(1)
- for i=1,16 do
- if turtle.getItemCount(i) > 0 and turtle.getItemDetail(i).name == tn then
- turtle.select(i)
- dropC()
- end
- end
- turtle.select(s)
- elseif meta == 1 then
- dropC(1)
- else
- dropC()
- end
- end,
- ["minecraft:stonebrick"]=function(meta)
- if meta == 0 then
- local s = turtle.getSelectedSlot()
- for i=1,16 do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- suckC()
- end
- end
- turtle.select(s)
- elseif meta == 3 then
- suckC(1)
- else
- suckC()
- end
- end,
- ["minecraft:crafting_table"]= function() turtle.craft() end,
- ["minecraft:wooden_slab"]=function() sleep(10) end,
- ["minecraft:double_wooden_slab"]=function() sleep(300) end,
- ["minecraft:glass"]=function()
- if movingDir == step then
- if not turtle.detectDown() then
- movingDir = stepDown
- elseif not turtle.detectUp() then
- movingDir = stepUp
- end
- else
- movingDir = step
- end
- end,
- ["minecraft:fence"]=function()
- if turtle.detect() then
- turtle.dig()
- end
- turtle.place()
- end,
- ["minecraft:cobblestone_wall"]=function()
- if turtle.detectDown() then
- turtle.digDown()
- end
- turtle.placeDown()
- end,
- ["minecraft:stone_slab"]=function(meta)
- if meta >=8 then
- turtle.select((turtle.getSelectedSlot()+14) % 16 + 1)
- else
- turtle.select(turtle.getSelectedSlot() % 16 + 1)
- end
- end,
- ["minecraft:redstone_block"]=function()
- if turtle.getItemCount() == 0 then
- movingDir()
- end
- end,
- ["minecraft:noteblock"]=function(n,side)
- rs.setOutput(side,true)
- sleep(0.2)
- rs.setOutput(side,false)
- sleep(0.2)
- end,
- ["minecraft:stone_stairs"]=function()
- if turtle.getItemSpace(16) > 0 then
- turtle.dig()
- repeatSpot = true
- end
- end,
- ["minecraft:coal_block"]=function()
- turtle.refuel()
- end,
- ["minecraft:stained_glass"]=function(meta)
- turtle.transferTo(meta+1,1)
- end,
- ["minecraft:stained_glass_pane"]=function(meta)
- turtle.transferTo(meta+1)
- end,
- ["minecraft:furnace"]=fuelFurnace,
- ["minecraft:lit_furnace"]=fuelFurnace,
- }
- while running do
- for side,inspection in ipairs(inspections) do
- local detect,blockTable = inspection()
- if detect and actions[blockTable.name] then
- actions[blockTable.name](blockTable.metadata,sideNames[side])
- if repeatSpot then
- break
- end
- end
- end
- if not repeatSpot then
- movingDir()
- end
- repeatSpot = false
- end
Advertisement
Add Comment
Please, Sign In to add comment