Beispiel #1
0
 public override void OnScheduledUpdate(World world, Vector3 position)
 {
     // Check for water
     int closest = int.MaxValue;
     for (int y = -1; y < 1; y++ )
         for (int x = -8; x < 8; x++)
             for (int z = -8; z < 8; z++)
             {
                 if (position.Y + y < 0)
                     continue;
                 var blockPosition = new Vector3(x, position.Y + y, z);
                 var block = world.GetBlock(blockPosition);
                 if (block is WaterFlowingBlock || block is WaterStillBlock)
                 {
                     var distance = position.DistanceTo(blockPosition);
                     if (distance < closest)
                         closest = (int)distance;
                 }
             }
     closest = -(closest - 4) + 4;
     Metadata = (byte)closest;
     if (closest >= 5 && MathHelper.Random.Next(5) == 0)
         world.SetBlock(position, new DirtBlock());
     else
     {
         world.SetBlock(position, this);
         ScheduleUpdate(world, position, DateTime.Now.AddSeconds(MathHelper.Random.Next(30, 120)));
     }
     base.OnScheduledUpdate(world, position);
 }
Beispiel #2
0
 /// <summary>
 /// Gets a byte representing block direction based on the rotation
 /// of the entity that placed it.
 /// </summary>
 /// <param name="p">The entity whose rotation should be used.</param>
 /// <param name="Position">The position of the block being placed.</param>
 /// <param name="invert">If set to <c>true</c>, the direction is inverted.</param>
 /// <returns></returns>
 /// <remarks></remarks>
 public static byte DirectionByRotation(PlayerEntity p, Vector3 Position, bool invert = false)
 {
     double d = Math.Asin(((p.Location.Y + 0.5) - Position.Y) / Position.DistanceTo(p.Location + new Vector3(0, 0.5, 0)));
     if (d > (Math.PI / 4)) return invert ? (byte)1 : (byte)0;
     if (d < -(Math.PI / 4)) return invert ? (byte)0 : (byte)1;
     return DirectionByRotationFlat(p, invert);
 }
Beispiel #3
0
 /// <summary>
 /// Gets a byte representing block direction based on the rotation
 /// of the entity that placed it.
 /// </summary>
 public static Direction DirectionByRotation(PlayerEntity p, Vector3 position, bool invert = false)
 {
     // TODO: Figure out some algorithm based on player's look yaw
     double d = Math.Asin((p.Position.Y - position.Y) / position.DistanceTo(p.Position));
     if (d > (Math.PI / 4)) return invert ? (Direction)1 : (Direction)0;
     if (d < -(Math.PI / 4)) return invert ? (Direction)0 : (Direction)1;
     return DirectionByRotationFlat(p, invert);
 }
 public static void RightClick(MinecraftClient client, MinecraftServer server, IPacket _packet)
 {
     var packet = (RightClickPacket)_packet;
     var slot = client.Entity.Inventory[client.Entity.SelectedSlot];
     var position = new Vector3(packet.X, packet.Y, packet.Z);
     var cursorPosition = new Vector3(packet.CursorX, packet.CursorY, packet.CursorZ);
     Block block = null;
     if (position != -Vector3.One)
     {
         if (position.DistanceTo(client.Entity.Position) > client.Reach)
             return;
         block = client.World.GetBlock(position);
     }
     bool use = true;
     if (block != null)
         use = block.OnBlockRightClicked(position, AdjustByDirection(packet.Direction), cursorPosition, client.World, client.Entity);
     var item = slot.AsItem();
     if (use && item != null)
     {
         if (block != null)
         {
             item.OnItemUsedOnBlock(client.World, position, AdjustByDirection(packet.Direction),
                 cursorPosition, client.Entity);
             if (item is Block)
             {
                 client.SendPacket(new NamedSoundEffectPacket((item as Block).PlacementSoundEffect,
                     (int)position.X, (int)position.Y, (int)position.Z, 1, 50));
             }
         }
         else
             item.OnItemUsed(client.World, client.Entity);
     }
 }
 public static void UpdateSign(MinecraftClient client, MinecraftServer server, IPacket _packet)
 {
     var packet = (UpdateSignPacket)_packet;
     var position = new Vector3(packet.X, packet.Y, packet.Z);
     if (position.DistanceTo(client.Entity.Position) < client.Reach)
     {
         var block = client.World.GetBlock(position);
         if (block is SignBlock)
         {
             var sign = block as SignBlock;
             var tile = sign.TileEntity as SignTileEntity;
             tile.Text1 = packet.Text1;
             tile.Text2 = packet.Text2;
             tile.Text3 = packet.Text3;
             tile.Text4 = packet.Text4;
             sign.TileEntity = tile;
             client.World.SetBlock(position, sign);
         }
     }
 }
