SHOW:
|
|
- or go back to the newest paste.
1 | - | --"Lumberjack Turtle" v1.1 |
1 | + | --"Lumberjack Turtle" v2.4-dev |
2 | - | -- Coded by: Jeff "Deczx" Kloos |
2 | + | -- Author: Daniele "Raniel" Sabre |
3 | - | -- -------READ BELOW FOR INSTRUCTIONS-------- |
3 | + | |
4 | - | -- This is a program that makes a ComputerCraft Mine Turtle chop down trees for you. It is fully automatic and replants after chopping the tree down. |
4 | + | -- configuration |
5 | - | -- Video tutorial: youtube.com/VideoURL |
5 | + | woodToUseForFuel = 1 -- higher number = less wood produced but more sustain (set 0 to deactivate) |
6 | - | -- Quick start: The way you have to set it up is pretty simple. Put a chest in the ground and place the turtle on top. Put a sapling of your choice in front of the turtle. Put a single block of the corresponding wood in the 4th inventory slot of the turtle (top-right). Now put some saplings in the 16th inventory slot (bottom-right) for the turtle to replant. Fuel up the turtle, run the program and voila! |
6 | + | minFuelRequired = 20 |
7 | wait = 5 | |
8 | slotWood = 1 | |
9 | - | print("Well I'm a lumberjack and I'm OK! ^.^") |
9 | + | slotsBoneMeal = {5, 6, 7, 8} |
10 | slotsSaplings = {9, 10, 11, 12} | |
11 | - | turtle.select(4) |
11 | + | slotCompare = 16 |
12 | ||
13 | - | while turtle.getFuelLevel() > 64 do -- If the Fuel gets below 64 the loop stops. |
13 | + | print("Lumberjack started") |
14 | - | -- You can change this, of course. |
14 | + | |
15 | - | while turtle.compare(4) == true do --Here, the turtle looks for the sapling to turn |
15 | + | |
16 | - | sleep(5) --into the woodblock. |
16 | + | turtle.select(slotCompare) |
17 | - | end |
17 | + | |
18 | counterLoop = 0 | |
19 | - | turtle.select(1) |
19 | + | continue = true |
20 | - | turtle.dig() --If it sees that the sapling is a woodblock it |
20 | + | |
21 | - | turtle.forward(1) --will start cutting the tree down. |
21 | + | while turtle.getFuelLevel() > minFuelRequired and continue do -- if the fuel gets below the loop stops |
22 | - | print("Aye! ^o^7") |
22 | + | -- increment counter |
23 | counterLoop = counterLoop + 1 | |
24 | - | while turtle.detectUp() == true do --The turtle will keep going up until there are no |
24 | + | |
25 | - | turtle.digUp() --more blocks above him. |
25 | + | -- compare the sapling with the block in front of the turtle |
26 | - | turtle.up(1) |
26 | + | while turtle.compare() do |
27 | - | end |
27 | + | -- bone meal action |
28 | for k, v in pairs(slotsBoneMeal) do | |
29 | - | while turtle.down() == true do --Then it will go down. |
29 | + | data = turtle.getItemDetail(v) |
30 | - | end |
30 | + | |
31 | if data then | |
32 | - | turtle.back() --Until it hits the ground. |
32 | + | if data.name == "minecraft:dye" then |
33 | - | turtle.select(16) --Then it will replant a sapling and put the wood |
33 | + | turtle.select(v) |
34 | - | turtle.place() --in a chest below. |
34 | + | turtle.place() |
35 | - | turtle.select(1) |
35 | + | turtle.select(slotCompare) |
36 | - | turtle.dropDown() |
36 | + | |
37 | - | turtle.select(4) |
37 | + | break |
38 | - | print("Hard Work Makes Me Sleepy! XoX <<ZZzzz>>.") --Then the turtle will go back to sleep mode. |
38 | + | end |
39 | end | |
40 | end | |
41 | - | print("So Hungry. -o-") --If the turtle runs out of fuel, it will print |
41 | + | |
42 | - | -- a message and terminate the program. |
42 | + | sleep(wait) |
43 | end | |
44 | ||
45 | -- init procedure to get wood from tree | |
46 | turtle.select(slotWood) | |
47 | turtle.dig() | |
48 | turtle.forward() | |
49 | ||
50 | -- the turtle will keep going up until there are no more blocks above him | |
51 | while turtle.detectUp() == true do | |
52 | turtle.digUp() | |
53 | turtle.up() | |
54 | end | |
55 | ||
56 | -- go down | |
57 | while turtle.down() == true do | |
58 | end | |
59 | ||
60 | -- until it hits the ground | |
61 | turtle.back() | |
62 | ||
63 | -- place a new sapling | |
64 | found = false | |
65 | for k, v in pairs(slotsSaplings) do | |
66 | data = turtle.getItemDetail(v) | |
67 | ||
68 | if data.name == "minecraft:sapling" then | |
69 | turtle.select(v) | |
70 | turtle.place() | |
71 | found = true -- sapling found | |
72 | ||
73 | break | |
74 | end | |
75 | end | |
76 | ||
77 | -- if no sapling are found this is the last cycle | |
78 | if not found then | |
79 | continue = false | |
80 | end | |
81 | ||
82 | -- select the slot of the wood | |
83 | turtle.select(1) | |
84 | ||
85 | -- use of wood to refuel turtle | |
86 | if woodToUseForFuel > 0 then | |
87 | turtle.refuel(woodToUseForFuel) | |
88 | end | |
89 | ||
90 | turtle.dropDown() -- dropDown the remain woods | |
91 | ||
92 | -- reselect slot compare | |
93 | turtle.select(slotCompare) | |
94 | ||
95 | print("Cycle "..counterLoop.." completed") | |
96 | end | |
97 | ||
98 | -- if the turtle runs out of fuel, it will print a message and terminate the program | |
99 | print("Empty fuel or saplings not found") |