Example #1
0
        public void UpdateBlock(Player p, ushort x, ushort y, ushort z,
                                byte block, byte extBlock, ushort flags)
        {
            byte old = GetTile(x, y, z), oldExt = 0;

            if (old == Block.custom_block)
            {
                oldExt = GetExtTile(x, y, z);
            }

            bool drawn = (flags & BlockDBFlags.ManualPlace) != 0;

            if (!DoBlockchange(p, x, y, z, block, extBlock, drawn))
            {
                return;
            }
            BlockDB.Add(p, x, y, z, flags,
                        old, oldExt, block, extBlock);

            int index = PosToInt(x, y, z);

            if (bufferblocks)
            {
                BlockQueue.Addblock(p, index, block, extBlock);
            }
            else
            {
                Player.GlobalBlockchange(this, x, y, z, block, extBlock);
            }
        }
Example #2
0
        void Init(string n, ushort x, ushort y, ushort z)
        {
            Width  = x;
            Height = y;
            Length = z;
            if (Width < 16)
            {
                Width = 16;
            }
            if (Height < 16)
            {
                Height = 16;
            }
            if (Length < 16)
            {
                Length = 16;
            }

            #pragma warning disable 0612
            width  = Width;
            length = Height;
            height = Length; depth = Length;
            #pragma warning restore 0612

            CustomBlockDefs = new BlockDefinition[256];
            for (int i = 0; i < CustomBlockDefs.Length; i++)
            {
                CustomBlockDefs[i] = BlockDefinition.GlobalDefs[i];
            }
            CustomBlockProps = new BlockProps[256];
            for (int i = 0; i < CustomBlockProps.Length; i++)
            {
                CustomBlockProps[i] = BlockDefinition.GlobalProps[i];
            }

            name         = n;
            BlockDB      = new BlockDB(this);
            EdgeLevel    = (short)(y / 2);
            CloudsHeight = (short)(y + 2);

            blocks       = new byte[Width * Height * Length];
            ChunksX      = (Width + 15) >> 4;
            ChunksY      = (Height + 15) >> 4;
            ChunksZ      = (Length + 15) >> 4;
            CustomBlocks = new byte[ChunksX * ChunksY * ChunksZ][];

            spawnx = (ushort)(Width / 2);
            spawny = (ushort)(Height * 0.75f);
            spawnz = (ushort)(Length / 2);
            rotx   = 0; roty = 0;

            ZoneList         = new List <Zone>();
            VisitAccess      = new LevelAccessController(this, true);
            BuildAccess      = new LevelAccessController(this, false);
            listCheckExists  = new SparseBitSet(Width, Height, Length);
            listUpdateExists = new SparseBitSet(Width, Height, Length);
        }
Example #3
0
        internal void Init(string name, ushort width, ushort height, ushort length)
        {
            if (width < 1)
            {
                width = 1;
            }
            if (height < 1)
            {
                height = 1;
            }
            if (length < 1)
            {
                length = 1;
            }
            Width = width; Height = height; Length = length;

            for (int i = 0; i < CustomBlockDefs.Length; i++)
            {
                CustomBlockDefs[i] = BlockDefinition.GlobalDefs[i];
            }
            if (blocks == null)
            {
                blocks = new byte[width * height * length];
            }

            LoadDefaultProps();
            for (int i = 0; i < blockAABBs.Length; i++)
            {
                blockAABBs[i] = Block.BlockAABB((ushort)i, this);
            }
            UpdateAllBlockHandlers();

            this.name = name; MapName = name.ToLower();
            BlockDB   = new BlockDB(this);

            ChunksX = Utils.CeilDiv16(width);
            ChunksY = Utils.CeilDiv16(height);
            ChunksZ = Utils.CeilDiv16(length);
            if (CustomBlocks == null)
            {
                CustomBlocks = new byte[ChunksX * ChunksY * ChunksZ][];
            }

            spawnx = (ushort)(width / 2);
            spawny = (ushort)(height * 0.75f);
            spawnz = (ushort)(length / 2);
            rotx   = 0; roty = 0;

            VisitAccess      = new LevelAccessController(Config, name, true);
            BuildAccess      = new LevelAccessController(Config, name, false);
            listCheckExists  = new SparseBitSet(width, height, length);
            listUpdateExists = new SparseBitSet(width, height, length);
        }
Example #4
0
        public Level(string name, ushort width, ushort height, ushort length)
        {
            if (width < 1)
            {
                width = 1;
            }
            if (height < 1)
            {
                height = 1;
            }
            if (length < 1)
            {
                length = 1;
            }

            Width = width; Height = height; Length = length;
            for (int i = 0; i < CustomBlockDefs.Length; i++)
            {
                CustomBlockDefs[i] = BlockDefinition.GlobalDefs[i];
            }

            LoadCoreProps();
            for (int i = 0; i < blockAABBs.Length; i++)
            {
                ExtBlock block = ExtBlock.FromIndex(i);
                blockAABBs[i] = Block.BlockAABB(block, this);
            }
            UpdateBlockHandlers();

            this.name           = name; MapName = name.ToLower();
            BlockDB             = new BlockDB(this);
            Config.EdgeLevel    = (short)(height / 2);
            Config.CloudsHeight = (short)(height + 2);

            blocks       = new byte[Width * Height * Length];
            ChunksX      = Utils.CeilDiv16(Width);
            ChunksY      = Utils.CeilDiv16(Height);
            ChunksZ      = Utils.CeilDiv16(Length);
            CustomBlocks = new byte[ChunksX * ChunksY * ChunksZ][];

            spawnx = (ushort)(Width / 2);
            spawny = (ushort)(Height * 0.75f);
            spawnz = (ushort)(Length / 2);
            rotx   = 0; roty = 0;

            VisitAccess      = new LevelAccessController(this, true);
            BuildAccess      = new LevelAccessController(this, false);
            listCheckExists  = new SparseBitSet(Width, Height, Length);
            listUpdateExists = new SparseBitSet(Width, Height, Length);
        }
Example #5
0
        public void SetTile(ushort x, ushort y, ushort z, byte block, Player p,
                            byte ext = 0, ushort flags = BlockDBFlags.ManualPlace)
        {
            int index = PosToInt(x, y, z);

            if (blocks == null || index < 0)
            {
                return;
            }

            byte oldBlock = blocks[index], oldExtBlock = 0;

            blocks[index] = block;
            changed       = true;

            if (oldBlock == Block.custom_block)
            {
                oldExtBlock = GetExtTile(x, y, z);
                if (block != Block.custom_block)
                {
                    RevertExtTileNoCheck(x, y, z);
                }
            }
            if (block == Block.custom_block)
            {
                SetExtTileNoCheck(x, y, z, ext);
            }
            if (p == null)
            {
                return;
            }

            BlockDB.Add(p, x, y, z, flags,
                        oldBlock, oldExtBlock, block, ext);
            Player.UndoPos Pos;
            Pos.x         = x; Pos.y = y; Pos.z = z;
            Pos.mapName   = this.name;
            Pos.type      = oldBlock; Pos.extType = oldExtBlock;
            Pos.newtype   = block; Pos.newExtType = ext;
            Pos.timeDelta = (int)DateTime.UtcNow.Subtract(Server.StartTime).TotalSeconds;
            p.UndoBuffer.Add(this, Pos);
        }