Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Damage Pipeline Update #792

Merged
merged 55 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
b0fc8d6
Damage Pipeline Changes
Caltinor Apr 8, 2024
acf194a
tweaks to implementation
Caltinor Apr 11, 2024
be0fc4d
add internal annotation to internal class
Caltinor Apr 11, 2024
0a92ec0
javadoc and type clarity changes
Caltinor Apr 11, 2024
2b6bf36
update armor event
Caltinor Apr 11, 2024
642b5ea
resolve missed formatting error
Caltinor Apr 11, 2024
4bff4ea
armor hook reorg
Caltinor Apr 11, 2024
55be2d4
minor tweaks - int cast, shield damage
Caltinor Apr 12, 2024
8f26b03
shield damage value verification
Caltinor Apr 12, 2024
49b2d0f
update javadoc, max block amount, og dmg amount
Caltinor Apr 12, 2024
db41d0e
javadoc update to refresh upstream tasks
Caltinor Apr 12, 2024
1f5ab24
fix 1.20.5 merge errors.
Caltinor Apr 24, 2024
69cb721
Fix branch updating errors
Caltinor Apr 30, 2024
628697e
fix porting errors
Caltinor May 15, 2024
c932aaa
resolve gametest issues
Caltinor May 16, 2024
f1af243
Address comments
Caltinor May 29, 2024
a2a1136
fix formatting issues.
Caltinor May 29, 2024
f4920b7
restore actuallyHurt invul checks
Caltinor Jun 3, 2024
3498f0d
collapse reduction methods
Caltinor Jun 3, 2024
85968d9
remove FQNs from javadocs
Caltinor Jun 3, 2024
66d092e
fix missed formatting issue
Caltinor Jun 3, 2024
2a43729
Update javadocs and formatting
Caltinor Jun 6, 2024
9fcd8cc
refactor event names
Caltinor Jun 6, 2024
4b09217
fix merge error
Caltinor Jun 7, 2024
c32dc60
event refactor in tests fix
Caltinor Jun 7, 2024
00d7a65
update javadoc and fix name typo
Caltinor Jun 7, 2024
e2719b3
update damage container as Stack
Caltinor Jun 8, 2024
ced60ab
update Stack method calls
Caltinor Jun 9, 2024
0b468a2
update javadocs and add helper methods
Caltinor Jun 9, 2024
124a830
update javadoc
Caltinor Jun 9, 2024
fa95f62
rebase patches
Caltinor Jun 13, 2024
9438989
more rebase fixes
Caltinor Jun 13, 2024
6fe17c2
final rebase fixes
Caltinor Jun 13, 2024
0d257a9
spotless cleanup
Caltinor Jun 13, 2024
a6ee880
Merge branch '1.21.x' into 1.20.x
Caltinor Jun 14, 2024
f206ed9
Merge branch '1.21.x' into 1.20.x
Caltinor Jun 14, 2024
1a2bb13
addressing review
Caltinor Jun 15, 2024
e927118
Merge branch '1.21.x' into 1.20.x
Caltinor Jun 15, 2024
60c8336
Merge branch '1.21.x' into 1.20.x
Caltinor Jun 15, 2024
867a2cf
Merge branch '1.21.x' into 1.20.x
Caltinor Jun 15, 2024
925e770
Merge branch '1.21.x' into 1.20.x
Caltinor Jun 16, 2024
b02da13
fix typo and clean javadocs
Caltinor Jun 16, 2024
c0012ca
Fix refactor not applied to patch
Caltinor Jun 16, 2024
da1de4b
Merge branch '1.21.x' into 1.20.x
Caltinor Jun 17, 2024
70471f0
Merge branch '1.21.x' into 1.20.x
Caltinor Jun 19, 2024
5917ebe
additional code cleanup
Caltinor Jun 19, 2024
968b0d9
Merge branch '1.21.x' into 1.20.x
Caltinor Jun 19, 2024
98ea295
Merge branch '1.21.x' into 1.20.x
Caltinor Jun 21, 2024
6ca06e7
Merge branch '1.21.x' into 1.20.x
Caltinor Jun 22, 2024
b386291
IDE friendly code replacement
Caltinor Jun 22, 2024
a736dea
Merge branch '1.20.x' of https://github.com/Caltinor/NeoForge into 1.…
Caltinor Jun 22, 2024
8a0168d
javadoc tweaks
Caltinor Jun 22, 2024
59aceae
rename invul check in CommonHooks
Caltinor Jun 22, 2024
c81c021
Merge branch '1.21.x' into 1.20.x
Caltinor Jun 22, 2024
a4342e8
Merge branch '1.21.x' into 1.20.x
Matyrobbrt Jun 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions patches/net/minecraft/client/player/LocalPlayer.java.patch
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
--- a/net/minecraft/client/player/LocalPlayer.java
+++ b/net/minecraft/client/player/LocalPlayer.java
@@ -161,6 +_,7 @@

