minetest.place schematic on vmanip

From Minetest Developer Wiki
Revision as of 11:21, 12 August 2017 by Beerholder (talk | contribs)
Jump to navigation Jump to search

Syntax

minetest.place_schematic_on_vmanip(vm, pos, schematic, rotation, replacements, force_placement)

Description

This method works in a similar fashion to [minetest.place_schematic], but can be used with a [VoxelManip] for better performance when manipulating large amounts of nodes.

  • Uses VoxelManip object vm, which is the voxel manipulator you are using to e.g. generate terrain
  • Places the schematic specified by schematic (see: Schematic specifier) at pos.
  • Rotation can be "0", "90", "180", "270", or "random".
  • If the rotation parameter is omitted, the schematic is not rotated.
  • replacements = {["old_name"] = "convert_to", ...}
  • force_placement is a boolean indicating whether nodes other than air and ignore are replaced by the schematic


note.png
Note: Schematics are volumes and the position where you place the schematic is the corner of the schematic. If for example you have a 5 by 5 by 5 schematic of a tree whose trunk is in the middle, you will need to offset the x and z position by -2. If you don't, you risk misplacing the tree causing them to float in the air or be generated inside blocks on e.g. steep slopes.


Example

The below snippet places the acacia tree from default at some terrain position with a random rotation when the data written at the voxelmanip index is dirt with dry grass. It does not do specific or general node replacements. Note that the schematic is offset by -2 in the x and z directions:

local data = {}
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
local area = VoxelArea:new({MinEdge = emin, MaxEdge = emax})
for z = minp.z, maxp.z do
	for x = minp.x, maxp.x do
		for y = minp.y-1, maxp.y+1 do
-- E.g. terrain generation code here
		end
	end
end
-- Decoration
for z = minp.z, maxp.z do
	for x = minp.x, maxp.x do
		local ivm = area:index(x, minp.y-1, z)
		for y = minp.y-1, maxp.y+1 do
			if data[ivm] == minetest.get_content_id("default:dirt_with_dry_grass") and math.random(0, 500) then
				minetest.place_schematic_on_vmanip(vm, { x = x - 2, y = y, z = z - 2}, minetest.get_modpath("default").."/schematics/acacia_tree.mts", "random", nil, false)
			end
		end
	end
end


note.png
Note: If you place schematics while performing the vmanip of e.g. the terrain from negative y to positive y, you may need to separate your terrain generation loop from the schematic placement loop or risk the schematics to be overwritten


See also

minetest.place_schematic