コード例 #1
0
ファイル: EntityLink.cs プロジェクト: ErtyHackward/utopia
        /// <summary>
        /// Finds exact static entity that links points to
        /// Supports container-in-container extraction
        /// </summary>
        /// <param name="landscapeManager"></param>
        /// <returns></returns>
        public IStaticEntity ResolveStatic(ILandscapeManager landscapeManager)
        {
            if (IsDynamic)
            {
                throw new InvalidOperationException();
            }

            var chunk = landscapeManager.GetChunk(ChunkPosition);

            if (chunk == null)
            {
                return(null);
            }

            var           collection = (IStaticContainer)chunk.Entities;
            IStaticEntity sEntity    = null;

            for (int i = 0; i < Tail.Length; i++)
            {
                if (!collection.ContainsId(Tail[i], out sEntity))
                {
                    return(null);
                }

                if (sEntity is IStaticContainer)
                {
                    collection = sEntity as IStaticContainer;
                }
            }

            return(sEntity);
        }
コード例 #2
0
        /// <summary>
        /// Returns block value from cursor moved by vector specified
        /// </summary>
        /// <param name="moveVector"></param>
        /// <returns></returns>
        public byte PeekValue(Vector3I moveVector)
        {
            var peekPosition = _internalPosition + moveVector;

            var newChunkPos = _currentChunk.Position;

            if (peekPosition.X >= AbstractChunk.ChunkSize.X)
            {
                newChunkPos.X += peekPosition.X / AbstractChunk.ChunkSize.X;
                peekPosition.X = peekPosition.X % AbstractChunk.ChunkSize.X;
            }
            if (peekPosition.Y >= AbstractChunk.ChunkSize.Y)
            {
                newChunkPos.Y += peekPosition.Y / AbstractChunk.ChunkSize.Y;
                peekPosition.Y = peekPosition.Y % AbstractChunk.ChunkSize.Y;
            }
            if (peekPosition.Z >= AbstractChunk.ChunkSize.Z)
            {
                newChunkPos.Z += peekPosition.Z / AbstractChunk.ChunkSize.Z;
                peekPosition.Z = peekPosition.Z % AbstractChunk.ChunkSize.Z;
            }
            if (peekPosition.X < 0)
            {
                newChunkPos.X += (int)Math.Floor((double)peekPosition.X / AbstractChunk.ChunkSize.X);
                peekPosition.X = AbstractChunk.ChunkSize.X + peekPosition.X % AbstractChunk.ChunkSize.X;
            }
            if (peekPosition.Y < 0)
            {
                newChunkPos.Y += (int)Math.Floor((double)peekPosition.Y / AbstractChunk.ChunkSize.Y);
                peekPosition.Y = AbstractChunk.ChunkSize.Y + peekPosition.Y % AbstractChunk.ChunkSize.Y;
            }
            if (peekPosition.Z < 0)
            {
                newChunkPos.Z += (int)Math.Floor((double)peekPosition.Z / AbstractChunk.ChunkSize.Z);
                peekPosition.Z = AbstractChunk.ChunkSize.Z + peekPosition.Z % AbstractChunk.ChunkSize.Z;
            }

            if (newChunkPos != _currentChunk.Position)
            {
                var chunk = _manager.GetChunk(newChunkPos);
                return(chunk.BlockData[peekPosition]);
            }
            return(_currentChunk.BlockData[peekPosition]);
        }