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.

Featured Replies

Posted

Hello,

 

When you (or any living thing) attack a mob (whether a monster or a mob) with your fist or anything that is not a tool, you apply a knockback on it.

This is handled by EntityLivingBase.attackEntityFrom(DamageSource source, float amount).

                        
if (source.getSourceOfDamage() instanceof EntityLivingBase)
                        {
                            ((EntityLivingBase)source.getSourceOfDamage()).knockBack(this, 0.5F, this.posX - source.getSourceOfDamage().posX, this.posZ - source.getSourceOfDamage().posZ);
                        }

I'd like to change this "0.5F" value. It represents the base knockback force. We could increase or decrease it.

 

Anyone would have an idea about how to edit it ?

Notes about what I already tried :

-LivingAttackEvent is triggered before the knockback, so we can't just cancel it by "pulling" the mob afterwards. Pulling it before looks glitchy.

-SharedMonsterAttributes.KNOCKBACK_RESISTANCE affects all knockbacks (and there are many, many many cases where it's used) so that's not an option.

-LivingHurtEvent is triggered for all damage and without way of knowing who did it so it's not possible either.

  • Author

Make a PullRequest with a knockback event maybe.

 

If one wants to affect all knockbacks, the already existing attribute works fine. Maybe a getBaseKnockback() { return 0.5F; } in EntityLivingBase ?

I have never made a Forge PR, I don't really know yet what's good practice, but I'll look at it.

Would be nice to edit this falue, for ex., to make stronger knockback from custom weapon - Hammer. But I didn't found any proper way to it =(

 

Also, anybody know how to apply a wide swing to custom weapon, like vanilla swords have?

 

 

Would be nice to edit this falue, for ex., to make stronger knockback from custom weapon - Hammer. But I didn't found any proper way to it =(

 

Also, anybody know how to apply a wide swing to custom weapon, like vanilla swords have?

Look in EntityPlayer on line 1408-1421 for an example and override hitEntity in the Items Class and apply this effect in that method as it is hardcoded for ItemSword.

 

*Edit and for knockback override

public MultiMap getAttributeModifiers(EntityEquipmentSlot slot, ItemStack stack)

in your Items class.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Look in EntityPlayer on line 1408-1421 for an example and override hitEntity in the Items Class and apply this effect in that method as it is hardcoded for ItemSword.

Hm, as I realize, the swing is hardcoded in EntityPlayer method attackTargetEntityWithCurrentItem, and there is section that checking if (itemstack != null && itemstack.getItem() instanceof ItemSword). How can I change it through overriding Item's hitEntity? Maybe this question looks noobish, but I missing something there and cannot understand...

Look in EntityPlayer on line 1408-1421 for an example and override hitEntity in the Items Class and apply this effect in that method as it is hardcoded for ItemSword.

Hm, as I realize, the swing is hardcoded in EntityPlayer method attackTargetEntityWithCurrentItem, and there is section that checking if (itemstack != null && itemstack.getItem() instanceof ItemSword). How can I change it through overriding Item's hitEntity? Maybe this question looks noobish, but I missing something there and cannot understand...

Item#hitEntity(...) is called when the Player hits an Entity. Therefore you can do the same thing within this method.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Thank you so much! It's working perfectly when I just copy-pasted the section inside if(flag3) and changed entries to attacker and target.

Well, now only knockback remains, I think I can win it  ;)

Thank you so much! It's working perfectly when I just copy-pasted the section inside if(flag3) and changed entries to attacker and target.

Well, now only knockback remains, I think I can win it  ;)

Awesome, but I think you should understand what that code does on a fundamental level before going on ahead, and if you already do just ignore this message.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Of course I do =)

I just edited swing distance and made it wider to match hammer's size, weight and low attack speed. Maybe I should change the swing and hit sounds too.

  • 2 years later...
On 9/6/2016 at 1:28 PM, Xanderr_K said:

Of course I do ?

I just edited swing distance and made it wider to match hammer's size, weight and low attack speed. Maybe I should change the swing and hit sounds too.

hey, im having some problems recreating what you did, is it possible to share your code, for us newbs ? ? 

35 minutes ago, stephanieNight said:

hey, im having some problems recreating what you did, is it possible to share your code, for us newbs ? ? 

Please don't necro old threads. Make your own.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

  • Guest locked this topic
Guest
This topic is now closed to further replies.

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.