Jump to content

[1.10.2] Edit base knockback.


Koward

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 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 ? ? 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Announcements



×
×
  • Create New...

Important Information

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