Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- **********************************************************************************
- -- **
- -- ** Minecraft Chopping Turtle v1.0 by Psychic__Panda
- -- ** ----------------------------------------------------
- -- **
- -- ** ************************************************************************
- -- ** *** THIS IS THE FIRST RELEASE OF chopit BY Psychic_Panda
- -- ** *** IT WORKS, IT MAY NOT BE VERY EFFICIENT YET
- -- ** *** THE NEXT VERSION IS IN DEVELOPMENT
- -- ** ************************************************************************
- -- **
- -- ** Recommend:
- -- ** 'label set myTurtle' on your turtle so that it saves state when you break it.
- -- **
- -- ** Get code on your turtle:
- -- ** pastebin get 1FdfpCPJ chopit
- -- ** chopit
- -- **
- -- ** Overview:
- -- ** A nearly perpetual logging turtle. This turtle will plant, fertilize, and chop down a specified number of trees,
- -- ** planted in a line in front of and extending to the right of the turtle.
- -- ** When your turtle runs low on fertilizer, saplings, or fuel, it will go get more from specified locations.
- -- ** When its inventory is full, it will dump its inventory into a chest at a specified location.
- -- ** You indicate how many trees to plant and chop down each iteration. After chopping down the trees, the
- -- ** turtle does a sweep of the area sucking up fallen saplings. This is very useful when when you are running a perpetual
- -- ** logging operation, to replenish saplings. If you are using a conveyor belt or slime channel to gather saplings,
- -- ** set enableSweep to false, but leave the sweep radius at its default, otherwise the chests will get in the
- -- ** way.
- -- **
- -- ** Usage:
- -- ** chopit help
- -- ** Print help and exit.
- -- **
- -- ** chopit [plantTrees] [sweepRadius]
- -- ** plantTarget is the target number of trees to plant.
- -- ** If it doesn't have enough saplings the turtle will attempt to get
- -- ** more saplings. It will then plant the number specified or
- -- ** the number of saplings you have (less one to save
- -- ** the place in its inventory) whichever is less. Default is 1 sapling.
- -- ** sweepRadius is the number of spaces around the planted trees the turtle will
- -- ** sweep for fallen saplings. Default is 4.
- -- **
- -- ** Set Up Example:
- -- ** In this example the turtle will plane 1 tree and sweep a radius of 4 around the tree
- -- ** chopping it down. Either of the following commands will work the same:
- -- **
- -- ** chopit
- -- **
- -- ** chopit 1 4
- -- **
- -- ** Inventory
- -- ** Start out with the following items in the following inventory
- -- ** slots:
- -- ** W: one block of wood. This saves the inventory spot for wood.
- -- ** B: A stack of Bonemeal or other fertilizer. The turtle will never use the last one.
- -- ** S: A stack of saplings (preferably Fir, Pine or Spruce that only grow up. (Not oak,
- -- ** eucalyptus, jungle wood, or sequoia!). The turtle will never use the last one.
- -- ** F: A stack of fuel, such as charcoal or coal, much more efficient than wood. The
- -- ** turtle will never use the last one. Recommend charcoal.
- -- **
- -- ** W . . .
- -- ** . . . .
- -- ** . . . .
- -- ** . B S F
- -- **
- -- **
- -- ** Map
- -- ** The turtle starts out at T. It checks for fuel and refuels if necessary. If there is no fuel in
- -- ** its inventory, it tries to get fuel from location F. Note that if the turtle starts out with no
- -- ** fuel in its inventory and no internal fuel it will not be able to get to the fuel barrel.
- -- ** The turtle then tries to plant a sapling. If it has 1 or 0 saplings it will try to get some from
- -- ** location S. It will plant the sapling and try to fertilize it. No fertilizer? It will try
- -- ** to get some from B (B for bonemeal, but it can use any fertilizer. Note that
- -- ** fertilizer doesn't work on rubber trees. If you want to try this with Rubber trees, set enableFertilizer
- -- ** to false.
- -- **
- -- ** . . . . . . . . . .
- -- ** . . . . . . . . . .
- -- ** . . . . . . . . . .
- -- ** . . . . . . . . . .
- -- ** . . . . . X . . . .
- -- ** S . . . . T . . . .
- -- ** B . . . . . . . . .
- -- ** C . . . . . . . . .
- -- ** W . . . . . . . . .
- -- ** F
- -- **
- -- ** Notes:
- -- ** You can set up a transport pipe system to sort the items in the Chest, sending the saplings to the
- -- ** Sapling barrel, and Wood blocks to a Wood Barrel. You can also set up a furnace to create more Charcoal from the
- -- ** Wood blocks, with an Emerald pipe to only take part of the wood, if you have another use for it.
- -- **
- -- ** Works with FTB TechWorld 2 and Minecraft 1.6.4 and later (probably).
- -- **
- -- ** You can change enableSweep in the variables below, as well as StorageX, SaplingY, FertilizerY, ChestY, WoodY, and FuelY
- -- **
- -- *********************************************************************************************************************
- local args = { ... }
- local enableSweep = true
- local StorageX = -4
- local SaplingY = 0
- local FertilizerY = -1
- local ChestY = -2
- local WoodY = -3
- local FuelY = -4
- local FurnaceY = -5
- local FurnaceZ = 1
- local enableFertilizer = true
- local maxTries
- local sleepTime
- if enableFertilizer then
- sleepTime=0.2
- maxTries=5
- else
- maxTries=20
- sleepTime=5
- end
- local blockSlot=1
- local fertilizerSlot=14
- local treeSlot=15
- local fuelSlot=16
- local plantTarget=1
- local plantMax=8
- local fuelMin=500
- local flagFuel=false
- local flagFertilizer=false
- local flagTrees=false
- local sweepRadius=4
- local positionX=0
- local positionY=0
- local positionZ=0
- right="right"
- left="left"
- up="up"
- down="down"
- forward="forward"
- back="back"
- if (#args > 0) then
- if args[1]=="help" then
- print("Usage: chopit [numberTrees] [sweepRadius]");
- print("where [numberTrees} is the number of trees");
- print("to plant each time, default is 1.");
- print("and [sweepRadius} is the number of blocks");
- print("around the tree to sweep for saplings, default is 4.");
- else
- plantTarget = tonumber(args[1])
- if (plantTarget>plantMax) then plantTarget = plantMax end
- end
- end
- if (#args > 1) then sweepRadius= tonumber(args[2]) end
- -- ********************************************************************************** --
- -- Check that turtle has fuel
- -- ********************************************************************************** --
- function doRefuel()
- local fuelLevel = turtle.getFuelLevel()
- print("Fuel level at "..fuelLevel)
- fuelLeft=turtle.getItemCount(fuelSlot)-1
- if ((fuelLevel ~= "unlimited") and (fuelLevel<fuelMin)) then
- if (fuelLeft <= 1) then
- print("Critically low on fuel")
- OK = getFuel()
- if not OK then return false end
- fuelLeft=turtle.getItemCount(fuelSlot)-1
- end
- print("Refuelling")
- turtle.select(fuelSlot)
- turtle.refuel(fuelLeft)
- OK = getFuel()
- else
- print("Plenty of fuel")
- end
- return true
- end
- -- ********************************************************************************** --
- -- Plant trees in a straight line
- -- ********************************************************************************** --
- function doPlant()
- --see if there are enough saplings
- treesLeft = turtle.getItemCount(treeSlot)-1
- if (treesLeft < plantTarget) then
- print("Not enough saplings: "..treesLeft..". Getting saplings")
- if not getTrees() then return false end
- end
- treesLeft = turtle.getItemCount(treeSlot)-1
- if (treesLeft < plantTarget) then
- plantTrees = treesLeft
- else
- plantTrees = plantTarget
- end
- print("Planting "..plantTrees)
- doReturn()
- for thisTree=1,plantTrees do
- turtle.select(treeSlot)
- turtle.place()
- doMove(right)
- end
- return true
- end
- -- ********************************************************************************** --
- -- Grow a Tree
- -- ********************************************************************************** --
- function doGrow()
- for thisTry=1,maxTries do
- if turtle.detectUp() then turtle.digUp() end
- doMove(up)
- if turtle.detect() then
- doMove(down)
- return true
- end
- doMove(down)
- if enableFertilizer then
- fertilizerLeft = turtle.getItemCount(fertilizerSlot)-1
- if (fertilizerLeft<1) then
- print("Out of fertilizer: "..fertilizerLeft)
- print("Getting more.")
- if not getFertilizer(positionX,positionY,positionZ) then return false end
- end
- turtle.select(fertilizerSlot)
- turtle.place()
- end
- sleep(sleepTime)
- end
- return true
- end
- -- ********************************************************************************** --
- -- Chop it down
- -- ********************************************************************************** --
- function doChop()
- --chop it down
- turtle.dig()
- doMove(forward)
- while turtle.detectUp() do
- turtle.digUp()
- doMove(up)
- end
- --go back down to the ground
- doMove(down,positionZ)
- doMove(back)
- doMove(right)
- end
- -- ********************************************************************************** --
- -- Sweep Up any floating saplings
- -- ********************************************************************************** --
- function doSweep()
- doReturn(plantTrees+sweepRadius-1,1-sweepRadius,0)
- thisDirection=-1
- for thisSweep=plantTrees+sweepRadius-1,0-sweepRadius,-1 do
- doReturn(thisSweep,1-(thisDirection*sweepRadius),0)
- thisDirection=thisDirection * -1
- end
- end
- -- ********************************************************************************** --
- -- Get tree saplings from chest or barrel
- -- ********************************************************************************** --
- function getFertilizer(returnToX,returnToY,returnToZ)
- -- Fertilizer Chest should be sweepRadius to the left and back 1 from the origin
- doReturn(StorageX,FertilizerY,0)
- --face the chest to extract
- turtle.turnLeft()
- turtle.select(fertilizerSlot)
- turtle.suck()
- turtle.turnRight()
- doDropOff() -- in case we got too many
- doReturn(returnToX,returnToY,returnToZ)
- return (turtle.getItemCount(fertilizerSlot)>1)
- end
- -- ********************************************************************************** --
- -- Get tree saplings from chest or barrel
- -- ********************************************************************************** --
- function getTrees()
- -- Sapling Chest should be sweepRadius to the left from the origin
- doReturn(StorageX,SaplingY,0)
- --face the chest to extract
- turtle.turnLeft()
- turtle.select(treeSlot)
- turtle.suck()
- turtle.turnRight()
- doDropOff() -- in case we got too many
- doReturn()
- return (turtle.getItemCount(treeSlot)>1)
- end
- -- ********************************************************************************** --
- -- Get fuel from chest or barrel
- -- ********************************************************************************** --
- function getFuel()
- -- Fuel Chest should be sweepRadius to the left, and 6 back from the origin
- doReturn(StorageX,FuelY,0)
- --face the chest to extract
- turtle.turnLeft()
- turtle.select(fuelSlot)
- turtle.suck()
- turtle.turnRight()
- doDropOff() -- in case we got too many
- return (turtle.getItemCount(fuelSlot)>1)
- end
- -- ********************************************************************************** --
- -- Drop Off Stuff in Chest
- -- ********************************************************************************** --
- function doDropOff()
- -- Chest should be sweepRadius to the left, and 2 back from the origin
- doReturn(StorageX,ChestY,0)
- --drop off all but one wood block (for comparison)
- turtle.turnLeft()
- lastSlot=fertilizerSlot
- if enableFertilizer then lastSlot=lastSlot-1 end
- for thisSlot=1,lastSlot do
- turtle.select(thisSlot)
- if (turtle.getItemCount(thisSlot) > 0) then
- if (thisSlot==blockSlot) then
- turtle.drop(turtle.getItemCount(thisSlot)-1)
- else
- turtle.drop()
- end
- end
- end
- turtle.turnRight()
- end
- -- ********************************************************************************** --
- -- Return to starting position
- -- ********************************************************************************** --
- function doReturn(toX,toY,toZ)
- toX=toX or 0
- toY=toY or 0
- toZ=toZ or 0
- --print("At X: "..positionX..", Y: "..positionY..", Z: "..positionZ)
- --print("To: X: "..toX..", Y: "..toY..", Z: "..toZ)
- doMove(right,toX-positionX)
- doMove(forward,toY - positionY)
- doMove(up,toZ - positionZ)
- --print("At X: "..positionX..", Y: "..positionY..", Z: "..positionZ)
- end
- -- ********************************************************************************** --
- -- Move, and keep track or relative position
- -- ********************************************************************************** --
- function doMove(direction,distance)
- -- set defaults
- if (distance==nil) then distance = 1 end
- if (distance==0) then return end
- direction=direction or "none"
- --fix negative distances
- if (distance<0) then
- distance=distance * -1
- if (direction==right) then direction=left
- elseif (direction==left) then direction=right
- elseif (direction==forward) then direction=back
- elseif (direction==back) then direction=forward
- elseif (direction==up) then direction=down
- elseif (direction==down) then direction=up
- end
- end
- -- increase or decrease position with increment
- if ((direction==right) or (direction==up) or (direction==forward)) then
- increment=1
- else
- increment=-1
- end
- --always face forward so that suck works
- --set temporary location to update
- if (direction==right) then
- tmpLocation=positionX
- turtle.turnRight()
- elseif (direction==left) then
- tmpLocation=positionX
- turtle.turnLeft()
- elseif (direction==back) then
- turtle.turnLeft()
- turtle.turnLeft()
- tmpLocation=positionY
- elseif (direction==forward) then
- tmpLocation=positionY
- elseif ((direction==up) or (direction==down)) then
- tmpLocation=positionZ
- else
- print("unknown direction: "..direction)
- return
- end
- --move and update position
- if (direction==up) then
- for d=1,distance do
- turtle.suckUp()
- if turtle.up() then tmpLocation=tmpLocation+increment end
- end
- elseif (direction==down) then
- for d=1,distance do
- turtle.suckDown()
- if turtle.down() then tmpLocation=tmpLocation+increment end
- end
- else
- for d=1,distance do
- turtle.suck()
- if turtle.forward() then tmpLocation=tmpLocation+increment end
- end
- end
- --set the globalposition and face correct direction
- if (direction==right) then
- positionX=tmpLocation
- turtle.turnLeft()
- elseif (direction==left) then
- positionX=tmpLocation
- turtle.turnRight()
- elseif (direction==back) then
- positionY=tmpLocation
- turtle.turnLeft()
- turtle.turnLeft()
- elseif (direction==forward) then
- positionY=tmpLocation
- elseif ((direction==up) or (direction==down)) then
- positionZ=tmpLocation
- end
- end
- -- ********************************************************************************** --
- -- The main loop
- -- ********************************************************************************** --
- OK = true
- while OK do
- OK = doRefuel()
- if OK then
- OK = doPlant()
- doReturn()
- if (OK) then
- for thisTree=1,plantTrees do
- OK = doGrow()
- doChop()
- end
- if enableSweep then doSweep() end
- end
- doDropOff()
- doReturn()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement