mirror of
https://git.minetest.org/BuckarooBanzay/digibuilder.git
synced 2024-12-12 02:53:19 +01:00
use item.on_place
This commit is contained in:
parent
89c9f51656
commit
59e5f192d2
55
digiline.lua
55
digiline.lua
@ -118,7 +118,7 @@ function digibuilder.digiline_effector(pos, _, channel, msg)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- get and validate place node definition
|
-- get and validate place node definition
|
||||||
local place_node_def = minetest.registered_nodes[msg.name]
|
local place_node_def = minetest.registered_items[msg.name]
|
||||||
if not place_node_def then
|
if not place_node_def then
|
||||||
digilines.receptor_send(pos, digibuilder.digiline_rules, set_channel, {
|
digilines.receptor_send(pos, digibuilder.digiline_rules, set_channel, {
|
||||||
pos = msg.pos,
|
pos = msg.pos,
|
||||||
@ -128,13 +128,23 @@ function digibuilder.digiline_effector(pos, _, channel, msg)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if not place_node_def.on_place then
|
||||||
|
-- can't place node
|
||||||
|
digilines.receptor_send(pos, digibuilder.digiline_rules, set_channel, {
|
||||||
|
pos = msg.pos,
|
||||||
|
error = true,
|
||||||
|
message = "node can't be placed: '" .. msg.name .. "'"
|
||||||
|
})
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
if not is_creative then
|
if not is_creative then
|
||||||
-- remove item
|
-- remove item
|
||||||
inv:remove_item("main", msg.name)
|
inv:remove_item("main", msg.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- only allow param2 setting for "facedir" types
|
-- only allow param2 setting for "facedir" types
|
||||||
local param2 = tonumber(msg.param2)
|
local param2 = tonumber(msg.param2) or 0
|
||||||
local enable_param2 = place_node_def.paramtype2 == "facedir" and param2 and param2 > 0 and param2 <= 255
|
local enable_param2 = place_node_def.paramtype2 == "facedir" and param2 and param2 > 0 and param2 <= 255
|
||||||
|
|
||||||
local place_node = {
|
local place_node = {
|
||||||
@ -152,22 +162,37 @@ function digibuilder.digiline_effector(pos, _, channel, msg)
|
|||||||
minetest.pos_to_string(absolute_pos)
|
minetest.pos_to_string(absolute_pos)
|
||||||
)
|
)
|
||||||
|
|
||||||
minetest.set_node(absolute_pos, place_node)
|
-- create fake player for certain function arguments (after_place_node, etc)
|
||||||
|
local player = digibuilder.create_fake_player({
|
||||||
|
name = owner
|
||||||
|
})
|
||||||
|
|
||||||
|
-- see:
|
||||||
|
-- https://github.com/minetest-mods/digtron/blob/843dbd227658a93ee4df791bfdd3d136ee7adf85/util_item_place_node.lua
|
||||||
|
local pointed_thing = {}
|
||||||
|
pointed_thing.type = "node"
|
||||||
|
pointed_thing.above = {x=absolute_pos.x, y=absolute_pos.y, z=absolute_pos.z}
|
||||||
|
pointed_thing.under = {x=absolute_pos.x, y=absolute_pos.y, z=absolute_pos.z}
|
||||||
|
|
||||||
|
if place_node_def.paramtype2 == "facedir" then
|
||||||
|
pointed_thing.under = vector.add(absolute_pos, minetest.facedir_to_dir(param2))
|
||||||
|
elseif place_node_def.paramtype2 == "wallmounted" then
|
||||||
|
pointed_thing.under = vector.add(absolute_pos, minetest.wallmounted_to_dir(param2))
|
||||||
|
end
|
||||||
|
|
||||||
|
local itemstack = ItemStack(msg.name .. " 1")
|
||||||
|
local returnstack, success = place_node_def.on_place(ItemStack(itemstack), player, pointed_thing)
|
||||||
|
if returnstack and returnstack:get_count() < itemstack:get_count() then success = true end
|
||||||
|
|
||||||
|
if success then
|
||||||
|
local placed_node = minetest.get_node(absolute_pos)
|
||||||
|
placed_node.param2 = param2
|
||||||
|
minetest.set_node(absolute_pos, placed_node)
|
||||||
|
end
|
||||||
|
|
||||||
-- check if "after_place_node" is defined
|
-- check if "after_place_node" is defined
|
||||||
if place_node_def.after_place_node then
|
if place_node_def.after_place_node then
|
||||||
local player = digibuilder.create_fake_player({
|
place_node_def.after_place_node(absolute_pos, player, ItemStack(), pointed_thing)
|
||||||
name = owner
|
|
||||||
})
|
|
||||||
|
|
||||||
local pointed_thing = {}
|
|
||||||
pointed_thing.type = "node"
|
|
||||||
pointed_thing.above = {x=absolute_pos.x, y=absolute_pos.y, z=absolute_pos.z}
|
|
||||||
pointed_thing.under = {x=absolute_pos.x, y=absolute_pos.y - 1, z=absolute_pos.z}
|
|
||||||
|
|
||||||
local itemstack = ItemStack()
|
|
||||||
|
|
||||||
place_node_def.after_place_node(absolute_pos, player, itemstack, pointed_thing)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- check if the node is falling
|
-- check if the node is falling
|
||||||
|
Loading…
Reference in New Issue
Block a user