-- Minetest: builtin/item.lua
+local function copy_pointed_thing(pointed_thing)
+ return {
+ type = pointed_thing.type,
+ above = vector.new(pointed_thing.above),
+ under = vector.new(pointed_thing.under),
+ ref = pointed_thing.ref,
+ }
+end
+
--
-- Item definition helpers
--
if def.after_place_node then
-- 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 pointed_thing_copy = {
- type = pointed_thing.type,
- under = {
- x = pointed_thing.under.x,
- y = pointed_thing.under.y,
- z = pointed_thing.under.z},
- above = {
- x = pointed_thing.above.x,
- y = pointed_thing.above.y,
- z = pointed_thing.above.z}
- }
+ local pointed_thing_copy = copy_pointed_thing(pointed_thing)
if def.after_place_node(place_to_copy, placer, itemstack,
pointed_thing_copy) then
take_item = false
-- Run script hook
local _, callback
for _, callback in ipairs(minetest.registered_on_placenodes) do
- -- Deepcopy pos, node and poined_thing because callback can modify them
+ -- Deepcopy pos, node and pointed_thing because callback can modify them
local place_to_copy = {x=place_to.x, y=place_to.y, z=place_to.z}
local newnode_copy = {name=newnode.name, param1=newnode.param1, param2=newnode.param2}
local oldnode_copy = {name=oldnode.name, param1=oldnode.param1, param2=oldnode.param2}
- local pointed_thing_copy = {
- type = pointed_thing.type,
- under = {
- x = pointed_thing.under.x,
- y = pointed_thing.under.y,
- z = pointed_thing.under.z},
- above = {
- x = pointed_thing.above.x,
- y = pointed_thing.above.y,
- z = pointed_thing.above.z}
- }
- if callback(place_to_copy, newnode_copy, placer, oldnode_copy, itemstack, poined_thing_copy) then
+ local pointed_thing_copy = copy_pointed_thing(pointed_thing)
+ if callback(place_to_copy, newnode_copy, placer, oldnode_copy, itemstack, pointed_thing_copy) then
take_item = false
end
end
end
end
-function minetest.node_punch(pos, node, puncher)
+function minetest.node_punch(pos, node, puncher, pointed_thing)
-- Run script hook
- local _, callback
for _, callback in ipairs(minetest.registered_on_punchnodes) do
-- Copy pos and node because callback can modify them
- local pos_copy = {x=pos.x, y=pos.y, z=pos.z}
+ local pos_copy = vector.new(pos)
local node_copy = {name=node.name, param1=node.param1, param2=node.param2}
- callback(pos_copy, node_copy, puncher)
+ local pointed_thing_copy = copy_pointed_thing(pointed_thing)
+ callback(pos_copy, node_copy, puncher, pointed_thing_copy)
end
end
^ Called when a node has been dug.
^ Not recommended: Use on_destruct or after_dig_node in node definition
^ whenever possible
-minetest.register_on_punchnode(func(pos, node, puncher))
+minetest.register_on_punchnode(func(pos, node, puncher, pointed_thing))
^ Called when a node is punched
minetest.register_on_generated(func(minp, maxp, blockseed))
^ Called after generating a piece of world. Modifying nodes inside the area
^ Eat the item. replace_with_item can be nil.
Defaults for the on_punch and on_dig node definition callbacks:
-minetest.node_punch(pos, node, puncher)
+minetest.node_punch(pos, node, puncher, pointed_thing)
^ Calls functions registered by minetest.register_on_punchnode()
minetest.node_dig(pos, node, digger)
^ Checks if node can be dug, puts item into inventory, removes node
^ returns true if node can be dug, or false if not
^ default: nil
- on_punch = func(pos, node, puncher),
+ on_punch = func(pos, node, puncher, pointed_thing),
^ default: minetest.node_punch
- ^ By default: does nothing
+ ^ By default: Calls minetest.register_on_punchnode callbacks
on_rightclick = func(pos, node, clicker, itemstack, pointed_thing),
^ default: nil
^ if defined, itemstack will hold clicker's wielded item
#include "nodedef.h"
#include "server.h"
#include "environment.h"
+#include "util/pointedthing.h"
struct EnumString ScriptApiNode::es_DrawType[] =
}
bool ScriptApiNode::node_on_punch(v3s16 p, MapNode node,
- ServerActiveObject *puncher)
+ ServerActiveObject *puncher, PointedThing pointed)
{
SCRIPTAPI_PRECHECKHEADER
push_v3s16(L, p);
pushnode(L, node, ndef);
objectrefGetOrCreate(puncher);
- if(lua_pcall(L, 3, 0, errorhandler))
+ pushPointedThing(pointed);
+ if(lua_pcall(L, 4, 0, errorhandler))
scriptError();
lua_pop(L, 1); // Pop error handler
return true;