Ejemplo n.º 1
0
        public override void Initialize(ICoreAPI api)
        {
            base.Initialize(api);
            BlockEntityAnimationUtil util = new BlockEntityAnimationUtil(api, this);
            Block block = api.World.BlockAccessor.GetBlock(pos);

            if (api.World.Side.IsClient())
            {
                for (int i = 0; i < pause.Length; i++)
                {
                    util.InitializeAnimator(pause[i], new Vec3f(0, block.Shape.rotateY, 0));
                }

                for (int i = 0; i < transition.Length; i++)
                {
                    util.InitializeAnimator(transition[i], new Vec3f(0, block.Shape.rotateY, 0));
                }

                if (prev != null)
                {
                    util.StartAnimation(new AnimationMetaData()
                    {
                        Code = prev
                    });
                }
            }
            float lastState = animState;

            api.World.RegisterGameTickListener(dt => {
                if (animState != lastState)
                {
                    lastState = animState;
                    if (api.World.Side.IsClient())
                    {
                        if (prev != null)
                        {
                            util.StopAnimation(prev);
                        }
                        util.StartAnimation(new AnimationMetaData()
                        {
                            Code = transition[(int)Math.Round(animState * (transition.Length - 1))]
                        });
                        api.World.PlaySoundAt(block.Sounds.Place, pos.X, pos.Y, pos.Z);
                        api.World.RegisterCallback(dtb =>
                        {
                            util.StopAnimation(transition[(int)Math.Round(animState * (transition.Length - 1))]);
                            util.StartAnimation(new AnimationMetaData()
                            {
                                Code = pause[(int)Math.Round(animState * (pause.Length - 1))]
                            });
                        }, 100);
                    }
                    prev = pause[(int)Math.Round(animState * (pause.Length - 1))];
                }
            }, 30);
        }
Ejemplo n.º 2
0
 public static void InitializeAnimators(this BlockEntityAnimationUtil util, Vec3f rot, params string[] CacheDictKeys)
 {
     foreach (var val in CacheDictKeys)
     {
         util.InitializeAnimator(val, rot);
     }
 }