Adds knockback attribute to players and updated knockback calculation to PlayerEntity#attack (#7806)

This commit is contained in:
Mike Garay authored and GitHub committed 2021-07-16 17:52:58 -07:00
1 parent e6c1814122
commit 2bd83b26aa
6 files changed
+89 -2

No files matched your search

@@ -23,7 +23,7 @@
public static AttributeModifierMap.MutableAttribute func_234570_el_() {
- return LivingEntity.func_233639_cI_().func_233815_a_(Attributes.field_233823_f_, 1.0D).func_233815_a_(Attributes.field_233821_d_, (double)0.1F).func_233814_a_(Attributes.field_233825_h_).func_233814_a_(Attributes.field_233828_k_);
+ return LivingEntity.func_233639_cI_().func_233815_a_(Attributes.field_233823_f_, 1.0D).func_233815_a_(Attributes.field_233821_d_, (double)0.1F).func_233814_a_(Attributes.field_233825_h_).func_233814_a_(Attributes.field_233828_k_).func_233814_a_(net.minecraftforge.common.ForgeMod.REACH_DISTANCE.get());
+ return LivingEntity.func_233639_cI_().func_233815_a_(Attributes.field_233823_f_, 1.0D).func_233815_a_(Attributes.field_233821_d_, (double)0.1F).func_233814_a_(Attributes.field_233825_h_).func_233814_a_(Attributes.field_233828_k_).func_233814_a_(net.minecraftforge.common.ForgeMod.REACH_DISTANCE.get()).func_233814_a_(Attributes.field_233824_g_);
}
protected void func_70088_a() {
@@ -198,6 +198,15 @@
if (p_71059_1_.func_70075_an()) {
if (!p_71059_1_.func_85031_j(this)) {
float f = (float)this.func_233637_b_(Attributes.field_233823_f_);
@@ -1028,7 +_,7 @@
if (f > 0.0F || f1 > 0.0F) {
boolean flag = f2 > 0.9F;
boolean flag1 = false;
- int i = 0;
+ float i = (float)this.func_233637_b_(Attributes.field_233824_g_); // Forge: Initialize this value to the attack knockback attribute of the player, which is by default 0
i = i + EnchantmentHelper.func_77501_a(this);
if (this.func_70051_ag() && flag) {
this.field_70170_p.func_184148_a((PlayerEntity)null, this.func_226277_ct_(), this.func_226278_cu_(), this.func_226281_cx_(), SoundEvents.field_187721_dT, this.func_184176_by(), 1.0F, 1.0F);
@@ -1038,8 +_,10 @@
boolean flag2 = flag && this.field_70143_R > 0.0F && !this.field_70122_E && !this.func_70617_f_() && !this.func_70090_H() && !this.func_70644_a(Effects.field_76440_q) && !this.func_184218_aH() && p_71059_1_ instanceof LivingEntity;
@@ -0,0 +1,67 @@
package net.minecraftforge.debug.entity.player;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import net.minecraft.entity.ai.attributes.Attribute;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.ai.attributes.Attributes;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.*;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import java.util.UUID;
/**
* Tests if the patch to PlayerEntity to make it utilize Attributes.ATTACK_KNOCKBACK works
* The Knockback Sword adds a modifier to the user's attack knockback
* The goal of this patch is to allow modders to more easily add equipment or potion effects that affect the attack knockback of players
* As well as allow command users to modify this attribute for a player
*/
@Mod(PlayerAttackKnockbackTest.MODID)
public class PlayerAttackKnockbackTest {
static final String MODID = "player_attack_knockback_test";
static final float ATTACK_KNOCKBACK_VALUE = 2.0F; // Change this value for testing, but note that the attribute is capped at 5.0D
static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
static RegistryObject<Item> KNOCKBACK_SWORD = ITEMS.register("knockback_sword", () ->
new KnockbackSwordItem(ItemTier.IRON, 3, -2.4F, ATTACK_KNOCKBACK_VALUE, (new Item.Properties()).tab(ItemGroup.TAB_COMBAT))
);
public PlayerAttackKnockbackTest()
{
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
ITEMS.register(modEventBus);
}
static class KnockbackSwordItem extends SwordItem{
private final float attackKnockback;
private final Multimap<Attribute, AttributeModifier> defaultModifiers = ArrayListMultimap.create(); // initialize as empty
protected static final UUID BASE_ATTACK_KNOCKBACK_UUID = UUID.fromString("01efce91-ab3a-4163-b464-5c7bd1ae5496");
KnockbackSwordItem(IItemTier itemTier, int attackDamageIn, float attackSpeedIn, float attackKnockbackIn, Properties properties) {
super(itemTier, attackDamageIn, attackSpeedIn, properties);
this.attackKnockback = attackKnockbackIn;
}
@Override
public Multimap<Attribute, AttributeModifier> getDefaultAttributeModifiers(EquipmentSlotType equipmentSlotType) {
if(equipmentSlotType == EquipmentSlotType.MAINHAND){
if(this.defaultModifiers.isEmpty()){
Multimap<Attribute, AttributeModifier> oldAttributeModifiers = super.getDefaultAttributeModifiers(equipmentSlotType);
this.defaultModifiers.putAll(oldAttributeModifiers);
this.defaultModifiers.put(Attributes.ATTACK_KNOCKBACK, new AttributeModifier(BASE_ATTACK_KNOCKBACK_UUID, "Weapon modifier", (double)this.attackKnockback, AttributeModifier.Operation.ADDITION));
}
return this.defaultModifiers;
}
else return super.getDefaultAttributeModifiers(equipmentSlotType);
}
}
}
+3 -1
View File
@@ -125,4 +125,6 @@ license="LGPL v2.1"
[[mods]]
modId="text_linear_filtering_test"
[[mods]]
modId="custom_tas_test"
modId="player_attack_knockback_test"
[[mods]]
modId="custom_tas_test"
@@ -0,0 +1,3 @@
{
"item.player_attack_knockback_test.knockback_sword": "Knockback Sword"
}
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "player_attack_knockback_test:item/knockback_sword"
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 196 B