Fix some placer nil checks

* backported upstream 70cf7a26fd
This commit is contained in:
mckaygerhard 2024-04-24 17:01:58 -04:00
parent 7590fea329
commit 16da62e7e4
11 changed files with 40 additions and 13 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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