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

[Lua][Question] Is there a way for Turtle to detect lava?

Started by PyromancerVx, 21 April 2012 - 08:27 AM
PyromancerVx #1
Posted 21 April 2012 - 10:27 AM
I'm designing my own small turtle API thing. And I need to know if there is a way for a turtle to detect if there is lava or water below, in front, or on top? And if yes then how?
Advert #2
Posted 21 April 2012 - 11:05 AM
You can't detect a specific block with turtles, unless they have one of those in it's inventory. You could try putting water/lava blocks in the inventory and comparing, but I think the damage values of flowing water/lava will break it.
PyromancerVx #3
Posted 21 April 2012 - 11:10 AM
Ok, thanks for a quick answer
OminousPenguin #4
Posted 21 April 2012 - 06:14 PM
detect will return false for lava and water, but dig() will return true and remove the block but it will not be added to the inventory.(This applies to flowing and source)
Using this information you can detect water and lava (but you won't know which)

Turtles are immune to lava, flowing or source.
Inksaver #5
Posted 24 May 2014 - 08:00 PM
Sorry to drag an old post to the front again, but this no longer applies in cc 1.6.3


turtle.detect() = false
turtle.dig() = false

This applies to flowing and source blocks
:(/>

Edit:
After some experimenting:
Place the turtle immediately above water
Select an empty slot

turtle.detectDown() = false -- no block below
turtle.compare() = true --assuming air in front of the turtle
turtle.compareDown() = false --assuming water below
turtle.compareUp() = true -- assuming air above the turtle

From this we conclude that an empty turtle slot contains air
:)/>
Function to check for liquid

function checkWater(direction)
local result = false
local slotNo = 0

for i = 1, 16 do
  if turtle.getItemCount(i) == 0 then
   slotNo = i
   break
  end
end
if slotNo > 0 then
  turtle.select(slotNo)
  if direction == "down" then
   if not turtle.detectDown() then
    if not turtle.compareDown() then --no block detected, but does not compare to air(empty slot)
	 result = true
    end
   end
  elseif direction == "up" then
   if not turtle.detectUp() then
    if not turtle.compareUp() then
	 result = true
    end
   end
  elseif direction == "forward" then
   if not turtle.detect() then
    if not turtle.compare() then
	 result = true
    end
   end
  end
end

return result --true if water, (or lava)
end
Edited on 24 May 2014 - 07:28 PM
Tenket #6
Posted 08 July 2014 - 03:02 AM
Thats a neat way to do it.

But the difference between water and lava is that sucking up lava increaces your fuel level.
As long as you dont mind destroying the lava, such as in the case of the nether or fuel collection programs. Then it's fine.