This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
ultimate88t's profile picture

Multi-Level Cactus Farm

Started by ultimate88t, 19 April 2014 - 06:31 AM
ultimate88t #1
Posted 19 April 2014 - 08:31 AM
Cactus Farm.

7-Layers

Features:
1. Simple design.
2. Covers a mere 11x11 footprint.
3. Fully automated, no maintenance needed.
4. Doubles as mob farm.

Planned Improvements:
1. Improve code efficiency and clean things up.
2. Add a user interface to select variables such as height.
3. Add refueling of materials capabilities.
4. Session Persist

Known Bugs:
1. Cannot handle mobs that are in the way, will totally screw up the process.
2. Water on top level sometimes has to be manually updated.
3. Does not have a fuel determiner, therefore may run out of fuel.


Video tutorial:
http://youtu.be/JGqFKHczvBA



Pastebin Link: http://pastebin.com/Jdp9gWRW


Disclaimer: This program might appear as it was written by a 5 year old, and I am completely aware that it is inferior to many other programs currently on the market, therefore please excuse my ignorance in coding and give some constructive criticism, have you any.
Edited on 20 April 2014 - 10:12 PM
jakemg #2
Posted 23 April 2014 - 08:55 PM
I like the idea but could you add what slots the materials need to go in? and roughly how much cactus this thing needs but other then that great job

Edit: Im sorry I did not watch the video forget what I said above =D
Edited on 23 April 2014 - 06:58 PM
TheGreekMan2 #3
Posted 18 June 2014 - 05:46 AM
im gonna spend some time cleaning up this code for you hope you dont mind :P/>
TheGreekMan2 #4
Posted 18 June 2014 - 06:10 AM
Spent 10 minutes just cleaning that a little not a huge difference, but now for making the height a variable size, thatll be a little complicated because the way your code is setup

term.clear()
term.setCursorPos(1,1)
x=tonumber(read())

thats how you want to get the input for the variable x which will determine that layers
additionally since as you add layers your distance from the chest changes you want to have another variable thats increased by 1 each layer and will go down by that much based on what layer its on

for example

--x was set to 3 in this case(3 layers) --
local z= 2 -- distance from chest to first layer where the turtle is placing blocks
if ---------------------- code that youll use to distinguish levels--- then
z=z+3 -- or whatever the distance of your levels is







local slot = 1
local turnRight = true
function sort()
  while true do
    for i=1,16 do
	  if turtle.getItemCount(i) > 0 then
		 return turtle.select(i)
	  end
    end
    printError("Out of resources, press a key after a refill.")
    os.pullEvent("key")
  end
end
function line()
sort()
for i=1, 8 do
  turtle.forward()
  turtle.placeDown()
end
sort()
turtle.forward()
turtle.placeDown()
turtle.forward()
sort()
end
function right()
sort()
turtle.turnRight()
for i=1,3 do
   turtle.down()
end
for i=1,3 do
   turtle.placeDown()
   turtle.up()
end
turtle.placeDown()
sort()
end
function forward(x)
   for i = 1, x do
    turtle.forward()
  end
end
function place()
turtle.place()
turtle.up()
turtle.forward()
turtle.select(6)
turtle.place()
turtle.select(1)
turtle.back()
turtle.down()
end

function chest()
turtle.turnRight()
turtle.turnRight()
forward(6)
turtle.turnRight()
forward(4)
dump()
for i =1,6 do
   turtle.suck()
end
for i=1, 4 do
   turtle.back()
end
turtle.turnRight()
forward(6)
end

function ice()
for i=1,3 do
   turtle.up()
end
for i=1, 7 do
  forward(4)
  turtle.turnLeft()
  forward(3)
  place()
  turtle.turnLeft()
  forward(8)
  turtle.turnRight()
  place()
  turtle.turnLeft()
  turtle.turnLeft()
  forward(6)
  place()
  turtle.turnLeft()
  forward(8)
  turtle.turnRight()
  place()
  turtle.turnLeft()
  turtle.turnLeft()
  forward(3)
  turtle.turnLeft()
  forward(4)
  turtle.turnRight()
  turtle.turnRight()
  for i=1, 4 do
    turtle.up()
  end
end
for i=1,4 do
   turtle.down()
end

end
function sandblock()
for i=1, 3 do
  turtle.place()
  turtle.back()
  turtle.back()
end
turtle.place()
end
function cactusblock()
for i=1, 3 do
  turtle.placeDown()
  turtle.back()
  turtle.back()
