Skip to content

Add texture modifier rendering itemstacks#17133

Open
Kindaglia wants to merge 2 commits into
luanti-org:masterfrom
Kindaglia:drawers-inventory-entity
Open

Add texture modifier rendering itemstacks#17133
Kindaglia wants to merge 2 commits into
luanti-org:masterfrom
Kindaglia:drawers-inventory-entity

Conversation

@Kindaglia
Copy link
Copy Markdown

  • Goal of the PR
    Add a server-side Lua API to generate accurate inventory preview textures
    for any item, so mods like drawers can display correct 2D icons of
    complex nodes (stairs, slabs, nodeboxes, meshes) on world entities.

  • How does the PR work?
    New Lua function core.get_item_inventory_texture(itemname) returns a
    virtual texture string [inventorypreview:<base64 itemstring>]. On the
    client, the texture source recognises this prefix, decodes the itemstring,
    and renders the item through the same drawItemStack pipeline used by
    the 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 },
})

@Kindaglia
Copy link
Copy Markdown
Author

@appgurueu
Copy link
Copy Markdown
Contributor

appgurueu commented Apr 25, 2026

Documentation is missing. No option to render to a desired resolution (64x64 is hardcoded) is also odd.

Add a server-side Lua API to generate accurate inventory preview textures for any item

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.

@appgurueu appgurueu changed the title Add inventory preview texture API Add texture modifier rendering itemstacks Apr 25, 2026
@Zughy Zughy added Action / change needed Code still needs changes (PR) / more information requested (Issues) Roadmap: Needs approval The change is not part of the current roadmap and needs to be approved by coredevs beforehand Feature ✨ PRs that add or enhance a feature labels Apr 25, 2026
- 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
@Kindaglia
Copy link
Copy Markdown
Author

@appgurueu thanks for the review! Here's my plan:

  1. Documentation — I'll add docs for both the [inventorypreview: texture modifier and core.get_item_inventory_texture() in doc/lua_api.md.

  2. Resolution — I'll make the modifier support an optional :WxH suffix, e.g. [inventorypreview:<base64>:128x128, and add an optional size parameter (default 64) to core.get_item_inventory_texture(itemstring[, size]).

  3. Comparison with your Item render-to-texture: Texture modifier, speedup #10570 — I chose base64-encoded itemstrings to avoid the : delimiter ambiguity you encountered and to support item metadata. Perhaps [inventorypreview:<base64>[:WxH] is reasonable syntax? Let me know what you think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Action / change needed Code still needs changes (PR) / more information requested (Issues) @ Client rendering Feature ✨ PRs that add or enhance a feature Roadmap: Needs approval The change is not part of the current roadmap and needs to be approved by coredevs beforehand @ Script API Textures

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nodes aren't correctly displayed in the drawer front.

3 participants