Skip to content

Commit 5a3b8e3

Browse files
DTA7nerzhul
authored andcommittedSep 21, 2017
Set placer to nil instead of a non-functional one in item_OnPlace (#6449)
* Set placer to nil instead of a non-functional one This requires nil checks in core.rotate_node and core.rotate_and_place.
1 parent 67f97f8 commit 5a3b8e3

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed
 

‎builtin/common/misc_helpers.lua

+8-6
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ if INIT == "game" then
349349
itemstack, pointed_thing)
350350
return
351351
end
352-
local fdir = core.dir_to_facedir(placer:get_look_dir())
352+
local fdir = placer and core.dir_to_facedir(placer:get_look_dir()) or 0
353353
local wield_name = itemstack:get_name()
354354

355355
local above = pointed_thing.above
@@ -369,9 +369,9 @@ if INIT == "game" then
369369
iswall = false
370370
end
371371

372-
if core.is_protected(pos, placer:get_player_name()) then
373-
core.record_protection_violation(pos,
374-
placer:get_player_name())
372+
local name = placer and placer:get_player_name() or ""
373+
if core.is_protected(pos, name) then
374+
core.record_protection_violation(pos, name)
375375
return
376376
end
377377

@@ -432,9 +432,11 @@ if INIT == "game" then
432432
end
433433

434434
core.rotate_node = function(itemstack, placer, pointed_thing)
435+
local name = placer and placer:get_player_name() or ""
436+
local invert_wall = placer and placer:get_player_control().sneak or false
435437
core.rotate_and_place(itemstack, placer, pointed_thing,
436-
is_creative(placer:get_player_name()),
437-
{invert_wall = placer:get_player_control().sneak})
438+
is_creative(name),
439+
{invert_wall = invert_wall})
438440
return itemstack
439441
end
440442
end

‎src/script/cpp_api/s_item.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,12 @@ bool ScriptApiItem::item_OnPlace(ItemStack &item,
6969

7070
// Call function
7171
LuaItemStack::create(L, item);
72-
objectrefGetOrCreate(L, placer);
72+
73+
if (!placer)
74+
lua_pushnil(L);
75+
else
76+
objectrefGetOrCreate(L, placer);
77+
7378
pushPointedThing(pointed);
7479
PCALL_RES(lua_pcall(L, 3, 1, error_handler));
7580
if (!lua_isnil(L, -1)) {

‎src/script/lua_api/l_env.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,8 @@ int ModApiEnvMod::l_place_node(lua_State *L)
396396
pointed.type = POINTEDTHING_NODE;
397397
pointed.node_abovesurface = pos;
398398
pointed.node_undersurface = pos + v3s16(0,-1,0);
399-
// Place it with a NULL placer (appears in Lua as a non-functional
400-
// ObjectRef)
401-
bool success = scriptIfaceItem->item_OnPlace(item, NULL, pointed);
399+
// Place it with a NULL placer (appears in Lua as nil)
400+
bool success = scriptIfaceItem->item_OnPlace(item, nullptr, pointed);
402401
lua_pushboolean(L, success);
403402
return 1;
404403
}

0 commit comments

Comments
 (0)