Fix some placer nil checks

This commit is contained in:
sfan5 2024-01-11 15:50:36 +01:00 committed by GitHub
parent a3b171e317
commit 70cf7a26fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 18 deletions

@ -40,7 +40,7 @@ for i in ipairs (butter_list) do
}, },
floodable = true, floodable = true,
on_place = function(itemstack, placer, pointed_thing) 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 local pos = pointed_thing.above
if not minetest.is_protected(pos, player_name) and 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}, groups = {not_in_creative_inventory = 1},
floodable = true, floodable = true,
on_place = function(itemstack, placer, pointed_thing) 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 local pos = pointed_thing.above
if not minetest.is_protected(pos, player_name) and if not minetest.is_protected(pos, player_name) and

@ -413,7 +413,8 @@ minetest.register_craftitem("carts:cart", {
minetest.sound_play({name = "default_place_node_metal", gain = 0.5}, minetest.sound_play({name = "default_place_node_metal", gain = 0.5},
{pos = pointed_thing.above}, true) {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() itemstack:take_item()
end end
return itemstack return itemstack

@ -1985,8 +1985,8 @@ minetest.register_node("default:sand_with_kelp", {
on_place = function(itemstack, placer, pointed_thing) on_place = function(itemstack, placer, pointed_thing)
-- Call on_rightclick if the pointed node defines it -- Call on_rightclick if the pointed node defines it
if pointed_thing.type == "node" and placer and if pointed_thing.type == "node" and not (placer and placer:is_player()
not placer:get_player_control().sneak then and placer:get_player_control().sneak) then
local node_ptu = minetest.get_node(pointed_thing.under) local node_ptu = minetest.get_node(pointed_thing.under)
local def_ptu = minetest.registered_nodes[node_ptu.name] local def_ptu = minetest.registered_nodes[node_ptu.name]
if def_ptu and def_ptu.on_rightclick then 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) 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 return itemstack
end 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_under = pointed_thing.under
local pos_above = pointed_thing.above local pos_above = pointed_thing.above
local node_under = minetest.get_node(pos_under) local node_under = minetest.get_node(pos_under)
local def_under = minetest.registered_nodes[node_under.name] 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, return def_under.on_rightclick(pos_under, node_under,
placer, itemstack, pointed_thing) or itemstack placer, itemstack, pointed_thing)
end end
if node_under.name ~= "default:coral_skeleton" or 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 if minetest.is_protected(pos_under, player_name) or
minetest.is_protected(pos_above, player_name) then 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) minetest.record_protection_violation(pos_under, player_name)
return itemstack return itemstack
end end

@ -488,16 +488,15 @@ function default.sapling_on_place(itemstack, placer, pointed_thing,
interval) then interval) then
minetest.record_protection_violation(pos, player_name) minetest.record_protection_violation(pos, player_name)
-- Print extra information to explain -- 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, minetest.chat_send_player(player_name,
S("@1 will intersect protection on growth.", S("@1 will intersect protection on growth.",
itemstack:get_definition().description)) itemstack:get_definition().description))
return itemstack return itemstack
end 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 take_item = not minetest.is_creative_enabled(player_name)
local newnode = {name = sapling_name} local newnode = {name = sapling_name}

@ -178,7 +178,9 @@ farming.place_seed = function(itemstack, placer, pointed_thing, plantname)
end end
-- add the node and remove 1 item from the itemstack -- 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}) minetest.add_node(pt.above, {name = plantname, param2 = 1})
tick(pt.above) tick(pt.above)
if not minetest.is_creative_enabled(player_name) then if not minetest.is_creative_enabled(player_name) then

@ -625,7 +625,7 @@ function tnt.register_tnt(def)
groups = {dig_immediate = 2, mesecon = 2, tnt = 1, flammable = 5}, groups = {dig_immediate = 2, mesecon = 2, tnt = 1, flammable = 5},
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
if placer:is_player() then if placer and placer:is_player() then
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_string("owner", placer:get_player_name()) meta:set_string("owner", placer:get_player_name())
end end