Jump to content

[1.10.2] How to increase/decrease a weapon's cooldown? (and other things)


Recommended Posts

Posted

I want to make an

ItemKnife

, that will inherit from

ItemSword

. I want a few things from this item:

 

[*]the main one is I want to make it attack faster. (have a lower cooldown). Is it possible. If so, how?

 

 

 

[*]Also, I suppose the best way of reducing it's damage is using Reflection to change

ItemSword.attackDamage

just for the knife, correct? Or should I override

ItemSword.getDamageVsEntity

instead? (not sure which of the two options is less hacky. What is usually prefered by the community?)

 

 

 

[*]I want the item to be used in craft recipes but not get consumed in the process, how can I do that?

 

 

 

[*]I want this item to deal more damage when used from behind the enemy if the attacker is sneaking. And an even greater damage if the attacker is behind the target, is invisible and is sneaking. I believe the best place to implement this logic would be in a handler of

AttackEntityEvent

, right? Handling events can be expensive, but I don't see an alternative.

 

 

 

[*]still, the problem is, how do I know the target has its back turned to the attacker?

 

 

Posted

the main one is I want to make it attack faster. (have a lower cooldown). Is it possible. If so, how?

I explain this here.

 

  • [*]Also, I suppose the best way of reducing it's damage is using Reflection to change
ItemSword.attackDamage

just for the knife, correct? Or should I override

ItemSword.getDamageVsEntity

instead? (not sure which of the two options is less hacky. What is usually prefered by the community?)

Use the same method I described in the post linked above to change the

ATTACK_DAMAGE

attribute modifier.

 

You'll probably want to override

ItemSword#getDamageVsEntity

as well, though this is only used by non-player entities to determine whether they should replace their currently held sword with one on the ground (the one with a higher return value from this method is favoured). The actual damage dealt when attacking is controlled by the attribute system.

 

I want the item to be used in craft recipes but not get consumed in the process, how can I do that?

Override

Item#hasContainerItem(ItemStack)

to return

true

and override

Item#getContainerItem(ItemStack)

to return its argument (after making any necessary modifications, e.g. damaging the item).

 

I want this item to deal more damage when used from behind the enemy if the attacker is sneaking. And an even greater damage if the attacker is behind the target, is invisible and is sneaking. I believe the best place to implement this logic would be in a handler of

AttackEntityEvent

, right? Handling events can be expensive, but I don't see an alternative.

AttackEntityEvent

is fired whenever a player tries to attack to an entity, before it checks whether the entity can actually be attacked and damaged. I'd recommend overriding

Item#hitEntity

and performing these checks there instead.

 

still, the problem is, how do I know the target has its back turned to the attacker?

You'll probably need to use the

Entity#rotationYaw

field of the target to get its facing and compare the positions of the entities. I don't know exactly how to achieve this.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

I explain this here.

 

So, to make it clear, because the forum post got a bit confusing. a high value to

modifier

in your method

replaceModifier

increases the damage in case the attribute is

ATTACK_DAMAGE

and it decreases the weapon cooldown in case the attribute is

ATTACK_SPEED

?

 

 

You'll probably need to use the

Entity#rotationYaw

field of the target to get its facing and compare the positions of the entities. I don't know exactly how to achieve this.

 

Looking into

Entity#rotationYaw

I found out there's a method

Entity#getAdjustedHorizontalFacing()

, which will make it even easier.

Posted

So, to make it clear, because the forum post got a bit confusing. a high value to

modifier

in your method

replaceModifier

increases the damage in case the attribute is

ATTACK_DAMAGE

and it decreases the weapon cooldown in case the attribute is

ATTACK_SPEED

?

 

Yes.

 

Higher attack damage = more damage dealt, higher attack speed = less cooldown after each attack.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

Thank you. One last thing. Do I have to worry about any of these getting invoked on the client too? I mean, should I not run the code if

world.isRemote

? like the logic for backstabing damage in

hitEntity

or the setting of attributes?

Posted

The attribute modifiers and backstabbing code should run on both sides.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.