end
turtle.placeDown()
turtle.back()
end
 
 
function sand()
turtle.select(2)
turtle.turnRight()
forward(3)
turtle.turnLeft()
forward(2)
sandblock()
turtle.turnLeft()
forward(2)
turtle.turnLeft()
turtle.back()
turtle.back()
sandblock()
turtle.turnRight()
forward(2)
turtle.turnRight()
turtle.back()
turtle.back()
sandblock()
turtle.turnLeft()
forward(2)
turtle.turnLeft()
turtle.back()
turtle.back()
sandblock()
turtle.turnLeft()
forward(3)
turtle.turnRight()
forward(4)
end
function sandd()
turtle.select(3)
turtle.turnRight()
forward(3)
turtle.turnLeft()
forward(2)
sandblock()
turtle.turnLeft()
forward(2)
turtle.turnLeft()
turtle.back()
turtle.back()
sandblock()
turtle.turnRight()
forward(2)
turtle.turnRight()
turtle.back()
turtle.back()
sandblock()
turtle.turnLeft()
forward(2)
turtle.turnLeft()
turtle.back()
turtle.back()
sandblock()
turtle.turnLeft()
forward(3)
turtle.turnRight()
forward(4)
end
function cactus()
turtle.select(4)
turtle.turnLeft()
turtle.up()
turtle.up()
forward(3)
turtle.turnLeft()
forward(3)
cactusblock()
turtle.turnLeft()
forward(2)
turtle.turnLeft()
turtle.back()
cactusblock()
turtle.turnRight()
forward(2)
turtle.turnRight()
turtle.back()
cactusblock()
turtle.turnLeft()
forward(2)
turtle.turnLeft()
turtle.back()
cactusblock()
turtle.turnLeft()
forward(3)
turtle.turnRight()
forward(4)
for i=1,6 do
   turtle.down()
end
end
function ground()
forward(5)
turtle.turnRight()
forward(5)
turtle.turnLeft()
turtle.down()
turtle.digDown()
for i=1, 26 do
  turtle.down()
  turtle.digDown()
end
turtle.down()
end
function dump()
for i = 16,1,-1 do
  turtle.select(i)
  turtle.dropDown()
end
end
function cactuss()
turtle.select(5)
turtle.turnLeft()
turtle.up()
turtle.up()
forward(3)
turtle.turnLeft()
forward(3)
cactusblock()
turtle.turnLeft()
forward(2)
turtle.turnLeft()
turtle.back()
cactusblock()
turtle.turnRight()
forward(2)
turtle.turnRight()
turtle.back()
cactusblock()
turtle.turnLeft()
forward(2)
turtle.turnLeft()
turtle.back()
cactusblock()
turtle.turnLeft()
forward(3)
turtle.turnRight()
forward(4)
for i =1, 6 do
   turtle.down()
end
end

function center()
for j = 1, 9, 1 do
 
   for i = 1, 9, 1 do
  if turtle.getItemCount(slot) == 0 then
    slot = slot + 1
    turtle.select(slot)
    turtle.digDown()
    turtle.placeDown()
  else
   turtle.digDown()
    turtle.placeDown()
  end
   
  if i < 9 then
   turtle.dig()
    turtle.forward()
  end
 
   end
 
   if j < 9 then
 
  if turnRight == true then
    turtle.turnRight()
    turtle.dig()
    turtle.forward()
    turtle.turnRight()
    turnRight = false
  else
    turtle.turnLeft()
    turtle.dig()
    turtle.forward()
    turtle.turnLeft()
    turnRight = true
  end
   
   end
end
end

function blocks()
sort()
turtle.turnLeft()
turtle.forward()
turtle.forward()
turtle.turnLeft()
turtle.up()
turtle.up()
turtle.up()
turtle.forward()
turtle.placeDown()
turtle.forward()
turtle.forward()
turtle.placeDown()
turtle.forward()
turtle.forward()
turtle.placeDown()
turtle.forward()
turtle.forward()
turtle.placeDown()
turtle.turnRight()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.turnRight()
turtle.placeDown()
turtle.forward()
turtle.forward()
turtle.placeDown()
turtle.forward()
turtle.forward()
turtle.placeDown()
turtle.forward()
turtle.forward()
turtle.placeDown()
turtle.turnLeft()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.turnLeft()
turtle.down()
turtle.down()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.turnRight()
turtle.turnRight()
sort()
end




for i=1, 7 do
if turtle.getItemCount(slot) == 1 then
    slot = slot + 1
    turtle.select(slot)
    turtle.digDown()
    turtle.placeDown()
  else
   
turtle.up()
turtle.placeDown()
turtle.up()
turtle.placeDown()
turtle.up()
turtle.placeDown()
turtle.up()
turtle.placeDown()
line()
right()
line()
right()
line()
right()
line()
turtle.back()
turtle.turnRight()
turtle.forward()
turtle.down()
center()
blocks()
end
end
ground()
chest()
ice()
for i=1,4 do
  sand()
  cactus()
end
for i=1, 3 do
sandd()
cactuss()
end




If i confused you let me know :P/> good luck and cool code
Ziriee #5
Posted 18 June 2014 - 05:17 PM

function forwards()
  while not turtle.forward() do
    turtle.attack()
  end
end
Example how to make the turtle not get stuck at mobs