SPIGOT-7604: Revert "SPIGOT-7365: DamageCause blocked by shield should trigger invulnerableTime"

This reverts commit 13b4e915a0.

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot 2024-03-20 20:31:48 +11:00
parent 13b4e915a0
commit 0223e7ff73
3 changed files with 48 additions and 52 deletions

View File

@ -398,14 +398,13 @@
return false; return false;
} else if (damagesource.is(DamageTypeTags.IS_FIRE) && this.hasEffect(MobEffects.FIRE_RESISTANCE)) { } else if (damagesource.is(DamageTypeTags.IS_FIRE) && this.hasEffect(MobEffects.FIRE_RESISTANCE)) {
return false; return false;
@@ -1167,10 +1383,12 @@ @@ -1167,10 +1383,11 @@
this.noActionTime = 0; this.noActionTime = 0;
float f1 = f; float f1 = f;
- boolean flag = false; - boolean flag = false;
+ boolean flag = f > 0.0F && this.isDamageSourceBlocked(damagesource); // Copied from below + boolean flag = f > 0.0F && this.isDamageSourceBlocked(damagesource); // Copied from below
float f2 = 0.0F; float f2 = 0.0F;
+ float originalDamage = f;
- if (f > 0.0F && this.isDamageSourceBlocked(damagesource)) { - if (f > 0.0F && this.isDamageSourceBlocked(damagesource)) {
+ // CraftBukkit - Moved into actuallyHurt(DamageSource, float) + // CraftBukkit - Moved into actuallyHurt(DamageSource, float)
@ -413,33 +412,29 @@
this.hurtCurrentlyUsedShield(f); this.hurtCurrentlyUsedShield(f);
f2 = f; f2 = f;
f = 0.0F; f = 0.0F;
@@ -1194,23 +1412,37 @@ @@ -1194,23 +1411,33 @@
this.walkAnimation.setSpeed(1.5F); this.walkAnimation.setSpeed(1.5F);
boolean flag1 = true; boolean flag1 = true;
- if ((float) this.invulnerableTime > 10.0F && !damagesource.is(DamageTypeTags.BYPASSES_COOLDOWN)) { - if ((float) this.invulnerableTime > 10.0F && !damagesource.is(DamageTypeTags.BYPASSES_COOLDOWN)) {
+ if ((float) this.invulnerableTime > (float) this.invulnerableDuration / 2.0F && !damagesource.is(DamageTypeTags.BYPASSES_COOLDOWN)) { // CraftBukkit - restore use of maxNoDamageTicks + if ((float) this.invulnerableTime > (float) this.invulnerableDuration / 2.0F && !damagesource.is(DamageTypeTags.BYPASSES_COOLDOWN)) { // CraftBukkit - restore use of maxNoDamageTicks
+ // CraftBukkit start
+ f = this.actuallyHurt(damagesource, f - this.lastHurt);
if (f <= this.lastHurt) { if (f <= this.lastHurt) {
return false; return false;
} }
- this.actuallyHurt(damagesource, f - this.lastHurt); - this.actuallyHurt(damagesource, f - this.lastHurt);
+ if (this instanceof EntityHuman && originalDamage == 0) { // CraftBukkit - Human entities can't be hurt by 0 damage + // CraftBukkit start
+ if (!this.actuallyHurt(damagesource, f - this.lastHurt)) {
+ return false; + return false;
+ } + }
+ f = Math.max(0, f);
+ // CraftBukkit end + // CraftBukkit end
this.lastHurt = f; this.lastHurt = f;
flag1 = false; flag1 = false;
} else { } else {
+ // CraftBukkit start + // CraftBukkit start
+ f = this.actuallyHurt(damagesource, f); // CraftBukkit - Ensure the human entities to call damage event before the method return false + if (!this.actuallyHurt(damagesource, f)) {
+ if (this instanceof EntityHuman && originalDamage == 0) { // CraftBukkit - Human entities can't be hurt by 0 damage
+ return false; + return false;
+ } + }
+ f = Math.max(0, f);
this.lastHurt = f; this.lastHurt = f;
- this.invulnerableTime = 20; - this.invulnerableTime = 20;
- this.actuallyHurt(damagesource, f); - this.actuallyHurt(damagesource, f);
@ -456,7 +451,7 @@
this.hurtHelmet(damagesource, f); this.hurtHelmet(damagesource, f);
f *= 0.75F; f *= 0.75F;
} }
@@ -1269,7 +1501,7 @@ @@ -1269,7 +1496,7 @@
d0 = (Math.random() - Math.random()) * 0.01D; d0 = (Math.random() - Math.random()) * 0.01D;
} }
@ -465,7 +460,7 @@
if (!flag) { if (!flag) {
this.indicateDamage(d0, d1); this.indicateDamage(d0, d1);
} }
@@ -1317,7 +1549,7 @@ @@ -1317,7 +1544,7 @@
} }
protected void blockedByShield(EntityLiving entityliving) { protected void blockedByShield(EntityLiving entityliving) {
@ -474,7 +469,7 @@
} }
private boolean checkTotemDeathProtection(DamageSource damagesource) { private boolean checkTotemDeathProtection(DamageSource damagesource) {
@@ -1328,19 +1560,32 @@ @@ -1328,19 +1555,32 @@
EnumHand[] aenumhand = EnumHand.values(); EnumHand[] aenumhand = EnumHand.values();
int i = aenumhand.length; int i = aenumhand.length;
@ -511,7 +506,7 @@
EntityPlayer entityplayer = (EntityPlayer) this; EntityPlayer entityplayer = (EntityPlayer) this;
entityplayer.awardStat(StatisticList.ITEM_USED.get(Items.TOTEM_OF_UNDYING)); entityplayer.awardStat(StatisticList.ITEM_USED.get(Items.TOTEM_OF_UNDYING));
@@ -1349,14 +1594,16 @@ @@ -1349,14 +1589,16 @@
} }
this.setHealth(1.0F); this.setHealth(1.0F);
@ -533,7 +528,7 @@
} }
} }
@@ -1463,14 +1710,22 @@ @@ -1463,14 +1705,22 @@
IBlockData iblockdata = Blocks.WITHER_ROSE.defaultBlockState(); IBlockData iblockdata = Blocks.WITHER_ROSE.defaultBlockState();
if (this.level().getBlockState(blockposition).isAir() && iblockdata.canSurvive(this.level(), blockposition)) { if (this.level().getBlockState(blockposition).isAir() && iblockdata.canSurvive(this.level(), blockposition)) {
@ -558,7 +553,7 @@
this.level().addFreshEntity(entityitem); this.level().addFreshEntity(entityitem);
} }
} }
@@ -1490,21 +1745,40 @@ @@ -1490,21 +1740,40 @@
boolean flag = this.lastHurtByPlayerTime > 0; boolean flag = this.lastHurtByPlayerTime > 0;
@ -602,7 +597,7 @@
} }
@@ -1533,13 +1807,25 @@ @@ -1533,13 +1802,25 @@
} }
public void knockback(double d0, double d1, double d2) { public void knockback(double d0, double d1, double d2) {
@ -631,7 +626,7 @@
} }
} }
@@ -1596,6 +1882,28 @@ @@ -1596,6 +1877,28 @@
return itemstack.getEatingSound(); return itemstack.getEatingSound();
} }
@ -660,7 +655,7 @@
public Optional<BlockPosition> getLastClimbablePos() { public Optional<BlockPosition> getLastClimbablePos() {
return this.lastClimbablePos; return this.lastClimbablePos;
} }
@@ -1642,9 +1950,14 @@ @@ -1642,9 +1945,14 @@
int i = this.calculateFallDamage(f, f1); int i = this.calculateFallDamage(f, f1);
if (i > 0) { if (i > 0) {
@ -676,7 +671,7 @@
return true; return true;
} else { } else {
return flag; return flag;
@@ -1696,7 +2009,7 @@ @@ -1696,7 +2004,7 @@
protected float getDamageAfterArmorAbsorb(DamageSource damagesource, float f) { protected float getDamageAfterArmorAbsorb(DamageSource damagesource, float f) {
if (!damagesource.is(DamageTypeTags.BYPASSES_ARMOR)) { if (!damagesource.is(DamageTypeTags.BYPASSES_ARMOR)) {
@ -685,7 +680,7 @@
f = CombatMath.getDamageAfterAbsorb(f, (float) this.getArmorValue(), (float) this.getAttributeValue(GenericAttributes.ARMOR_TOUGHNESS)); f = CombatMath.getDamageAfterAbsorb(f, (float) this.getArmorValue(), (float) this.getAttributeValue(GenericAttributes.ARMOR_TOUGHNESS));
} }
@@ -1709,7 +2022,8 @@ @@ -1709,7 +2017,8 @@
} else { } else {
int i; int i;
@ -695,19 +690,20 @@
i = (this.getEffect(MobEffects.DAMAGE_RESISTANCE).getAmplifier() + 1) * 5; i = (this.getEffect(MobEffects.DAMAGE_RESISTANCE).getAmplifier() + 1) * 5;
int j = 25 - i; int j = 25 - i;
float f1 = f * (float) j; float f1 = f * (float) j;
@@ -1742,16 +2056,125 @@ @@ -1742,16 +2051,125 @@
} }
} }
- protected void actuallyHurt(DamageSource damagesource, float f) { - protected void actuallyHurt(DamageSource damagesource, float f) {
+ // CraftBukkit start - if (!this.isInvulnerableTo(damagesource)) {
+ protected float actuallyHurt(final DamageSource damagesource, float f) { // void -> float, returned value means the final damage
if (!this.isInvulnerableTo(damagesource)) {
- f = this.getDamageAfterArmorAbsorb(damagesource, f); - f = this.getDamageAfterArmorAbsorb(damagesource, f);
- f = this.getDamageAfterMagicAbsorb(damagesource, f); - f = this.getDamageAfterMagicAbsorb(damagesource, f);
- float f1 = f; - float f1 = f;
+ // CraftBukkit start
+ protected boolean actuallyHurt(final DamageSource damagesource, float f) { // void -> boolean, add final
+ if (!this.isInvulnerableTo(damagesource)) {
+ final boolean human = this instanceof EntityHuman; + final boolean human = this instanceof EntityHuman;
+ float originalDamage = f; // CraftBukkit - Storing the original damage to judge whether the human entities should be hurt + float originalDamage = f;
+ Function<Double, Double> hardHat = new Function<Double, Double>() { + Function<Double, Double> hardHat = new Function<Double, Double>() {
+ @Override + @Override
+ public Double apply(Double f) { + public Double apply(Double f) {
@ -779,7 +775,7 @@
+ ((EntityHuman) damagesource.getEntity()).resetAttackStrengthTicker(); // Moved from EntityHuman in order to make the cooldown reset get called after the damage event is fired + ((EntityHuman) damagesource.getEntity()).resetAttackStrengthTicker(); // Moved from EntityHuman in order to make the cooldown reset get called after the damage event is fired
+ } + }
+ if (event.isCancelled()) { + if (event.isCancelled()) {
+ return 0; + return false;
+ } + }
+ +
+ f = (float) event.getFinalDamage(); + f = (float) event.getFinalDamage();
@ -828,7 +824,7 @@
if (f2 > 0.0F && f2 < 3.4028235E37F) { if (f2 > 0.0F && f2 < 3.4028235E37F) {
Entity entity = damagesource.getEntity(); Entity entity = damagesource.getEntity();
@@ -1762,13 +2185,47 @@ @@ -1762,13 +2180,47 @@
} }
} }
@ -851,7 +847,7 @@
+ } + }
this.gameEvent(GameEvent.ENTITY_DAMAGE); this.gameEvent(GameEvent.ENTITY_DAMAGE);
+ +
+ return f; + return true;
+ } else { + } else {
+ // Duplicate triggers if blocking + // Duplicate triggers if blocking
+ if (event.getDamage(DamageModifier.BLOCKING) < 0) { + if (event.getDamage(DamageModifier.BLOCKING) < 0) {
@ -867,18 +863,18 @@
+ CriterionTriggers.PLAYER_HURT_ENTITY.trigger((EntityPlayer) damagesource.getEntity(), this, damagesource, f, originalDamage, true); + CriterionTriggers.PLAYER_HURT_ENTITY.trigger((EntityPlayer) damagesource.getEntity(), this, damagesource, f, originalDamage, true);
+ } + }
+ +
+ return -1; // -1 means the damage is blocked + return false;
+ } else { + } else {
+ return f; + return originalDamage > 0;
+ } + }
+ // CraftBukkit end + // CraftBukkit end
} }
} }
+ return 0; // CraftBukkit + return false; // CraftBukkit
} }
public CombatTracker getCombatTracker() { public CombatTracker getCombatTracker() {
@@ -1793,8 +2250,18 @@ @@ -1793,8 +2245,18 @@
} }
public final void setArrowCount(int i) { public final void setArrowCount(int i) {
@ -898,7 +894,7 @@
public final int getStingerCount() { public final int getStingerCount() {
return (Integer) this.entityData.get(EntityLiving.DATA_STINGER_COUNT_ID); return (Integer) this.entityData.get(EntityLiving.DATA_STINGER_COUNT_ID);
@@ -2036,6 +2503,12 @@ @@ -2036,6 +2498,12 @@
public abstract ItemStack getItemBySlot(EnumItemSlot enumitemslot); public abstract ItemStack getItemBySlot(EnumItemSlot enumitemslot);
@ -911,7 +907,7 @@
@Override @Override
public abstract void setItemSlot(EnumItemSlot enumitemslot, ItemStack itemstack); public abstract void setItemSlot(EnumItemSlot enumitemslot, ItemStack itemstack);
@@ -2270,6 +2743,7 @@ @@ -2270,6 +2738,7 @@
} }
if (this.onGround() && !this.level().isClientSide) { if (this.onGround() && !this.level().isClientSide) {
@ -919,7 +915,7 @@
this.setSharedFlag(7, false); this.setSharedFlag(7, false);
} }
} else { } else {
@@ -2440,7 +2914,7 @@ @@ -2440,7 +2909,7 @@
} }
} }
@ -928,7 +924,7 @@
if (this.tickCount % 20 == 0) { if (this.tickCount % 20 == 0) {
this.getCombatTracker().recheckStatus(); this.getCombatTracker().recheckStatus();
} }
@@ -2537,7 +3011,7 @@ @@ -2537,7 +3006,7 @@
this.refreshDirtyAttributes(); this.refreshDirtyAttributes();
} }
@ -937,7 +933,7 @@
Map<EnumItemSlot, ItemStack> map = this.collectEquipmentChanges(); Map<EnumItemSlot, ItemStack> map = this.collectEquipmentChanges();
if (map != null) { if (map != null) {
@@ -2839,6 +3313,7 @@ @@ -2839,6 +3308,7 @@
} }
if (!this.level().isClientSide) { if (!this.level().isClientSide) {
@ -945,7 +941,7 @@
this.setSharedFlag(7, flag); this.setSharedFlag(7, flag);
} }
@@ -3029,14 +3504,21 @@ @@ -3029,14 +3499,21 @@
@Override @Override
public boolean isPickable() { public boolean isPickable() {
@ -969,7 +965,7 @@
@Override @Override
public float getYHeadRot() { public float getYHeadRot() {
return this.yHeadRot; return this.yHeadRot;
@@ -3231,7 +3713,26 @@ @@ -3231,7 +3708,26 @@
} else { } else {
if (!this.useItem.isEmpty() && this.isUsingItem()) { if (!this.useItem.isEmpty() && this.isUsingItem()) {
this.triggerItemUseEffects(this.useItem, 16); this.triggerItemUseEffects(this.useItem, 16);
@ -997,7 +993,7 @@
if (itemstack != this.useItem) { if (itemstack != this.useItem) {
this.setItemInHand(enumhand, itemstack); this.setItemInHand(enumhand, itemstack);
@@ -3309,6 +3810,12 @@ @@ -3309,6 +3805,12 @@
} }
public boolean randomTeleport(double d0, double d1, double d2, boolean flag) { public boolean randomTeleport(double d0, double d1, double d2, boolean flag) {
@ -1010,7 +1006,7 @@
double d3 = this.getX(); double d3 = this.getX();
double d4 = this.getY(); double d4 = this.getY();
double d5 = this.getZ(); double d5 = this.getZ();
@@ -3333,16 +3840,41 @@ @@ -3333,16 +3835,41 @@
} }
if (flag2) { if (flag2) {
@ -1055,7 +1051,7 @@
} else { } else {
if (flag) { if (flag) {
world.broadcastEntityEvent(this, (byte) 46); world.broadcastEntityEvent(this, (byte) 46);
@@ -3354,7 +3886,7 @@ @@ -3354,7 +3881,7 @@
entitycreature.getNavigation().stop(); entitycreature.getNavigation().stop();
} }
@ -1064,7 +1060,7 @@
} }
} }
@@ -3443,7 +3975,7 @@ @@ -3443,7 +3970,7 @@
} }
public void stopSleeping() { public void stopSleeping() {
@ -1073,7 +1069,7 @@
World world = this.level(); World world = this.level();
java.util.Objects.requireNonNull(world); java.util.Objects.requireNonNull(world);
@@ -3477,7 +4009,7 @@ @@ -3477,7 +4004,7 @@
@Nullable @Nullable
public EnumDirection getBedOrientation() { public EnumDirection getBedOrientation() {
@ -1082,7 +1078,7 @@
return blockposition != null ? BlockBed.getBedOrientation(this.level(), blockposition) : null; return blockposition != null ? BlockBed.getBedOrientation(this.level(), blockposition) : null;
} }
@@ -3525,7 +4057,7 @@ @@ -3525,7 +4052,7 @@
Pair<MobEffect, Float> pair = (Pair) iterator.next(); Pair<MobEffect, Float> pair = (Pair) iterator.next();
if (!world.isClientSide && pair.getFirst() != null && world.random.nextFloat() < (Float) pair.getSecond()) { if (!world.isClientSide && pair.getFirst() != null && world.random.nextFloat() < (Float) pair.getSecond()) {

View File

@ -14,10 +14,10 @@
@Override @Override
- protected void actuallyHurt(DamageSource damagesource, float f) { - protected void actuallyHurt(DamageSource damagesource, float f) {
+ // CraftBukkit start - void -> float, returned value means the final damage + // CraftBukkit start - void -> boolean
+ protected float actuallyHurt(final DamageSource damagesource, float f) { + protected boolean actuallyHurt(DamageSource damagesource, float f) {
+ float hurt = super.actuallyHurt(damagesource, f); + boolean hurt = super.actuallyHurt(damagesource, f);
+ if (hurt <= 0) { + if (!hurt) {
+ return hurt; + return hurt;
+ } + }
+ // CraftBukkit end + // CraftBukkit end

View File

@ -235,7 +235,7 @@
+ // CraftBukkit start + // CraftBukkit start
@Override @Override
- protected void actuallyHurt(DamageSource damagesource, float f) { - protected void actuallyHurt(DamageSource damagesource, float f) {
+ protected float actuallyHurt(final DamageSource damagesource, float f) { // void -> float, returned value means the final damage + protected boolean actuallyHurt(DamageSource damagesource, float f) { // void -> boolean
+ if (true) { + if (true) {
+ return super.actuallyHurt(damagesource, f); + return super.actuallyHurt(damagesource, f);
+ } + }
@ -256,7 +256,7 @@
this.gameEvent(GameEvent.ENTITY_DAMAGE); this.gameEvent(GameEvent.ENTITY_DAMAGE);
} }
} }
+ return 0; // CraftBukkit + return false; // CraftBukkit
} }
@Override @Override