From ba55e4286f14c49291d94ae58f6bdf2f93635468 Mon Sep 17 00:00:00 2001 From: Johannes Fritz Date: Mon, 27 Jun 2022 16:29:06 -0500 Subject: [PATCH] Remove image stack wieldview: code review improvment --- mods/ITEMS/mcl_maps/init.lua | 3 +- mods/ITEMS/mcl_shields/init.lua | 4 +-- mods/PLAYER/mcl_wieldview/README.txt | 9 +++--- mods/PLAYER/mcl_wieldview/init.lua | 41 ++++++++++++++++------------ 4 files changed, 31 insertions(+), 26 deletions(-) diff --git a/mods/ITEMS/mcl_maps/init.lua b/mods/ITEMS/mcl_maps/init.lua index 890635722..7b22ffef1 100644 --- a/mods/ITEMS/mcl_maps/init.lua +++ b/mods/ITEMS/mcl_maps/init.lua @@ -227,8 +227,7 @@ filled_wield_def.drawtype = "mesh" filled_wield_def.node_placement_prediction = "" filled_wield_def.range = minetest.registered_items[""].range filled_wield_def.on_place = mcl_util.call_on_rightclick -filled_wield_def.groups.no_wieldview = 1 -filled_wield_def._wieldview_item = "mcl_maps:filled_map" +filled_wield_def._mcl_wieldview_item = "mcl_maps:filled_map" for _, texture in pairs(mcl_skins.list) do local def = table.copy(filled_wield_def) diff --git a/mods/ITEMS/mcl_shields/init.lua b/mods/ITEMS/mcl_shields/init.lua index eb7d45ff9..3ad2ada51 100644 --- a/mods/ITEMS/mcl_shields/init.lua +++ b/mods/ITEMS/mcl_shields/init.lua @@ -31,12 +31,12 @@ minetest.register_tool("mcl_shields:shield", { shield = 1, weapon = 1, enchantability = -1, - no_wieldview = 1, offhand_item = 1, }, sound = {breaks = "default_tool_breaks"}, _repair_material = "group:wood", wield_scale = vector.new(2, 2, 2), + _mcl_wieldview_item = "", }) local function wielded_item(obj, i) @@ -438,7 +438,6 @@ for _, colortab in pairs(mcl_banners.colors) do shield = 1, weapon = 1, enchantability = -1, - no_wieldview = 1, not_in_creative_inventory = 1, offhand_item = 1, }, @@ -446,6 +445,7 @@ for _, colortab in pairs(mcl_banners.colors) do _repair_material = "group:wood", wield_scale = vector.new(2, 2, 2), _shield_color = colortab[4], + _mcl_wieldview_item = "", }) local banner = "mcl_banners:banner_item_" .. color diff --git a/mods/PLAYER/mcl_wieldview/README.txt b/mods/PLAYER/mcl_wieldview/README.txt index 660974f9b..b6de5b208 100644 --- a/mods/PLAYER/mcl_wieldview/README.txt +++ b/mods/PLAYER/mcl_wieldview/README.txt @@ -1,4 +1,4 @@ -[mod] visible wielded items [wieldview] +[mod] visible wielded items [mcl_wieldview] ======================================= Makes hand wielded items visible to other players. @@ -7,6 +7,7 @@ Makes hand wielded items visible to other players. Info for modders ################ -Add an item to the "no_wieldview" group with a rating of 1 and it will not be shown by the wieldview. -If an item has the "no_wieldview" group rating of 1, the item definition can specify the property "_wieldview_item". -"_wieldview_item" should be set to an item name that will be shown by the wieldview instead of the item. +Register an item with the property "_mcl_wieldview_item" to change the third person wield view appearance of the item. +"_mcl_wieldview_item" should be set to an item name that will be shown by the wield view instead of the item. +If you use an empty string, nothing will be shown. + diff --git a/mods/PLAYER/mcl_wieldview/init.lua b/mods/PLAYER/mcl_wieldview/init.lua index 947c2fdce..b09543844 100644 --- a/mods/PLAYER/mcl_wieldview/init.lua +++ b/mods/PLAYER/mcl_wieldview/init.lua @@ -1,5 +1,3 @@ -local get_item_group = minetest.get_item_group - minetest.register_on_joinplayer(function(player) if not player or not player:is_player() then return @@ -12,31 +10,38 @@ minetest.register_on_joinplayer(function(player) end) minetest.register_entity("mcl_wieldview:wieldnode", { - visual = "wielditem", - physical = false, - pointable = false, - collide_with_objects = false, - static_save = false, - visual_size = {x = 0.21, y = 0.21}, + initial_properties = { + hp_max = 1, + visual = "wielditem", + physical = false, + textures = {""}, + automatic_rotate = 1.5, + is_visible = true, + pointable = false, + collide_with_objects = false, + static_save = false, + collisionbox = {-0.21, -0.21, -0.21, 0.21, 0.21, 0.21}, + selectionbox = {-0.21, -0.21, -0.21, 0.21, 0.21, 0.21}, + visual_size = {x = 0.21, y = 0.21}, + }, + on_step = function(self) - if not self._wielder or not self._wielder:is_player() then - self.object:remove() - end local player = self._wielder + if not player or not player:is_player() then + self.object:remove() + return + end + local item = player:get_wielded_item():get_name() if item == self._item then return end self._item = item - if get_item_group(item, "no_wieldview") ~= 0 then - local def = player:get_wielded_item():get_definition() - if def and def._wieldview_item then - item = def._wieldview_item - else - item = "" - end + local def = player:get_wielded_item():get_definition() + if def and def._mcl_wieldview_item then + item = def._mcl_wieldview_item end local item_def = minetest.registered_items[item]