コード例 #1
0
ファイル: EntityBase.cs プロジェクト: withlin/c-raft
        /// <summary>
        /// Move less than four blocks to the given destination and rotate.
        /// </summary>
        /// <param name="x">The X coordinate of the target.</param>
        /// <param name="y">The Y coordinate of the target.</param>
        /// <param name="z">The Z coordinate of the target.</param>
        /// <param name="yaw">The absolute yaw to which entity should change.</param>
        /// <param name="pitch">The absolute pitch to which entity should change.</param>
        public virtual void MoveTo(AbsWorldCoords absCoords, float yaw, float pitch)
        {
            //Vector3 newPosition = new Vector3(absCoords.X, absCoords.Y, absCoords.Z);
            AbsWorldCoords newPosition = absCoords;

            //Event
            EntityMoveEventArgs e = new EntityMoveEventArgs(this, newPosition, Position);

            Server.PluginManager.CallEvent(Event.EntityMove, e);
            if (e.EventCanceled)
            {
                return;
            }
            newPosition = e.NewPosition;
            //End Event

            sbyte oldPacketPosX = (sbyte)Math.Floor(Position.X * 32.0);
            sbyte oldPacketPosY = (sbyte)Math.Floor(Position.Y * 32.0);
            sbyte oldPacketPosZ = (sbyte)Math.Floor(Position.Z * 32.0);

            sbyte newPacketPosX = (sbyte)Math.Floor(newPosition.X * 32.0);
            sbyte newPacketPosY = (sbyte)Math.Floor(newPosition.Y * 32.0);
            sbyte newPacketPosZ = (sbyte)Math.Floor(newPosition.Z * 32.0);

            sbyte dx = (sbyte)(newPacketPosX - oldPacketPosX);
            sbyte dy = (sbyte)(newPacketPosY - oldPacketPosY);
            sbyte dz = (sbyte)(newPacketPosZ - oldPacketPosZ);

            Position   = newPosition;
            this.Yaw   = yaw;
            this.Pitch = pitch;

            OnMoveRotateTo(dx, dy, dz);
        }
コード例 #2
0
 protected virtual void OnPositionChanged(EntityMoveEventArgs e)
 {
     if (PositionChanged != null)
     {
         PositionChanged(this, e);
     }
 }
コード例 #3
0
ファイル: EntityBase.cs プロジェクト: withlin/c-raft
        /// <summary>
        /// Move less than four blocks to the given destination and update all affected clients.
        /// </summary>
        /// <param name="x">The X coordinate of the target.</param>
        /// <param name="y">The Y coordinate of the target.</param>
        /// <param name="z">The Z coordinate of the target.</param>
        public virtual void MoveTo(AbsWorldCoords absCoords)
        {
            AbsWorldCoords newPosition = absCoords;

            //Event
            EntityMoveEventArgs e = new EntityMoveEventArgs(this, newPosition, Position);

            Server.PluginManager.CallEvent(Event.EntityMove, e);
            if (e.EventCanceled)
            {
                return;
            }
            newPosition = e.NewPosition;
            //End Event

            sbyte oldPacketPosX = (sbyte)Math.Floor(Position.X * 32.0);
            sbyte oldPacketPosY = (sbyte)Math.Floor(Position.Y * 32.0);
            sbyte oldPacketPosZ = (sbyte)Math.Floor(Position.Z * 32.0);

            sbyte newPacketPosX = (sbyte)Math.Floor(newPosition.X * 32.0);
            sbyte newPacketPosY = (sbyte)Math.Floor(newPosition.Y * 32.0);
            sbyte newPacketPosZ = (sbyte)Math.Floor(newPosition.Z * 32.0);

            sbyte dx = (sbyte)(newPacketPosX - oldPacketPosX);
            sbyte dy = (sbyte)(newPacketPosY - oldPacketPosY);
            sbyte dz = (sbyte)(newPacketPosZ - oldPacketPosZ);

            Position = newPosition; // TODO: this doesn't prevent changing the Position by more than 4 blocks

            OnMoveTo(dx, dy, dz);
        }
コード例 #4
0
 void EntityPositionChanged(object sender, EntityMoveEventArgs e)
 {
     OnPositionChanged(new ServerDynamicEntityMoveEventArgs {
         ServerDynamicEntity = this,
         PreviousPosition    = e.PreviousPosition
     });
 }
コード例 #5
0
 private void PlayerEntityPositionChanged(object sender, EntityMoveEventArgs e)
 {
     _server.ServerConnection.Send(new EntityPositionMessage
     {
         Position = e.Entity.Position,
         EntityId = e.Entity.DynamicId
     });
 }
コード例 #6
0
ファイル: MapArea.cs プロジェクト: ErtyHackward/utopia
        private void OnEntityMoved(EntityMoveEventArgs e)
        {
            var handler = EntityMoved;

            if (handler != null)
            {
                handler(this, e);
            }
        }
コード例 #7
0
ファイル: EntityEvent.cs プロジェクト: withlin/c-raft
 private void OnMove(EntityMoveEventArgs e)
 {
     foreach (EventListener el in Plugins)
     {
         if (el.Event == Event.EntityMove)
         {
             IEntityListener l = el.Listener as IEntityListener;
             l.OnMove(e);
         }
     }
 }
コード例 #8
0
 public void OnMove(EntityMoveEventArgs e)
 {
 }