You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A function that would be useful for many mods. Inverse to dig_up, build_row would add nodes of the same kind in a specified direction. Can be used for stacking, chains, etc. Might be easy to abuse on servers (maybe add an optional limit).
Rudimentary code that works as far as tested (up, down):
-- Add to row
function default.place_row(pos, node, user, itemstack, dir)
if user == nil then return end
if not dir then dir = {x = 0, y = 1, z = 0} end
local nn = minetest.get_node(pos)
if nn.name ~= itemstack:get_name() then return end
local above = {x = pos.x + dir.x, y = pos.y + dir.y, z = pos.z + dir.z}
local n_above = minetest.get_node(above)
n_above_def = minetest.registered_nodes[n_above.name]
if n_above.name == node.name then
n_above_def.on_rightclick(above, n_above, user, itemstack)
elseif n_above_def.buildable_to == true then
minetest.set_node(above, node, user)
minetest.sound_play("default_place_node", {pos = above, gain = 0.5})
if minetest.setting_getbool("creative_mode") then return end
itemstack:take_item()
return itemstack
end
end
In node definition:
on_rightclick = function(pos, node, user, itemstack)
local dir = {x = 0, y = 1, z = 0}
default.place_row(pos, node, user, itemstack, dir)
end,
The text was updated successfully, but these errors were encountered:
-- Add to row
function default.place_row(pointed_thing, node, user, itemstack, dir)
if not user then return end
if not pointed_thing.under then return end
local pos = pointed_thing.under
if not dir then dir = {x = 0, y = 1, z = 0} end
local previous_node = minetest.get_node(pos)
if previous_node.name ~= itemstack:get_name() then
itemstack = minetest.item_place_node(itemstack, user, pointed_thing)
return itemstack
end
local next_pos = {x = pos.x + dir.x, y = pos.y + dir.y, z = pos.z + dir.z}
pointed_thing.under = next_pos
local n_next_node = minetest.get_node(next_pos)
local n_next_node_def = minetest.registered_nodes[n_next_node.name]
if n_next_node.name == node.name then
-- There is already a row, so we call the next node in line.
n_next_node_def.on_place(itemstack, user, pointed_thing)
return itemstack
elseif n_next_node_def.buildable_to == true then
-- Free space. We can add a node.
itemstack = minetest.item_place_node(itemstack, user, pointed_thing)
return itemstack
end
end
Node def:
on_place = function(itemstack, user, pointed_thing)
local dir = {x = 0, y = 1, z = 0}
itemstack = default.place_row(pointed_thing, {name="default:papyrus"}, user, itemstack, dir)
return itemstack
end,
A function that would be useful for many mods. Inverse to dig_up, build_row would add nodes of the same kind in a specified direction. Can be used for stacking, chains, etc. Might be easy to abuse on servers (maybe add an optional limit).
Rudimentary code that works as far as tested (up, down):
In node definition:
The text was updated successfully, but these errors were encountered: