public bool CheckVoxelOnGlobalXyz(float x, float y, float z) { var coords = WorldModelHelper.GetChunkCoordsFromWorldXy(x, z); var chunkMap = GetMapByChunkCoords(coords); WorldModelHelper.GetLocalXyzFromWorldPosition(x, y, z, out int xOut, out int yOut, out int zOut); return(chunkMap[ArrayHelper.To1DMap(xOut, yOut, zOut)] != BlockTypeByte.AIR); }
/// <summary> /// Returns voxel on world coordinates - decides if we need to generate the voxel or we can retrieve that from existing chunk /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="z"></param> /// <returns></returns> public byte GetVoxel(int x, int y, int z) { // ======== STATIC RULES ======== if (y < 0 || y >= GeometryConsts.CHUNK_HEIGHT) { return(BlockTypeByte.AIR); } if (y == 0) { return(BlockTypeByte.GREY_STONE); } // ======== RETURN CACHED VOXELS OR PLAYER MODIFIED VOXELS ======== var coords = WorldModelHelper.GetChunkCoordsFromWorldXy(x, z); var map = GetMapByChunkCoords(coords); var index = ArrayHelper.To1DMap(x - coords.x * GeometryConsts.CHUNK_SIZE, y, z - coords.y * GeometryConsts.CHUNK_SIZE); return(map[index]); }