Example #1
0
 private void OnRemoveBlockBefore(ChunkPrimer chunk, int x, int y, int z, VoxelMaterial voxel)
 {
     Task.Run(() =>
     {
         _dbControl.RemoveBlock(chunk.position.x, chunk.position.y, chunk.position.z, x, y, z);
     });
 }
Example #2
0
 private void OnLoadChunkDataAfter(ChunkPrimer chunk)
 {
     if (_events.OnLoadChunkAfter != null)
     {
         _events.OnLoadChunkAfter.Invoke(chunk);
     }
 }
        public bool AddBlockByRay(Ray ray, int hitDistance, VoxelMaterial block)
        {
            Debug.Assert(block != null);

            byte        x, y, z, lx, ly, lz;
            ChunkPrimer chunkNow  = null;
            ChunkPrimer chunkLast = null;

            if (HitTestByRay(ray, hitDistance, out chunkNow, out x, out y, out z, out chunkLast, out lx, out ly, out lz))
            {
                var chunk = chunkLast != null ? chunkLast : chunkNow;

                if (_callbacks.OnAddBlockBefore != null)
                {
                    _callbacks.OnAddBlockBefore(chunk, lx, ly, lz, block);
                }

                chunk.voxels.Set(lx, ly, lz, block);
                chunk.dirty = true;

                if (_callbacks.OnAddBlockAfter != null)
                {
                    _callbacks.OnAddBlockAfter(chunk, lx, ly, lz, block);
                }

                return(true);
            }

            return(false);
        }
        public bool HitTestByScreenPos(Vector3 pos, int hitDistance, out ChunkPrimer chunk, out byte outX, out byte outY, out byte outZ)
        {
            var ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            ray.origin = Camera.main.transform.position;
            return(this.HitTestByRay(ray, hitDistance, out chunk, out outX, out outY, out outZ));
        }
Example #5
0
 private void OnLoadChunkDataAfter(ChunkPrimer chunk)
 {
     if (chunk != null)
     {
         _dbControl.LoadChunk(chunk);
     }
 }
Example #6
0
 private void OnAddBlockBefore(ChunkPrimer chunk, int x, int y, int z, VoxelMaterial voxel)
 {
     Task.Run(() =>
     {
         _dbControl.InsertBlock(chunk.position.x, chunk.position.y, chunk.position.z, x, y, z, voxel.GetInstanceID());
     });
 }
        public bool HitTestByRay(Ray ray, int hitDistance, out ChunkPrimer chunk, out byte outX, out byte outY, out byte outZ)
        {
            byte        lx, ly, lz;
            ChunkPrimer chunkLast = null;

            return(this.HitTestByRay(ray, hitDistance, out chunk, out outX, out outY, out outZ, out chunkLast, out lx, out ly, out lz));
        }
Example #8
0
 private void OnDestroyChunkData(ChunkPrimer chunk)
 {
     if (_events.OnDestroyChunk != null)
     {
         _events.OnDestroyChunk.Invoke(chunk);
     }
 }
Example #9
0
        public ChunkPrimer OnCreateChunk(CubizerBehaviour terrain, int x, int y, int z)
        {
            var map = new ChunkPrimer(terrain.profile.chunk.settings.chunkSize, (short)x, (short)y, (short)z);

            int offsetX = x * map.voxels.Bound.x;
            int offsetY = y * map.voxels.Bound.y;
            int offsetZ = z * map.voxels.Bound.z;

            for (int ix = 0; ix < map.voxels.Bound.x; ix++)
            {
                for (int iz = 0; iz < map.voxels.Bound.y; iz++)
                {
                    int dx = offsetX + ix;
                    int dz = offsetZ + iz;

                    for (int iy = 0; iy < 8; iy++)
                    {
                        int dy = offsetY + iy;

                        if (Math.Noise.Simplex3(dx * 0.01f, dy * 0.1f, dz * 0.01f, 8, 0.5f, 2) > _params.thresholdCloud)
                        {
                            map.voxels.Set((byte)ix, (byte)iy, (byte)iz, _materials.cloud);
                        }
                    }
                }
            }

            return(map);
        }