@Override
public boolean hurt(DamageSource p_108662_, float p_108663_) {
+ net.neoforged.neoforge.common.CommonHooks.onPlayerAttack(this, p_108662_, p_108663_);
return false;
}

@@ -297,6 +_,7 @@
ServerboundPlayerActionPacket.Action serverboundplayeractionpacket$action = p_108701_
? ServerboundPlayerActionPacket.Action.DROP_ALL_ITEMS
Expand Down
10 changes: 0 additions & 10 deletions patches/net/minecraft/client/player/RemotePlayer.java.patch

This file was deleted.

13 changes: 13 additions & 0 deletions patches/net/minecraft/world/entity/Entity.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,19 @@
}

public boolean is(Entity p_20356_) {
@@ -2516,10 +_,11 @@
}

public boolean isInvulnerableTo(DamageSource p_20122_) {
- return this.isRemoved()
+ boolean isVanillaInvulnerable = this.isRemoved()
|| this.invulnerable && !p_20122_.is(DamageTypeTags.BYPASSES_INVULNERABILITY) && !p_20122_.isCreativePlayer()
|| p_20122_.is(DamageTypeTags.IS_FIRE) && this.fireImmune()
|| p_20122_.is(DamageTypeTags.IS_FALL) && this.getType().is(EntityTypeTags.FALL_DAMAGE_IMMUNE);
+ return net.neoforged.neoforge.common.CommonHooks.onEntityInvulnerabilityCheck(this, p_20122_, isVanillaInvulnerable);
}

