Skip to content

Commit 80af58c

Browse files
BluebirdGreycoatsfan5
authored andcommittedDec 18, 2019
Make core.item_place_node return position of placed node. (#7713)
1 parent 39a1e66 commit 80af58c

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed
 

‎builtin/game/item.lua

+8-8
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ function core.item_place_node(itemstack, placer, pointed_thing, param2,
259259
prevent_after_place)
260260
local def = itemstack:get_definition()
261261
if def.type ~= "node" or pointed_thing.type ~= "node" then
262-
return itemstack, false
262+
return itemstack, nil
263263
end
264264

265265
local under = pointed_thing.under
@@ -272,7 +272,7 @@ function core.item_place_node(itemstack, placer, pointed_thing, param2,
272272
if not oldnode_under or not oldnode_above then
273273
log("info", playername .. " tried to place"
274274
.. " node in unloaded position " .. core.pos_to_string(above))
275-
return itemstack, false
275+
return itemstack, nil
276276
end
277277

278278
local olddef_under = core.registered_nodes[oldnode_under.name]
@@ -284,7 +284,7 @@ function core.item_place_node(itemstack, placer, pointed_thing, param2,
284284
log("info", playername .. " tried to place"
285285
.. " node in invalid position " .. core.pos_to_string(above)
286286
.. ", replacing " .. oldnode_above.name)
287-
return itemstack, false
287+
return itemstack, nil
288288
end
289289

290290
-- Place above pointed node
@@ -302,7 +302,7 @@ function core.item_place_node(itemstack, placer, pointed_thing, param2,
302302
.. " at protected position "
303303
.. core.pos_to_string(place_to))
304304
core.record_protection_violation(place_to, playername)
305-
return itemstack
305+
return itemstack, nil
306306
end
307307

308308
log("action", playername .. " places node "
@@ -361,7 +361,7 @@ function core.item_place_node(itemstack, placer, pointed_thing, param2,
361361
not builtin_shared.check_attached_node(place_to, newnode) then
362362
log("action", "attached node " .. def.name ..
363363
" can not be placed at " .. core.pos_to_string(place_to))
364-
return itemstack, false
364+
return itemstack, nil
365365
end
366366

367367
-- Add node and update
@@ -395,7 +395,7 @@ function core.item_place_node(itemstack, placer, pointed_thing, param2,
395395
if take_item then
396396
itemstack:take_item()
397397
end
398-
return itemstack, true
398+
return itemstack, place_to
399399
end
400400

401401
-- deprecated, item_place does not call this
@@ -416,15 +416,15 @@ function core.item_place(itemstack, placer, pointed_thing, param2)
416416
local nn = n.name
417417
if core.registered_nodes[nn] and core.registered_nodes[nn].on_rightclick then
418418
return core.registered_nodes[nn].on_rightclick(pointed_thing.under, n,
419-
placer, itemstack, pointed_thing) or itemstack, false
419+
placer, itemstack, pointed_thing) or itemstack, nil
420420
end
421421
end
422422

423423
-- Place if node, otherwise do nothing
424424
if itemstack:get_definition().type == "node" then
425425
return core.item_place_node(itemstack, placer, pointed_thing, param2)
426426
end
427-
return itemstack
427+
return itemstack, nil
428428
end
429429

430430
function core.item_secondary_use(itemstack, placer)

‎doc/lua_api.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -4859,7 +4859,8 @@ Defaults for the `on_place` and `on_drop` item definition functions
48594859
* `param2` overrides `facedir` and wallmounted `param2`
48604860
* `prevent_after_place`: if set to `true`, `after_place_node` is not called
48614861
for the newly placed node to prevent a callback and placement loop
4862-
* returns `itemstack, success`
4862+
* returns `itemstack, position`
4863+
* `position`: the location the node was placed to. `nil` if nothing was placed.
48634864
* `minetest.item_place_object(itemstack, placer, pointed_thing)`
48644865
* Place item as-is
48654866
* returns the leftover itemstack
@@ -4869,7 +4870,8 @@ Defaults for the `on_place` and `on_drop` item definition functions
48694870
* Calls `on_rightclick` of `pointed_thing.under` if defined instead
48704871
* **Note**: is not called when wielded item overrides `on_place`
48714872
* `param2` overrides facedir and wallmounted `param2`
4872-
* returns `itemstack, success`
4873+
* returns `itemstack, position`
4874+
* `position`: the location the node was placed to. `nil` if nothing was placed.
48734875
* `minetest.item_drop(itemstack, dropper, pos)`
48744876
* Drop the item
48754877
* returns the leftover itemstack

0 commit comments

Comments
 (0)
Please sign in to comment.