Example #10
0
 private void OnLoadChunkDataBefore(int x, int y, int z, ref ChunkPrimer chunk)
 {
     if (_events.OnLoadChunkBefore != null)
     {
         _events.OnLoadChunkBefore.Invoke(x, y, z, ref chunk);
     }
 }
Example #11
0
 private void OnRemoveBlockAfter(ChunkPrimer chunk, int x, int y, int z, VoxelMaterial voxel)
 {
     if (_events.OnRemoveBlockAfter != null)
     {
         _events.OnRemoveBlockAfter.Invoke(chunk, x, y, z, voxel);
     }
 }
Example #12
0
 private void OnAddBlockBefore(ChunkPrimer chunk, int x, int y, int z, VoxelMaterial voxel)
 {
     if (_events.OnAddBlockBefore != null)
     {
         _events.OnAddBlockBefore.Invoke(chunk, x, y, z, voxel);
     }
 }
Example #13
0
    /**
     * Will return back a chunk, if it doesn't exist and its not a MP client it will generates all the blocks for the
     * specified chunk from the map seed and chunk seed
     */
    public Chunk provideChunk(int x, int z)
    {
        ChunkPrimer chunkprimer = new ChunkPrimer();

        setBlocksInChunk(x, z, chunkprimer);
        biomesForGeneration = worldObj.getWorldChunkManager().loadBlockGeneratorData(biomesForGeneration, x * MinecraftConfig.chunkSize, z * MinecraftConfig.chunkSize, MinecraftConfig.chunkSize, MinecraftConfig.chunkSize);

        Chunk chunk = new Chunk(worldObj, chunkprimer, x, z);

        byte[] abyte = chunk.getBiomeArray();
        for (int i = 0; i < abyte.Length; ++i)
        {
            abyte [i] = (byte)biomesForGeneration [i].biomeID;
        }

        return(chunk);
    }
        public ChunkPrimer buildObsidian(CubizerBehaviour terrain, int x, int y, int z)
        {
            var size = terrain.profile.chunk.settings.chunkSize;
            var map  = new ChunkPrimer(size, x, y, z, size * size * 8);

            for (byte ix = 0; ix < map.voxels.Bound.x; ix++)
            {
                for (byte iz = 0; iz < map.voxels.Bound.z; iz++)
                {
                    for (byte iy = 0; iy < 8; iy++)
                    {
                        map.voxels.Set(ix, iy, iz, _materials.obsidian);
                    }
                }
            }

            return(map);
        }
Example #15
0
        public ChunkPrimer OnCreateChunk(CubizerBehaviour terrain, int x, int y, int z)
        {
            var size = terrain.profile.chunk.settings.chunkSize;
            var map  = new ChunkPrimer(size, x, y, z, size * size * _params.floorBase);

            for (byte ix = 0; ix < map.voxels.Bound.x; ix++)
            {
                for (byte iz = 0; iz < map.voxels.Bound.z; iz++)
                {
                    for (byte iy = 0; iy < _params.floorBase; iy++)
                    {
                        map.voxels.Set(ix, iy, iz, _materials.grass);
                    }
                }
            }

            return(map);
        }
