mirror of
https://github.com/minetest/minetest.git
synced 2024-11-14 03:33:44 +01:00
Allow to manually specify param2 in minetest.item_place() and return success
This commit is contained in:
parent
5dce44ec5e
commit
731392866f
@ -179,11 +179,11 @@ function minetest.get_node_drops(nodename, toolname)
|
|||||||
return got_items
|
return got_items
|
||||||
end
|
end
|
||||||
|
|
||||||
function minetest.item_place_node(itemstack, placer, pointed_thing)
|
function minetest.item_place_node(itemstack, placer, pointed_thing, param2)
|
||||||
local item = itemstack:peek_item()
|
local item = itemstack:peek_item()
|
||||||
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
|
return itemstack, false
|
||||||
end
|
end
|
||||||
|
|
||||||
local under = pointed_thing.under
|
local under = pointed_thing.under
|
||||||
@ -194,7 +194,7 @@ function minetest.item_place_node(itemstack, placer, pointed_thing)
|
|||||||
if not oldnode_under or not oldnode_above then
|
if not oldnode_under or not oldnode_above then
|
||||||
minetest.log("info", placer:get_player_name() .. " tried to place"
|
minetest.log("info", placer:get_player_name() .. " tried to place"
|
||||||
.. " node in unloaded position " .. minetest.pos_to_string(above))
|
.. " node in unloaded position " .. minetest.pos_to_string(above))
|
||||||
return itemstack
|
return itemstack, false
|
||||||
end
|
end
|
||||||
|
|
||||||
local olddef_under = ItemStack({name=oldnode_under.name}):get_definition()
|
local olddef_under = ItemStack({name=oldnode_under.name}):get_definition()
|
||||||
@ -206,7 +206,7 @@ function minetest.item_place_node(itemstack, placer, pointed_thing)
|
|||||||
minetest.log("info", placer:get_player_name() .. " tried to place"
|
minetest.log("info", placer:get_player_name() .. " tried to place"
|
||||||
.. " node in invalid position " .. minetest.pos_to_string(above)
|
.. " node in invalid position " .. minetest.pos_to_string(above)
|
||||||
.. ", replacing " .. oldnode_above.name)
|
.. ", replacing " .. oldnode_above.name)
|
||||||
return itemstack
|
return itemstack, false
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Place above pointed node
|
-- Place above pointed node
|
||||||
@ -222,10 +222,10 @@ function minetest.item_place_node(itemstack, placer, pointed_thing)
|
|||||||
.. def.name .. " at " .. minetest.pos_to_string(place_to))
|
.. def.name .. " at " .. minetest.pos_to_string(place_to))
|
||||||
|
|
||||||
local oldnode = minetest.get_node(place_to)
|
local oldnode = minetest.get_node(place_to)
|
||||||
local newnode = {name = def.name, param1 = 0, param2 = 0}
|
local newnode = {name = def.name, param1 = 0, param2 = param2}
|
||||||
|
|
||||||
-- Calculate direction for wall mounted stuff like torches and signs
|
-- Calculate direction for wall mounted stuff like torches and signs
|
||||||
if def.paramtype2 == 'wallmounted' then
|
if def.paramtype2 == 'wallmounted' and not param2 then
|
||||||
local dir = {
|
local dir = {
|
||||||
x = under.x - above.x,
|
x = under.x - above.x,
|
||||||
y = under.y - above.y,
|
y = under.y - above.y,
|
||||||
@ -233,7 +233,7 @@ function minetest.item_place_node(itemstack, placer, pointed_thing)
|
|||||||
}
|
}
|
||||||
newnode.param2 = minetest.dir_to_wallmounted(dir)
|
newnode.param2 = minetest.dir_to_wallmounted(dir)
|
||||||
-- Calculate the direction for furnaces and chests and stuff
|
-- Calculate the direction for furnaces and chests and stuff
|
||||||
elseif def.paramtype2 == 'facedir' then
|
elseif def.paramtype2 == 'facedir' and not param2 then
|
||||||
local placer_pos = placer:getpos()
|
local placer_pos = placer:getpos()
|
||||||
if placer_pos then
|
if placer_pos then
|
||||||
local dir = {
|
local dir = {
|
||||||
@ -251,7 +251,7 @@ function minetest.item_place_node(itemstack, placer, pointed_thing)
|
|||||||
not check_attached_node(place_to, newnode) then
|
not check_attached_node(place_to, newnode) then
|
||||||
minetest.log("action", "attached node " .. def.name ..
|
minetest.log("action", "attached node " .. def.name ..
|
||||||
" can not be placed at " .. minetest.pos_to_string(place_to))
|
" can not be placed at " .. minetest.pos_to_string(place_to))
|
||||||
return itemstack
|
return itemstack, false
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Add node and update
|
-- Add node and update
|
||||||
@ -283,7 +283,7 @@ function minetest.item_place_node(itemstack, placer, pointed_thing)
|
|||||||
if take_item then
|
if take_item then
|
||||||
itemstack:take_item()
|
itemstack:take_item()
|
||||||
end
|
end
|
||||||
return itemstack
|
return itemstack, true
|
||||||
end
|
end
|
||||||
|
|
||||||
function minetest.item_place_object(itemstack, placer, pointed_thing)
|
function minetest.item_place_object(itemstack, placer, pointed_thing)
|
||||||
@ -295,19 +295,19 @@ function minetest.item_place_object(itemstack, placer, pointed_thing)
|
|||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
function minetest.item_place(itemstack, placer, pointed_thing)
|
function minetest.item_place(itemstack, placer, pointed_thing, param2)
|
||||||
-- Call on_rightclick if the pointed node defines it
|
-- Call on_rightclick if the pointed node defines it
|
||||||
if pointed_thing.type == "node" and placer and
|
if pointed_thing.type == "node" and placer and
|
||||||
not placer:get_player_control().sneak then
|
not placer:get_player_control().sneak then
|
||||||
local n = minetest.get_node(pointed_thing.under)
|
local n = minetest.get_node(pointed_thing.under)
|
||||||
local nn = n.name
|
local nn = n.name
|
||||||
if minetest.registered_nodes[nn] and minetest.registered_nodes[nn].on_rightclick then
|
if minetest.registered_nodes[nn] and minetest.registered_nodes[nn].on_rightclick then
|
||||||
return minetest.registered_nodes[nn].on_rightclick(pointed_thing.under, n, placer, itemstack) or itemstack
|
return minetest.registered_nodes[nn].on_rightclick(pointed_thing.under, n, placer, itemstack) or itemstack, false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if itemstack:get_definition().type == "node" then
|
if itemstack:get_definition().type == "node" then
|
||||||
return minetest.item_place_node(itemstack, placer, pointed_thing)
|
return minetest.item_place_node(itemstack, placer, pointed_thing, param2)
|
||||||
end
|
end
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
@ -1361,14 +1361,18 @@ minetest.rollback_revert_actions_by(actor, seconds) -> bool, log messages
|
|||||||
|
|
||||||
Defaults for the on_* item definition functions:
|
Defaults for the on_* item definition functions:
|
||||||
(These return the leftover itemstack)
|
(These return the leftover itemstack)
|
||||||
minetest.item_place_node(itemstack, placer, pointed_thing)
|
minetest.item_place_node(itemstack, placer, pointed_thing, param2)
|
||||||
^ Place item as a node
|
^ Place item as a node
|
||||||
|
^ param2 overrides facedir and wallmounted param2
|
||||||
|
^ 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
|
||||||
minetest.item_place(itemstack, placer, pointed_thing)
|
minetest.item_place(itemstack, placer, pointed_thing, param2)
|
||||||
^ Use one of the above based on what the item is.
|
^ Use one of the above based on what the item is.
|
||||||
^ 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
|
||||||
|
^ returns itemstack, success
|
||||||
minetest.item_drop(itemstack, dropper, pos)
|
minetest.item_drop(itemstack, dropper, pos)
|
||||||
^ Drop the item
|
^ Drop the item
|
||||||
minetest.item_eat(hp_change, replace_with_item)
|
minetest.item_eat(hp_change, replace_with_item)
|
||||||
|
Loading…
Reference in New Issue
Block a user