core.rotate_node: Do not trigger after_place_node (#6900)

This commit is contained in:
SmallJoker 2018-03-29 21:44:13 +02:00 committed by SmallJoker
parent 5624cf750f
commit fe41725e50
3 changed files with 27 additions and 20 deletions

View File

@ -341,7 +341,7 @@ if INIT == "game" then
local dirs2 = {20, 23, 22, 21} local dirs2 = {20, 23, 22, 21}
function core.rotate_and_place(itemstack, placer, pointed_thing, function core.rotate_and_place(itemstack, placer, pointed_thing,
infinitestacks, orient_flags) infinitestacks, orient_flags, prevent_after_place)
orient_flags = orient_flags or {} orient_flags = orient_flags or {}
local unode = core.get_node_or_nil(pointed_thing.under) local unode = core.get_node_or_nil(pointed_thing.under)
@ -394,7 +394,7 @@ if INIT == "game" then
local old_itemstack = ItemStack(itemstack) local old_itemstack = ItemStack(itemstack)
local new_itemstack, removed = core.item_place_node( local new_itemstack, removed = core.item_place_node(
itemstack, placer, pointed_thing, param2 itemstack, placer, pointed_thing, param2, prevent_after_place
) )
return infinitestacks and old_itemstack or new_itemstack return infinitestacks and old_itemstack or new_itemstack
end end
@ -415,7 +415,7 @@ if INIT == "game" then
local invert_wall = placer and placer:get_player_control().sneak or false 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(name), is_creative(name),
{invert_wall = invert_wall}) {invert_wall = invert_wall}, true)
return itemstack return itemstack
end end
end end

View File

@ -261,7 +261,8 @@ local function make_log(name)
return name ~= "" and core.log or function() end return name ~= "" and core.log or function() end
end end
function core.item_place_node(itemstack, placer, pointed_thing, param2) function core.item_place_node(itemstack, placer, pointed_thing, param2,
prevent_after_place)
local def = itemstack:get_definition() local def = itemstack:get_definition()
if def.type ~= "node" or pointed_thing.type ~= "node" then if def.type ~= "node" or pointed_thing.type ~= "node" then
return itemstack, false return itemstack, false
@ -375,7 +376,7 @@ function core.item_place_node(itemstack, placer, pointed_thing, param2)
local take_item = true local take_item = true
-- Run callback -- Run callback
if def.after_place_node then if def.after_place_node and not prevent_after_place then
-- Deepcopy place_to and pointed_thing because callback can modify it -- Deepcopy place_to and pointed_thing because callback can modify it
local place_to_copy = {x=place_to.x, y=place_to.y, z=place_to.z} local place_to_copy = {x=place_to.x, y=place_to.y, z=place_to.z}
local pointed_thing_copy = copy_pointed_thing(pointed_thing) local pointed_thing_copy = copy_pointed_thing(pointed_thing)

View File

@ -2857,9 +2857,11 @@ and `minetest.auth_reload` call the authetification handler.
### Defaults for the `on_*` item definition functions ### Defaults for the `on_*` item definition functions
These functions return the leftover itemstack. These functions return the leftover itemstack.
* `minetest.item_place_node(itemstack, placer, pointed_thing, param2)` * `minetest.item_place_node(itemstack, placer, pointed_thing[, param2, prevent_after_place])`
* Place item as a node * Place item as a node
* `param2` overrides `facedir` and wallmounted `param2` * `param2` overrides `facedir` and wallmounted `param2`
* `prevent_after_place`: if set to `true`, `after_place_node` is not called
for the newly placed node to prevent a callback and placement loop
* returns `itemstack, success` * returns `itemstack, success`
* `minetest.item_place_object(itemstack, placer, pointed_thing)` * `minetest.item_place_object(itemstack, placer, pointed_thing)`
* Place item as-is * Place item as-is
@ -3100,25 +3102,29 @@ These functions return the leftover itemstack.
* `minetest.record_protection_violation(pos, name)` * `minetest.record_protection_violation(pos, name)`
* This function calls functions registered with * This function calls functions registered with
`minetest.register_on_protection_violation`. `minetest.register_on_protection_violation`.
* `minetest.rotate_and_place(itemstack, placer, pointed_thing, infinitestacks, orient_flags)` * `minetest.rotate_and_place(itemstack, placer, pointed_thing[, infinitestacks,
orient_flags, prevent_after_place])`
* Attempt to predict the desired orientation of the facedir-capable node * Attempt to predict the desired orientation of the facedir-capable node
defined by `itemstack`, and place it accordingly (on-wall, on the floor, or defined by `itemstack`, and place it accordingly (on-wall, on the floor,
hanging from the ceiling). Stacks are handled normally if the `infinitestacks` or hanging from the ceiling).
field is false or omitted (else, the itemstack is not changed). `orient_flags` * `infinitestacks`: if `true`, the itemstack is not changed. Otherwise the
is an optional table containing extra tweaks to the placement code: stacks are handled normally.
* `invert_wall`: if `true`, place wall-orientation on the ground and ground- * `orient_flags`: Optional table containing extra tweaks to the placement code:
orientation on the wall. * `invert_wall`: if `true`, place wall-orientation on the ground and
ground-orientation on the wall.
* `force_wall` : if `true`, always place the node in wall orientation. * `force_wall` : if `true`, always place the node in wall orientation.
* `force_ceiling`: if `true`, always place on the ceiling. * `force_ceiling`: if `true`, always place on the ceiling.
* `force_floor`: if `true`, always place the node on the floor. * `force_floor`: if `true`, always place the node on the floor.
* `force_facedir`: if `true`, forcefully reset the facedir to north when placing on * `force_facedir`: if `true`, forcefully reset the facedir to north
the floor or ceiling when placing on the floor or ceiling.
* The first four options are mutually-exclusive; the last in the list takes * The first four options are mutually-exclusive; the last in the list
precedence over the first. takes precedence over the first.
* `prevent_after_place` is directly passed to `minetest.item_place_node`
* Returns the new itemstack after placement
* `minetest.rotate_node(itemstack, placer, pointed_thing)` * `minetest.rotate_node(itemstack, placer, pointed_thing)`
* calls `rotate_and_place()` with infinitestacks set according to the state of * calls `rotate_and_place()` with `infinitestacks` set according to the state
the creative mode setting, and checks for "sneak" to set the `invert_wall` of the creative mode setting, checks for "sneak" to set the `invert_wall`
parameter. parameter and `prevent_after_place` set to `true`.
* `minetest.forceload_block(pos[, transient])` * `minetest.forceload_block(pos[, transient])`
* forceloads the position `pos`. * forceloads the position `pos`.