Example #16
0
    /**
     * Will return back a chunk, if it doesn't exist and its not a MP client it will generates all the blocks for the
     * specified chunk from the map seed and chunk seed
     */
    public Chunk provideChunk(int x, int z)
    {
        ChunkPrimer chunkprimer = new ChunkPrimer();

        for (int i = 0; i < this.cachedBlockIDs.Length; ++i)
        {
            IBlockState iblockstate = this.cachedBlockIDs[i];

            if (iblockstate != null)
            {
                for (int j = 0; j < 16; ++j)
                {
                    for (int k = 0; k < 16; ++k)
                    {
                        chunkprimer.setBlockState(j, i, k, iblockstate);
                    }
                }
            }
        }

        for (int i = 0; i < this.structureGenerators.Count; ++i)
        {
            MapGenBase mapGenBase = this.structureGenerators [i];
            mapGenBase.generate(this, this.worldObj, x, z, chunkprimer);
        }


        Chunk chunk = new Chunk(this.worldObj, chunkprimer, x, z);

        BiomeGenBase[] abiomegenbase = this.worldObj.getWorldChunkManager().loadBlockGeneratorData((BiomeGenBase[])null, x * 16, z * 16, 16, 16);
//		byte[] abyte = chunk.getBiomeArray();
//
//		for (int l = 0; l < abyte.length; ++l)
//		{
//			abyte[l] = (byte)abiomegenbase[l].biomeID;
//		}
//
//		chunk.generateSkylightMap();
        return(chunk);
    }
        public void BuildGrass(ChunkPrimer map, byte ix, byte iz, int dx, int dz, VoxelMaterial main, out float f, out byte h)
        {
            f = Noise.Simplex2(_params.grass.loopX * dx, _params.grass.loopZ * dz, _params.grass.octaves, _params.grass.persistence, _params.grass.lacunarity);
            f = (f * (f * _params.floorHeightLismit + _params.floorBase));

            h = System.Math.Max((byte)1, (byte)f);

            if (_params.isGenGrass || _params.isGenSand)
            {
                if (_params.isGenGrass && _params.isGenSand)
                {
                    for (byte iy = 0; iy < h; iy++)
                    {
                        map.voxels.Set(ix, iy, iz, random.Next() > _params.thresholdSand ? _materials.grass : _materials.sand);
                    }
                }
                else
                {
                    var waterHeight = _params.floorBase - _params.floorHeightLismit * 0.2f;
                    if (h < waterHeight)
                    {
                        for (byte iy = 0; iy < h; iy++)
                        {
                            map.voxels.Set(ix, iy, iz, _materials.dirt);
                        }
                    }
                    else
                    {
                        for (byte iy = 0; iy < h - 1; iy++)
                        {
                            map.voxels.Set(ix, iy, iz, _materials.dirt);
                        }

                        map.voxels.Set(ix, (byte)(h - 1), iz, main);
                    }
                }
            }
        }
Example #18
0
        public void CreateChunk(IPlayer player, int x, int y, int z)
        {
            ChunkPrimer chunk = null;

            if (_callbacks.OnLoadChunkBefore != null)
            {
                _callbacks.OnLoadChunkBefore(x, y, z, ref chunk);
            }

            if (chunk == null)
            {
                IBiomeData biomeData = context.behaviour.biomeManager.BuildBiomeIfNotExist(x, y, z);
                if (biomeData != null)
                {
                    if (chunk == null)
                    {
                        chunk = biomeData.OnBuildChunk(this.context.behaviour, x, y, z);
                    }
                }
            }

            if (chunk == null)
            {
                chunk = new ChunkPrimer(model.settings.chunkSize, x, y, z);
            }

            if (_callbacks.OnLoadChunkAfter != null)
            {
                _callbacks.OnLoadChunkAfter(chunk);
            }

            this.manager.Set(x, y, z, chunk);

            if (chunk.voxels.Count > 0)
            {
                _deferredUpdater.Enqueue(chunk);
            }
        }
