Jump to content

Binding default actions to different buttons


Recommended Posts

Ok so I tried using OnAttackStart and Step instead and it works but now I can't get it to stop the custom action.
Just to clarify I am trying to add a stream of particles to the attack/mining action of my item.
Also the custom action (particles) stops itself if used with OnInteractStart and Step but the returns are different for OnAttack so I am sure it's a simple fix to do with where/how the return is used I just can't figure it out.
Here is my code:

namespace ExampleMods
    public class MinerMod : ModSystem

        public override void Start(ICoreAPI api)
            api.RegisterItemClass("miner", typeof(MinerItem));


    public class MinerItem : Item
        public static SimpleParticleProperties particles = new SimpleParticleProperties(
                    1, 1,
                    ColorUtil.ToRgba(50, 220, 220, 220),
                    new Vec3d(),
                    new Vec3d(),
                    new Vec3f(-0.25f, 0.1f, -0.25f),
                    new Vec3f(0.25f, 0.1f, 0.25f),

        public override void OnHeldAttackStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handling)
            handling = EnumHandHandling.PreventDefaultAnimation;

        public override bool OnHeldAttackStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
            if (byEntity.World is IClientWorldAccessor)
                ModelTransform tf = new ModelTransform();

                tf.Origin.Set(0, -1, 0);
                tf.Rotation.Z = Math.Min(30, secondsUsed * 40);
                byEntity.Controls.UsingHeldItemTransformAfter = tf;

                if (secondsUsed > 0.6)
                    Vec3d pos =
                            byEntity.Pos.XYZ.Add(0, byEntity.EyeHeight, 0)
                            .Ahead(1f, byEntity.Pos.Pitch, byEntity.Pos.Yaw)

                    Vec3f speedVec = new Vec3d(0, 0, 0).Ahead(5, byEntity.Pos.Pitch, byEntity.Pos.Yaw).ToVec3f();
                    particles.MinVelocity = speedVec;
                    Random rand = new Random();
                    particles.Color = ColorUtil.ToRgba(255, 255, 100, 200);
                    particles.MinPos = pos.AddCopy(-0.05, -0.05, -0.05);
                    particles.AddPos.Set(0.1, 0.1, 0.1);
                    particles.MinSize = 0.1F;
                    particles.MaxSize = 0.5F;
                    particles.SizeEvolve = new EvolvingNatFloat(EnumTransformFunction.LINEAR, 0);
            return true;


Link to comment
Share on other sites

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.