Here's a function I wrote to get details of either a slot or block. It also uses the "name" to create a "mod" and "nickname" results.
function getDetails(slot) --returns details about that slot or block
if slot=="down" or slot=="bottom" then
result,details=turtle.inspectDown(slot)
elseif slot=="up" or slot=="top" then
result,details=turtle.inspectUp(slot)
elseif slot=="forward" or slot=="front" then
result,details=turtle.inspect(slot)
elseif
type(slot)~="number" then print("your getDetails arguement is not recognized")
elseif type(slot)=="number" and math.floor(slot)>0 and math.floor(slot)<17 then
details=turtle.getItemDetail(slot)
else
print("your getDetails arguement is not between 1 and 16")
end
if details then --delete this 'if' statement if you don't want nickname and mod
details.mod=string.sub(details.name,1,string.find(details.name,":")-1)
details.nickname=string.sub(details.name,string.find(details.name,":")+1)
end
if details then --delete this 'if' statement if you don't want it printed in the terminal
print("name: "..details.name)
if details.metadata then print("metadata: "..details.metadata) end
if details.damage then print("damage: "..details.damage) end
if details.nickname then print("nickname: "..details.nickname) end
if details.mod then print("mod: "..details.mod) end
if details.count then print("item count: "..details.count) end
else
print("ERROR")
end
return details
end
info=getDetails(7) --this is how you call the function and save the data
If your turtle is in front of a tree and you call this function with: info=getDetails("front") then you will see info printed on the terminal and you will get:
info.name="minecraft:log"
info.metadata=0
info.nickname="log"
info.mod="minecraft"
If you call this function with 64 red wool in slot 7: info=getDetails(7) then you get:
info.name="minecraft:wool"
info.damage=14
info.nickname="wool"
info.mod="minecraft"
info.count=64
I'm new to coding so there may be better ways to do what I'm doing but at least this works most of the time. It doesn't tell you if your slot is empty or if there is air where you are checking- that could be room for improvement.
Hope this helps.
-BOOYAAH