Example #19
0
        public void LoadChunk(ChunkPrimer chunk)
        {
            var x = chunk.position.x;
            var y = chunk.position.y;
            var z = chunk.position.z;

            using (var _dbCommandLoadBlocks = _dbConnection.CreateCommand())
            {
                _dbCommandLoadBlocks.CommandText = queryLoadBlocks;
                _dbCommandLoadBlocks.Parameters.Add(new SqliteParameter("x", x));
                _dbCommandLoadBlocks.Parameters.Add(new SqliteParameter("y", y));
                _dbCommandLoadBlocks.Parameters.Add(new SqliteParameter("z", z));

                using (var dbReader = _dbCommandLoadBlocks.ExecuteReader())
                {
                    if (dbReader.HasRows)
                    {
                        while (dbReader.Read())
                        {
                            var xx = dbReader.GetByte(0);
                            var yy = dbReader.GetByte(1);
                            var zz = dbReader.GetByte(2);
                            var ww = dbReader.GetByte(3);
                            if (ww > 0)
                            {
                                chunk.voxels.Set(xx, yy, zz, VoxelMaterialManager.GetInstance().GetMaterial(ww));
                            }
                            else
                            {
                                chunk.voxels.Set(xx, yy, zz, null);
                            }
                        }
                    }
                }
            }
        }
Example #20
0
        public void SaveChunk(ChunkPrimer chunk)
        {
            var x = chunk.position.x;
            var y = chunk.position.y;
            var z = chunk.position.z;

            string query = "";

            foreach (var it in chunk.voxels.GetEnumerator())
            {
                var xx = it.position.x;
                var yy = it.position.y;
                var zz = it.position.z;
                var ww = it.value.GetInstanceID();

                query += $"insert or replace into block (x, y, z, xx, yy, zz, ww) values ({x}, {y}, {z}, {xx}, {yy}, {zz}, {ww});";
            }

            using (var _dbCommandSaveBlock = _dbConnection.CreateCommand())
            {
                _dbCommandSaveBlock.CommandText = query;
                _dbCommandSaveBlock.ExecuteNonQuery();
            }
        }
Example #21
0
 private void OnLoadChunkDataAfter(ChunkPrimer chunk)
 {
 }
Example #22
0
 /**
  * Recursively called by generate()
  */
 protected void recursiveGenerate(World worldIn, int chunkX, int chunkZ, int p_180701_4_, int p_180701_5_, ChunkPrimer chunkPrimerIn)
 {
 }
Example #23
0
    public void generate(IChunkProvider chunkProviderIn, World worldIn, int x, int z, ChunkPrimer chunkPrimerIn)
    {
        int i = this.range;

        this.worldObj = worldIn;
        this.rand     = new System.Random(worldIn.getSeed());
        int j = this.rand.Next();
        int k = this.rand.Next();

        for (int l = x - i; i <= x + i; ++l)
        {
            for (int i1 = z - i; i1 <= z + i; ++i1)
            {
                int j1 = l * j;
                int k1 = i1 * k;

                this.rand = new System.Random(j1 ^ k1 ^ worldIn.getSeed());
                this.recursiveGenerate(worldIn, l, i1, x, z, chunkPrimerIn);
            }
        }
    }