Beispiel #6
0
		protected virtual bool AcceptPlayerMove(McpeMovePlayer message)
		{
			if (GameMode != GameMode.Creative && _isKnownCheater <= _cheatLimit)
			{
				long td = DateTime.UtcNow.Ticks - LastUpdatedTime.Ticks;
				if (HealthManager.CooldownTick == 0 && td > 49*TimeSpan.TicksPerMillisecond && td < 500*TimeSpan.TicksPerMillisecond && Level.SpawnPoint.DistanceTo(KnownPosition) > 2.0)
				{
					double horizSpeed;
					{
						// Speed in the xz plane

						Vector3 origin = new Vector3(KnownPosition.X, 0, KnownPosition.Z);
						double distanceTo = origin.DistanceTo(new Vector3(message.x, 0, message.z));
						horizSpeed = distanceTo/td*TimeSpan.TicksPerSecond;
						//if (horizSpeed > 11.0d)
						//{
						//	_isKnownCheater = true;
						//	Level.BroadcastMessage(string.Format("{0} is spead cheating {3:##.##}m/s {1:##.##}m {2}ms", Username, distanceTo, (int) ((double) td/TimeSpan.TicksPerMillisecond), horizSpeed), type: MessageType.Raw);
						//	AddPopup(new Popup
						//	{
						//		MessageType = MessageType.Tip,
						//		Message = string.Format("{0} sprinting {3:##.##}m/s {1:##.##}m {2}ms", Username, distanceTo, (int)((double)td / TimeSpan.TicksPerMillisecond), horizSpeed),
						//		Duration = 1
						//	});

						//	LastUpdatedTime = DateTime.UtcNow;
						//	//HealthManager.TakeHit(this, 1, DamageCause.Suicide);
						//	//SendMovePlayer();
						//	return;
						//}
					}

					double verticalSpeed;
					{
						// Speed in 3d
						double speedLimit = (message.y - 1.62) - KnownPosition.Y < 0 ? -70d : 12d; //6d;
						double distanceTo = (message.y - 1.62) - KnownPosition.Y;
						verticalSpeed = distanceTo/td*TimeSpan.TicksPerSecond;
						if (!(horizSpeed > 0) && Math.Abs(verticalSpeed) > Math.Abs(speedLimit))
						{
							if (_isKnownCheater == _cheatLimit)
							{
								Level.BroadcastMessage(string.Format("{0} is detected as flying {3:##.##}m/s {1:##.##}m {2}ms", Username, distanceTo, (int) ((double) td/TimeSpan.TicksPerMillisecond), verticalSpeed), type: MessageType.Raw);
								Log.WarnFormat("{0} is fly cheating {3:##.##}m/s {1:##.##}m {2}ms", Username, distanceTo, (int) ((double) td/TimeSpan.TicksPerMillisecond), verticalSpeed);
							}
							//AddPopup(new Popup
							//{
							//	MessageType = MessageType.Tip,
							//	Message = string.Format("{3:##.##}m/s {1:##.##}m {2}ms", Username, distanceTo, (int)((double)td / TimeSpan.TicksPerMillisecond), verticalSpeed),
							//	Duration = 1
							//});

							LastUpdatedTime = DateTime.UtcNow;
							//HealthManager.TakeHit(this, 1, DamageCause.Suicide);
							//SendMovePlayer();
							_isKnownCheater++;
							return false;
						}
					}

					AddPopup(new Popup
					{
						MessageType = MessageType.Tip,
						Message = string.Format("Horiz: {0:##.##}m/s Vert: {1:##.##}m/s", horizSpeed, verticalSpeed),
						Duration = 1
					});
				}
			}

			return true;
		}
