예제 #1
0
        /// <summary>
        /// Get the id of the block in this transaction. Returns <see langword="null"/> if not found.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="z"></param>
        /// <returns></returns>
        public NamespacedBlock GetBlock(int x, int y, int z)
        {
            var sec = y >> 4;

            if (_blocks[sec] == null)
            {
                return(null);
            }

            return(_palette[sec][_blocks[sec][LowLevelChunk.GetBlockIndexByCoord(x, y, z)]]);
        }
예제 #2
0
        /// <summary>
        /// Get the id of the block in this transaction. Returns -1 if not found.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="z"></param>
        /// <returns></returns>
        public int GetBlockId(int x, int y, int z)
        {
            var sec = y >> 4;

            if (_blocks[sec] == null)
            {
                return(-1);
            }

            return(_blocks[sec][LowLevelChunk.GetBlockIndexByCoord(x, y, z)]);
        }
예제 #3
0
        /// <summary>
        /// Set a block by its id in the palette.
        /// See <see cref="FindOrCreate"/> for the id.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="z"></param>
        /// <param name="paletteId"></param>
        public void SetBlock(int x, int y, int z, ushort paletteId)
        {
            if (IsAbandoned)
            {
                throw new InvalidOperationException();
            }

            var sec = y >> 4;

            EnsureSection(sec);

            _blocks[sec][LowLevelChunk.GetBlockIndexByCoord(x, y, z)] = paletteId;

            ModifiedSection(sec);
            Modified();
        }
예제 #4
0
        /// <summary>
        /// Set a block.
        /// For an efficient way to set multiple blocks, see other overloads.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="z"></param>
        /// <param name="block"></param>
        public void SetBlock(int x, int y, int z, NamespacedBlock block)
        {
            if (IsAbandoned)
            {
                throw new InvalidOperationException();
            }

            var sec          = y >> 4;
            var inArrayIndex = LowLevelChunk.GetBlockIndexByCoord(x, y, z);

            EnsureSection(sec);
            var index = FindOrCreateInternal(sec, block);

            _paletteCountUse[sec][_blocks[sec][inArrayIndex]]--;
            _paletteCountUse[sec][index]++;

            _blocks[sec][inArrayIndex] = unchecked ((ushort)index);
            ModifiedSection(sec);
            Modified();
        }
예제 #5
0
        public void SetBlock(ICollection <ChangeBlockRequest> requests, IList <NamespacedBlock> customPalette)
        {
            if (IsAbandoned)
            {
                throw new InvalidOperationException();
            }

            var paletteMapping = new int[customPalette.Count];

            foreach (var grp in requests.GroupBy(req => req.Y >> 4))
            {
                EnsureSection(grp.Key);
                var blocks       = _blocks[grp.Key];
                var blockChanges = grp.ToArray();

                foreach (var rq in blockChanges)
                {
                    paletteMapping[rq.InListIndex] = FindOrCreateInternal(grp.Key, customPalette[rq.InListIndex]);
                }

                var paletteCount = _paletteCountUse[grp.Key];

                foreach (var rq in blockChanges)
                {
                    var mappedId  = paletteMapping[rq.InListIndex];
                    var inArrayId = LowLevelChunk.GetBlockIndexByCoord(rq.X, rq.Y, rq.Z);

                    paletteCount[blocks[inArrayId]]--;
                    paletteCount[mappedId]++;

                    blocks[inArrayId] = (ushort)mappedId;
                }

                ModifiedSection(grp.Key);
            }

            Modified();
        }
예제 #6
0
        public void Calculate(LowLevelChunk chunk)
        {
            var maxHeight = (chunk.GetExistingYs().Max() << 4) + 15;
            var heightMap = new int[256];

            for (var z = 0; z < 16; z++)
            {
                for (var x = 0; x < 16; x++)
                {
                    for (var y = maxHeight; y >= 0; y--)
                    {
                        if (!chunk.IsAirBlock(x, y, z))
                        {
                            heightMap[GetIndexByXZ(x, z)] = y;
                            break;
                        }
                    }
                }
            }

            if (chunk is NamespacedChunk)
            {
                var arr = DynBitArray.CreateEmpty(9, 256);
                for (var i = 0; i < 256; i++)
                {
                    arr[i] = heightMap[i];
                }

                HeightMaps[(int)HeightmapType.WorldSurface] = arr;
                State = AttributeVersion.Post113;
            }
            else
            {
                ClassicHeightMap = heightMap;
                State            = AttributeVersion.Pre113;
            }
        }