Update 0.27 docs (#484)

* update doc/*/scripting/builtins/libinventory.md

* add doc/*/scripting/builtins/libgfx-weather.md

* update doc/*/scripting/builtins/libfile.md

* update doc/*/item-properties & update doc/*/scripting/builtins/libinventory.md

* add inventory.decrement docs

* update doc/*/scripting/builtins/libinventory.md
This commit is contained in:
MihailRis
2025-03-16 20:10:41 +03:00
committed by GitHub
parent a74a4fcf53
commit b1e854a73c
10 changed files with 358 additions and 2 deletions
+20
View File
@@ -144,3 +144,23 @@ file.prefix(path: str) --> str
```
Extracts the entry point (prefix) from the path. Example: `world:data/base/config.toml` -> `world`.
```lua
file.parent(path: str) --> str
```
Returns the path one level up. Example: `world:data/base/config.toml` -> `world:data/base`
```lua
file.path(path: str) --> str
```
Removes the entry point (prefix) from the path. Example: `world:data/base/config.toml` -> `data/base/config.toml`
```lua
file.join(directory: str, path: str) --> str
```
Joins the path. Example: `file.join("world:data", "base/config.toml)` -> `world:data/base/config.toml`.
You should use this function instead of concatenating with `/`, since `prefix:/path` is not valid.
@@ -0,0 +1,53 @@
# *gfx.weather* library
A library for managing audio/visual weather effects.
Weather settings:
| Property | Description | Default |
| ------------ | ------------------------------ | ------- |
| fall | Precipitation (see table 2) | {} |
| clouds | Cloudiness [0.0, 1.0] | 0.0 |
| fog_opacity | Maximum fog density [0.0, 1.0] | 0.0 |
| fog_dencity | Fog density | 1.0 |
| fog_curve | Fog curve | 1.0 |
| thunder_rate | Thunder rate [0.0, 1.0] | 0.0 |
Precipitation:
| Property | Description | Default |
| ------------- | -------------------------------------------- | ------- |
| texture | Precipitation texture | "" |
| noise | Precipitation noise | "" |
| vspeed | Precipitation vertical speed | 1.0 |
| hspeed | Maximum horizontal speed of precipitation | 0.1 |
| scale | Precipitation UV scale | 0.1 |
| min_opacity | Minimum alpha multiplier for precipitation | 0.0 |
| max_opacity | Maximum alpha multiplier for precipitation | 1.0 |
| max_intensity | Maximum precipitation intensity | 1.0 |
| opaque | Disable precipitation translucency | false |
| splash | Precipitation splash particle settings table | {} |
```lua
-- Smoothly switches weather
gfx.weather.change(
-- weather settings table
weather: table,
-- weather change duration in seconds
time: number,
-- weather preset name
[optional] name: str
)
-- Returns weather preset name
gfx.weather.get_current() -> str
-- Returns a copy of the weather settings table
gfx.weather.get_current_data() -> table
-- Returns the current precipitation intensity
gfx.weather.get_fall_intensity() -> number
-- Checks if weather is currently switching
gfx.weather.is_transition() -> bool
```
+91 -1
View File
@@ -12,7 +12,7 @@ inventory.get(
) -> int, int
-- Returns item ID and count.
-- Set slot content.
-- Set slot content, deleting the data contained before.
inventory.set(
-- inventory ID
invid: int,
@@ -24,6 +24,27 @@ inventory.set(
count: int
)
-- Sets the count of items in the slot without affecting the data if the argument is non-zero.
inventory.set_count(
-- inventory ID
invid: int,
-- slot index
slot: int,
-- item count
count: int
)
-- Checks for the presence of a local property by name without copying its value.
-- Preferably for tables, but not primitive types.
inventory.has_data(
-- inventory ID
invid: int,
-- slot index
slot: int,
-- property name
name: str
) -> bool
-- Returns inventory size (slots number).
-- Throws an exception if there's no inventory having specified ID.
inventory.size(invid: int) -> int
@@ -63,6 +84,53 @@ inventory.remove(invid: int)
> [!WARNING]
> Unbound inventories will be deleted on world close.
Local properties of an item are data attached to the last item in the stack.
When splitting the stack (RMB), the data is not copied but moved to a new stack.
Properties can be of any serializable type, including tables.
Unlike block fields, property names do not need to be registered in the item definition.
The combination of
```lua
inventory.get(...)
inventory.get_all_data(...)
inventory.set(...)
inventory.set_all_data(...)
```
for moving is inefficient, use inventory.move or inventory.move_range.
```lua
-- Returns a copy of value of a local property of an item by name or nil.
inventory.get_data(
-- inventory ID
invid: int,
-- slot index
slot: int,
-- property name
name: str
) -> any
-- Sets the value of a local property of an item by name.
-- Nil value removes the property.
inventory.set_data(
-- inventory ID
invid: int,
-- slot index
slot: int,
-- property name
name: str
-- value
value: any
)
-- Returns a copy of the table of all local item properties.
inventory.get_all_data(
-- inventory ID
invid: int,
-- slot index
slot: int,
) -> table
```
```lua
-- Create inventory. Returns the created ID.
inventory.create(size: int) -> int
@@ -87,4 +155,26 @@ inventory.move(
rangeBegin: int,
[optional] rangeEnd: int
)
-- Decreases the item count in the slot by 1.
inventory.decrement(
-- inventory id
invid: int,
-- slot index
slot: int,
-- count to subtract
[optional] count: int = 1
)
-- Decreases the remaining uses counter / durability of an item,
-- creating a local `uses` property if none.
-- Removes one item from the slot when the counter reaches zero.
-- Does nothing if the `uses` property is not specified in the item's JSON.
-- See [property `uses`](../../item-properties.md#number-of-uses-durability---uses)
inventory.use(
-- inventory id
invid: int,
-- slot index
slot: int
)
```