minetest.place_schematic_on_vmanip

From Old MT Dev
Revision as of 14:49, 5 August 2023 by Poetry (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search
Mbox warning.png This page contains unofficial, low-quality Lua API documentation and is likely to be outdated or wrong. Do not rely on it!
For the official and up-to-date documentation, see Lua API Documentation.
Mbox warning.png This page has been proposed for deletion for the following reason: "Contains unofficial and potentially outdated, redundant and inconsistent Lua API information"
If you don't think that this page should be deleted, please explain why on the talk page.

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

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
			-- We place the tree if there is grass with dirt, but we could also have retrieved the y from the
			-- terrain heightmap in which case we would not necessarily have to loop from minp.y to maxp.y again 
			minetest.place_schematic_on_vmanip(vm, { x = x - 4, y = y, z = z - 4},
								   minetest.get_modpath("default").."/schematics/acacia_tree.mts",
"random", nil, false)


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