Node boxes

From Minetest Developer Wiki
Jump to: navigation, search

Node selection boxes are defined using "node boxes"

The "nodebox" node drawtype allows defining visual of nodes consisting of arbitrary number of boxes. It allows defining stuff like stairs. Only the "fixed" and "leveled" box type is supported for these.
Please note that this is still experimental, and may be incompatibly changed in the future.

A nodebox is defined as any of:

code description
{

    type = "regular"
}

A normal cube; the default in most things
{

    type = "fixed",
    fixed = box OR {box1, box2, ...}
}

A fixed box (facedir param2 is used, if applicable)
{

    type = "wallmounted",
    wall_top = box,
    wall_bottom = box,
    wall_side = box
}

A box like the selection box for torches

(wallmounted param2 is used, if applicable)

{

    type = "connected",
    fixed = box OR {box1, box2, ...},
    connect_top = box OR {box1, box2, ...}
    connect_bottom = box OR {box1, box2, ...}
    connect_front = box OR {box1, box2, ...}
    connect_left = box OR {box1, box2, ...}
    connect_back = box OR {box1, box2, ...}
    connect_right = box OR {box1, box2, ...}
}

A node that has optional boxes depending on neighboring nodes.

Also requires connects_to key in the node definition so the engine knows what blocks the node is connectable to.


A box is defined as:

 {x1, y1, z1, x2, y2, z2}

A box of a regular node would look like:

 {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},

type = "leveled" is same as "fixed", but y2 will be automatically set to level from param2

Example

local load_time_start = os.clock()
local RANGE = 0.6
 
minetest.register_node("trashcan:trashcan", {
	description = "Trash can",
	tiles = {"default_steel_block.png","default_steel_block.png","trashcan.png"},
	groups = {snappy=1,bendy=2,cracky=1},
	sounds = default_stone_sounds,
	paramtype = "light",
	drawtype = "nodebox",
	node_box = {
		type = "fixed",
		fixed = {
				{-0.5, -0.5, -0.5, 0.5, -0.4375, 0.5},
				{-0.5, -0.5, -0.5, -0.4375, 0.5, 0.5},
				{-0.5, -0.5, -0.5, 0.5, 0.5, -0.4375},
				{-0.5, -0.5, 0.4375, 0.5, 0.5, 0.5},
				{0.4375, -0.5, -0.5, 0.5, 0.5, 0.5},
			},
		},
	on_punch = function(pos, node, puncher)
		if node.name == "trashcan:trashcan" then --why should this be checked???
			local objs = minetest.env:get_objects_inside_radius({x=pos.x, y=pos.y+0.3, z=pos.z}, RANGE)
			minetest.chat_send_player(puncher:get_player_name(), 'Garbage removed!')
			for _, obj in pairs(objs) do
				obj:remove()
				minetest.sound_play("trashcan", {pos = pos, gain = 1.0, max_hear_distance = 10})
			end
			print("[trashcan] someone used a trashcan at ("..pos.x..", "..pos.y..", "..pos.z..")")
		end
	end,
	on_construct = function(pos)
		local meta = minetest.env:get_meta(pos)
		meta:set_string("infotext","Trash can")
	end,
})
 
minetest.register_craft({
	output = 'trashcan:trashcan',
	recipe = {
		{'default:steel_ingot', '', 'default:steel_ingot'},
		{'default:steel_ingot', '', 'default:steel_ingot'},
		{'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
	}
})
 
print(string.format("[trashcan] loaded after ca. %.2fs", os.clock() - load_time_start))
Personal tools
Namespaces

Variants
Actions
Navigation
API
Toolbox