Example #24
0
    public void setBlocksInChunk(int x, int z, ChunkPrimer chunkPrimer)
    {
        for (int i = 0; i < 4; ++i)
        {
            int j = i * 5;
            int k = (i + 1) * 5;

            for (int l = 0; l < 4; ++l)
            {
                int i1 = (j + l) * 33;
                int j1 = (j + l + 1) * 33;
                int k1 = (k + l) * 33;
                int l1 = (k + l + 1) * 33;

                for (int i2 = 0; i2 < 32; ++i2)
                {
                    double d0 = 0.125D;
                    double d1 = this.field_147434_q[i1 + i2];
                    double d2 = this.field_147434_q[j1 + i2];
                    double d3 = this.field_147434_q[k1 + i2];
                    double d4 = this.field_147434_q[l1 + i2];
                    double d5 = (this.field_147434_q[i1 + i2 + 1] - d1) * d0;
                    double d6 = (this.field_147434_q[j1 + i2 + 1] - d2) * d0;
                    double d7 = (this.field_147434_q[k1 + i2 + 1] - d3) * d0;
                    double d8 = (this.field_147434_q[l1 + i2 + 1] - d4) * d0;

                    for (int j2 = 0; j2 < 8; ++j2)
                    {
                        double d9  = 0.25D;
                        double d10 = d1;
                        double d11 = d2;
                        double d12 = (d3 - d1) * d9;
                        double d13 = (d4 - d2) * d9;

                        for (int k2 = 0; k2 < 4; ++k2)
                        {
                            double d14       = 0.25D;
                            double d16       = (d11 - d10) * d14;
                            double lvt_45_1_ = d10 - d16;

                            for (int l2 = 0; l2 < 4; ++l2)
                            {
                                if ((lvt_45_1_ += d16) > 0.0D)
                                {
                                    chunkPrimer.setBlockState(i * 4 + k2, i2 * 8 + j2, l * 4 + l2, Blocks.stone.getDefaultState());
                                }
//								else if (i2 * 8 + j2 < this.settings.seaLevel)
//								{
//									chunkPrimer.setBlockState(i * 4 + k2, i2 * 8 + j2, l * 4 + l2, this.field_177476_s.getDefaultState());
//								}
                            }

                            d10 += d12;
                            d11 += d13;
                        }

                        d1 += d5;
                        d2 += d6;
                        d3 += d7;
                        d4 += d8;
                    }
                }
            }
        }
    }
Example #25
0
 public Chunk(World worldIn, ChunkPrimer primer, int x, int z)
 {
     blockBiomeArray = new byte[MinecraftConfig.chunkSize * MinecraftConfig.chunkSize];
 }
 public void BuildTree(ChunkPrimer map, byte ix, byte iz, byte h)
 {
     map.voxels.Set(ix, h, iz, _materials.trees[random.Next(0, _materials.trees.Length - 1)]);
 }
Example #27
0
 private void OnRemoveBlockAfter(ChunkPrimer chunk, int x, int y, int z, VoxelMaterial voxel)
 {
 }
        public ChunkPrimer Buildland(CubizerBehaviour terrain, int x, int y, int z, VoxelMaterial main)
        {
            var size = terrain.profile.chunk.settings.chunkSize;
            var map  = new ChunkPrimer(size, x, y, z, size * size * _params.floorBase);

            int offsetX = x * map.voxels.Bound.x;
            int offsetZ = z * map.voxels.Bound.z;

            for (byte ix = 0; ix < map.voxels.Bound.x; ix++)
            {
                for (byte iz = 0; iz < map.voxels.Bound.z; iz++)
                {
                    int dx = offsetX + ix;
                    int dz = offsetZ + iz;

                    float f; byte h;
                    this.BuildGrass(map, ix, iz, dx, dz, main, out f, out h);

                    var waterHeight = (byte)(_params.floorBase - _params.floorHeightLismit * 0.2f);
                    if (_params.isGenWater && h <= waterHeight)
                    {
                        for (byte iy = h; iy <= waterHeight; iy++)
                        {
                            map.voxels.Set(ix, iy, iz, _materials.water);
                        }
                    }
                    else
                    {
                        if (f > waterHeight && f < (waterHeight + 0.1))
                        {
                            map.voxels.Set(ix, (byte)(h - 1), iz, _materials.sand);
                        }

                        if (_params.isGenWeed && Noise.Simplex2(
                                _params.weeds.loopX * dx,
                                _params.weeds.loopZ * dz,
                                _params.weeds.octaves,
                                _params.weeds.persistence,
                                _params.weeds.lacunarity) > _params.weeds.threshold)
                        {
                            map.voxels.Set(ix, h, iz, _materials.weed[random.Next(0, _materials.weed.Length - 1)]);
                        }
                        else if (_params.isGenFlower && Noise.Simplex2(
                                     _params.flowers.loopX * dx,
                                     _params.flowers.loopZ * dz,
                                     _params.flowers.octaves,
                                     _params.flowers.persistence,
                                     _params.flowers.lacunarity) > _params.flowers.threshold)
                        {
                            map.voxels.Set(ix, h, iz, _materials.flower[random.Next(0, _materials.flower.Length - 1)]);
                        }
                        else if (_params.isGenTree && h < map.voxels.Bound.y - 8)
                        {
                            if (ix > 3 && ix < map.voxels.Bound.y - 3 && iz > 3 && iz < map.voxels.Bound.y - 3)
                            {
                                if (Noise.Simplex2(
                                        _params.tree.loopX * dx,
                                        _params.tree.loopZ * dz,
                                        _params.tree.octaves,
                                        _params.tree.persistence,
                                        _params.tree.lacunarity) > _params.tree.threshold)
                                {
                                    this.BuildTree(map, ix, iz, h);
                                }
                            }
                        }
                    }
                }
            }

            return(map);
        }
