From 45099ae25acabcea585437fbb4d9a6ee0f2d63e8 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Thu, 30 Mar 2017 06:02:54 +0200 Subject: [PATCH] Mod-defined wield item transformation w/ group --- wieldview/README.txt | 8 ++++++++ wieldview/init.lua | 11 +++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/wieldview/README.txt b/wieldview/README.txt index cffae46..977afcc 100644 --- a/wieldview/README.txt +++ b/wieldview/README.txt @@ -13,3 +13,11 @@ wieldview_update_time = 2 # Show nodes as tiles, disabled by default wieldview_node_tiles = false + +Info for modders +################ + +Wield image transformation: To apply a simple transformation to the item in +hand, add the group “wieldview_transform” to the item definition. The group +rating equals one of the numbers used for the [transform texture modifier +of the Lua API. diff --git a/wieldview/init.lua b/wieldview/init.lua index 7a5a619..8fcf001 100644 --- a/wieldview/init.lua +++ b/wieldview/init.lua @@ -29,8 +29,15 @@ wieldview.get_item_texture = function(self, item) texture = minetest.inventorycube(minetest.registered_items[item].tiles[1]) end end - if wieldview.transform[item] then - texture = texture.."^[transform"..wieldview.transform[item] + -- Get item image transformation, first from group, then from transform.lua + local transform = minetest.get_item_group(item, "wieldview_transform") + if transform == 0 then + transform = wieldview.transform[item] + end + if transform then + -- This actually works with groups ratings because transform1, transform2, etc. + -- have meaning and transform0 is used for identidy, so it can be ignored + texture = texture.."^[transform"..tostring(transform) end end return texture