From 70cf7a26fd55d48154ad93d1b1409d0dcc822fe0 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 11 Jan 2024 15:50:36 +0100 Subject: [PATCH] Fix some placer nil checks --- mods/butterflies/init.lua | 4 ++-- mods/carts/cart_entity.lua | 3 ++- mods/default/nodes.lua | 16 +++++++--------- mods/default/trees.lua | 7 +++---- mods/farming/api.lua | 4 +++- mods/tnt/init.lua | 2 +- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/mods/butterflies/init.lua b/mods/butterflies/init.lua index 49240eea..0d61b33d 100644 --- a/mods/butterflies/init.lua +++ b/mods/butterflies/init.lua @@ -40,7 +40,7 @@ for i in ipairs (butter_list) do }, floodable = true, on_place = function(itemstack, placer, pointed_thing) - local player_name = placer:get_player_name() + local player_name = placer and placer:get_player_name() or "" local pos = pointed_thing.above if not minetest.is_protected(pos, player_name) and @@ -73,7 +73,7 @@ for i in ipairs (butter_list) do groups = {not_in_creative_inventory = 1}, floodable = true, on_place = function(itemstack, placer, pointed_thing) - local player_name = placer:get_player_name() + local player_name = placer and placer:get_player_name() or "" local pos = pointed_thing.above if not minetest.is_protected(pos, player_name) and diff --git a/mods/carts/cart_entity.lua b/mods/carts/cart_entity.lua index 3015409e..3dfebe1d 100644 --- a/mods/carts/cart_entity.lua +++ b/mods/carts/cart_entity.lua @@ -413,7 +413,8 @@ minetest.register_craftitem("carts:cart", { minetest.sound_play({name = "default_place_node_metal", gain = 0.5}, {pos = pointed_thing.above}, true) - if not minetest.is_creative_enabled(placer:get_player_name()) then + local player_name = placer and placer:get_player_name() or "" + if not minetest.is_creative_enabled(player_name) then itemstack:take_item() end return itemstack diff --git a/mods/default/nodes.lua b/mods/default/nodes.lua index 947dba6c..2bde6f8e 100644 --- a/mods/default/nodes.lua +++ b/mods/default/nodes.lua @@ -1985,8 +1985,8 @@ minetest.register_node("default:sand_with_kelp", { on_place = function(itemstack, placer, pointed_thing) -- Call on_rightclick if the pointed node defines it - if pointed_thing.type == "node" and placer and - not placer:get_player_control().sneak then + if pointed_thing.type == "node" and not (placer and placer:is_player() + and placer:get_player_control().sneak) then local node_ptu = minetest.get_node(pointed_thing.under) local def_ptu = minetest.registered_nodes[node_ptu.name] if def_ptu and def_ptu.on_rightclick then @@ -2035,19 +2035,20 @@ minetest.register_node("default:sand_with_kelp", { -- local function coral_on_place(itemstack, placer, pointed_thing) - if pointed_thing.type ~= "node" or not placer then + if pointed_thing.type ~= "node" then return itemstack end - local player_name = placer:get_player_name() + local player_name = placer and placer:get_player_name() local pos_under = pointed_thing.under local pos_above = pointed_thing.above local node_under = minetest.get_node(pos_under) local def_under = minetest.registered_nodes[node_under.name] - if def_under and def_under.on_rightclick and not placer:get_player_control().sneak then + if def_under and def_under.on_rightclick and not ( + placer and placer:is_player() and placer:get_player_control().sneak) then return def_under.on_rightclick(pos_under, node_under, - placer, itemstack, pointed_thing) or itemstack + placer, itemstack, pointed_thing) end if node_under.name ~= "default:coral_skeleton" or @@ -2057,9 +2058,6 @@ local function coral_on_place(itemstack, placer, pointed_thing) if minetest.is_protected(pos_under, player_name) or minetest.is_protected(pos_above, player_name) then - default.log_player_action(placer, - "tried to place", itemstack:get_name(), - "at protected position", pos_under) minetest.record_protection_violation(pos_under, player_name) return itemstack end diff --git a/mods/default/trees.lua b/mods/default/trees.lua index c9f94120..9536369c 100644 --- a/mods/default/trees.lua +++ b/mods/default/trees.lua @@ -488,16 +488,15 @@ function default.sapling_on_place(itemstack, placer, pointed_thing, interval) then minetest.record_protection_violation(pos, player_name) -- Print extra information to explain --- minetest.chat_send_player(player_name, --- itemstack:get_definition().description .. " will intersect protection " .. --- "on growth") minetest.chat_send_player(player_name, S("@1 will intersect protection on growth.", itemstack:get_definition().description)) return itemstack end - default.log_player_action(placer, "places node", sapling_name, "at", pos) + if placer then + default.log_player_action(placer, "places node", sapling_name, "at", pos) + end local take_item = not minetest.is_creative_enabled(player_name) local newnode = {name = sapling_name} diff --git a/mods/farming/api.lua b/mods/farming/api.lua index 414ebc0f..96f9f636 100644 --- a/mods/farming/api.lua +++ b/mods/farming/api.lua @@ -178,7 +178,9 @@ farming.place_seed = function(itemstack, placer, pointed_thing, plantname) end -- add the node and remove 1 item from the itemstack - default.log_player_action(placer, "places node", plantname, "at", pt.above) + if placer then + default.log_player_action(placer, "places node", plantname, "at", pt.above) + end minetest.add_node(pt.above, {name = plantname, param2 = 1}) tick(pt.above) if not minetest.is_creative_enabled(player_name) then diff --git a/mods/tnt/init.lua b/mods/tnt/init.lua index c59363a5..622b6c97 100644 --- a/mods/tnt/init.lua +++ b/mods/tnt/init.lua @@ -625,7 +625,7 @@ 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 and placer:is_player() then local meta = minetest.get_meta(pos) meta:set_string("owner", placer:get_player_name()) end