Beispiel #7
0
		private Entity CheckEntityCollide(Vector3 position, Vector3 direction)
		{
			var players = Level.GetSpawnedPlayers().OrderBy(player => position.DistanceTo(player.KnownPosition.ToVector3()));
			Ray2 ray = new Ray2
			{
				x = position,
				d = direction.Normalize()
			};

			foreach (var entity in players)
			{
				if (entity == Shooter) continue;

				if (Intersect(entity.GetBoundingBox(), ray))
				{
					if (ray.tNear < direction.Distance) break;

					Vector3 p = ray.x + ray.tNear*ray.d;
					KnownPosition = new PlayerLocation((float) p.X, (float) p.Y, (float) p.Z);
					return entity;
				}
			}

			var entities = Level.Entities.Values.OrderBy(entity => position.DistanceTo(entity.KnownPosition.ToVector3()));
			foreach (Entity entity in entities)
			{
				if (entity == Shooter) continue;
				if (entity == this) continue;

				if (Intersect(entity.GetBoundingBox(), ray))
				{
					if (ray.tNear < direction.Distance) break;

					Vector3 p = ray.x + ray.tNear*ray.d;
					KnownPosition = new PlayerLocation((float) p.X, (float) p.Y, (float) p.Z);
					return entity;
				}
			}

			return null;
		}
