add cached item.has_tag, block.has_tag & update docs
This commit is contained in:
parent
185b6cc661
commit
19acda1a88
@ -68,6 +68,9 @@ block.get_variant(x: int, y: int, z: int) -> int
|
|||||||
|
|
||||||
-- Sets the block variant by index
|
-- Sets the block variant by index
|
||||||
block.set_variant(x: int, y: int, z: int, index: int) -> int
|
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
|
## Rotation
|
||||||
|
|||||||
@ -33,4 +33,7 @@ item.emission(itemid: int) -> str
|
|||||||
|
|
||||||
-- Returns the value of the `uses` property
|
-- Returns the value of the `uses` property
|
||||||
item.uses(itemid: int) -> int
|
item.uses(itemid: int) -> int
|
||||||
|
|
||||||
|
-- Checks if an item has specified tag
|
||||||
|
item.has_tag(itemid: int, tag: str) -> bool
|
||||||
```
|
```
|
||||||
|
|||||||
@ -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.set_variant(x: int, y: int, z: int, index: int) -> int
|
||||||
|
|
||||||
|
-- Проверяет наличие тега у блока
|
||||||
|
block.has_tag(id: int, tag: str) -> bool
|
||||||
```
|
```
|
||||||
|
|
||||||
### Raycast
|
### Raycast
|
||||||
|
|||||||
@ -33,6 +33,9 @@ item.emission(itemid: int) -> str
|
|||||||
|
|
||||||
-- Возвращает значение свойства `uses`
|
-- Возвращает значение свойства `uses`
|
||||||
item.uses(itemid: int) -> int
|
item.uses(itemid: int) -> int
|
||||||
|
|
||||||
|
-- Проверяет наличие тега у предмета
|
||||||
|
item.has_tag(itemid: int, tag: str) -> bool
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -12,22 +12,31 @@ local names = {
|
|||||||
for name, _ in pairs(user_props) do
|
for name, _ in pairs(user_props) do
|
||||||
table.insert(names, name)
|
table.insert(names, name)
|
||||||
end
|
end
|
||||||
-- remove undefined properties
|
|
||||||
for id, blockprops in pairs(block.properties) do
|
-- remove undefined properties and build tags set
|
||||||
for propname, value in pairs(blockprops) do
|
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
|
if not table.has(names, propname) then
|
||||||
blockprops[propname] = nil
|
props[propname] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
props.tags_set = tags_set
|
||||||
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
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
process_properties(block.properties)
|
||||||
|
process_properties(item.properties)
|
||||||
|
|
||||||
local function make_read_only(t)
|
local function make_read_only(t)
|
||||||
setmetatable(t, {
|
setmetatable(t, {
|
||||||
__newindex = function()
|
__newindex = function()
|
||||||
@ -57,6 +66,15 @@ local function cache_names(library)
|
|||||||
function library.index(name)
|
function library.index(name)
|
||||||
return indices[name]
|
return indices[name]
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
cache_names(block)
|
cache_names(block)
|
||||||
|
|||||||
@ -61,7 +61,7 @@ std::unique_ptr<Content> ContentBuilder::build() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
blockDefsIndices.push_back(&def);
|
blockDefsIndices.push_back(&def);
|
||||||
groups->insert(def.defaults.drawGroup); // FIXME
|
groups->insert(def.defaults.drawGroup); // FIXME: variants
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<ItemDef*> itemDefsIndices;
|
std::vector<ItemDef*> itemDefsIndices;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user