Update 'Turtle/Turtle.lua'
This commit is contained in:
parent
7e8e495ee2
commit
57e08dcf07
@ -83,3 +83,73 @@ function Turtle:reverseArray(a)
|
|||||||
end
|
end
|
||||||
return a2
|
return a2
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Turtle:isInInv(item, update)
|
||||||
|
assert(type(item) == "string", "item must be a string")
|
||||||
|
self:assertInvUpdate(update)
|
||||||
|
|
||||||
|
local tag = self:resolveTag(item)
|
||||||
|
if (tag == "") then
|
||||||
|
for i = 1, 16 do
|
||||||
|
if self:checkItemName(item, i) == true then return true end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
for i = 1, 16 do
|
||||||
|
if self:checkItemTag(tag, i) == true then return true end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
function Turtle:resolveTag(item)
|
||||||
|
local tag = ""
|
||||||
|
if (item == "sapling") then
|
||||||
|
tag = "minecraft:saplings"
|
||||||
|
elseif (item == "log" or item == "wood") then
|
||||||
|
tag = "minecraft:logs"
|
||||||
|
elseif (item == "coal") then
|
||||||
|
tag = "minecraft:coals"
|
||||||
|
elseif (item == "seed") then
|
||||||
|
tag = "forge:seeds"
|
||||||
|
end
|
||||||
|
return tag
|
||||||
|
end
|
||||||
|
|
||||||
|
function Turtle:checkItemName(name, slot)
|
||||||
|
assert(type(name) == "string", "tag must be a string")
|
||||||
|
assert(type(slot) == "number" and slot > 0 and slot <= 16, "slot must be between 1 and 16")
|
||||||
|
if self.inv[slot] == nil then
|
||||||
|
self:log("self.inv is empty at slot "..tostring(slot))
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
if self.inv[slot].name == nil then
|
||||||
|
self:log("no name found")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
if name == "any" then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
if self.inv[slot].name == name then
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Turtle:checkItemTag(tag, slot)
|
||||||
|
assert(type(tag) == "string", "tag must be a string")
|
||||||
|
assert(type(slot) == "number" and slot > 0 and slot <= 16, "slot must be between 1 and 16")
|
||||||
|
if self.inv[slot] == nil then
|
||||||
|
self:log("self.inv is empty at slot "..tostring(slot))
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
if self.inv[slot].tags == nil then
|
||||||
|
self:log("no tags found")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
if self.inv[slot].tags[tag] == true then
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user