Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

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?

 

 

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.

  • Author

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.

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.

  • Author

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?

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.