public virtual void OnTick() { Age++; if (DoRotationCalculations) { UpdateRotations(); } _previousPosition = KnownPosition; if (IsNoAi) { return; } // IsMoving = Velocity.LengthSquared() > 0f; var feetBlock = Level?.GetBlock(new BlockCoordinates(KnownPosition)); if (feetBlock != null) { if (!feetBlock.Solid) { if (KnownPosition.OnGround) { KnownPosition.OnGround = false; } else { } } else { //KnownPosition.OnGround = true; } } var headBlock = Level?.GetBlock(KnownPosition.GetCoordinates3D() + new BlockCoordinates(0, 1, 0)); if (headBlock != null) { if (headBlock.IsWater) { IsInWater = true; } else { IsInWater = false; } } //HealthManager.OnTick(); }
private void PositionCheck() { BlockCoordinates check = KnownPosition.GetCoordinates3D() + Level.Down; if (!Level.GetBlock(check).IsSolid) { KnownPosition.Y -= 1; } else { CheckPosition = false; } }
public override void Update(IUpdateArgs args) { if (WaitingOnChunk && Age % 4 == 0) { NoAi = true; if (Level.GetChunk(KnownPosition.GetCoordinates3D(), true) != null) { Velocity = Vector3.Zero; WaitingOnChunk = false; NoAi = false; } } ChunkCoordinates oldChunkCoordinates = new ChunkCoordinates(base.KnownPosition); bool sprint = IsSprinting; bool sneak = IsSneaking; if (!CanFly && IsFlying) { IsFlying = false; } if (IsSprinting && !CanSprint) { IsSprinting = false; } Controller.Update(args.GameTime); //KnownPosition.HeadYaw = KnownPosition.Yaw; if (IsSprinting && !sprint) { FOVModifier = 10; Network.EntityAction((int)EntityId, EntityAction.StartSprinting); } else if (!IsSprinting && sprint) { FOVModifier = 0; Network.EntityAction((int)EntityId, EntityAction.StopSprinting); } if (IsSneaking != sneak) { if (IsSneaking) { Network.EntityAction((int)EntityId, EntityAction.StartSneaking); Camera.UpdateOffset(new Vector3(0f, -0.15f, 0.35f)); } else { Network.EntityAction((int)EntityId, EntityAction.StopSneaking); Camera.UpdateOffset(Vector3.Zero); } } // DoHealthAndExhaustion(); var previousCheckedInput = _prevCheckedInput; if ((Controller.CheckInput && Controller.CheckMovementInput)) { _prevCheckedInput = true; if (!previousCheckedInput || World.FormManager.IsShowingForm) { return; } UpdateRayTracer(); //if (Controller.InputManager.IsDown(InputCommand.LeftClick) && DateTime.UtcNow - _lastAnimate >= TimeSpan.FromMilliseconds(500)) //{ // SwingArm(true); //} var hitEntity = HitEntity; if (hitEntity != null && Controller.InputManager.IsPressed(InputCommand.LeftClick) && hitEntity is LivingEntity) { if (_destroyingBlock) { StopBreakingBlock(forceCanceled: true); } InteractWithEntity(hitEntity, true); } else if (hitEntity != null && Controller.InputManager.IsPressed(InputCommand.RightClick) && hitEntity is LivingEntity) { if (_destroyingBlock) { StopBreakingBlock(forceCanceled: true); } InteractWithEntity(hitEntity, false); } else if (hitEntity == null && !_destroyingBlock && Controller.InputManager.IsPressed(InputCommand.LeftClick) && !HasRaytraceResult) { HandleLeftClick(Inventory[Inventory.SelectedSlot], Inventory.SelectedSlot); } else if (hitEntity == null && !_destroyingBlock && Controller.InputManager.IsDown(InputCommand.LeftClick) && !IsWorldImmutable && HasRaytraceResult) //Destroying block. { StartBreakingBlock(); } else if (_destroyingBlock && Controller.InputManager.IsUp(InputCommand.LeftClick)) { StopBreakingBlock(); } else if (_destroyingBlock && Controller.InputManager.IsDown(InputCommand.LeftClick)) { if (_destroyingTarget != new BlockCoordinates(Vector3.Floor(Raytraced))) { StopBreakingBlock(true, true); if (Gamemode != Gamemode.Creative) { StartBreakingBlock(); } } else { if ((DateTime.UtcNow - _lastAnimate).TotalMilliseconds > 500) { _lastAnimate = DateTime.UtcNow; SwingArm(true); } var timeRan = (DateTime.UtcNow - _destroyingTick).TotalMilliseconds / 50d; if (timeRan >= _destroyTimeNeeded) { StopBreakingBlock(true); } } } else if (Controller.InputManager.IsPressed(InputCommand.RightClick)) { bool handledClick = false; var item = Inventory[Inventory.SelectedSlot]; // Log.Debug($"Right click!"); if (item != null) { handledClick = HandleClick(item, Inventory.SelectedSlot); } /*if (!handledClick && Inventory.OffHand != null && !(Inventory.OffHand is ItemAir)) * { * handledClick = HandleRightClick(Inventory.OffHand, 1); * }*/ } if (hitEntity != null && HasCollision) { if (IsColliding(hitEntity)) { //var distance = DistanceToHorizontal(hitEntity); // Velocity += (KnownPosition.ToVector3() - hitEntity.KnownPosition.ToVector3()); } } } else { if (_destroyingBlock) { StopBreakingBlock(); } _prevCheckedInput = false; _lastTimeWithoutInput = DateTime.UtcNow; } if (PreviousSlot != Inventory.SelectedSlot) { var slot = Inventory.SelectedSlot; Network?.HeldItemChanged(Inventory[Inventory.SelectedSlot], (short)slot); PreviousSlot = slot; } base.Update(args); }
public override void Update(IUpdateArgs args) { bool hasActiveDialog = Alex.Instance.GuiManager.ActiveDialog != null; Controller.CheckMovementInput = !hasActiveDialog; if (WaitingOnChunk && Age % 4 == 0) { NoAi = true; if (Level.GetChunk(KnownPosition.GetCoordinates3D(), true) != null) { WaitingOnChunk = false; } } if (!IsSpawned) { base.Update(args); return; } bool sprint = IsSprinting; bool sneak = IsSneaking; if (!CanFly && IsFlying) { IsFlying = false; } if (IsSprinting && !CanSprint) { IsSprinting = false; } Controller.Update(args.GameTime); //KnownPosition.HeadYaw = KnownPosition.Yaw; if (IsSprinting && !sprint) { FOVModifier = 10; Network.EntityAction((int)EntityId, EntityAction.StartSprinting); } else if (!IsSprinting && sprint) { FOVModifier = 0; Network.EntityAction((int)EntityId, EntityAction.StopSprinting); } if (IsSneaking != sneak) { if (IsSneaking) { Network.EntityAction((int)EntityId, EntityAction.StartSneaking); Level.Camera.UpdateOffset(new Vector3(0f, -0.15f, 0.35f)); } else { Network.EntityAction((int)EntityId, EntityAction.StopSneaking); Level.Camera.UpdateOffset(Vector3.Zero); } } // DoHealthAndExhaustion(); //var previousCheckedInput = _prevCheckedInput; if (_skipUpdate) { _skipUpdate = false; } else if ((Controller.CheckInput && Controller.CheckMovementInput && !hasActiveDialog)) { UpdateBlockRayTracer(); UpdateRayTracer(); //if (Controller.InputManager.IsDown(InputCommand.LeftClick) && DateTime.UtcNow - _lastAnimate >= TimeSpan.FromMilliseconds(500)) //{ // SwingArm(true); //} bool didLeftClick = Controller.InputManager.IsPressed(InputCommand.LeftClick); bool didRightClick = Controller.InputManager.IsPressed(InputCommand.RightClick); bool leftMouseBtnDown = Controller.InputManager.IsDown(InputCommand.LeftClick); var hitEntity = HitEntity; if (hitEntity != null && didLeftClick && hitEntity is LivingEntity) { if (_destroyingBlock) { StopBreakingBlock(forceCanceled: true); } InteractWithEntity(hitEntity, true, IsLeftHanded ? 1 : 0); } else if (hitEntity != null && didRightClick && hitEntity is LivingEntity) { if (_destroyingBlock) { StopBreakingBlock(forceCanceled: true); } InteractWithEntity(hitEntity, false, IsLeftHanded ? 1 : 0); } else if (hitEntity == null && !_destroyingBlock && didLeftClick && !HasRaytraceResult) { HandleLeftClick(IsLeftHanded ? Inventory.OffHand : Inventory.MainHand, IsLeftHanded ? 1 : 0); } else if (hitEntity == null && !_destroyingBlock && Controller.InputManager.IsBeginPress(InputCommand.LeftClick) && !IsWorldImmutable && HasRaytraceResult) //Destroying block. { StartBreakingBlock(); } else if (_destroyingBlock) { if (!leftMouseBtnDown) { StopBreakingBlock(); } else if (_destroyingTarget != new BlockCoordinates(Vector3.Floor(Raytraced))) { StopBreakingBlock(true, true); if (Gamemode != Gamemode.Creative) { // StartBreakingBlock(); } } } else if (didRightClick) { bool handledClick = false; var item = IsLeftHanded ? Inventory.OffHand : Inventory.MainHand; // [Inventory.SelectedSlot]; // Log.Debug($"Right click!"); if (item != null) { handledClick = HandleClick( item, IsLeftHanded ? 1 : 0, Inventory.HotbarOffset + Inventory.SelectedSlot); } /*if (!handledClick && Inventory.OffHand != null && !(Inventory.OffHand is ItemAir)) * { * handledClick = HandleRightClick(Inventory.OffHand, 1); * }*/ } if (hitEntity != null && HasCollision) { if (IsColliding(hitEntity)) { //var distance = DistanceToHorizontal(hitEntity); // Velocity += (KnownPosition.ToVector3() - hitEntity.KnownPosition.ToVector3()); } } } else { if (_destroyingBlock) { StopBreakingBlock(); } } if (PreviousSlot != Inventory.SelectedSlot) { var slot = Inventory.SelectedSlot; Network?.HeldItemChanged(Inventory[Inventory.SelectedSlot], (short)slot); PreviousSlot = slot; } if (hasActiveDialog) { _skipUpdate = true; } base.Update(args); }
public virtual void OnTick() { SeenEntities.Clear(); UnseenEntities.Clear(); Age++; HealthManager.OnTick(); if (_isHit && Age > _hitAnimationEnd) { _isHit = false; ModelRenderer.EntityColor = Color.White.ToVector3(); } if (DoRotationCalculations) { UpdateRotations(); } else { KnownPosition.Yaw = KnownPosition.HeadYaw; } _previousPosition = KnownPosition; if (ServerEntity && DateTime.UtcNow >= NextUpdate) { var distanceMoved = DistanceMoved; DistanceMoved = 0; //PreviousUpdate _mvSpeed = (float)(distanceMoved * (TimeSpan.FromSeconds(1) / (DateTime.UtcNow - PreviousUpdate))); PreviousUpdate = DateTime.UtcNow; NextUpdate = DateTime.UtcNow + TimeSpan.FromMilliseconds(500); } if (IsNoAi) { return; } // IsMoving = Velocity.LengthSquared() > 0f; var knownPos = new BlockCoordinates(new Vector3(KnownPosition.X, KnownPosition.Y, KnownPosition.Z)); var knownDown = KnownPosition.GetCoordinates3D(); if (!(Network is JavaNetworkProvider)) { knownDown = knownDown.BlockDown(); } var blockBelowFeet = Level?.GetBlockStates(knownDown.X, knownDown.Y, knownDown.Z); var feetBlock = Level?.GetBlockStates(knownPos.X, knownPos.Y, knownPos.Z).ToArray(); var headBlock = Level?.GetBlock(KnownPosition.GetCoordinates3D() + new BlockCoordinates(0, 1, 0)); if (headBlock != null) { if (headBlock.BlockMaterial == Material.Water || headBlock.IsWater) { HeadInWater = true; } else { HeadInWater = false; } } if (blockBelowFeet != null) { if (blockBelowFeet.Any(b => b.State.Block.BlockMaterial == Material.Water || b.State.Block.IsWater)) { AboveWater = true; } else { AboveWater = false; } } else { AboveWater = false; } if (feetBlock != null) { if (feetBlock.Any(b => b.State.Block.BlockMaterial == Material.Water || b.State.Block.IsWater)) { FeetInWater = true; } else { FeetInWater = false; } if (feetBlock.Any(b => b.State.Block.BlockMaterial == Material.Lava)) { IsInLava = true; } else { IsInLava = false; } if (!feetBlock.Any(x => x.Storage == 0 && x.State.Block.Solid)) { KnownPosition.OnGround = false; } } IsInWater = FeetInWater || HeadInWater; /* * if (headBlock != null) * { * if (headBlock.IsWater) * { * IsInWater = true; * } * else * { * IsInWater = false; * } * }*/ //HealthManager.OnTick(); }