forked from Mirrorlandia_minetest/minetest
Make core.item_place_node return position of placed node. (#7713)
This commit is contained in:
parent
39a1e6660e
commit
80af58c8c5
@ -259,7 +259,7 @@ function core.item_place_node(itemstack, placer, pointed_thing, param2,
|
|||||||
prevent_after_place)
|
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, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local under = pointed_thing.under
|
local under = pointed_thing.under
|
||||||
@ -272,7 +272,7 @@ function core.item_place_node(itemstack, placer, pointed_thing, param2,
|
|||||||
if not oldnode_under or not oldnode_above then
|
if not oldnode_under or not oldnode_above then
|
||||||
log("info", playername .. " tried to place"
|
log("info", playername .. " tried to place"
|
||||||
.. " node in unloaded position " .. core.pos_to_string(above))
|
.. " node in unloaded position " .. core.pos_to_string(above))
|
||||||
return itemstack, false
|
return itemstack, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local olddef_under = core.registered_nodes[oldnode_under.name]
|
local olddef_under = core.registered_nodes[oldnode_under.name]
|
||||||
@ -284,7 +284,7 @@ function core.item_place_node(itemstack, placer, pointed_thing, param2,
|
|||||||
log("info", playername .. " tried to place"
|
log("info", playername .. " tried to place"
|
||||||
.. " node in invalid position " .. core.pos_to_string(above)
|
.. " node in invalid position " .. core.pos_to_string(above)
|
||||||
.. ", replacing " .. oldnode_above.name)
|
.. ", replacing " .. oldnode_above.name)
|
||||||
return itemstack, false
|
return itemstack, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Place above pointed node
|
-- Place above pointed node
|
||||||
@ -302,7 +302,7 @@ function core.item_place_node(itemstack, placer, pointed_thing, param2,
|
|||||||
.. " at protected position "
|
.. " at protected position "
|
||||||
.. core.pos_to_string(place_to))
|
.. core.pos_to_string(place_to))
|
||||||
core.record_protection_violation(place_to, playername)
|
core.record_protection_violation(place_to, playername)
|
||||||
return itemstack
|
return itemstack, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
log("action", playername .. " places node "
|
log("action", playername .. " places node "
|
||||||
@ -361,7 +361,7 @@ function core.item_place_node(itemstack, placer, pointed_thing, param2,
|
|||||||
not builtin_shared.check_attached_node(place_to, newnode) then
|
not builtin_shared.check_attached_node(place_to, newnode) then
|
||||||
log("action", "attached node " .. def.name ..
|
log("action", "attached node " .. def.name ..
|
||||||
" can not be placed at " .. core.pos_to_string(place_to))
|
" can not be placed at " .. core.pos_to_string(place_to))
|
||||||
return itemstack, false
|
return itemstack, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Add node and update
|
-- Add node and update
|
||||||
@ -395,7 +395,7 @@ function core.item_place_node(itemstack, placer, pointed_thing, param2,
|
|||||||
if take_item then
|
if take_item then
|
||||||
itemstack:take_item()
|
itemstack:take_item()
|
||||||
end
|
end
|
||||||
return itemstack, true
|
return itemstack, place_to
|
||||||
end
|
end
|
||||||
|
|
||||||
-- deprecated, item_place does not call this
|
-- deprecated, item_place does not call this
|
||||||
@ -416,7 +416,7 @@ function core.item_place(itemstack, placer, pointed_thing, param2)
|
|||||||
local nn = n.name
|
local nn = n.name
|
||||||
if core.registered_nodes[nn] and core.registered_nodes[nn].on_rightclick then
|
if core.registered_nodes[nn] and core.registered_nodes[nn].on_rightclick then
|
||||||
return core.registered_nodes[nn].on_rightclick(pointed_thing.under, n,
|
return core.registered_nodes[nn].on_rightclick(pointed_thing.under, n,
|
||||||
placer, itemstack, pointed_thing) or itemstack, false
|
placer, itemstack, pointed_thing) or itemstack, nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -424,7 +424,7 @@ function core.item_place(itemstack, placer, pointed_thing, param2)
|
|||||||
if itemstack:get_definition().type == "node" then
|
if itemstack:get_definition().type == "node" then
|
||||||
return core.item_place_node(itemstack, placer, pointed_thing, param2)
|
return core.item_place_node(itemstack, placer, pointed_thing, param2)
|
||||||
end
|
end
|
||||||
return itemstack
|
return itemstack, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function core.item_secondary_use(itemstack, placer)
|
function core.item_secondary_use(itemstack, placer)
|
||||||
|
@ -4859,7 +4859,8 @@ Defaults for the `on_place` and `on_drop` item definition functions
|
|||||||
* `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
|
* `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
|
for the newly placed node to prevent a callback and placement loop
|
||||||
* returns `itemstack, success`
|
* returns `itemstack, position`
|
||||||
|
* `position`: the location the node was placed to. `nil` if nothing was placed.
|
||||||
* `minetest.item_place_object(itemstack, placer, pointed_thing)`
|
* `minetest.item_place_object(itemstack, placer, pointed_thing)`
|
||||||
* Place item as-is
|
* Place item as-is
|
||||||
* returns the leftover itemstack
|
* returns the leftover itemstack
|
||||||
@ -4869,7 +4870,8 @@ Defaults for the `on_place` and `on_drop` item definition functions
|
|||||||
* Calls `on_rightclick` of `pointed_thing.under` if defined instead
|
* Calls `on_rightclick` of `pointed_thing.under` if defined instead
|
||||||
* **Note**: is not called when wielded item overrides `on_place`
|
* **Note**: is not called when wielded item overrides `on_place`
|
||||||
* `param2` overrides facedir and wallmounted `param2`
|
* `param2` overrides facedir and wallmounted `param2`
|
||||||
* returns `itemstack, success`
|
* returns `itemstack, position`
|
||||||
|
* `position`: the location the node was placed to. `nil` if nothing was placed.
|
||||||
* `minetest.item_drop(itemstack, dropper, pos)`
|
* `minetest.item_drop(itemstack, dropper, pos)`
|
||||||
* Drop the item
|
* Drop the item
|
||||||
* returns the leftover itemstack
|
* returns the leftover itemstack
|
||||||
|
Loading…
Reference in New Issue
Block a user