Beispiel #8
0
        protected virtual void HandleMovePlayer(McpeMovePlayer message)
        {
            if (!IsSpawned || HealthManager.IsDead) return;

            lock (_moveSyncLock)
            {
                if (_lastPlayerMoveSequenceNUmber > message.DatagramSequenceNumber)
                {
                    Log.DebugFormat("Skipping move datagram {1}/{2} for player {0}", Username, _lastPlayerMoveSequenceNUmber, message.DatagramSequenceNumber);
                    return;
                }
                else
                {
                    _lastPlayerMoveSequenceNUmber = message.DatagramSequenceNumber;
                }

                if (_lastOrderingIndex > message.OrderingIndex)
                {
                    Log.DebugFormat("Skipping move ordering {1}/{2} for player {0}", Username, _lastOrderingIndex, message.OrderingIndex);
                    return;
                }
                else
                {
                    _lastOrderingIndex = message.OrderingIndex;
                }

                long td = DateTime.UtcNow.Ticks - LastUpdatedTime.Ticks;
                Vector3 origin = new Vector3(KnownPosition.X, 0, KnownPosition.Z);
                double distanceTo = origin.DistanceTo(new Vector3(message.x, 0, message.z));
                if (distanceTo/td*TimeSpan.TicksPerSecond > 25.0d)
                {
                    //SendMovePlayer();
                    return;
                }
            }

            //bool useAntiCheat = false;
            //if (useAntiCheat)
            //{
            //	long td = DateTime.UtcNow.Ticks - LastUpdatedTime.Ticks;
            //	if (GameMode == GameMode.Survival
            //		&& HealthManager.CooldownTick == 0
            //		&& td > 49*TimeSpan.TicksPerMillisecond
            //		&& td < 500*TimeSpan.TicksPerMillisecond
            //		&& Level.SpawnPoint.DistanceTo(new BlockCoordinates(KnownPosition)) > 2.0
            //		)
            //	{
            //		double horizSpeed;
            //		{
            //			// Speed in the xz plane

            //			Vector3 origin = new Vector3(KnownPosition.X, 0, KnownPosition.Z);
            //			double distanceTo = origin.DistanceTo(new Vector3(message.x, 0, message.z));
            //			horizSpeed = distanceTo/td*TimeSpan.TicksPerSecond;
            //			if (horizSpeed > 11.0d)
            //			{
            //				//Level.BroadcastTextMessage(string.Format("{0} spead cheating {3:##.##}m/s {1:##.##}m {2}ms", Username, distanceTo, (int) ((double) td/TimeSpan.TicksPerMillisecond), horizSpeed), type: MessageType.Raw);
            //				AddPopup(new Popup
            //				{
            //					MessageType = MessageType.Tip,
            //					Message = string.Format("{0} sprinting {3:##.##}m/s {1:##.##}m {2}ms", Username, distanceTo, (int) ((double) td/TimeSpan.TicksPerMillisecond), horizSpeed),
            //					Duration = 1
            //				});

            //				LastUpdatedTime = DateTime.UtcNow;
            //				HealthManager.TakeHit(this, 1, DamageCause.Suicide);
            //				SendMovePlayer();
            //				return;
            //			}
            //		}

            //		double verticalSpeed;
            //		{
            //			// Speed in 3d
            //			double speedLimit = (message.y - 1.62) - KnownPosition.Y < 0 ? -70d : 6d;
            //			double distanceTo = (message.y - 1.62) - KnownPosition.Y;
            //			verticalSpeed = distanceTo/td*TimeSpan.TicksPerSecond;
            //			if (!(horizSpeed > 0) && Math.Abs(verticalSpeed) > Math.Abs(speedLimit))
            //			{
            //				//Level.BroadcastTextMessage(string.Format("{0} fly cheating {3:##.##}m/s {1:##.##}m {2}ms", Username, distanceTo, (int) ((double) td/TimeSpan.TicksPerMillisecond), verticalSpeed), type: MessageType.Raw);
            //				AddPopup(new Popup
            //				{
            //					MessageType = MessageType.Tip,
            //					Message = string.Format("{3:##.##}m/s {1:##.##}m {2}ms", Username, distanceTo, (int) ((double) td/TimeSpan.TicksPerMillisecond), verticalSpeed),
            //					Duration = 1
            //				});

            //				LastUpdatedTime = DateTime.UtcNow;
            //				HealthManager.TakeHit(this, 1, DamageCause.Suicide);
            //				//SendMovePlayer();
            //				return;
            //			}
            //		}
            //		AddPopup(new Popup
            //		{
            //			MessageType = MessageType.Tip,
            //			Message = string.Format("Horiz: {0:##.##}m/s Vert: {1:##.##}m/s", horizSpeed, verticalSpeed),
            //			Duration = 1
            //		});
            //	}
            //}

            KnownPosition = new PlayerLocation
            {
                X = message.x,
                Y = message.y - 1.62f,
                Z = message.z,
                Pitch = message.pitch,
                Yaw = message.yaw,
                HeadYaw = message.headYaw
            };

            LastUpdatedTime = DateTime.UtcNow;

            //if (Level.Random.Next(0, 5) == 0)
            //{
            //	int data = 0;
            //	//data = (int) uint.Parse("FFFF0000", NumberStyles.HexNumber);
            //	data = Level.Random.Next((int) uint.Parse("FFFF0000", NumberStyles.HexNumber), (int) uint.Parse("FFFFFFFF", NumberStyles.HexNumber));

            //	Level.RelayBroadcast(new McpeLevelEvent
            //	{
            //		eventId = 0x4000 | 22,
            //		x = KnownPosition.X,
            //		//y = KnownPosition.Y - 1.62f,
            //		y = KnownPosition.Y - 1f,
            //		z = KnownPosition.Z,
            //		data = data
            //	});
            //}

            ThreadPool.QueueUserWorkItem(delegate(object state) { SendChunksForKnownPosition(); });
        }
