示例#1
0
        //BlocksToBePlacedInSystem = ChunkPos -> [localpos, BlockID]
        public static bool PlaceBlocksInSystem(Dictionary <Point3D, Dictionary <Point3D, ushort> > BlocksToBePlacedInSystem, IBiomeSystem System, bool replacemode, ushort replaceThisBlockID)
        {
            Dictionary <Point3D, IChunk> ChunkDictionary = SNScriptUtils._Utils.CreateChunkDictionary(System);

            foreach (KeyValuePair <Point3D, Dictionary <Point3D, ushort> > BlockToBePlacedInChunk in BlocksToBePlacedInSystem)
            {
                bool   chunkNeedsCleanup = false;
                IChunk workChunk         = null as IChunk;
                if (ChunkDictionary.ContainsKey(BlockToBePlacedInChunk.Key))
                {//Chunk exists already, just retrieve it from the ChunkDictionary
                    workChunk = System.ChunkCollection.First(item => item.Position == BlockToBePlacedInChunk.Key.ToDoubleVector3);
                }
                else
                {//The Chunk does not exist, it has to be created first
                    ushort[] tmpBlock = new ushort[32768];
                    tmpBlock[0] = 4;
                    System.CreateLandChunk(tmpBlock, BlockToBePlacedInChunk.Key.ToDoubleVector3);
                    workChunk         = System.ChunkCollection.First(item => item.Position == BlockToBePlacedInChunk.Key.ToDoubleVector3);
                    chunkNeedsCleanup = true;
                }

                List <Point3D> replacePoints = new List <Point3D>();
                if (replacemode)
                {
                    for (int i = 0; i < workChunk.Blocks.Count(); i++)
                    {
                        if (replaceThisBlockID == workChunk.Blocks[i])
                        {
                            replacePoints.Add(_Utils.getLocalPosFromBlockIndex(i));
                        }
                    }
                }

                //Place all Blocks in the Chunk
                foreach (KeyValuePair <Point3D, ushort> BlocksInChunk in BlockToBePlacedInChunk.Value)
                {
                    if (replacemode && replacePoints.Contains(BlocksInChunk.Key))
                    {
                        workChunk.ChangeBlock(BlocksInChunk.Value, BlocksInChunk.Key.X, BlocksInChunk.Key.Y, BlocksInChunk.Key.Z, true, true);
                    }

                    if (!replacemode)
                    {
                        workChunk.ChangeBlock(BlocksInChunk.Value, BlocksInChunk.Key.X, BlocksInChunk.Key.Y, BlocksInChunk.Key.Z, true, true);
                    }
                }

                if (chunkNeedsCleanup)
                {
                    ushort tmpBlockID = 4;
                    ushort blockID;
                    blockID = workChunk.Blocks[0];
                    if (blockID == tmpBlockID)
                    {
                        workChunk.ChangeBlock(0, 0, 0, 0, true, true);
                    }
                }
            }
            return(true);
        }
