Optimization of inventory list handling

This commit is contained in:
MoNTE48 2020-02-07 18:05:23 +01:00
parent b03e048710
commit 17a53a0101
5 changed files with 6 additions and 7 deletions

View File

@ -178,7 +178,7 @@ armor.update_armor = function(self, player)
state = state + stack:get_wear() state = state + stack:get_wear()
count = count + 1 count = count + 1
if stack:get_count() == 0 then if stack:get_count() == 0 then
local desc = minetest.registered_items[item].description local desc = minetest.registered_tools[item].description
if name and desc then if name and desc then
minetest.chat_send_player(name, Sl("Your @1 got destroyed!", desc)) minetest.chat_send_player(name, Sl("Your @1 got destroyed!", desc))
end end

View File

@ -21,7 +21,7 @@ minetest.register_on_joinplayer(function(player)
local name = player:get_player_name() local name = player:get_player_name()
local armor_inv = minetest.create_detached_inventory(name .. "_armor", { local armor_inv = minetest.create_detached_inventory(name .. "_armor", {
allow_put = function(_, _, index, stack) allow_put = function(_, _, index, stack)
local item = minetest.registered_items[stack:get_name()] local item = minetest.registered_tools[stack:get_name()]
if not item or not item.groups then if not item or not item.groups then
return 0 return 0
end end

View File

@ -12,7 +12,7 @@ function default.register_torch(name, def)
oldnode.name = name or name .. "_wall" or name .. "_celling" oldnode.name = name or name .. "_wall" or name .. "_celling"
minetest.add_item(pos, ItemStack(oldnode)) minetest.add_item(pos, ItemStack(oldnode))
-- Play flame-extinguish sound if liquid is not an 'igniter' -- Play flame-extinguish sound if liquid is not an 'igniter'
local nodedef = minetest.registered_items[newnode.name] local nodedef = minetest.registered_nodes[newnode.name]
if not (nodedef and nodedef.groups and if not (nodedef and nodedef.groups and
nodedef.groups.igniter and nodedef.groups.igniter > 0) then nodedef.groups.igniter and nodedef.groups.igniter > 0) then
minetest.sound_play( minetest.sound_play(

View File

@ -7,7 +7,7 @@ fire = {}
-- Flood flame function -- Flood flame function
local function flood_flame(pos, _, newnode) local function flood_flame(pos, _, newnode)
-- Play flame extinguish sound if liquid is not an 'igniter' -- Play flame extinguish sound if liquid is not an 'igniter'
local nodedef = minetest.registered_items[newnode.name] local nodedef = minetest.registered_nodes[newnode.name]
if not (nodedef and nodedef.groups and if not (nodedef and nodedef.groups and
nodedef.groups.igniter and nodedef.groups.igniter > 0) then nodedef.groups.igniter and nodedef.groups.igniter > 0) then
minetest.sound_play("fire_extinguish_flame", minetest.sound_play("fire_extinguish_flame",

View File

@ -130,11 +130,10 @@ minetest.register_on_dieplayer(function(player)
local inv = player:get_inventory() local inv = player:get_inventory()
-- Drop inventory items -- Drop inventory items
for i = 1, inv:get_size("main") do for _, stack in pairs(inv:get_list("main")) do
local stack = inv:get_stack("main", i)
minetest.item_drop(stack, nil, pos) minetest.item_drop(stack, nil, pos)
inv:set_stack("main", i, nil)
end end
inv:set_list("main", {})
-- Display death coordinates -- Display death coordinates
minetest.chat_send_player(player:get_player_name(), Sl("Your last coordinates:") .. " " minetest.chat_send_player(player:get_player_name(), Sl("Your last coordinates:") .. " "