Beispiel #9
0
        /// <summary>
        ///     Handles the move player.
        /// </summary>
        /// <param name="message">The message.</param>
        private void HandleMovePlayer(McpeMovePlayer message)
        {
            if (HealthManager.IsDead) return;

            long td = DateTime.UtcNow.Ticks - LastUpdatedTime.Ticks;
            if (GameMode == GameMode.Survival
                && HealthManager.CooldownTick == 0
                && td > 49*TimeSpan.TicksPerMillisecond
                && td < 500*TimeSpan.TicksPerMillisecond
                && Level.SpawnPoint.DistanceTo(new BlockCoordinates(KnownPosition)) > 2.0
                )
            {
                double horizSpeed;
                {
                    // Speed in the xz plane

                    Vector3 origin = new Vector3(KnownPosition.X, 0, KnownPosition.Z);
                    double distanceTo = origin.DistanceTo(new Vector3(message.x, 0, message.z));
                    horizSpeed = distanceTo/td*TimeSpan.TicksPerSecond;
                    if (horizSpeed > 11.0d)
                    {
                        Level.BroadcastTextMessage(string.Format("{0} spead cheating {3:##.##}m/s {1:##.##}m {2}ms", Username, distanceTo, (int) ((double) td/TimeSpan.TicksPerMillisecond), horizSpeed), type: MessageType.Chat);
                        AddPopup(new Popup
                        {
                            MessageType = MessageType.Chat,
                            Message = string.Format("{0} sprinting {3:##.##}m/s {1:##.##}m {2}ms", Username, distanceTo, (int) ((double) td/TimeSpan.TicksPerMillisecond), horizSpeed),
                            Duration = 1
                        });

                        LastUpdatedTime = DateTime.UtcNow;
                        HealthManager.TakeHit(this, 1, DamageCause.Suicide);
                        SendMovePlayer();
                        return;
                    }
                }

                double verticalSpeed;
                {
                    // Speed in 3d
                    double speedLimit = (message.y - 1.62) - KnownPosition.Y < 0 ? -70d : 6d;
                    double distanceTo = (message.y - 1.62) - KnownPosition.Y;
                    verticalSpeed = distanceTo/td*TimeSpan.TicksPerSecond;
                    if (!(horizSpeed > 0) && Math.Abs(verticalSpeed) > Math.Abs(speedLimit))
                    {
                        //Level.BroadcastTextMessage(string.Format("{0} fly cheating {3:##.##}m/s {1:##.##}m {2}ms", Username, distanceTo, (int) ((double) td/TimeSpan.TicksPerMillisecond), verticalSpeed), type: MessageType.Raw);
                        AddPopup(new Popup
                        {
                            MessageType = MessageType.Tip,
                            Message = string.Format("{3:##.##}m/s {1:##.##}m {2}ms", Username, distanceTo, (int) ((double) td/TimeSpan.TicksPerMillisecond), verticalSpeed),
                            Duration = 1
                        });

                        LastUpdatedTime = DateTime.UtcNow;
                        HealthManager.TakeHit(this, 1, DamageCause.Suicide);
                        //SendMovePlayer();
                        return;
                    }
                }
                AddPopup(new Popup
                {
                    MessageType = MessageType.Tip,
                    Message = string.Format("Horiz: {0:##.##}m/s Vert: {1:##.##}m/s", horizSpeed, verticalSpeed),
                    Duration = 1
                });
            }

            KnownPosition = new PlayerLocation
            {
                X = message.x,
                Y = message.y - 1.62f,
                Z = message.z,
                Pitch = message.pitch,
                Yaw = message.yaw,
                HeadYaw = message.headYaw
            };
            LastUpdatedTime = DateTime.UtcNow;

            if (IsBot) return;

            //if (Level.Random.Next(0, 5) == 0)
            //{
            //	int data = 0;
            //	//data = (int) uint.Parse("FFFF0000", NumberStyles.HexNumber);
            //	data = Level.Random.Next((int) uint.Parse("FFFF0000", NumberStyles.HexNumber), (int) uint.Parse("FFFFFFFF", NumberStyles.HexNumber));

            //	Level.RelayBroadcast(new McpeLevelEvent
            //	{
            //		eventId = 0x4000 | 22,
            //		x = KnownPosition.X,
            //		//y = KnownPosition.Y - 1.62f,
            //		y = KnownPosition.Y - 1f,
            //		z = KnownPosition.Z,
            //		data = data
            //	});
            //}

            SendChunksForKnownPosition();
        }
        public override void ScheduledUpdate(World world, Vector3 position)
        {
            bool canSpread = !(world.GetBlock(position + Vector3.Down) is AirBlock);

            // Check inward flow
            Block above = world.GetBlock(position + Vector3.Up);
            Block[] neighbors = new Block[]
            {
                world.GetBlock(position + Vector3.Forward),
                world.GetBlock(position + Vector3.Backward),
                world.GetBlock(position + Vector3.Left),
                world.GetBlock(position + Vector3.Right),
            };
            if (this.Metadata != 0)
            {
                if (above is WaterFlowingBlock || above is WaterStillBlock)
                    this.Metadata = 1;
                else
                {
                    byte minLevel = 8;
                    int sourceCount = 0;
                    for (int i = 0; i < neighbors.Length; i++)
                    {
                        if (neighbors[i] is WaterFlowingBlock ||
                            neighbors[i] is WaterStillBlock)
                        {
                            if (neighbors[i].Metadata < minLevel)
                                minLevel = neighbors[i].Metadata;
                            if (neighbors[i].Metadata == 0)
                                sourceCount++;
                        }
                    }
                    if (sourceCount >= 2)
                    {
                        this.Metadata = 0;
                        return;
                    }
                    if (minLevel > 0)
                    {
                        this.Metadata = (byte)(minLevel + 1);
                        if (this.Metadata > 7)
                        {
                            this.Metadata = 7;
                            world.SetBlock(position, new AirBlock());
                            return;
                        }
                    }
                }
            }

            // Check outward flow
            if (this.Metadata < 7)
            {
                Vector3 shortestLocation = new Vector3(6, 0, 6);
                List<Vector3> additionalLocations = new List<Vector3>();
                for (int x = -5; x <= 5; x++)
                    for (int z = -5; z <= 5; z++)
                    {
                        if (Math.Abs(x) + Math.Abs(z) > 5)
                            continue;
                        if (world.GetBlock(position + new Vector3(x, -1, z)) is AirBlock)
                        {
                            if (position.DistanceTo(position + new Vector3(x, 0, z)) ==
                                position.DistanceTo(position + shortestLocation))
                                additionalLocations.Add(new Vector3(x, 0, z));
                            if (position.DistanceTo(position + new Vector3(x, 0, z)) <
                                position.DistanceTo(position + shortestLocation))
                            {
                                shortestLocation = new Vector3(x, 0, z);
                                additionalLocations.Clear();
                            }
                        }
                    }
                if (shortestLocation.Equals(new Vector3(6, 0, 6)))
                {
                    additionalLocations.Add(new Vector3(-6, 0, 6));
                    additionalLocations.Add(new Vector3(6, 0, -6));
                    additionalLocations.Add(new Vector3(-6, 0, -6));
                }
                additionalLocations.Add(shortestLocation);
                foreach (Vector3 v in additionalLocations)
                {
                    Vector3 vC = v.Clamp(1);
                    Vector3 newLocation = position + new Vector3(vC.X, 0, 0);
                    Block b = world.GetBlock(newLocation);
                    if (b is AirBlock)
                        world.SetBlock(newLocation, new WaterFlowingBlock((byte)(this.Metadata + 1)));
                    newLocation = position + new Vector3(0, 0, vC.Z);
                    b = world.GetBlock(newLocation);
                    if (b is AirBlock)
                        world.SetBlock(newLocation, new WaterFlowingBlock((byte)(this.Metadata + 1)));
                }
            }
        }
        internal unsafe void RenderVerts(TKContext ctx, IMatrixNode _singleBind, MDL0BoneNode selectedBone, Vector3 cam, bool pass2)
        {
            if (!_render)
                return;

            foreach (Vertex3 v in _vertices)
            {
                Color w = v._highlightColor != Color.Transparent ? v._highlightColor : (_singleBind != null && _singleBind == selectedBone) ? Color.Red : v.GetWeightColor(selectedBone);
                if (w != Color.Transparent)
                    GL.Color4(w);
                else
                    GL.Color4(DefaultVertColor);

                float d = cam.DistanceTo(_singleBind == null ? v.WeightedPosition : _singleBind.Matrix * v.WeightedPosition);
                if (d == 0) d = 0.000000000001f;
                GL.PointSize((5000 / d).Clamp(1.0f, !pass2 ? 5.0f : 8.0f));

                GL.Begin(BeginMode.Points);
                GL.Vertex3(v.WeightedPosition._x, v.WeightedPosition._y, v.WeightedPosition._z);
                GL.End();
            }
        }