forked from Mirrorlandia_minetest/minetest
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.
This commit is contained in:
parent
67f97f8d32
commit
5a3b8e34b3
@ -349,7 +349,7 @@ if INIT == "game" then
|
|||||||
itemstack, pointed_thing)
|
itemstack, pointed_thing)
|
||||||
return
|
return
|
||||||
end
|
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 wield_name = itemstack:get_name()
|
||||||
|
|
||||||
local above = pointed_thing.above
|
local above = pointed_thing.above
|
||||||
@ -369,9 +369,9 @@ if INIT == "game" then
|
|||||||
iswall = false
|
iswall = false
|
||||||
end
|
end
|
||||||
|
|
||||||
if core.is_protected(pos, placer:get_player_name()) then
|
local name = placer and placer:get_player_name() or ""
|
||||||
core.record_protection_violation(pos,
|
if core.is_protected(pos, name) then
|
||||||
placer:get_player_name())
|
core.record_protection_violation(pos, name)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -432,9 +432,11 @@ if INIT == "game" then
|
|||||||
end
|
end
|
||||||
|
|
||||||
core.rotate_node = function(itemstack, placer, pointed_thing)
|
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,
|
core.rotate_and_place(itemstack, placer, pointed_thing,
|
||||||
is_creative(placer:get_player_name()),
|
is_creative(name),
|
||||||
{invert_wall = placer:get_player_control().sneak})
|
{invert_wall = invert_wall})
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -69,7 +69,12 @@ bool ScriptApiItem::item_OnPlace(ItemStack &item,
|
|||||||
|
|
||||||
// Call function
|
// Call function
|
||||||
LuaItemStack::create(L, item);
|
LuaItemStack::create(L, item);
|
||||||
|
|
||||||
|
if (!placer)
|
||||||
|
lua_pushnil(L);
|
||||||
|
else
|
||||||
objectrefGetOrCreate(L, placer);
|
objectrefGetOrCreate(L, placer);
|
||||||
|
|
||||||
pushPointedThing(pointed);
|
pushPointedThing(pointed);
|
||||||
PCALL_RES(lua_pcall(L, 3, 1, error_handler));
|
PCALL_RES(lua_pcall(L, 3, 1, error_handler));
|
||||||
if (!lua_isnil(L, -1)) {
|
if (!lua_isnil(L, -1)) {
|
||||||
|
@ -396,9 +396,8 @@ int ModApiEnvMod::l_place_node(lua_State *L)
|
|||||||
pointed.type = POINTEDTHING_NODE;
|
pointed.type = POINTEDTHING_NODE;
|
||||||
pointed.node_abovesurface = pos;
|
pointed.node_abovesurface = pos;
|
||||||
pointed.node_undersurface = pos + v3s16(0,-1,0);
|
pointed.node_undersurface = pos + v3s16(0,-1,0);
|
||||||
// Place it with a NULL placer (appears in Lua as a non-functional
|
// Place it with a NULL placer (appears in Lua as nil)
|
||||||
// ObjectRef)
|
bool success = scriptIfaceItem->item_OnPlace(item, nullptr, pointed);
|
||||||
bool success = scriptIfaceItem->item_OnPlace(item, NULL, pointed);
|
|
||||||
lua_pushboolean(L, success);
|
lua_pushboolean(L, success);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user