Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---------------------------------------
- -- Sandai's NeoMiner --
- -- "It's not a bug, it's a feature!" --
- ---------------------------------------
- local program_version = "0.1"
- local min_torch_distance = 6
- local whitelisted_items_fuel = {
- -- Fuel items
- "minecraft:coal",
- "minecraft:blaze_rod",
- "minecraft:lava_bucket",
- }
- local whitelisted_items_misc = {
- -- misc items
- "minecraft:torch",
- "minecraft:chest"
- }
- function is_fuel_item_whitelisted(item_id) -- returns true if the item given is in the whitelisted list
- for current_item in whitelisted_items_fuel do
- if item_id == current_item then
- return true
- else
- return false
- end
- end
- end
- function is_misc_item_whitelisted(item_id) -- returns true if the item given is in the whitelisted list
- for current_item in whitelisted_items_misc do
- if item_id == current_item then
- return true
- else
- return false
- end
- end
- end
- function refuel_turtle()
- for i = 1, 16 do -- For slot 1 to 16...
- turtle.select(i) -- Select slot
- if turtle.getItemCount() > 0 then -- if there is an item there...
- if is_item_whitelisted(turtle.getItemDetail(i).name) == true then -- If the item is whitelisted...
- turtle.refuel()
- print("[INFO]: The turtle has been refueled!")
- break
- end
- elseif i == 16 then
- print("[WARN]: No fuel found !")
- break
- end
- end
- end
- function break_3x3()
- -- breaks a 3x3 area of blocks in front of it,
- -- We're assuming that the turtle is in the middle-ground block
- turtle.dig()
- turtle.forward()
- for i=1,3 do -- Each iteration is 1x3 blocks
- turtle.turnLeft()
- turtle.dig()
- turtle.turnRight()
- turtle.turnRight()
- turtle.dig()
- turtle.turnLeft()
- turtle.up()
- end
- turtle.down()
- turtle.down() -- The turtle is now on the ground. (middle-ground block)
- end
- function check_if_turtle_full()
- -- Scans the inventory, if it's full, then it will place a chest
- -- Then dump all of it's items in it
- if turtle.getItemCount(15) > 0 then -- If the slot 15 has an item, then...
- -- We scan the inventory for chests
- for i=1,16 do
- if turtle.getItemDetail(i).name == "minecraft:chest" then -- If a chest was detected...
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.forward()
- turtle.turnRight()
- turtle.turnRight()
- turtle.up()
- turtle.select(i)
- turtle.placeDown() -- Place the chest down
- for item=1,16 do -- Drop all items without whitelisted ones
- turtle.select(item)
- if is_fuel_item_whitelisted(turtle.getItemDetail(item).name) == true then
- -- If the current item is whitelisted, do nothing
- elseif is_misc_item_whitelisted(turtle.getItemDetail(item).name) == true then
- -- If the current item is whitelisted, do nothing
- else
- -- The item is not whitelisted
- turtle.dropDown()
- end
- turtle.forward()
- turtle.down()
- end
- else
- print("==> There is no chests in the inventory!")
- end
- end
- end
- end
- function drop_all_cobblestone()
- for i=1,16 do
- if turtle.getItemDetail(i).name == "minecraft:cobblestone" then -- If the item is cobblestone, then...
- turtle.select(i)
- turtle.dropDown()
- end
- end
- end
- function place_torch() -- The turtle will place a torch in the upper-right block (wall side)
- -- Here we're assuming that the turtle is on the middle-ground block.
- turtle.up()
- turtle.turnRight()
- for item=1,16 do -- Loops through the inventory to search for torches.
- if turtle.getItemDetail(item).name == "minecraft:torch" then -- If the item is a torch
- turtle.select(item)
- turtle.place() -- Place the torch on the wall
- end
- end
- turtle.turnLeft()
- turtle.down()
- end
- function main()
- -- Starting point of the program
- print("Sandai's NeoMiner [v"..program_version.."]")
- print("Number of blocks to mine : ")
- local blocks_to_mine = read().tonumber() -- cast the user's input to int
- local actual_torch_distance = 0 -- The actual distance to the nearest torch
- print("[INSTRUCTIONS] :")
- print("==> Items to have : chest, torches, coal/charcoal")
- print("==> Items MUST be in the first slots of the turtle!")
- print("Press [ENTER] to start mining...")
- read()
- for mining_status=1,blocks_to_mine do
- term.setCursorPos(1,1)
- term.clear()
- print("[STATUS] : Mining...")
- print("[MINING_STATUS]: ["..mining_status.."/"..blocks_to_mine.."] blocks")
- break_3x3() -- breaks a 3x3 area of blocks, then return at the middle-ground block.
- if turtle.getFuelLevel() <= 100 then -- if fuel level is behind 100 then refuel the turtle.
- refuel_turtle()
- end
- drop_all_cobblestone()
- check_if_turtle_full()
- refuel_turtle()
- if actual_torch_distance >= min_torch_distance then -- If we need to place a torch...
- place_torch()
- actual_torch_distance = 0
- end
- actual_torch_distance = actual_torch_distance + 1
- end
- print("Done!")
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement