public override void OnTick() { base.OnTick(); TimeToLive--; PickupDelay--; if (TimeToLive <= 0) { DespawnEntity(); return; } // Motion if (PickupDelay > 0) { return; } var players = Level.GetSpawnedPlayers(); foreach (var player in players) { if (KnownPosition.DistanceTo(player.KnownPosition) <= 2) { if (player.GameMode == GameMode.Survival) { //Add the items to the inventory if posible if (player.Inventory.SetFirstEmptySlot((short)Item.Id, (byte)Count, Item.Metadata)) { //BUG: If this is sent, the client crashes for some unknown reason. var takeItemEntity = McpeTakeItemEntity.CreateObject(); takeItemEntity.entityId = EntityId; takeItemEntity.target = player.EntityId; Level.RelayBroadcast(takeItemEntity); DespawnEntity(); break; } } } } }
public override void OnTick(Entity[] entities) { if (Velocity == Vector3.Zero) { // Object was resting and now someone removed the block on which it was resting // or someone places a block over it. if (IsMobInGround(KnownPosition)) { Velocity += new Vector3(0, (float)Gravity, 0); } else { bool onGround = IsMobOnGround(KnownPosition); if (!onGround) { Velocity -= new Vector3(0, (float)Gravity, 0); } } } if (Velocity.Length() > 0.01) { bool onGroundBefore = IsMobOnGround(KnownPosition); if (IsMobInGround(KnownPosition)) { Velocity += new Vector3(0, (float)Gravity, 0); KnownPosition.X += Velocity.X; KnownPosition.Y += Velocity.Y; KnownPosition.Z += Velocity.Z; BroadcastMove(); BroadcastMotion(); return; } Vector3 adjustedVelocity = GetAdjustedLengthFromCollision(Velocity); KnownPosition.X += adjustedVelocity.X; KnownPosition.Y += adjustedVelocity.Y; KnownPosition.Z += adjustedVelocity.Z; BroadcastMove(); BroadcastMotion(); bool adjustAngle = adjustedVelocity != Velocity; if (adjustAngle) { CheckBlockAhead(); } bool onGround = IsMobOnGround(KnownPosition); if (!onGroundBefore && onGround) { float ff = 0.6f * 0.98f; Velocity *= new Vector3(ff, 0, ff); } else { Velocity *= (float)(1.0 - Drag); if (!onGround) { Velocity -= new Vector3(0, (float)Gravity, 0); } else { float ff = 0.6f * 0.98f; Velocity *= new Vector3(ff, 0, ff); } } } else if (Velocity != Vector3.Zero) { KnownPosition.X += (float)Velocity.X; KnownPosition.Y += (float)Velocity.Y; KnownPosition.Z += (float)Velocity.Z; Velocity = Vector3.Zero; LastUpdatedTime = DateTime.UtcNow; NoAi = true; BroadcastMove(true); BroadcastMotion(true); } TimeToLive--; PickupDelay--; if (TimeToLive <= 0) { DespawnEntity(); return; } // Motion if (PickupDelay > 0) { return; } var bbox = GetBoundingBox(); var players = Level.GetSpawnedPlayers(); foreach (var player in players) { if (player.GameMode != GameMode.Spectator && bbox.Intersects(player.GetBoundingBox() + 1)) { if (player.PickUpItem(this)) { { var takeItemEntity = McpeTakeItemEntity.CreateObject(); takeItemEntity.runtimeEntityId = EntityId; takeItemEntity.target = player.EntityId; Level.RelayBroadcast(player, takeItemEntity); } { var takeItemEntity = McpeTakeItemEntity.CreateObject(); takeItemEntity.runtimeEntityId = EntityId; takeItemEntity.target = EntityManager.EntityIdSelf; player.SendPacket(takeItemEntity); } DespawnEntity(); if (Item.Count > 0) { Level.DropItem(KnownPosition, Item); } break; } } } }