Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -----------------
- --Name: miningLIB
- --Version: 1.0.0
- --Requires: riewestLIB 1.1.0
- --By: Riewest (AKA Riewest14)
- -----------------
- os.loadAPI("riewestLIB")
- lib = riewestLIB
- --junk item array
- junkItems = {"stone", "gravel", "dirt", "sand"}
- function test()
- local keepSlots = {}
- keepSlots.fuelSlot = 16
- keepSlots.chestSlot = 15
- addSlotskeepSlots
- --strip(10, true, false, 15)
- branchMine(10, 2, 2, true, true)
- --lib.turnAround()
- --dropJunk()
- end
- --slotsToKeep
- --just calls the function
- --from riewestLIB
- function addSlots(keepSlots)
- if not keepSlots then
- return
- end
- lib.addSlots(keepSlots)
- end
- --Veinmine the block in front
- --Returning to the starting position
- function veinMine()
- --TODO
- end
- --Does a branch mine
- --Length: length of the mine
- --spaceBet: space between branches
- --branchLength: length of branches
- --retStart: returns to start if true
- --chestSlot: if not nil will dump items
- -- into that chest
- --fuelSlot: slot to attempt refueling
- -- from if not nil
- function branchMine(length, spaceBet, branchLength, retStart, dropjunk)
- if not length then
- length = 15
- end
- if not spaceBet then
- spaceBet = 1
- end
- if not branchLength then
- branchLength = 5
- end
- if not retStart then
- retStart = false
- end
- local count = 0
- local lengthLeft = length
- for i = 1, length do
- if count > 100 then
- count = 0
- end
- if lengthLeft < spaceBet then
- strip(lengthLeft)
- break
- end
- local moved = strip(spaceBet + 1)
- i = i + moved
- count = count + math.fmod(moved, 100)
- lengthLeft = lengthLeft - moved
- turtle.turnLeft()
- local s1 = strip(branchLength, true)
- local s2 = strip(branchLength, true)
- count = count + (math.fmod(s1, 100) + math.fmod(s2, 100))
- print("Count: " .. count)
- doChestG(count, 100, dropjunk)
- turtle.turnRight()
- end
- if retStart then
- lib.turnAround()
- lib.tMoveF(length)
- end
- end
- --Drops junk items
- function dropJunk()
- for k, v in pairs(junkItems) do
- lib.dropItem(v, "bottom")
- end
- end
- --Method to check if chest should be
- --placed above and empty the inventory
- --chestSlot: slot the chest is in if nil
- -- will not empty inventory
- --dist: Distance the turtle has traveled
- --interval: interval inventory should
- -- be checked
- --fuelSlot: optional fuelslot
- --dropjunk: drops the junk items
- function doChest(dist, interval, dropjunk)
- if lib.slotsToKeep.chestSlot and (math.fmod(dist, interval) == 0) and (turtle.getItemCount(lib.slotsToKeep.chestSlot) > 0 ) then
- local oldSlot = turtle.getSelectedSlot()
- turtle.select(lib.slotsToKeep.chestSlot)
- local chestData = turtle.getItemDetail()
- lib.tMoveU()
- turtle.digUp()
- lib.tMoveD()
- while not turtle.placeUp() do
- turtle.digUp()
- sleep(.1)
- end
- if lib.slotsToKeep.fuelSlot then
- lib.sortItem(lib.slotsToKeep.fuelSlot)
- end
- if dropjunk then
- dropJunk()
- end
- lib.emptyInvExcept("top")
- turtle.select(lib.slotsToKeep.chestSlot)
- if not (chestData.name == "minecraft:chest") then
- while not turtle.digUp() do
- sleep(.1)
- end
- end
- turtle.select(oldSlot)
- end
- end
- --Slight variation on do chest where
- -- it does the function if blocks
- -- moved is greater than chest interval
- -- takes same parameters
- function doChestG(dist, interval, dropjunk)
- if not lib.slotsToKeep.chestSlot then
- return
- end
- if dist > interval then
- dist = interval
- end
- doChest(dist, interval, dropjunk)
- end
- --Mine a 1b wide 3b tall tunnel
- --for length passed. Returns to
- -- the start if retStart is true
- -- chestSlot: if not nil will dump items
- -- into that chest
- -- fuelSlot: if not nill will refuel from
- -- that slot.
- function strip(length, retStart, dropjunk)
- if not length then
- length = 5
- end
- if not retStart then
- retStart = false
- end
- for i = 1, length do
- lib.tMoveF()
- turtle.digUp()
- turtle.digDown()
- if lib.slotsToKeep.fuelSlot then
- lib.tRefuel(lib.slotsToKeep.fuelSlot)
- end
- doChest( i, 100, dropjunk)
- end
- if retStart then
- lib.turnAround()
- lib.tMoveF(length)
- end
- return length
- end
- test()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement