Remove image stack wieldview: code review improvment

This commit is contained in:
Johannes Fritz 2022-06-27 16:29:06 -05:00
parent 587f9be4d7
commit ba55e4286f
4 changed files with 31 additions and 26 deletions

View File

@ -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)

View File

@ -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

View File

@ -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.

View File

@ -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]