Example #29
0
        private bool HitTestByRay(Ray ray, int hitDistance, out ChunkPrimer chunk, out byte outX, out byte outY, out byte outZ, out ChunkPrimer lastChunk, out byte lastX, out byte lastY, out byte lastZ)
        {
            var chunkX = CalculateChunkPosByWorld(ray.origin.x);
            var chunkY = CalculateChunkPosByWorld(ray.origin.y);
            var chunkZ = CalculateChunkPosByWorld(ray.origin.z);

            lastChunk = null;
            lastX     = lastY = lastZ = outX = outY = outZ = 255;

            if (!this.manager.Get(chunkX, chunkY, chunkZ, out chunk))
            {
                return(false);
            }

            Vector3 origin = ray.origin;

            origin.x -= chunk.position.x * model.settings.chunkSize;
            origin.y -= chunk.position.y * model.settings.chunkSize;
            origin.z -= chunk.position.z * model.settings.chunkSize;

            VoxelMaterial block = null;

            for (int i = 0; i < hitDistance && block == null; i++)
            {
                int ix = Mathf.RoundToInt(origin.x);
                int iy = Mathf.RoundToInt(origin.y);
                int iz = Mathf.RoundToInt(origin.z);

                if (outX == ix && outY == iy && outZ == iz)
                {
                    continue;
                }

                bool isOutOfChunk = false;
                if (ix < 0)
                {
                    ix = ix + model.settings.chunkSize; origin.x += model.settings.chunkSize; chunkX--; isOutOfChunk = true;
                }
                if (iy < 0)
                {
                    iy = iy + model.settings.chunkSize; origin.y += model.settings.chunkSize; chunkY--; isOutOfChunk = true;
                }
                if (iz < 0)
                {
                    iz = iz + model.settings.chunkSize; origin.z += model.settings.chunkSize; chunkZ--; isOutOfChunk = true;
                }
                if (ix + 1 > model.settings.chunkSize)
                {
                    ix = ix - model.settings.chunkSize; origin.x -= model.settings.chunkSize; chunkX++; isOutOfChunk = true;
                }
                if (iy + 1 > model.settings.chunkSize)
                {
                    iy = iy - model.settings.chunkSize; origin.y -= model.settings.chunkSize; chunkY++; isOutOfChunk = true;
                }
                if (iz + 1 > model.settings.chunkSize)
                {
                    iz = iz - model.settings.chunkSize; origin.z -= model.settings.chunkSize; chunkZ++; isOutOfChunk = true;
                }

                lastX     = outX;
                lastY     = outY;
                lastZ     = outZ;
                lastChunk = chunk;

                if (isOutOfChunk)
                {
                    chunk = FindChunk(chunkX, chunkY, chunkZ);
                    if (chunk == null)
                    {
                        return(false);
                    }
                }

                chunk.voxels.Get(ix, iy, iz, ref block);

                origin += ray.direction;

                outX = (byte)ix;
                outY = (byte)iy;
                outZ = (byte)iz;
            }

            return(block != null);
        }