add cached item.has_tag, block.has_tag & update docs

This commit is contained in:
MihailRis 2025-08-31 12:55:02 +03:00
parent 185b6cc661
commit 19acda1a88
6 changed files with 43 additions and 13 deletions

View File

@ -68,6 +68,9 @@ block.get_variant(x: int, y: int, z: int) -> int
-- Sets the block variant by index
block.set_variant(x: int, y: int, z: int, index: int) -> int
-- Checks if an block has specified tag
block.has_tag(id: int, tag: str) -> bool
```
## Rotation

View File

@ -33,4 +33,7 @@ item.emission(itemid: int) -> str
-- Returns the value of the `uses` property
item.uses(itemid: int) -> int
-- Checks if an item has specified tag
item.has_tag(itemid: int, tag: str) -> bool
```

View File

@ -67,6 +67,9 @@ block.get_variant(x: int, y: int, z: int) -> int
-- Устанавливает вариант блока по индексу
block.set_variant(x: int, y: int, z: int, index: int) -> int
-- Проверяет наличие тега у блока
block.has_tag(id: int, tag: str) -> bool
```
### Raycast

View File

@ -33,6 +33,9 @@ item.emission(itemid: int) -> str
-- Возвращает значение свойства `uses`
item.uses(itemid: int) -> int
-- Проверяет наличие тега у предмета
item.has_tag(itemid: int, tag: str) -> bool
```

View File

@ -12,22 +12,31 @@ local names = {
for name, _ in pairs(user_props) do
table.insert(names, name)
end
-- remove undefined properties
for id, blockprops in pairs(block.properties) do
for propname, value in pairs(blockprops) do
if not table.has(names, propname) then
blockprops[propname] = nil
end
end
end
for id, itemprops in pairs(item.properties) do
for propname, value in pairs(itemprops) do
if not table.has(names, propname) then
itemprops[propname] = nil
-- remove undefined properties and build tags set
local function process_properties(properties)
for id, props in pairs(properties) do
local tags_set = nil
for propname, value in pairs(props) do
if propname == "tags" then
if #value > 0 then
tags_set = tags_set or {}
end
for _, tag in ipairs(value) do
tags_set[tag] = true
end
end
if not table.has(names, propname) then
props[propname] = nil
end
end
props.tags_set = tags_set
end
end
process_properties(block.properties)
process_properties(item.properties)
local function make_read_only(t)
setmetatable(t, {
__newindex = function()
@ -57,6 +66,15 @@ local function cache_names(library)
function library.index(name)
return indices[name]
end
function library.has_tag(id, tag)
local tags_set = library.properties[id].tags_set
if tags_set then
return tags_set[tag]
else
return false
end
end
end
cache_names(block)

View File

@ -61,7 +61,7 @@ std::unique_ptr<Content> ContentBuilder::build() {
}
blockDefsIndices.push_back(&def);
groups->insert(def.defaults.drawGroup); // FIXME
groups->insert(def.defaults.drawGroup); // FIXME: variants
}
std::vector<ItemDef*> itemDefsIndices;