Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ACCEPTABLE_FUEL = {"minecraft:coal"}
- FUEL_COUNT = -1
- FUEL_INDEX = -1
- TORCHES_INDEX = -1
- TORCHES_COUNT = -1
- TORCHES_CURRENT = 0
- TORCHES_DISTANCE = 15
- ACCEPTABLE_BLOCKS = {"minecraft:cobblestone", "minecraft:cobbled_deepslate", "minecraft:tuff", "minecraft:granite", "minecraft:andesite", "minecraft:diorite", "minecraft:dirt", "minecraft:sandstone"}
- DUMP_BLOCKS = {"minecraft:gravel", "minecraft:sand", "minecraft:flint"}
- BLOCK_INDEX = -1
- BLOCK_COUNT = 0
- DUMP_TRASH = true
- -- Utilities
- function arrHasValue(arr, val)
- for index, value in ipairs(arr) do
- if value == val then
- return true
- end
- end
- return false
- end
- -- Fuel
- function hasFuel()
- return FUEL_COUNT > 0
- end
- function shouldRefuel()
- return turtle.getFuelLevel() <= 0
- end
- function refuel()
- if shouldRefuel() == true then
- if hasFuel() ~= true then
- return false
- end
- turtle.select(1)
- turtle.refuel(1)
- FUEL_COUNT = FUEL_COUNT - 1
- end
- return true
- end
- -- Torches
- function canUseTorches()
- return TORCHES_INDEX ~= -1
- end
- function hasTorches()
- return TORCHES_COUNT > 0
- end
- function shouldPlaceTorch()
- return TORCHES_CURRENT == TORCHES_DISTANCE
- end
- function placeTorch()
- turtle.select(TORCHES_INDEX)
- turnAround()
- turtle.place()
- turnAround()
- end
- function handleTorches()
- if TORCHES_COUNT == 0 then
- TORCHES_INDEX = -1
- end
- if canUseTorches() == true then
- if hasTorches() == true then
- if shouldPlaceTorch() then
- placeTorch()
- TORCHES_CURRENT = 0
- else
- TORCHES_CURRENT = TORCHES_CURRENT + 1
- end
- return true
- else
- return false
- end
- end
- return true
- end
- -- Blocks
- function hasBlocks()
- return BLOCK_COUNT > 0
- end
- function findBlocks()
- for i=1, 16 do
- turtle.select(i)
- local curr_slot_data = getSlotData(i)
- if curr_slot_data ~= nil then
- if arrHasValue(ACCEPTABLE_BLOCKS, curr_slot_data["name"]) then
- BLOCK_INDEX = i
- BLOCK_COUNT = curr_slot_data["count"]
- return true
- end
- end
- end
- return false
- end
- function handleBlocks()
- if BLOCK_INDEX == -1 or BLOCK_COUNT == 0 then
- if findBlocks() == false then
- return
- end
- end
- local has_block, data = turtle.inspectDown()
- if has_block == false then
- turtle.select(BLOCK_INDEX)
- turtle.placeDown()
- BLOCK_COUNT = BLOCK_COUNT - 1
- else
- if data["name"] == "minecraft:lava" or data["name"] == "minecraft:water" then
- turtle.select(BLOCK_INDEX)
- turtle.placeDown()
- BLOCK_COUNT = BLOCK_COUNT - 1
- end
- end
- end
- -- Movement
- function turnAround()
- turtle.turnLeft()
- turtle.turnLeft()
- end
- -- Inventory
- function getSlotData(index)
- turtle.select(index)
- local slotData = turtle.getItemDetail()
- return slotData
- end
- function getSlotName(index)
- local data = getSlotData(index)
- if data ~= nil then
- return data["name"]
- end
- return nil
- end
- function getSlotCount(index)
- local data = getSlotData(index)
- if data ~= nil then
- return data["count"]
- end
- return -1
- end
- function slotHasItem(index)
- local data = getSlotData(index)
- return data ~= nil
- end
- function inventoryFull()
- for i=1, 16 do
- turtle.select(i)
- local curr_slot_data = getSlotData(i)
- if curr_slot_data == nil then
- return false
- end
- end
- return true
- end
- function main()
- -- Setup
- for i=1, 16 do
- local curr_slot_data = getSlotData(i)
- if curr_slot_data ~= nil then
- if FUEL_INDEX == -1 then
- if arrHasValue(ACCEPTABLE_FUEL, curr_slot_data["name"]) then
- FUEL_INDEX = i
- FUEL_COUNT = curr_slot_data["count"]
- end
- end
- if TORCHES_INDEX == -1 then
- if curr_slot_data["name"] == "minecraft:torch" then
- TORCHES_INDEX = i
- TORCHES_COUNT = curr_slot_data["count"]
- end
- end
- end
- end
- if FUEL_INDEX == -1 then
- print("No fuel!")
- return
- end
- print("Fuel Index: " .. FUEL_INDEX)
- print("Torch Index: " .. TORCHES_INDEX)
- -- Loop
- while true do
- if refuel() == false then
- print("Ran out of fuel!")
- return
- end
- if inventoryFull() == true then
- print("Inventory full!")
- if DUMP_TRASH == true then
- local items_dumped = false
- turnAround()
- for i=1,16 do repeat
- if i == BLOCK_INDEX or i == TORCHES_DISTANCE or i == FUEL_INDEX then
- do break end
- end
- local data = getSlotData(i)
- if data ~= nil then
- if arrHasValue(ACCEPTABLE_BLOCKS, data["name"]) == true then
- turtle.select(i)
- turtle.drop()
- items_dumped = true
- elseif arrHasValue(DUMP_BLOCKS, data["name"]) == true then
- turtle.select(i)
- turtle.drop()
- items_dumped = true
- end
- end
- until true end
- turnAround()
- if items_dumped == false then
- return
- end
- else
- return
- end
- end
- turtle.select(1)
- turtle.dig()
- handleTorches()
- turtle.forward()
- handleBlocks()
- turtle.digUp()
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement