Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -----------------
- --Name: miningLIB
- --Version: 1.0.0
- --Requires: riewestLIB
- --By: Riewest (AKA Riewest14)
- -----------------
- os.loadAPI("riewestLIB")
- lib = riewestLIB
- function test()
- --strip(10, true, false, 15)
- branchMine(10, 2, 2, true, false, 15)
- lib.turnAround()
- 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, fuelSlot, chestSlot)
- 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
- if not fuelSlot then
- fuelSlot = false
- end
- if not chestSlot then
- chestSlot = false
- end
- local count = 0
- local lengthLeft = length
- for i = 1, length do
- if count > 10 then
- count = 0
- end
- if lengthLeft < spaceBet then
- strip(lengthLeft, false, fuelSlot, chestSlot)
- break
- end
- local moved = strip(spaceBet + 1, false, fuelSlot, chestSlot)
- i = i + moved
- count = count + math.fmod(moved, 10)
- lengthLeft = lengthLeft - moved
- turtle.turnLeft()
- local s1 = strip(branchLength, true, fuelSlot, chestSlot)
- local s2 = strip(branchLength, true, fuelSlot, chestSlot)
- count = count + (math.fmod(s1, 10) + math.fmod(s2, 10))
- print("Count: " .. count)
- doChestG(chestSlot, count, 10, fuelSlot)
- turtle.turnRight()
- end
- if retStart then
- lib.turnAround()
- lib.tMoveF(length)
- 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
- function doChest(chestSlot, dist, interval, fuelSlot)
- if chestSlot and (math.fmod(dist, interval) == 0) and (turtle.getItemCount(chestSlot) > 0 ) then
- local oldSlot = turtle.getSelectedSlot()
- turtle.select(chestSlot)
- local chestData = turtle.getItemDetail()
- turtle.placeUp()
- local slotsToKeep = {chestSlot}
- if fuelSlot then
- lib.sortItem(fuelSlot)
- table.insert(slotsToKeep, fuelSlot)
- end
- lib.emptyInvExcept(slotsToKeep, "top")
- turtle.select(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(chestSlot, dist, interval, fuelSlot)
- if not chestSlot then
- return
- end
- if dist > interval then
- dist = interval
- end
- doChest(chestSlot, dist, interval, fuelSlot)
- 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, fuelSlot, chestSlot)
- if not length then
- length = 5
- end
- if not retStart then
- retStart = false
- end
- if not chestSlot then
- chestSlot = false
- end
- if not fuelSlot then
- fuelSlot = false
- end
- for i = 1, length do
- lib.tMoveF()
- turtle.digUp()
- turtle.digDown()
- if fuelSlot then
- lib.tRefuel(fuelSlot)
- end
- doChest(chestSlot, i, 10, fuelSlot)
- end
- if retStart then
- lib.turnAround()
- lib.tMoveF(length)
- end
- return length
- end
- test()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement