Exemplo n.º 1
0
        internal static void RaisePlayerPlacedBlockEvent(Player player, Map map, Vector3I coords,
                                                         Block oldBlock, Block newBlock, BlockChangeContext context)
        {
            var e = new PlayerPlacedBlockEventArgs(player, map, coords, oldBlock, newBlock, context);

            PlacedBlockEvent.Raise(e);
        }
Exemplo n.º 2
0
        internal static void RaisePlayerPlacedBlockEvent(PlayerPlacedBlockEventArgs args)
        {
            var handler = PlacedBlock;

            if (handler != null)
            {
                handler(null, args);
            }
        }
Exemplo n.º 3
0
        protected bool DrawOneBlock() {
            BlocksProcessed++;

            if (!Map.InBounds(Coords)) {
                BlocksSkipped++;
                return false;
            }

#if DEBUG_CHECK_DUPLICATE_COORDS
            TestForDuplicateModification();
#endif

            Block newBlock = Brush.NextBlock(this);
            if (newBlock == Block.None)
                return false;

            int blockIndex = Map.Index(Coords);

            Block oldBlock = (Block)Map.Blocks[blockIndex];
            if (oldBlock == newBlock) {
                BlocksSkipped++;
                return false;
            }

            if (Player.CanPlace(Map, Coords, newBlock, Context) != CanPlaceResult.Allowed) {
                BlocksDenied++;
                return false;
            }

            Map.SetBlock(blockIndex, newBlock);

            World world = Map.World;
            if (world != null && !world.IsFlushing) {
                // cannot reuse packet as each player may require different modifications to block field
                Player[] players = world.Players;
                for (int i = 0; i < players.Length; i++)
                    players[i].SendBlock(Coords, newBlock);
            }

            // Reuse instance to avoid memory allocations
            if (placeArgs == null)
                placeArgs = new PlayerPlacedBlockEventArgs(Player, Map, Vector3I.Zero, Block.Air, Block.Air, Context);
            placeArgs.Coords = Coords;
            placeArgs.OldBlock = oldBlock;
            placeArgs.NewBlock = newBlock;
            Player.RaisePlayerPlacedBlockEvent(placeArgs);

            if (!UndoState.IsTooLargeToUndo) {
                if (!UndoState.Add(Coords, Map, oldBlock)) {
                    Player.LastDrawOp = null;
                    Player.Message("{0}: Too many blocks to undo.", Description);
                }
            }

            BlocksUpdated++;
            return true;
        }
Exemplo n.º 4
0
        public static void OnPlayerPlacedBlock(Object sender, PlayerPlacedBlockEventArgs e)
        {
            if (e.Context != BlockChangeContext.Manual && e.Context != BlockChangeContext.Replaced)
            {
                return;
            }

            try {
                SetHistory(e.Player.World, e.Coords.X, e.Coords.Y, e.Coords.Z, e.Player, e.OldBlock);
            } catch (Exception) {
            }
        }
Exemplo n.º 5
0
        static void OnPlayerPlacedBlock(object sender, [NotNull] PlayerPlacedBlockEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }
            World world = e.Map.World;

            if (world != null && world.BlockDB.IsEnabled)
            {
                BlockDBEntry newEntry = new BlockDBEntry((int)DateTime.UtcNow.ToUnixTime(),
                                                         e.Player.Info.ID,
                                                         e.Coords,
                                                         e.OldBlock,
                                                         e.NewBlock,
                                                         e.Context);
                world.BlockDB.AddEntry(newEntry);
            }
        }
Exemplo n.º 6
0
        protected bool DrawOneBlock()
        {
            BlocksProcessed++;

            if (!Map.InBounds(Coords))
            {
                BlocksSkipped++;
                return(false);
            }

#if DEBUG_CHECK_DUPLICATE_COORDS
            TestForDuplicateModification();
#endif

            Block newBlock = Brush.NextBlock(this);
            if (newBlock == Block.Undefined)
            {
                return(false);
            }

            int blockIndex = Map.Index(Coords);

            Block oldBlock = (Block)Map.Blocks[blockIndex];
            if (oldBlock == newBlock)
            {
                BlocksSkipped++;
                return(false);
            }

            if (Player.CanPlace(Map, Coords, newBlock, Context) != CanPlaceResult.Allowed)
            {
                BlocksDenied++;
                return(false);
            }

            Map.Blocks[blockIndex] = (byte)newBlock;

            World world = Map.World;
            if (world != null && !world.IsFlushing)
            {
                world.Players.SendLowPriority(PacketWriter.MakeSetBlock(Coords, newBlock));
            }

            // Reuse instance to avoid memory allocations
            if (placeArgs == null)
            {
                placeArgs = new PlayerPlacedBlockEventArgs(Player, Map, Vector3I.Zero, Block.Air, Block.Air, Context);
            }
            placeArgs.Coords   = Coords;
            placeArgs.OldBlock = oldBlock;
            placeArgs.NewBlock = newBlock;
            Player.RaisePlayerPlacedBlockEvent(placeArgs);

            if (!UndoState.IsTooLargeToUndo)
            {
                if (!UndoState.Add(Coords, oldBlock))
                {
                    Player.LastDrawOp = null;
                    Player.Message("{0}: Too many blocks to undo.", Description);
                }
            }

            BlocksUpdated++;
            return(true);
        }