示例#2
0
        //BlocksToBePlacedInSystem = ChunkPos -> [localpos, BlockID]
        public static bool PlaceBlocksInSystem(Dictionary <Point3D, Dictionary <Point3D, ushort> > BlocksToBePlacedInSystem, IBiomeSystem System)
        {
            List <IChunk> newChunkList = new List <IChunk>();

            Dictionary <Point3D, IChunk> ChunkDictionary = SNScriptUtils._Utils.CreateChunkDictionary(System);

            foreach (KeyValuePair <Point3D, Dictionary <Point3D, ushort> > BlockToBePlacedInChunk in BlocksToBePlacedInSystem)
            {
                bool   chunkNeedsCleanup = false;
                IChunk workChunk         = null as IChunk;
                if (ChunkDictionary.ContainsKey(BlockToBePlacedInChunk.Key))
                {//Chunk exists already, just retrieve it from the ChunkDictionary
                    workChunk = System.ChunkCollection.First(item => item.Position == BlockToBePlacedInChunk.Key.ToDoubleVector3);
                }
                else
                {//The Chunk does not exist, it has to be created first
                    ushort[] tmpBlock = new ushort[32768];
                    tmpBlock[32767] = 4;
                    System.CreateLandChunk(tmpBlock, BlockToBePlacedInChunk.Key.ToDoubleVector3);
                    workChunk = System.ChunkCollection.First(item => item.Position == BlockToBePlacedInChunk.Key.ToDoubleVector3);

                    chunkNeedsCleanup = true;
                }

                //Place all Blocks in the Chunk
                foreach (KeyValuePair <Point3D, ushort> BlocksInChunk in BlockToBePlacedInChunk.Value)
                {
                    workChunk.ChangeBlock(BlocksInChunk.Value, BlocksInChunk.Key.X, BlocksInChunk.Key.Y, BlocksInChunk.Key.Z, true, true);
                }

                if (chunkNeedsCleanup)
                {
                    ushort tmpBlockID = 4;
                    ushort blockID;
                    blockID = workChunk.Blocks[32767];
                    if (blockID == tmpBlockID)
                    {
                        workChunk.ChangeBlock(0, 31, 31, 31, true, true);
                    }
                    newChunkList.Add(workChunk);
                }
            }

            return(true);
        }
示例#3
0
        //BlocksToBePlacedInSystem = ChunkPos -> [localpos, BlockID]
        public static bool PlaceBlocksInSystem(Dictionary<Point3D, Dictionary<Point3D, ushort>> BlocksToBePlacedInSystem, IBiomeSystem System, bool replacemode, ushort replaceThisBlockID)
        {
            Dictionary<Point3D, IChunk> ChunkDictionary = SNScriptUtils._Utils.CreateChunkDictionary(System);

            foreach (KeyValuePair<Point3D, Dictionary<Point3D, ushort>> BlockToBePlacedInChunk in BlocksToBePlacedInSystem)
            {
                bool chunkNeedsCleanup = false;
                IChunk workChunk = null as IChunk;
                if (ChunkDictionary.ContainsKey(BlockToBePlacedInChunk.Key))
                {//Chunk exists already, just retrieve it from the ChunkDictionary
                    workChunk = System.ChunkCollection.First(item => item.Position == BlockToBePlacedInChunk.Key.ToDoubleVector3);
                }
                else
                {//The Chunk does not exist, it has to be created first
                    ushort[] tmpBlock = new ushort[32768];
                    tmpBlock[0] = 4;
                    System.CreateLandChunk(tmpBlock, BlockToBePlacedInChunk.Key.ToDoubleVector3);
                    workChunk = System.ChunkCollection.First(item => item.Position == BlockToBePlacedInChunk.Key.ToDoubleVector3);
                    chunkNeedsCleanup = true;
                }

                List<Point3D> replacePoints = new List<Point3D>();
                if (replacemode)
                {
                    for ( int i = 0; i < workChunk.Blocks.Count(); i++)
                    {
                        if (replaceThisBlockID == workChunk.Blocks[i])
                        {
                            replacePoints.Add(_Utils.getLocalPosFromBlockIndex(i));
                        }
                    }
                }

                //Place all Blocks in the Chunk
                foreach (KeyValuePair<Point3D, ushort> BlocksInChunk in BlockToBePlacedInChunk.Value)
                {
                    if (replacemode && replacePoints.Contains(BlocksInChunk.Key))
                    {
                        workChunk.ChangeBlock(BlocksInChunk.Value, BlocksInChunk.Key.X, BlocksInChunk.Key.Y, BlocksInChunk.Key.Z, true, true);
                    }

                    if (!replacemode)
                    {
                        workChunk.ChangeBlock(BlocksInChunk.Value, BlocksInChunk.Key.X, BlocksInChunk.Key.Y, BlocksInChunk.Key.Z, true, true);
                    }
                }

                if (chunkNeedsCleanup)
                {
                    ushort tmpBlockID = 4;
                    ushort blockID;
                    blockID = workChunk.Blocks[0];
                    if (blockID == tmpBlockID)
                    {
                        workChunk.ChangeBlock(0, 0, 0, 0, true, true);
                    }
                }
            }
            return true;
        }