I have created a spear weapon in the mod I am making, and I want this spear to be able to attack entites farther than 3 blocks away. I have spent a good amount of time looking for explanations, but the only ones I could find were for Minecraft versions 1.8 or 1.12, while I am modding on 1.16.4.
The tutorial i found most helpful was Jabelar's tutorial. I was able to refractor most of the code, but I couldn't figure out what I needed to do for the Raytracing and mouseEvent. Does anyone know what I should do?
You're making this much more complicated than it needs to be. You can use Attribute Modifiers to complete what you need. Not sure if this is the best way to do this, but I declared a public static final IAttribute that equals a new RangedAttribute((IAttribute)null, "generic.reachDistance", 5.0D, 0.0D, 1024.0D
Then, just declare a public static final UUID for it and grab a random UUID from the internet
after that, it's as simple as using
builder.put(<Your main class . your attack range IAttribute variable name>, new AttributeModifier(<your attack range UUID variable name>, "Weapon modifier", (double)<the amount of bonus range you want here>, AttributeModifier.Operation.ADDITION));
I believe this should work, but I'm not 100% as I'm on 1.12 just glancing at 1.16 code for reference
Rollback Post to RevisionRollBack
"You know you're joke is good when you have to explain it to everyone."
I had originally tried to use Attribute modifiers, but that only changed the distance where i could mine blocks. I have figured out how to increase the attack reach with Ray Tracing though.
You're making this much more complicated than it needs to be. You can use Attribute Modifiers to complete what you need. Not sure if this is the best way to do this, but I declared a public static final IAttribute that equals a new RangedAttribute((IAttribute)null, "generic.reachDistance", 5.0D, 0.0D, 1024.0D
Then, just declare a public static final UUID for it and grab a random UUID from the internet
after that, it's as simple as using
builder.put(<Your main class . your attack range IAttribute variable name>, new AttributeModifier(<your attack range UUID variable name>, "Weapon modifier", (double)<the amount of bonus range you want here>, AttributeModifier.Operation.ADDITION));
I believe this should work, but I'm not 100% as I'm on 1.12 just glancing at 1.16 code for reference
Hello.
I have created a spear weapon in the mod I am making, and I want this spear to be able to attack entites farther than 3 blocks away. I have spent a good amount of time looking for explanations, but the only ones I could find were for Minecraft versions 1.8 or 1.12, while I am modding on 1.16.4.
The tutorial i found most helpful was Jabelar's tutorial. I was able to refractor most of the code, but I couldn't figure out what I needed to do for the Raytracing and mouseEvent. Does anyone know what I should do?
You're making this much more complicated than it needs to be. You can use Attribute Modifiers to complete what you need. Not sure if this is the best way to do this, but I declared a public static final IAttribute that equals a new RangedAttribute((IAttribute)null, "generic.reachDistance", 5.0D, 0.0D, 1024.0D
Then, just declare a public static final UUID for it and grab a random UUID from the internet
after that, it's as simple as using
builder.put(<Your main class . your attack range IAttribute variable name>, new AttributeModifier(<your attack range UUID variable name>, "Weapon modifier", (double)<the amount of bonus range you want here>, AttributeModifier.Operation.ADDITION));
I believe this should work, but I'm not 100% as I'm on 1.12 just glancing at 1.16 code for reference
"You know you're joke is good when you have to explain it to everyone."
I had originally tried to use Attribute modifiers, but that only changed the distance where i could mine blocks. I have figured out how to increase the attack reach with Ray Tracing though.