From 16da62e7e4e1ce5d26ee18c6674ad117f472dbe4 Mon Sep 17 00:00:00 2001 From: mckaygerhard Date: Wed, 24 Apr 2024 17:01:58 -0400 Subject: [PATCH] Fix some placer nil checks * backported upstream https://github.com/minetest/minetest_game/commit/70cf7a26fd55d48154ad93d1b1409d0dcc822fe0 --- mods/bucket/init.lua | 4 +++- mods/default/craftitems.lua | 5 +++-- mods/default/functions.lua | 2 +- mods/default/item_entity.lua | 6 +++++- mods/default/legacy.lua | 11 +++++++++++ mods/default/torch.lua | 6 ++++++ mods/doors/init.lua | 5 ++++- mods/mobs/spawner.lua | 5 ++--- mods/mobs_jam/chicken.lua | 4 ++-- mods/nsspf/spawn.lua | 1 + mods/tnt/init.lua | 4 ++-- 11 files changed, 40 insertions(+), 13 deletions(-) diff --git a/mods/bucket/init.lua b/mods/bucket/init.lua index 62392e9..37cbd05 100644 --- a/mods/bucket/init.lua +++ b/mods/bucket/init.lua @@ -65,6 +65,7 @@ function bucket.register_liquid(source, flowing, itemname, inventory_image, name end local node = minetest.get_node_or_nil(pointed_thing.under) + if not node then return end local ndef = node and minetest.registered_nodes[node.name] -- Call on_rightclick if the pointed node defines it @@ -125,6 +126,7 @@ minetest.register_craftitem("bucket:bucket_empty", { end -- Check if pointing to a liquid source local node = minetest.get_node(pointed_thing.under) + if not node then return end local liquiddef = bucket.liquids[node.name] local item_count = user:get_wielded_item():get_count() @@ -148,7 +150,7 @@ minetest.register_craftitem("bucket:bucket_empty", { if inv:room_for_item("main", {name=liquiddef.itemname}) then inv:add_item("main", liquiddef.itemname) else - local pos = user:getpos() + local pos = user:get_pos() pos.y = math.floor(pos.y + 0.5) minetest.add_item(pos, liquiddef.itemname) end diff --git a/mods/default/craftitems.lua b/mods/default/craftitems.lua index e1d224d..e622340 100644 --- a/mods/default/craftitems.lua +++ b/mods/default/craftitems.lua @@ -121,7 +121,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) if inv:room_for_item("main", new_stack) then inv:add_item("main", new_stack) else - minetest.add_item(player:getpos(), new_stack) + minetest.add_item(player:get_pos(), new_stack) end else stack:get_meta():from_table({ fields = data }) @@ -216,7 +216,8 @@ minetest.register_craftitem("default:skeleton_key", { return itemstack end - local on_skeleton_key_use = minetest.registered_nodes[node.name].on_skeleton_key_use + local node_reg = minetest.registered_nodes[node.name] + local on_skeleton_key_use = node_reg and node_reg.on_skeleton_key_use if not on_skeleton_key_use then return itemstack end diff --git a/mods/default/functions.lua b/mods/default/functions.lua index 60c8d6e..51f835d 100644 --- a/mods/default/functions.lua +++ b/mods/default/functions.lua @@ -562,7 +562,7 @@ minetest.register_abm({ -- function default.can_interact_with_node(player, pos) - if player then + if player and player:is_player() then if minetest.check_player_privs(player, "protection_bypass") then return true end diff --git a/mods/default/item_entity.lua b/mods/default/item_entity.lua index c37c58f..41ef864 100644 --- a/mods/default/item_entity.lua +++ b/mods/default/item_entity.lua @@ -48,7 +48,11 @@ local item = { if self.ignite_timer > 10 then self.ignite_timer = 0 - local node = minetest.get_node_or_nil(self.object:getpos()) + local pos = self.object:get_pos() + if pos == nil then + return -- object already deleted + end + local node = minetest.get_node_or_nil(pos) if not node then return end diff --git a/mods/default/legacy.lua b/mods/default/legacy.lua index ef2f999..71b8bbb 100644 --- a/mods/default/legacy.lua +++ b/mods/default/legacy.lua @@ -49,3 +49,14 @@ else player_api.set_animation = default.player_set_animation end +-- Chests +default.register_chest = default.chest.register_chest + +-- Check for a volume intersecting protection +if minetest.is_area_protected then + function default.intersects_protection(minp, maxp, player_name, interval) + minetest.log("warning", "default.intersects_protection() is " .. + "deprecated, use minetest.is_area_protected() instead.") + return minetest.is_area_protected(minp, maxp, player_name, interval) + end +end diff --git a/mods/default/torch.lua b/mods/default/torch.lua index 10fc922..b6b2d89 100644 --- a/mods/default/torch.lua +++ b/mods/default/torch.lua @@ -110,6 +110,9 @@ minetest.register_node("default:torch_wall", { wall_side = {-1/2, -1/2, -1/8, -1/8, 1/8, 1/8}, }, sounds = default.node_sound_wood_defaults(), + floodable = true, + on_flood = on_flood, + on_rotate = false }) minetest.register_node("default:torch_ceiling", { @@ -132,6 +135,9 @@ minetest.register_node("default:torch_ceiling", { wall_top = {-1/8, -1/16, -5/16, 1/8, 1/2, 1/8}, }, sounds = default.node_sound_wood_defaults(), + floodable = true, + on_flood = on_flood, + on_rotate = false }) minetest.register_lbm({ diff --git a/mods/doors/init.lua b/mods/doors/init.lua index f80c753..92f96ec 100644 --- a/mods/doors/init.lua +++ b/mods/doors/init.lua @@ -82,6 +82,7 @@ minetest.register_node("doors:hidden", { paramtype = "light", paramtype2 = "facedir", sunlight_propagates = true, + use_texture_alpha = (is_54 and "clip" or true), -- has to be walkable for falling nodes to stop falling. walkable = true, pointable = false, @@ -89,7 +90,6 @@ minetest.register_node("doors:hidden", { buildable_to = false, floodable = false, drop = "", - use_texture_alpha = (is_54 and "clip" or true), groups = {not_in_creative_inventory = 1}, on_blast = function() end, tiles = {"doors_blank.png"}, @@ -323,6 +323,9 @@ function doors.register(name, def) meta:set_int("state", state) if def.protected then + + local pn = placer:get_player_name() + meta:set_string("owner", pn) meta:set_string("infotext", "Owned by " .. pn) end diff --git a/mods/mobs/spawner.lua b/mods/mobs/spawner.lua index 4686bd4..aff2677 100644 --- a/mods/mobs/spawner.lua +++ b/mods/mobs/spawner.lua @@ -41,9 +41,8 @@ minetest.register_node("mobs:spawner", { end, on_right_click = function(pos, placer) - - if minetest.is_protected(pos, placer:get_player_name()) then - return + if placer and type(placer) == "userdata" then + if minetest.is_protected(pos, placer:get_player_name()) then return end end end, diff --git a/mods/mobs_jam/chicken.lua b/mods/mobs_jam/chicken.lua index 2ae8ab5..df0a23a 100644 --- a/mods/mobs_jam/chicken.lua +++ b/mods/mobs_jam/chicken.lua @@ -262,8 +262,8 @@ minetest.register_node(":mobs:egg", { }, groups = {food_egg = 1, snappy = 2, dig_immediate = 3}, after_place_node = function(pos, placer, itemstack) - if placer:is_player() then - minetest.set_node(pos, {name = "mobs:egg", param2 = 1}) + if placer then + if placer:is_player() then minetest.set_node(pos, {name = "mobs:egg", param2 = 1}) end end end, on_use = mobs_shoot_egg diff --git a/mods/nsspf/spawn.lua b/mods/nsspf/spawn.lua index 4696c8b..31b7687 100644 --- a/mods/nsspf/spawn.lua +++ b/mods/nsspf/spawn.lua @@ -16,6 +16,7 @@ function place_spore(itemstack, placer, pointed_thing, name, topoint, soilblock) end -- if not protected then add node and remove 1 item from the itemstack + if not placer then return end if not minetest.is_protected(pt.under, placer:get_player_name()) then if (under.name == topoint) and (minetest.get_node(uu).name == soilblock) then minetest.set_node(uu, {name = name}) diff --git a/mods/tnt/init.lua b/mods/tnt/init.lua index d12e814..7356bed 100644 --- a/mods/tnt/init.lua +++ b/mods/tnt/init.lua @@ -589,9 +589,9 @@ function tnt.register_tnt(def) groups = {dig_immediate = 2, mesecon = 2, tnt = 1, flammable = 5}, sounds = default.node_sound_wood_defaults(), after_place_node = function(pos, placer) - if placer:is_player() then + if placer then local meta = minetest.get_meta(pos) - meta:set_string("owner", placer:get_player_name()) + meta:set_string("owner", placer and placer:get_player_name() or "") end end, on_punch = function(pos, node, puncher)