public boolean isInvulnerable() {
@@ -2544,6 +_,7 @@

@Nullable
Expand Down
141 changes: 115 additions & 26 deletions patches/net/minecraft/world/entity/LivingEntity.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@
private static final Logger LOGGER = LogUtils.getLogger();
private static final String TAG_ACTIVE_EFFECTS = "active_effects";
private static final ResourceLocation SPEED_MODIFIER_POWDER_SNOW_ID = ResourceLocation.withDefaultNamespace("powder_snow");
@@ -254,6 +_,14 @@
private boolean skipDropExperience;
private final Reference2ObjectMap<Enchantment, Set<EnchantmentLocationBasedEffect>> activeLocationDependentEnchantments = new Reference2ObjectArrayMap<>();
protected float appliedScale = 1.0F;
+ /**
+ * This field stores information about damage dealt to this entity.
+ * a new {@link net.neoforged.neoforge.common.damagesource.DamageContainer} is instantiated
+ * via {@link #hurt(DamageSource, float)} after invulnerability checks, and is removed from
+ * the stack before the method's return.
+ **/
+ @Nullable
+ protected java.util.Stack<net.neoforged.neoforge.common.damagesource.DamageContainer> damageContainers = new java.util.Stack<>();

protected LivingEntity(EntityType<? extends LivingEntity> p_20966_, Level p_20967_) {
super(p_20966_, p_20967_);
@@ -320,7 +_,9 @@
.add(Attributes.EXPLOSION_KNOCKBACK_RESISTANCE)
.add(Attributes.WATER_MOVEMENT_EFFICIENCY)
Expand Down Expand Up @@ -152,36 +167,70 @@
float f = this.getHealth();
if (f > 0.0F) {
this.setHealth(f + p_21116_);
@@ -1081,6 +_,7 @@

@Override
public boolean hurt(DamageSource p_21016_, float p_21017_) {
+ if (!net.neoforged.neoforge.common.CommonHooks.onLivingAttack(this, p_21016_, p_21017_)) return false;
if (this.isInvulnerableTo(p_21016_)) {
@@ -1090,23 +_,30 @@
} else if (p_21016_.is(DamageTypeTags.IS_FIRE) && this.hasEffect(MobEffects.FIRE_RESISTANCE)) {
return false;
} else if (this.level().isClientSide) {
@@ -1099,14 +_,17 @@
} else {
+ this.damageContainers.push(new net.neoforged.neoforge.common.damagesource.DamageContainer(p_21016_, p_21017_));
+ if (net.neoforged.neoforge.common.CommonHooks.onEntityIncomingDamage(this, this.damageContainers.peek())) return false;
if (this.isSleeping() && !this.level().isClientSide) {
this.stopSleeping();
}

this.noActionTime = 0;
+ p_21017_ = this.damageContainers.peek().getNewDamage(); //Neo: enforce damage container as source of truth for damage amount
float f = p_21017_;
boolean flag = false;
float f1 = 0.0F;
if (p_21017_ > 0.0F && this.isDamageSourceBlocked(p_21016_)) {
- if (p_21017_ > 0.0F && this.isDamageSourceBlocked(p_21016_)) {
- this.hurtCurrentlyUsedShield(p_21017_);
- f1 = p_21017_;
- p_21017_ = 0.0F;
+ net.neoforged.neoforge.event.entity.living.ShieldBlockEvent ev = net.neoforged.neoforge.common.CommonHooks.onShieldBlock(this, p_21016_, p_21017_);
+ if(!ev.isCanceled()) {
+ if(ev.shieldTakesDamage()) this.hurtCurrentlyUsedShield(p_21017_);
+ net.neoforged.neoforge.event.entity.living.LivingShieldBlockEvent ev;
+ if (p_21017_ > 0.0F && (ev = net.neoforged.neoforge.common.CommonHooks.onDamageBlock(this, this.damageContainers.peek(), this.isDamageSourceBlocked(p_21016_))).getBlocked()) {
+ this.damageContainers.peek().setBlockedDamage(ev);
+ if(ev.shieldDamage() > 0) {
+ this.hurtCurrentlyUsedShield(ev.shieldDamage());
+ }
+ f1 = ev.getBlockedDamage();
+ p_21017_ -= ev.getBlockedDamage();
+ p_21017_ = ev.getDamageContainer().getNewDamage();
if (!p_21016_.is(DamageTypeTags.IS_PROJECTILE) && p_21016_.getDirectEntity() instanceof LivingEntity livingentity) {
this.blockUsingShield(livingentity);
}

- flag = true;
+ flag = p_21017_ <= 0;
+ }
}

if (p_21016_.is(DamageTypeTags.IS_FREEZING) && this.getType().is(EntityTypeTags.FREEZE_HURTS_EXTRA_TYPES)) {
@@ -1118,10 +_,12 @@
p_21017_ *= 0.75F;
}

+ this.damageContainers.peek().setNewDamage(p_21017_); //update container with vanilla changes
this.walkAnimation.setSpeed(1.5F);
boolean flag1 = true;
if ((float)this.invulnerableTime > 10.0F && !p_21016_.is(DamageTypeTags.BYPASSES_COOLDOWN)) {
if (p_21017_ <= this.lastHurt) {
+ this.damageContainers.pop();
return false;
}

@@ -1130,12 +_,13 @@
flag1 = false;
} else {
this.lastHurt = p_21017_;
- this.invulnerableTime = 20;
+ this.invulnerableTime = this.damageContainers.peek().getPostAttackInvulnerabilityTicks();
this.actuallyHurt(p_21016_, p_21017_);
this.hurtDuration = 10;
this.hurtTime = this.hurtDuration;
}

+ p_21017_ = this.damageContainers.peek().getNewDamage(); //update local with container value
Entity entity = p_21016_.getEntity();
if (entity != null) {
if (entity instanceof LivingEntity livingentity1
@@ -1147,9 +_,9 @@
if (entity instanceof Player player1) {
this.lastHurtByPlayerTime = 100;
Expand All @@ -203,6 +252,14 @@
}
}

@@ -1220,6 +_,7 @@
CriteriaTriggers.PLAYER_HURT_ENTITY.trigger((ServerPlayer)entity, this, p_21016_, f, p_21017_, flag);
}

+ this.damageContainers.pop();
return flag2;
}
}
@@ -1240,7 +_,7 @@

for (InteractionHand interactionhand : InteractionHand.values()) {
Expand Down Expand Up @@ -330,9 +387,20 @@
this.playSound(soundtype.getFallSound(), soundtype.getVolume() * 0.5F, soundtype.getPitch() * 0.75F);
}
}
@@ -1649,9 +_,9 @@
@@ -1616,6 +_,8 @@
if (!(p_330394_ <= 0.0F)) {
int i = (int)Math.max(1.0F, p_330394_ / 4.0F);

+ net.neoforged.neoforge.common.CommonHooks.onArmorHurt(p_330843_, p_331314_, p_330394_, this);
+ p_331314_ = new EquipmentSlot[0]; //Neo: invalidates the loop. armor damage happens in common hook
Caltinor marked this conversation as resolved.
Show resolved Hide resolved
for (EquipmentSlot equipmentslot : p_331314_) {
ItemStack itemstack = this.getItemBySlot(equipmentslot);
if (itemstack.getItem() instanceof ArmorItem && itemstack.canBeHurtBy(p_330843_)) {
@@ -1648,10 +_,11 @@
p_21194_ = Math.max(f / 25.0F, 0.0F);
float f2 = f1 - p_21194_;
if (f2 > 0.0F && f2 < 3.4028235E37F) {
+ this.damageContainers.peek().setReduction(net.neoforged.neoforge.common.damagesource.DamageContainer.Reduction.MOB_EFFECTS, f2);
if (this instanceof ServerPlayer) {
- ((ServerPlayer)this).awardStat(Stats.DAMAGE_RESISTED, Math.round(f2 * 10.0F));
+ ((ServerPlayer)this).awardStat(Stats.CUSTOM.get(Stats.DAMAGE_RESISTED), Math.round(f2 * 10.0F));
TelepathicGrunt marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -342,23 +410,44 @@
}
}
}
@@ -1679,6 +_,8 @@
@@ -1670,6 +_,7 @@

if (f3 > 0.0F) {
p_21194_ = CombatRules.getDamageAfterMagicAbsorb(p_21194_, f3);
+ this.damageContainers.peek().setReduction(net.neoforged.neoforge.common.damagesource.DamageContainer.Reduction.ENCHANTMENTS,this.damageContainers.peek().getNewDamage() - p_21194_);
}

return p_21194_;
@@ -1679,11 +_,14 @@

protected void actuallyHurt(DamageSource p_21240_, float p_21241_) {
if (!this.isInvulnerableTo(p_21240_)) {
+ p_21241_ = net.neoforged.neoforge.common.CommonHooks.onLivingHurt(this, p_21240_, p_21241_);
+ if (p_21241_ <= 0) return;
p_21241_ = this.getDamageAfterArmorAbsorb(p_21240_, p_21241_);
p_21241_ = this.getDamageAfterMagicAbsorb(p_21240_, p_21241_);
float f1 = Math.max(p_21241_ - this.getAbsorptionAmount(), 0.0F);
@@ -1688,6 +_,7 @@
- p_21241_ = this.getDamageAfterArmorAbsorb(p_21240_, p_21241_);
- p_21241_ = this.getDamageAfterMagicAbsorb(p_21240_, p_21241_);
- float f1 = Math.max(p_21241_ - this.getAbsorptionAmount(), 0.0F);
- this.setAbsorptionAmount(this.getAbsorptionAmount() - (p_21241_ - f1));
- float f = p_21241_ - f1;
+ this.damageContainers.peek().setReduction(net.neoforged.neoforge.common.damagesource.DamageContainer.Reduction.ARMOR, this.damageContainers.peek().getNewDamage() - this.getDamageAfterArmorAbsorb(p_21240_, this.damageContainers.peek().getNewDamage()));
+ this.getDamageAfterMagicAbsorb(p_21240_, this.damageContainers.peek().getNewDamage());
+ this.damageContainers.peek().setReduction(net.neoforged.neoforge.common.damagesource.DamageContainer.Reduction.ABSORPTION, this.getAbsorptionAmount());
+ float f1 = Math.max(this.damageContainers.peek().getNewDamage() - this.damageContainers.peek().getReduction(net.neoforged.neoforge.common.damagesource.DamageContainer.Reduction.ABSORPTION), 0.0F);
+ this.setAbsorptionAmount(this.damageContainers.peek().getReduction(net.neoforged.neoforge.common.damagesource.DamageContainer.Reduction.ABSORPTION) - (this.damageContainers.peek().getNewDamage() - f1));
+ f1 = net.neoforged.neoforge.common.CommonHooks.onLivingDamagePre(this, this.damageContainers.peek());
+ if (f1 <= 0) return;
+ float f = this.damageContainers.peek().getNewDamage() - f1;
if (f > 0.0F && f < 3.4028235E37F && p_21240_.getEntity() instanceof ServerPlayer serverplayer) {
serverplayer.awardStat(Stats.DAMAGE_DEALT_ABSORBED, Math.round(f * 10.0F));
}

+ f1 = net.neoforged.neoforge.common.CommonHooks.onLivingDamage(this, p_21240_, f1);
if (f1 != 0.0F) {
this.getCombatTracker().recordDamage(p_21240_, f1);
@@ -1693,7 +_,9 @@
this.setHealth(this.getHealth() - f1);
this.setAbsorptionAmount(this.getAbsorptionAmount() - f1);
this.gameEvent(GameEvent.ENTITY_DAMAGE);
+ this.onDamageTaken(this.damageContainers.peek());
}
+ net.neoforged.neoforge.common.CommonHooks.onLivingDamagePost(this, this.damageContainers.peek());
}
}

@@ -1747,6 +_,8 @@
}

Expand Down
42 changes: 25 additions & 17 deletions patches/net/minecraft/world/entity/player/Player.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,6 @@
@Override
public void readAdditionalSaveData(CompoundTag p_36215_) {
super.readAdditionalSaveData(p_36215_);
@@ -859,6 +_,7 @@

@Override
public boolean hurt(DamageSource p_36154_, float p_36155_) {
+ if (!net.neoforged.neoforge.common.CommonHooks.onPlayerAttack(this, p_36154_, p_36155_)) return false;
if (this.isInvulnerableTo(p_36154_)) {
return false;
} else if (this.abilities.invulnerable && !p_36154_.is(DamageTypeTags.BYPASSES_INVULNERABILITY)) {
@@ -872,7 +_,9 @@
this.removeEntitiesOnShoulder();
}
Expand Down Expand Up @@ -159,20 +151,36 @@
if (this.useItem.isEmpty()) {
if (interactionhand == InteractionHand.MAIN_HAND) {
this.setItemSlot(EquipmentSlot.MAINHAND, ItemStack.EMPTY);
@@ -952,10 +_,13 @@
@@ -952,11 +_,14 @@
@Override
protected void actuallyHurt(DamageSource p_36312_, float p_36313_) {
if (!this.isInvulnerableTo(p_36312_)) {
+ p_36313_ = net.neoforged.neoforge.common.CommonHooks.onLivingHurt(this, p_36312_, p_36313_);
+ if (p_36313_ <= 0) return;
p_36313_ = this.getDamageAfterArmorAbsorb(p_36312_, p_36313_);
p_36313_ = this.getDamageAfterMagicAbsorb(p_36312_, p_36313_);
float f1 = Math.max(p_36313_ - this.getAbsorptionAmount(), 0.0F);
this.setAbsorptionAmount(this.getAbsorptionAmount() - (p_36313_ - f1));
+ f1 = net.neoforged.neoforge.common.CommonHooks.onLivingDamage(this, p_36312_, f1);
float f = p_36313_ - f1;
- p_36313_ = this.getDamageAfterArmorAbsorb(p_36312_, p_36313_);
- p_36313_ = this.getDamageAfterMagicAbsorb(p_36312_, p_36313_);
- float f1 = Math.max(p_36313_ - this.getAbsorptionAmount(), 0.0F);
- this.setAbsorptionAmount(this.getAbsorptionAmount() - (p_36313_ - f1));
- float f = p_36313_ - f1;
+ this.damageContainers.peek().setReduction(net.neoforged.neoforge.common.damagesource.DamageContainer.Reduction.ARMOR, this.damageContainers.peek().getNewDamage() - this.getDamageAfterArmorAbsorb(p_36312_, this.damageContainers.peek().getNewDamage()));
+ this.getDamageAfterMagicAbsorb(p_36312_, this.damageContainers.peek().getNewDamage());
+ this.damageContainers.peek().setReduction(net.neoforged.neoforge.common.damagesource.DamageContainer.Reduction.ABSORPTION, this.getAbsorptionAmount());
+ float f1 = Math.max(this.damageContainers.peek().getNewDamage() - this.damageContainers.peek().getReduction(net.neoforged.neoforge.common.damagesource.DamageContainer.Reduction.ABSORPTION), 0.0F);
+ this.setAbsorptionAmount(this.damageContainers.peek().getReduction(net.neoforged.neoforge.common.damagesource.DamageContainer.Reduction.ABSORPTION) - (this.damageContainers.peek().getNewDamage() - f1));
+ f1 = net.neoforged.neoforge.common.CommonHooks.onLivingDamagePre(this, this.damageContainers.peek());
+ if (f1 <= 0) return;
+ float f = this.damageContainers.peek().getNewDamage() - f1;
if (f > 0.0F && f < 3.4028235E37F) {
this.awardStat(Stats.DAMAGE_ABSORBED, Math.round(f * 10.0F));
}
@@ -970,7 +_,9 @@
}

this.gameEvent(GameEvent.ENTITY_DAMAGE);
+ this.onDamageTaken(this.damageContainers.peek());
}
+ net.neoforged.neoforge.common.CommonHooks.onLivingDamagePost(this, this.damageContainers.peek());
}
}

@@ -1014,6 +_,8 @@

return InteractionResult.PASS;
Expand Down
Loading
Loading