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

turtle.inspect() mining

Started by Games_Arsenal96, 11 May 2017 - 07:39 AM
Games_Arsenal96 #1
Posted 11 May 2017 - 09:39 AM
I am trying to currently code a working efficient mine straight down, but I can't get the code working for the block blacklists


--Once the code starts working I will add a fuel check
local b=0
local ignore={"minecraft:dirt","minecraft:stone","minecraft:cobblestone","minecraft:gravel","minecraft:sand"}
local function valuable()
success,data=turtle.inspect()
for k,v in pairs(ignore) do
  if v~=data.name then
   return true
  else
   return false
  end
end
end
local function checkSurroundings()
for I=1,4 do
  if valuable() then
   turtle.dig()
  end
  turtle.turnLeft()
end
end
for I=1,2 do
turtle.digDown()
turtle.down()
b=b+1
end
turtle.select(15)
turtle.placeUp() --Place cobblestone over entry hole
turtle.select(1)
while true do
turtle.digDown()
if turtle.down() then
  b=b+1
else
  for I=1,b do
   b=b-1
  end
end
checkSurroundings()

end

Can you amazing people help me?

Minecraft version: 1.7.10 (Just incase the mod changed in versions)
Lupus590 #2
Posted 11 May 2017 - 04:45 PM

local function valuable()
success,data=turtle.inspect()
for k,v in pairs(ignore) do
  if v~=data.name then
   --# don't return, let the loop continue
  else
	 return false
  end
end
return true --# loop ended,
end

there is a more efficient way to do this though

local ignore={["minecraft:dirt"] = true,["minecraft:stone"] = true,["minecraft:cobblestone"] = true,["minecraft:gravel"] = true,["minecraft:sand"] = true}
--# set the ignores as the keys, then for quick access trick later
local function valuable()
success,data=turtle.inspect()
  if ignore[data.name] then --# quick access trick: we have the name of the block now, if it's in the list we will get true for the if
   return false
  else
   return true
  end
end

Edited on 11 May 2017 - 02:46 PM
Games_Arsenal96 #3
Posted 11 May 2017 - 07:16 PM
Oh I see it only went through the iterator once because it returned a value?
Lupus590 #4
Posted 11 May 2017 - 09:16 PM
Oh I see it only went through the iterator once because it returned a value?

correct
Games_Arsenal96 #5
Posted 11 May 2017 - 09:23 PM
I am trying to make the same code Ben did for his lets play of ComputerCraft challenge but to use inspect instead of certain blocks in slots?

I got it working now I just need to work on the fuel check