Difference between revisions of "minetest.get content id"

From Minetest Developer Wiki
Jump to navigation Jump to search
m
(An other example with vmanip)
Line 6: Line 6:
 
the internal [[content id|content ID]] of name
 
the internal [[content id|content ID]] of name
  
 +
== Example ==
 +
<source>
 +
local c_air = minetest.get_content_id("air")
 +
print("Air has the content id: " .. tostring(c_air))
 +
 +
local manip = minetest.get_voxel_manip()
 +
local emin, emax = manip:read_from_map(minp, maxp)
 +
local area = VoxelArea:new({MinEdge=emin, MaxEdge=emax})
 +
local data = manip:get_data()
 +
for z = minp.z, maxp.z do
 +
  for y = minp.y, maxp.y do
 +
      local vi = data:index(minp.x, y, z)
 +
      for x = minp.x, maxp.x do
 +
        --remove all nodes in the area - set to air
 +
        data[vi] = c_air
 +
        vi = vi + 1
 +
      end
 +
  end
 +
end
 +
manip:set_data(data)
 +
manip:write_to_map()
 +
manip:update_map()
 +
</source>
 +
Function required by vmanip.
  
{{MissingExample}}
 
 
[[Category:Methods]]
 
[[Category:Methods]]

Revision as of 20:19, 6 June 2014

Syntax

minetest.get_content_id(name)

Description

Returns an integer: the internal content ID of name

Example

local c_air = minetest.get_content_id("air")
print("Air has the content id: " .. tostring(c_air))

local manip = minetest.get_voxel_manip()
local emin, emax = manip:read_from_map(minp, maxp)
local area = VoxelArea:new({MinEdge=emin, MaxEdge=emax})
local data = manip:get_data()
for z = minp.z, maxp.z do
   for y = minp.y, maxp.y do
      local vi = data:index(minp.x, y, z)
      for x = minp.x, maxp.x do
         --remove all nodes in the area - set to air
         data[vi] = c_air
         vi = vi + 1
      end
   end
end
manip:set_data(data)
manip:write_to_map()
manip:update_map()

Function required by vmanip.