Add texture modifier rendering itemstacks#17133
Conversation
|
drawer mod fixed here https://github.com/Kindaglia/drawers/tree/simplify-visual-rendering |
|
Documentation is missing. No option to render to a desired resolution (64x64 is hardcoded) is also odd.
To be precise, this is not what this is. This is effectively a texture modifier so clients can generate the proper texture (same as my PR #10570 back in the day, might want to compare), plus a convenience API wrapper to build this texture modifier. |
- Support optional :WxH suffix in [inventorypreview:*] modifier (default 64x64, clamp 16-512) - Add optional size parameter to core.get_item_inventory_texture() - Document both the texture modifier and Lua function in lua_api.md
|
@appgurueu thanks for the review! Here's my plan:
|
Goal of the PR
Add a server-side Lua API to generate accurate inventory preview textures
for any item, so mods like
drawerscan display correct 2D icons ofcomplex nodes (stairs, slabs, nodeboxes, meshes) on world entities.
How does the PR work?
New Lua function
core.get_item_inventory_texture(itemname)returns avirtual texture string
[inventorypreview:<base64 itemstring>]. On theclient, the texture source recognises this prefix, decodes the itemstring,
and renders the item through the same
drawItemStackpipeline used bythe inventory GUI, producing an accurate 2D snapshot.
Does it resolve any reported issue?
Yes, fixes Nodes aren't correctly displayed in the drawer front. minetest-mods/drawers#60
Does this relate to a goal in the roadmap?
Not directly, but it improves the modding API and enables better visual
fidelity for entity-based storage mods.
If not a bug fix, why is this PR needed? What usecases does it solve?
Without this API, mods can only approximate inventory icons using
[inventorycube], which produces incorrect results for stairs, slabs,walls, and other non-fullblock nodes. This prevents drawer/barrel/crate
mods from showing recognisable item previews on their entities.
If you have used an LLM/AI to help with code or assets, you must disclose this.
Yes -- this PR was created with assistance from opencode + GPT 5.5 xhigh
To do
This PR is Ready for Review.
How to test
.. code-block:: lua
local texture = core.get_item_inventory_texture("mcl_stairs:stair_oak")
local obj = minetest.add_entity(pos, "drawers:drawer")
obj:set_properties({
visual = "upright_sprite",
textures = { texture },
})