aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--builtin/common/misc_helpers.lua14
-rw-r--r--src/script/cpp_api/s_item.cpp7
-rw-r--r--src/script/lua_api/l_env.cpp5
3 files changed, 16 insertions, 10 deletions
diff --git a/builtin/common/misc_helpers.lua b/builtin/common/misc_helpers.lua
index 31d335fe2..d7e0b6ae2 100644
--- a/builtin/common/misc_helpers.lua
+++ b/builtin/common/misc_helpers.lua
@@ -349,7 +349,7 @@ if INIT == "game" then
itemstack, pointed_thing)
return
end
- local fdir = core.dir_to_facedir(placer:get_look_dir())
+ local fdir = placer and core.dir_to_facedir(placer:get_look_dir()) or 0
local wield_name = itemstack:get_name()
local above = pointed_thing.above
@@ -369,9 +369,9 @@ if INIT == "game" then
iswall = false
end
- if core.is_protected(pos, placer:get_player_name()) then
- core.record_protection_violation(pos,
- placer:get_player_name())
+ local name = placer and placer:get_player_name() or ""
+ if core.is_protected(pos, name) then
+ core.record_protection_violation(pos, name)
return
end
@@ -432,9 +432,11 @@ if INIT == "game" then
end
core.rotate_node = function(itemstack, placer, pointed_thing)
+ local name = placer and placer:get_player_name() or ""
+ local invert_wall = placer and placer:get_player_control().sneak or false
core.rotate_and_place(itemstack, placer, pointed_thing,
- is_creative(placer:get_player_name()),
- {invert_wall = placer:get_player_control().sneak})
+ is_creative(name),
+ {invert_wall = invert_wall})
return itemstack
end
end
diff --git a/src/script/cpp_api/s_item.cpp b/src/script/cpp_api/s_item.cpp
index d48a3aee9..3876272d7 100644
--- a/src/script/cpp_api/s_item.cpp
+++ b/src/script/cpp_api/s_item.cpp
@@ -69,7 +69,12 @@ bool ScriptApiItem::item_OnPlace(ItemStack &item,
// Call function
LuaItemStack::create(L, item);
- objectrefGetOrCreate(L, placer);
+
+ if (!placer)
+ lua_pushnil(L);
+ else
+ objectrefGetOrCreate(L, placer);
+
pushPointedThing(pointed);
PCALL_RES(lua_pcall(L, 3, 1, error_handler));
if (!lua_isnil(L, -1)) {
diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp
index f9498a9a7..ca8b6bf13 100644
--- a/src/script/lua_api/l_env.cpp
+++ b/src/script/lua_api/l_env.cpp
@@ -396,9 +396,8 @@ int ModApiEnvMod::l_place_node(lua_State *L)
pointed.type = POINTEDTHING_NODE;
pointed.node_abovesurface = pos;
pointed.node_undersurface = pos + v3s16(0,-1,0);
- // Place it with a NULL placer (appears in Lua as a non-functional
- // ObjectRef)
- bool success = scriptIfaceItem->item_OnPlace(item, NULL, pointed);
+ // Place it with a NULL placer (appears in Lua as nil)
+ bool success = scriptIfaceItem->item_OnPlace(item, nullptr, pointed);
lua_pushboolean(L, success);
return 1;
}