private void onSqueezing(float dt) { secondsPassed += dt; if (Api.Side == EnumAppSide.Client) { RunningAnimation anim = animUtil.animator.RunningAnimations[0]; } if (secondsPassed > 5) { animUtil?.StopAnimation("twist"); squeezed = true; Api.World.UnregisterGameTickListener(listenerId); } // 4/16f if (Api.Side == EnumAppSide.Server) { Vec3d pos = RandomParticlePos(BlockFacing.HORIZONTALS[Api.World.Rand.Next(4)]); props.MinPos.Set(pos.X, Pos.Y + 0.5f / 16f, pos.Z); props.AddPos.Set(0f, 6 / 16f, 0f); Api.World.SpawnParticles(props); } }
/// <summary> /// Triggers a new animation to play depending on the StackMode setting. /// </summary> /// <param name="targetKey">The key to center the animation around.</param> private void StartAnimation(DeviceKeys targetKey = default(DeviceKeys)) { RunningAnimation anim = null; // Store a reference to the new animation (or the restarted one) if (runningAnimations.Count == 0) { // If there are no running animations, we will always start a new one runningAnimations.Add(anim = new RunningAnimation()); } else if (Properties.TriggerMode != AnimationTriggerMode.AlwaysOn) // Ignore stack/reset when animation is always on // If there are already running animations, exactly what happens depends on StackMode { switch (Properties.StackMode) { case AnimationStackMode.Reset: anim = runningAnimations[0].Reset(); break; case AnimationStackMode.Stack: runningAnimations.Add(anim = new RunningAnimation()); break; } } // If a new animation has been started or an existing one restarted, and we are translating based on key press // assign the target ket to the animation to allow it to calculate the offset. if (anim != null) { anim.assignedKey = targetKey; } }
private void udpateSqueezeRel(RunningAnimation anim) { if (anim == null || mashStack == null) { return; } double squeezeRel = GameMath.Clamp(1f - anim.CurrentFrame / anim.Animation.QuantityFrames / 2f, 0.1f, 1f); float selfHeight = (float)(juiceableLitresTransfered + juiceableLitresLeft) / 10f; squeezeRel += Math.Max(0, 0.9f - selfHeight); squeezeRel = GameMath.Clamp(Math.Min(mashStack.Attributes.GetDouble("squeezeRel", 1), squeezeRel), 0.1f, 1f); mashStack.Attributes.SetDouble("squeezeRel", squeezeRel); }
public override void OnActivated() { players[0].GetComponent <BodyControl>().AddEventListener(this.gameObject); for (int i = 0; i < players.Count; i++) { if (players[i].active) { RunningAnimation runningAnimation = players[i].GetComponentInChildren <RunningAnimation>(); if (runningAnimation) { runningAnimation.SetCurrentFrame(Random.Range(0, runningAnimation.frames.Length)); } players[i].GetComponent <BodyControl>().MoveAutomaticKinematicForTime(moveTime, moveSpeed); } } }
public bool OnBlockInteractCancel(float secondsUsed, IPlayer byPlayer) { RunningAnimation anim = animUtil.animator.GetAnimationState("compress"); udpateSqueezeRel(anim); if (CompressAnimActive) { compressAnimMeta.AnimationSpeed = 0f; (Api as ICoreServerAPI)?.Network.BroadcastBlockEntityPacket(Pos, PacketIdAnimUpdate, new FruitPressAnimPacket() { AnimationActive = true, AnimationSpeed = 0f }); } return(true); }
public bool OnBlockInteractStep(float secondsUsed, IPlayer byPlayer, EnumFruitPressSection section) { if (section != EnumFruitPressSection.Screw) { return(false); } if (mashStack != null) { RunningAnimation anim = animUtil.animator.GetAnimationState("compress"); if (anim != null) { udpateSqueezeRel(anim); } } return(CompressAnimActive && secondsUsed < 4f); }
public void OnBlockInteractStop(float secondsUsed, IPlayer byPlayer) { RunningAnimation anim = animUtil.animator.GetAnimationState("compress"); udpateSqueezeRel(anim); if (!CompressAnimActive) { return; } if (secondsUsed >= 4.8f) { compressAnimMeta.AnimationSpeed = 0f; // Fast forward the server anim.CurrentFrame = anim.Animation.QuantityFrames - 1; (Api as ICoreServerAPI)?.Network.BroadcastBlockEntityPacket(Pos, PacketIdAnimUpdate, new FruitPressAnimPacket() { AnimationActive = true, AnimationSpeed = 0f }); } }