Skip to content

Add VoxelArea support #34

Open
Open

Description

@S-S-X

A helper class for voxel areas.
It can be created via VoxelArea:new{MinEdge = pmin, MaxEdge = pmax}.
The coordinates are inclusive, like most other things in Minetest.

Methods

  • getExtent(): returns a 3D vector containing the size of the area formed by
    MinEdge and MaxEdge.
  • getVolume(): returns the volume of the area formed by MinEdge and
    MaxEdge.
  • index(x, y, z): returns the index of an absolute position in a flat array
    starting at 1.
    • x, y and z must be integers to avoid an incorrect index result.
    • The position (x, y, z) is not checked for being inside the area volume,
      being outside can cause an incorrect index result.
    • Useful for things like VoxelManip, raw Schematic specifiers,
      PerlinNoiseMap:get2d/3dMap, and so on.
  • indexp(p): same functionality as index(x, y, z) but takes a vector.
    • As with index(x, y, z), the components of p must be integers, and p
      is not checked for being inside the area volume.
  • position(i): returns the absolute position vector corresponding to index
    i.
  • contains(x, y, z): check if (x,y,z) is inside area formed by
    MinEdge and MaxEdge.
  • containsp(p): same as above, except takes a vector
  • containsi(i): same as above, except takes an index i
  • iter(minx, miny, minz, maxx, maxy, maxz): returns an iterator that returns
    indices.
    • from (minx,miny,minz) to (maxx,maxy,maxz) in the order of
      [z [y [x]]].
  • iterp(minp, maxp): same as above, except takes a vector

Activity

  1. S-S-X commented on Oct 28, 2021

    @S-S-X
    OwnerAuthor
    -- mapnode.h
    -- Built-in Content IDs (for use with VoxelManip API)
    core.CONTENT_UNKNOWN = 125
    core.CONTENT_AIR     = 126
    core.CONTENT_IGNORE  = 127

    Content id allocation
    https://github.com/minetest/minetest/blob/8dfeba02b9f084ddd52090ccd906534200f468b3/src/nodedef.cpp#L1161-L1179

    // returns CONTENT_IGNORE if no free ID found
    content_t NodeDefManager::allocateId()
    {
    	for (content_t id = m_next_id;
    			id >= m_next_id; // overflow?
    			++id) {
    		while (id >= m_content_features.size()) {
    			m_content_features.emplace_back();
    		}
    		const ContentFeatures &f = m_content_features[id];
    		if (f.name.empty()) {
    			m_next_id = id + 1;
    			return id;
    		}
    	}
    	// If we arrive here, an overflow occurred in id.
    	// That means no ID was found
    	return CONTENT_IGNORE;
    }

    Variable m_next_id is reset to zero. First id returned by allocateId is 1 effectively making content id 1 based.

  2. S-S-X commented on Jun 11, 2022

    @S-S-X
    OwnerAuthor

    This should probably be using VoxelArea from engine core Lua libraries, VoxelArea class itself is just Lua helper and #74 already pulls that in when specified version is not "mineunit".

    Having tests from #84 would probably still be useful even while it is engine library, tests would still allow some verification about Mineunit behavior.

    Directory structure and loading of Minetest engine Lua libraries should be made better and more correct, when those were first added there was no plans to actually support many engine features.

    Now things have changed a bit and a lot of Minetest c++ side things are already implemented. Mineunit is actually able to load significant amount of core Lua scripts and even pulls those directly from Minetest repo when asked to do so.

  3. added
    in-latest-dockerIncluded with latest docker images, might not yet be available elsewhere
    and removed on Jan 12, 2025
  4. moved this to In review in Mineuniton Feb 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestin-latest-dockerIncluded with latest docker images, might not yet be available elsewhere

    Projects

    • Status
      In review

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions