SPIGOT-7732: Issue with the "hurt()" method of EntityLiving and invulnerable time

By: LoliColleen <76620594+LoliColleen@users.noreply.github.com>
This commit is contained in:
CraftBukkit/Spigot 2024-06-22 18:46:41 +10:00
parent 7667932681
commit aef018b9c4
7 changed files with 291 additions and 226 deletions

View file

@ -417,22 +417,37 @@
float f2 = 0.0F;
- if (f > 0.0F && this.isDamageSourceBlocked(damagesource)) {
+ // CraftBukkit - Moved into actuallyHurt(DamageSource, float)
+ // CraftBukkit - Moved into handleEntityDamage(DamageSource, float)
+ if (false && f > 0.0F && this.isDamageSourceBlocked(damagesource)) {
this.hurtCurrentlyUsedShield(f);
f2 = f;
f = 0.0F;
@@ -1180,7 +1397,8 @@
@@ -1176,30 +1393,50 @@
flag = true;
}
- if (damagesource.is(DamageTypeTags.IS_FREEZING) && this.getType().is(TagsEntity.FREEZE_HURTS_EXTRA_TYPES)) {
+ // CraftBukkit - Moved into handleEntityDamage(DamageSource, float)
+ if (false && damagesource.is(DamageTypeTags.IS_FREEZING) && this.getType().is(TagsEntity.FREEZE_HURTS_EXTRA_TYPES)) {
f *= 5.0F;
}
- if (damagesource.is(DamageTypeTags.DAMAGES_HELMET) && !this.getItemBySlot(EnumItemSlot.HEAD).isEmpty()) {
+ // CraftBukkit - Moved into actuallyHurt(DamageSource, float)
+ // CraftBukkit - Moved into handleEntityDamage(DamageSource, float)
+ if (false && damagesource.is(DamageTypeTags.DAMAGES_HELMET) && !this.getItemBySlot(EnumItemSlot.HEAD).isEmpty()) {
this.hurtHelmet(damagesource, f);
f *= 0.75F;
}
@@ -1188,18 +1406,27 @@
+ // CraftBukkit start
+ EntityDamageEvent event = handleEntityDamage(damagesource, f);
+ f = 0;
+ f += (float) event.getDamage(DamageModifier.BASE);
+ f += (float) event.getDamage(DamageModifier.BLOCKING);
+ f += (float) event.getDamage(DamageModifier.FREEZING);
+ f += (float) event.getDamage(DamageModifier.HARD_HAT);
+ // CraftBukkit end
+
this.walkAnimation.setSpeed(1.5F);
boolean flag1 = true;
@ -444,7 +459,7 @@
- this.actuallyHurt(damagesource, f - this.lastHurt);
+ // CraftBukkit start
+ if (!this.actuallyHurt(damagesource, f - this.lastHurt)) {
+ if (!this.actuallyHurt(damagesource, (float) event.getFinalDamage() - this.lastHurt, event)) {
+ return false;
+ }
+ // CraftBukkit end
@ -452,7 +467,7 @@
flag1 = false;
} else {
+ // CraftBukkit start
+ if (!this.actuallyHurt(damagesource, f)) {
+ if (!this.actuallyHurt(damagesource, (float) event.getFinalDamage(), event)) {
+ return false;
+ }
this.lastHurt = f;
@ -464,7 +479,7 @@
this.hurtDuration = 10;
this.hurtTime = this.hurtDuration;
}
@@ -1245,7 +1472,7 @@
@@ -1245,7 +1482,7 @@
this.level().broadcastDamageEvent(this, damagesource);
}
@ -473,7 +488,7 @@
this.markHurt();
}
@@ -1265,7 +1492,7 @@
@@ -1265,7 +1502,7 @@
d1 = damagesource.getSourcePosition().z() - this.getZ();
}
@ -482,7 +497,7 @@
if (!flag) {
this.indicateDamage(d0, d1);
}
@@ -1284,7 +1511,7 @@
@@ -1284,7 +1521,7 @@
this.playHurtSound(damagesource);
}
@ -491,7 +506,7 @@
if (flag2) {
this.lastDamageSource = damagesource;
@@ -1318,7 +1545,7 @@
@@ -1318,7 +1555,7 @@
}
protected void blockedByShield(EntityLiving entityliving) {
@ -500,7 +515,7 @@
}
private boolean checkTotemDeathProtection(DamageSource damagesource) {
@@ -1329,19 +1556,32 @@
@@ -1329,19 +1566,32 @@
EnumHand[] aenumhand = EnumHand.values();
int i = aenumhand.length;
@ -537,7 +552,7 @@
EntityPlayer entityplayer = (EntityPlayer) this;
entityplayer.awardStat(StatisticList.ITEM_USED.get(Items.TOTEM_OF_UNDYING));
@@ -1350,14 +1590,16 @@
@@ -1350,14 +1600,16 @@
}
this.setHealth(1.0F);
@ -559,7 +574,7 @@
}
}
@@ -1464,14 +1706,22 @@
@@ -1464,14 +1716,22 @@
IBlockData iblockdata = Blocks.WITHER_ROSE.defaultBlockState();
if (this.level().getBlockState(blockposition).isAir() && iblockdata.canSurvive(this.level(), blockposition)) {
@ -584,7 +599,7 @@
this.level().addFreshEntity(entityitem);
}
}
@@ -1482,26 +1732,41 @@
@@ -1482,26 +1742,41 @@
protected void dropAllDeathLoot(WorldServer worldserver, DamageSource damagesource) {
boolean flag = this.lastHurtByPlayerTime > 0;
@ -629,7 +644,7 @@
}
protected void dropCustomDeathLoot(WorldServer worldserver, DamageSource damagesource, boolean flag) {}
@@ -1540,9 +1805,14 @@
@@ -1540,9 +1815,14 @@
}
public void knockback(double d0, double d1, double d2) {
@ -646,7 +661,7 @@
Vec3D vec3d;
@@ -1552,7 +1822,14 @@
@@ -1552,7 +1832,14 @@
Vec3D vec3d1 = (new Vec3D(d1, 0.0D, d2)).normalize().scale(d0);
@ -662,7 +677,7 @@
}
}
@@ -1613,6 +1890,28 @@
@@ -1613,6 +1900,28 @@
return itemstack.getEatingSound();
}
@ -691,7 +706,7 @@
public Optional<BlockPosition> getLastClimbablePos() {
return this.lastClimbablePos;
}
@@ -1666,9 +1965,14 @@
@@ -1666,9 +1975,14 @@
int i = this.calculateFallDamage(f, f1);
if (i > 0) {
@ -707,164 +722,184 @@
return true;
} else {
return flag;
@@ -1738,7 +2042,7 @@
@@ -1738,7 +2052,7 @@
protected float getDamageAfterArmorAbsorb(DamageSource damagesource, float f) {
if (!damagesource.is(DamageTypeTags.BYPASSES_ARMOR)) {
- this.hurtArmor(damagesource, f);
+ // this.hurtArmor(damagesource, f); // CraftBukkit - Moved into actuallyHurt(DamageSource, float)
+ // this.hurtArmor(damagesource, f); // CraftBukkit - Moved into handleEntityDamage(DamageSource, float)
f = CombatMath.getDamageAfterAbsorb(this, f, damagesource, (float) this.getArmorValue(), (float) this.getAttributeValue(GenericAttributes.ARMOR_TOUGHNESS));
}
@@ -1749,7 +2053,8 @@
@@ -1749,7 +2063,8 @@
if (damagesource.is(DamageTypeTags.BYPASSES_EFFECTS)) {
return f;
} else {
- if (this.hasEffect(MobEffects.DAMAGE_RESISTANCE) && !damagesource.is(DamageTypeTags.BYPASSES_RESISTANCE)) {
+ // CraftBukkit - Moved to actuallyHurt(DamageSource, float)
+ // CraftBukkit - Moved to handleEntityDamage(DamageSource, float)
+ if (false && this.hasEffect(MobEffects.DAMAGE_RESISTANCE) && !damagesource.is(DamageTypeTags.BYPASSES_RESISTANCE)) {
int i = (this.getEffect(MobEffects.DAMAGE_RESISTANCE).getAmplifier() + 1) * 5;
int j = 25 - i;
float f1 = f * (float) j;
@@ -1792,16 +2097,125 @@
@@ -1792,15 +2107,145 @@
}
}
- protected void actuallyHurt(DamageSource damagesource, float f) {
- if (!this.isInvulnerableTo(damagesource)) {
+ // CraftBukkit start
+ private EntityDamageEvent handleEntityDamage(final DamageSource damagesource, float f) {
+ float originalDamage = f;
+
+ Function<Double, Double> freezing = new Function<Double, Double>() {
+ @Override
+ public Double apply(Double f) {
+ if (damagesource.is(DamageTypeTags.IS_FREEZING) && EntityLiving.this.getType().is(TagsEntity.FREEZE_HURTS_EXTRA_TYPES)) {
+ return -(f - (f * 5.0F));
+ }
+ return -0.0;
+ }
+ };
+ float freezingModifier = freezing.apply((double) f).floatValue();
+ f += freezingModifier;
+
+ Function<Double, Double> hardHat = new Function<Double, Double>() {
+ @Override
+ public Double apply(Double f) {
+ if (damagesource.is(DamageTypeTags.DAMAGES_HELMET) && !EntityLiving.this.getItemBySlot(EnumItemSlot.HEAD).isEmpty()) {
+ return -(f - (f * 0.75F));
+ }
+ return -0.0;
+ }
+ };
+ float hardHatModifier = hardHat.apply((double) f).floatValue();
+ f += hardHatModifier;
+
+ Function<Double, Double> blocking = new Function<Double, Double>() {
+ @Override
+ public Double apply(Double f) {
+ return -((EntityLiving.this.isDamageSourceBlocked(damagesource)) ? f : 0.0);
+ }
+ };
+ float blockingModifier = blocking.apply((double) f).floatValue();
+ f += blockingModifier;
+
+ Function<Double, Double> armor = new Function<Double, Double>() {
+ @Override
+ public Double apply(Double f) {
+ return -(f - EntityLiving.this.getDamageAfterArmorAbsorb(damagesource, f.floatValue()));
+ }
+ };
+ float armorModifier = armor.apply((double) f).floatValue();
+ f += armorModifier;
+
+ Function<Double, Double> resistance = new Function<Double, Double>() {
+ @Override
+ public Double apply(Double f) {
+ if (!damagesource.is(DamageTypeTags.BYPASSES_EFFECTS) && EntityLiving.this.hasEffect(MobEffects.DAMAGE_RESISTANCE) && !damagesource.is(DamageTypeTags.BYPASSES_RESISTANCE)) {
+ int i = (EntityLiving.this.getEffect(MobEffects.DAMAGE_RESISTANCE).getAmplifier() + 1) * 5;
+ int j = 25 - i;
+ float f1 = f.floatValue() * (float) j;
+ return -(f - (f1 / 25.0F));
+ }
+ return -0.0;
+ }
+ };
+ float resistanceModifier = resistance.apply((double) f).floatValue();
+ f += resistanceModifier;
+
+ Function<Double, Double> magic = new Function<Double, Double>() {
+ @Override
+ public Double apply(Double f) {
+ return -(f - EntityLiving.this.getDamageAfterMagicAbsorb(damagesource, f.floatValue()));
+ }
+ };
+ float magicModifier = magic.apply((double) f).floatValue();
+ f += magicModifier;
+
+ Function<Double, Double> absorption = new Function<Double, Double>() {
+ @Override
+ public Double apply(Double f) {
+ return -(Math.max(f - Math.max(f - EntityLiving.this.getAbsorptionAmount(), 0.0F), 0.0F));
+ }
+ };
+ float absorptionModifier = absorption.apply((double) f).floatValue();
+
+ EntityDamageEvent event = CraftEventFactory.handleLivingEntityDamageEvent(this, damagesource, originalDamage, freezingModifier, hardHatModifier, blockingModifier, armorModifier, resistanceModifier, magicModifier, absorptionModifier, freezing, hardHat, blocking, armor, resistance, magic, absorption);
+ if (damagesource.getEntity() instanceof EntityHuman) {
+ ((EntityHuman) damagesource.getEntity()).resetAttackStrengthTicker(); // Moved from EntityHuman in order to make the cooldown reset get called after the damage event is fired
+ }
+
+ if (this.isInvulnerableTo(damagesource)) {
+ event.setCancelled(true);
+ }
+
+ // Resistance
+ if (event.getDamage(DamageModifier.RESISTANCE) < 0) {
+ float f3 = (float) -event.getDamage(DamageModifier.RESISTANCE);
+ if (f3 > 0.0F && f3 < 3.4028235E37F) {
+ if (this instanceof EntityPlayer) {
+ ((EntityPlayer) this).awardStat(StatisticList.DAMAGE_RESISTED, Math.round(f3 * 10.0F));
+ } else if (damagesource.getEntity() instanceof EntityPlayer) {
+ ((EntityPlayer) damagesource.getEntity()).awardStat(StatisticList.DAMAGE_DEALT_RESISTED, Math.round(f3 * 10.0F));
+ }
+ }
+ }
+
+ // Apply damage to helmet
+ if (damagesource.is(DamageTypeTags.DAMAGES_HELMET) && !this.getItemBySlot(EnumItemSlot.HEAD).isEmpty()) {
+ this.hurtHelmet(damagesource, f);
+ }
+
+ // Apply damage to armor
+ if (!damagesource.is(DamageTypeTags.BYPASSES_ARMOR)) {
+ float armorDamage = (float) (event.getDamage() + event.getDamage(DamageModifier.BLOCKING) + event.getDamage(DamageModifier.HARD_HAT));
+ this.hurtArmor(damagesource, armorDamage);
+ }
+
+ // Apply blocking code // PAIL: steal from above
+ if (event.getDamage(DamageModifier.BLOCKING) < 0) {
+ this.hurtCurrentlyUsedShield((float) -event.getDamage(DamageModifier.BLOCKING));
+ Entity entity = damagesource.getDirectEntity();
+
+ if (entity instanceof EntityLiving) {
+ this.blockUsingShield((EntityLiving) entity);
+ }
+ }
+
+ return event;
+ }
+
+ protected boolean actuallyHurt(final DamageSource damagesource, float f, final EntityDamageEvent event) { // void -> boolean, add final
if (!this.isInvulnerableTo(damagesource)) {
- f = this.getDamageAfterArmorAbsorb(damagesource, f);
- f = this.getDamageAfterMagicAbsorb(damagesource, 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;
+ float originalDamage = f;
+ Function<Double, Double> hardHat = new Function<Double, Double>() {
+ @Override
+ public Double apply(Double f) {
+ if (damagesource.is(DamageTypeTags.DAMAGES_HELMET) && !EntityLiving.this.getItemBySlot(EnumItemSlot.HEAD).isEmpty()) {
+ return -(f - (f * 0.75F));
+ if (event.isCancelled()) {
+ return false;
+ }
- f = Math.max(f - this.getAbsorptionAmount(), 0.0F);
- this.setAbsorptionAmount(this.getAbsorptionAmount() - (f1 - f));
- float f2 = f1 - f;
+ }
+ return -0.0;
+ }
+ };
+ float hardHatModifier = hardHat.apply((double) f).floatValue();
+ f += hardHatModifier;
+
+ Function<Double, Double> blocking = new Function<Double, Double>() {
+ @Override
+ public Double apply(Double f) {
+ return -((EntityLiving.this.isDamageSourceBlocked(damagesource)) ? f : 0.0);
+ }
+ };
+ float blockingModifier = blocking.apply((double) f).floatValue();
+ f += blockingModifier;
+
+ Function<Double, Double> armor = new Function<Double, Double>() {
+ @Override
+ public Double apply(Double f) {
+ return -(f - EntityLiving.this.getDamageAfterArmorAbsorb(damagesource, f.floatValue()));
+ }
+ };
+ float armorModifier = armor.apply((double) f).floatValue();
+ f += armorModifier;
+ Function<Double, Double> resistance = new Function<Double, Double>() {
+ @Override
+ public Double apply(Double f) {
+ if (!damagesource.is(DamageTypeTags.BYPASSES_EFFECTS) && EntityLiving.this.hasEffect(MobEffects.DAMAGE_RESISTANCE) && !damagesource.is(DamageTypeTags.BYPASSES_RESISTANCE)) {
+ int i = (EntityLiving.this.getEffect(MobEffects.DAMAGE_RESISTANCE).getAmplifier() + 1) * 5;
+ int j = 25 - i;
+ float f1 = f.floatValue() * (float) j;
+ return -(f - (f1 / 25.0F));
+ }
+ return -0.0;
+ }
+ };
+ float resistanceModifier = resistance.apply((double) f).floatValue();
+ f += resistanceModifier;
+
+ Function<Double, Double> magic = new Function<Double, Double>() {
+ @Override
+ public Double apply(Double f) {
+ return -(f - EntityLiving.this.getDamageAfterMagicAbsorb(damagesource, f.floatValue()));
+ }
+ };
+ float magicModifier = magic.apply((double) f).floatValue();
+ f += magicModifier;
+
+ Function<Double, Double> absorption = new Function<Double, Double>() {
+ @Override
+ public Double apply(Double f) {
+ return -(Math.max(f - Math.max(f - EntityLiving.this.getAbsorptionAmount(), 0.0F), 0.0F));
+ }
+ };
+ float absorptionModifier = absorption.apply((double) f).floatValue();
+
+ EntityDamageEvent event = CraftEventFactory.handleLivingEntityDamageEvent(this, damagesource, originalDamage, hardHatModifier, blockingModifier, armorModifier, resistanceModifier, magicModifier, absorptionModifier, hardHat, blocking, armor, resistance, magic, absorption);
+ if (damagesource.getEntity() instanceof EntityHuman) {
+ ((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()) {
+ return false;
+ }
+
+ f = (float) event.getFinalDamage();
+
+ // Resistance
+ if (event.getDamage(DamageModifier.RESISTANCE) < 0) {
+ float f3 = (float) -event.getDamage(DamageModifier.RESISTANCE);
+ if (f3 > 0.0F && f3 < 3.4028235E37F) {
+ if (this instanceof EntityPlayer) {
+ ((EntityPlayer) this).awardStat(StatisticList.DAMAGE_RESISTED, Math.round(f3 * 10.0F));
+ } else if (damagesource.getEntity() instanceof EntityPlayer) {
+ ((EntityPlayer) damagesource.getEntity()).awardStat(StatisticList.DAMAGE_DEALT_RESISTED, Math.round(f3 * 10.0F));
+ }
+ }
+ }
+
+ // Apply damage to helmet
+ if (damagesource.is(DamageTypeTags.DAMAGES_HELMET) && !this.getItemBySlot(EnumItemSlot.HEAD).isEmpty()) {
+ this.hurtHelmet(damagesource, f);
+ }
+
+ // Apply damage to armor
+ if (!damagesource.is(DamageTypeTags.BYPASSES_ARMOR)) {
+ float armorDamage = (float) (event.getDamage() + event.getDamage(DamageModifier.BLOCKING) + event.getDamage(DamageModifier.HARD_HAT));
+ this.hurtArmor(damagesource, armorDamage);
+ }
+
+ // Apply blocking code // PAIL: steal from above
+ if (event.getDamage(DamageModifier.BLOCKING) < 0) {
+ this.level().broadcastEntityEvent(this, (byte) 29); // SPIGOT-4635 - shield damage sound
+ this.hurtCurrentlyUsedShield((float) -event.getDamage(DamageModifier.BLOCKING));
+ Entity entity = damagesource.getDirectEntity();
+
+ if (entity instanceof EntityLiving) {
+ this.blockUsingShield((EntityLiving) entity);
+ }
+ }
+
+ absorptionModifier = (float) -event.getDamage(DamageModifier.ABSORPTION);
+ boolean human = this instanceof EntityHuman;
+ float originalDamage = (float) event.getDamage();
+ float absorptionModifier = (float) -event.getDamage(DamageModifier.ABSORPTION);
+ this.setAbsorptionAmount(Math.max(this.getAbsorptionAmount() - absorptionModifier, 0.0F));
+ float f2 = absorptionModifier;
+
+ if (f2 > 0.0F && f2 < 3.4028235E37F && this instanceof EntityHuman) {
+ ((EntityHuman) this).awardStat(StatisticList.DAMAGE_ABSORBED, Math.round(f2 * 10.0F));
+ }
+ // CraftBukkit end
if (f2 > 0.0F && f2 < 3.4028235E37F) {
Entity entity = damagesource.getEntity();
@@ -1812,13 +2226,47 @@
@@ -1812,13 +2257,48 @@
}
}
- if (f != 0.0F) {
+ // CraftBukkit start
+ if (f > 0 || !human) {
+ if (human) {
+ // PAIL: Be sure to drag all this code from the EntityHuman subclass each update.
@ -910,27 +945,28 @@
}
public CombatTracker getCombatTracker() {
@@ -1843,8 +2291,18 @@
@@ -1843,9 +2323,19 @@
}
public final void setArrowCount(int i) {
- this.entityData.set(EntityLiving.DATA_ARROW_COUNT_ID, i);
+ // CraftBukkit start
+ setArrowCount(i, false);
+ }
+
}
+ public final void setArrowCount(int i, boolean flag) {
+ ArrowBodyCountChangeEvent event = CraftEventFactory.callArrowBodyCountChangeEvent(this, getArrowCount(), i, flag);
+ if (event.isCancelled()) {
+ return;
+ }
+ this.entityData.set(EntityLiving.DATA_ARROW_COUNT_ID, event.getNewAmount());
}
+ }
+ // CraftBukkit end
+
public final int getStingerCount() {
return (Integer) this.entityData.get(EntityLiving.DATA_STINGER_COUNT_ID);
@@ -2086,6 +2544,12 @@
}
@@ -2086,6 +2576,12 @@
public abstract ItemStack getItemBySlot(EnumItemSlot enumitemslot);
@ -943,7 +979,7 @@
public abstract void setItemSlot(EnumItemSlot enumitemslot, ItemStack itemstack);
public Iterable<ItemStack> getHandSlots() {
@@ -2336,6 +2800,7 @@
@@ -2336,6 +2832,7 @@
}
if (this.onGround() && !this.level().isClientSide) {
@ -951,7 +987,7 @@
this.setSharedFlag(7, false);
}
} else {
@@ -2506,7 +2971,7 @@
@@ -2506,7 +3003,7 @@
}
}
@ -960,7 +996,7 @@
if (this.tickCount % 20 == 0) {
this.getCombatTracker().recheckStatus();
}
@@ -2610,7 +3075,7 @@
@@ -2610,7 +3107,7 @@
}
@ -969,7 +1005,7 @@
Map<EnumItemSlot, ItemStack> map = this.collectEquipmentChanges();
if (map != null) {
@@ -2949,6 +3414,7 @@
@@ -2949,6 +3446,7 @@
}
if (!this.level().isClientSide) {
@ -977,7 +1013,7 @@
this.setSharedFlag(7, flag);
}
@@ -3141,14 +3607,21 @@
@@ -3141,14 +3639,21 @@
@Override
public boolean isPickable() {
@ -1001,7 +1037,7 @@
@Override
public float getYHeadRot() {
return this.yHeadRot;
@@ -3346,7 +3819,26 @@
@@ -3346,7 +3851,26 @@
} else {
if (!this.useItem.isEmpty() && this.isUsingItem()) {
this.triggerItemUseEffects(this.useItem, 16);
@ -1029,7 +1065,7 @@
if (itemstack != this.useItem) {
this.setItemInHand(enumhand, itemstack);
@@ -3424,6 +3916,12 @@
@@ -3424,6 +3948,12 @@
}
public boolean randomTeleport(double d0, double d1, double d2, boolean flag) {
@ -1042,7 +1078,7 @@
double d3 = this.getX();
double d4 = this.getY();
double d5 = this.getZ();
@@ -3448,16 +3946,41 @@
@@ -3448,16 +3978,41 @@
}
if (flag2) {
@ -1087,7 +1123,7 @@
} else {
if (flag) {
world.broadcastEntityEvent(this, (byte) 46);
@@ -3469,7 +3992,7 @@
@@ -3469,7 +4024,7 @@
entitycreature.getNavigation().stop();
}
@ -1096,7 +1132,7 @@
}
}
@@ -3562,7 +4085,7 @@
@@ -3562,7 +4117,7 @@
}
public void stopSleeping() {
@ -1105,7 +1141,7 @@
World world = this.level();
java.util.Objects.requireNonNull(world);
@@ -3596,7 +4119,7 @@
@@ -3596,7 +4151,7 @@
@Nullable
public EnumDirection getBedOrientation() {
@ -1114,7 +1150,7 @@
return blockposition != null ? BlockBed.getBedOrientation(this.level(), blockposition) : null;
}
@@ -3633,7 +4156,7 @@
@@ -3633,7 +4188,7 @@
FoodInfo.b foodinfo_b = (FoodInfo.b) iterator.next();
if (this.random.nextFloat() < foodinfo_b.probability()) {

View file

@ -1,12 +1,13 @@
--- a/net/minecraft/world/entity/animal/EntityAnimal.java
+++ b/net/minecraft/world/entity/animal/EntityAnimal.java
@@ -29,12 +29,19 @@
@@ -29,12 +29,20 @@
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.pathfinder.PathType;
+// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.entity.EntityBreedEvent;
+import org.bukkit.event.entity.EntityDamageEvent;
+import org.bukkit.event.entity.EntityEnterLoveModeEvent;
+// CraftBukkit end
+
@ -20,25 +21,25 @@
protected EntityAnimal(EntityTypes<? extends EntityAnimal> entitytypes, World world) {
super(entitytypes, world);
@@ -72,9 +79,15 @@
@@ -72,9 +80,15 @@
}
@Override
- protected void actuallyHurt(DamageSource damagesource, float f) {
+ // CraftBukkit start - void -> boolean
+ public boolean actuallyHurt(DamageSource damagesource, float f) {
+ boolean result = super.actuallyHurt(damagesource, f);
+ if (!result) {
+ return result;
+ public boolean actuallyHurt(DamageSource damagesource, float f, EntityDamageEvent event) {
+ boolean damageResult = super.actuallyHurt(damagesource, f, event);
+ if (!damageResult) {
+ return false;
+ }
this.resetLove();
- super.actuallyHurt(damagesource, f);
+ return result;
+ return true;
+ // CraftBukkit end
}
@Override
@@ -162,10 +175,17 @@
@@ -162,10 +176,17 @@
}
public void setInLove(@Nullable EntityHuman entityhuman) {
@ -57,7 +58,7 @@
this.level().broadcastEntityEvent(this, (byte) 18);
}
@@ -207,12 +227,29 @@
@@ -207,12 +228,29 @@
if (entityageable != null) {
entityageable.setBaby(true);
entityageable.moveTo(this.getX(), this.getY(), this.getZ(), 0.0F, 0.0F);
@ -89,7 +90,7 @@
Optional.ofNullable(this.getLoveCause()).or(() -> {
return Optional.ofNullable(entityanimal.getLoveCause());
}).ifPresent((entityplayer) -> {
@@ -225,7 +262,11 @@
@@ -225,7 +263,11 @@
entityanimal.resetLove();
worldserver.broadcastEntityEvent(this, (byte) 18);
if (worldserver.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) {

View file

@ -1,10 +1,11 @@
--- a/net/minecraft/world/entity/animal/EntityWolf.java
+++ b/net/minecraft/world/entity/animal/EntityWolf.java
@@ -90,6 +90,12 @@
@@ -90,6 +90,13 @@
import net.minecraft.world.level.pathfinder.PathType;
import net.minecraft.world.phys.Vec3D;
+// CraftBukkit start
+import org.bukkit.event.entity.EntityDamageEvent;
+import org.bukkit.event.entity.EntityRegainHealthEvent;
+import org.bukkit.event.entity.EntityTargetEvent;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
@ -13,7 +14,7 @@
public class EntityWolf extends EntityTameableAnimal implements IEntityAngerable, VariantHolder<Holder<WolfVariant>> {
private static final DataWatcherObject<Boolean> DATA_INTERESTED_ID = DataWatcher.defineId(EntityWolf.class, DataWatcherRegistry.BOOLEAN);
@@ -360,11 +366,14 @@
@@ -360,11 +367,14 @@
if (this.isInvulnerableTo(damagesource)) {
return false;
} else {
@ -30,19 +31,19 @@
}
}
@@ -374,9 +383,9 @@
@@ -374,9 +384,9 @@
}
@Override
- protected void actuallyHurt(DamageSource damagesource, float f) {
+ public boolean actuallyHurt(DamageSource damagesource, float f) { // CraftBukkit - void -> boolean
+ public boolean actuallyHurt(DamageSource damagesource, float f, EntityDamageEvent event) { // CraftBukkit - void -> boolean
if (!this.canArmorAbsorb(damagesource)) {
- super.actuallyHurt(damagesource, f);
+ return super.actuallyHurt(damagesource, f); // CraftBukkit
+ return super.actuallyHurt(damagesource, f, event); // CraftBukkit
} else {
ItemStack itemstack = this.getBodyArmorItem();
int i = itemstack.getDamageValue();
@@ -395,6 +404,7 @@
@@ -395,6 +405,7 @@
}
}
@ -50,7 +51,7 @@
}
private boolean canArmorAbsorb(DamageSource damagesource) {
@@ -405,7 +415,7 @@
@@ -405,7 +416,7 @@
protected void applyTamingSideEffects() {
if (this.isTame()) {
this.getAttribute(GenericAttributes.MAX_HEALTH).setBaseValue(40.0D);
@ -59,7 +60,7 @@
} else {
this.getAttribute(GenericAttributes.MAX_HEALTH).setBaseValue(8.0D);
}
@@ -432,7 +442,7 @@
@@ -432,7 +443,7 @@
FoodInfo foodinfo = (FoodInfo) itemstack.get(DataComponents.FOOD);
float f = foodinfo != null ? (float) foodinfo.nutrition() : 1.0F;
@ -68,7 +69,7 @@
return EnumInteractionResult.sidedSuccess(this.level().isClientSide());
} else {
if (item instanceof ItemDye) {
@@ -480,7 +490,7 @@
@@ -480,7 +491,7 @@
this.setOrderedToSit(!this.isOrderedToSit());
this.jumping = false;
this.navigation.stop();
@ -77,7 +78,7 @@
return EnumInteractionResult.SUCCESS_NO_ITEM_USED;
} else {
return enuminteractionresult;
@@ -498,7 +508,8 @@
@@ -498,7 +509,8 @@
}
private void tryToTame(EntityHuman entityhuman) {

View file

@ -1,6 +1,17 @@
--- a/net/minecraft/world/entity/animal/armadillo/Armadillo.java
+++ b/net/minecraft/world/entity/animal/armadillo/Armadillo.java
@@ -132,14 +132,16 @@
@@ -47,6 +47,10 @@
import net.minecraft.world.level.block.state.IBlockData;
import net.minecraft.world.level.gameevent.GameEvent;
+// CraftBukkit start
+import org.bukkit.event.entity.EntityDamageEvent;
+// CraftBukkit end
+
public class Armadillo extends EntityAnimal {
public static final float BABY_SCALE = 0.6F;
@@ -132,14 +136,16 @@
@Override
protected void customServerAiStep() {
this.level().getProfiler().push("armadilloBrain");
@ -18,31 +29,31 @@
this.gameEvent(GameEvent.ENTITY_PLACE);
this.scuteTime = this.pickNextScuteDropTime();
}
@@ -286,8 +288,13 @@
@@ -286,8 +292,13 @@
}
@Override
- protected void actuallyHurt(DamageSource damagesource, float f) {
- super.actuallyHurt(damagesource, f);
+ // CraftBukkit start - void -> boolean
+ public boolean actuallyHurt(DamageSource damagesource, float f) {
+ boolean hurt = super.actuallyHurt(damagesource, f);
+ if (!hurt) {
+ return hurt;
+ public boolean actuallyHurt(DamageSource damagesource, float f, EntityDamageEvent event) {
+ boolean damageResult = super.actuallyHurt(damagesource, f, event);
+ if (!damageResult) {
+ return false;
+ }
+ // CraftBukkit end
if (!this.isNoAi() && !this.isDeadOrDying()) {
if (damagesource.getEntity() instanceof EntityLiving) {
this.getBrain().setMemoryWithExpiry(MemoryModuleType.DANGER_DETECTED_RECENTLY, true, 80L);
@@ -299,6 +306,7 @@
@@ -299,6 +310,7 @@
}
}
+ return hurt; // CraftBukkit
+ return true; // CraftBukkit
}
@Override
@@ -326,7 +334,9 @@
@@ -326,7 +338,9 @@
if (this.isBaby()) {
return false;
} else {

View file

@ -1,6 +1,17 @@
--- a/net/minecraft/world/entity/animal/camel/Camel.java
+++ b/net/minecraft/world/entity/animal/camel/Camel.java
@@ -141,7 +141,7 @@
@@ -50,6 +50,10 @@
import net.minecraft.world.phys.Vec2F;
import net.minecraft.world.phys.Vec3D;
+// CraftBukkit start
+import org.bukkit.event.entity.EntityDamageEvent;
+// CraftBukkit end
+
public class Camel extends EntityHorseAbstract implements IJumpable, ISaddleable {
public static final float BABY_SCALE = 0.45F;
@@ -141,7 +145,7 @@
@Override
protected void customServerAiStep() {
this.level().getProfiler().push("camelBrain");
@ -9,21 +20,21 @@
behaviorcontroller.tick((WorldServer) this.level(), this);
this.level().getProfiler().pop();
@@ -452,9 +452,15 @@
@@ -452,9 +456,15 @@
}
@Override
- protected void actuallyHurt(DamageSource damagesource, float f) {
+ // CraftBukkit start - void -> boolean
+ public boolean actuallyHurt(DamageSource damagesource, float f) {
+ boolean hurt = super.actuallyHurt(damagesource, f);
+ if (!hurt) {
+ return hurt;
+ public boolean actuallyHurt(DamageSource damagesource, float f, EntityDamageEvent event) {
+ boolean damageResult = super.actuallyHurt(damagesource, f, event);
+ if (!damageResult) {
+ return false;
+ }
+ // CraftBukkit end
this.standUpInstantly();
- super.actuallyHurt(damagesource, f);
+ return hurt; // CraftBukkit
+ return true; // CraftBukkit
}
@Override

View file

@ -1,6 +1,6 @@
--- a/net/minecraft/world/entity/player/EntityHuman.java
+++ b/net/minecraft/world/entity/player/EntityHuman.java
@@ -115,6 +115,22 @@
@@ -115,6 +115,23 @@
import net.minecraft.world.scores.ScoreboardTeam;
import org.slf4j.Logger;
@ -13,6 +13,7 @@
+import org.bukkit.entity.Player;
+import org.bukkit.event.entity.CreatureSpawnEvent;
+import org.bukkit.event.entity.EntityCombustByEntityEvent;
+import org.bukkit.event.entity.EntityDamageEvent;
+import org.bukkit.event.entity.EntityExhaustionEvent;
+import org.bukkit.event.entity.EntityKnockbackEvent;
+import org.bukkit.event.entity.EntityRemoveEvent;
@ -23,7 +24,7 @@
public abstract class EntityHuman extends EntityLiving {
private static final Logger LOGGER = LogUtils.getLogger();
@@ -135,7 +151,8 @@
@@ -135,7 +152,8 @@
private static final int CURRENT_IMPULSE_CONTEXT_RESET_GRACE_TIME_TICKS = 40;
public static final Vec3D DEFAULT_VEHICLE_ATTACHMENT = new Vec3D(0.0D, 0.6D, 0.0D);
public static final EntitySize STANDING_DIMENSIONS = EntitySize.scalable(0.6F, 1.8F).withEyeHeight(1.62F).withAttachments(EntityAttachments.builder().attach(EntityAttachment.VEHICLE, EntityHuman.DEFAULT_VEHICLE_ATTACHMENT));
@ -33,7 +34,7 @@
private static final DataWatcherObject<Float> DATA_PLAYER_ABSORPTION_ID = DataWatcher.defineId(EntityHuman.class, DataWatcherRegistry.FLOAT);
private static final DataWatcherObject<Integer> DATA_SCORE_ID = DataWatcher.defineId(EntityHuman.class, DataWatcherRegistry.INT);
protected static final DataWatcherObject<Byte> DATA_PLAYER_MODE_CUSTOMISATION = DataWatcher.defineId(EntityHuman.class, DataWatcherRegistry.BYTE);
@@ -144,10 +161,10 @@
@@ -144,10 +162,10 @@
protected static final DataWatcherObject<NBTTagCompound> DATA_SHOULDER_RIGHT = DataWatcher.defineId(EntityHuman.class, DataWatcherRegistry.COMPOUND_TAG);
private long timeEntitySatOnShoulder;
final PlayerInventory inventory = new PlayerInventory(this);
@ -46,7 +47,7 @@
protected int jumpTriggerTime;
public float oBob;
public float bob;
@@ -182,6 +199,16 @@
@@ -182,6 +200,16 @@
private boolean ignoreFallDamageFromCurrentImpulse;
private int currentImpulseContextResetGraceTime;
@ -63,7 +64,7 @@
public EntityHuman(World world, BlockPosition blockposition, float f, GameProfile gameprofile) {
super(EntityTypes.PLAYER, world);
this.lastItemInMainHand = ItemStack.EMPTY;
@@ -330,7 +357,7 @@
@@ -330,7 +358,7 @@
ItemStack itemstack = this.getItemBySlot(EnumItemSlot.HEAD);
if (itemstack.is(Items.TURTLE_HELMET) && !this.isEyeInFluid(TagsFluid.WATER)) {
@ -72,7 +73,7 @@
}
}
@@ -482,8 +509,14 @@
@@ -482,8 +510,14 @@
public void rideTick() {
if (!this.level().isClientSide && this.wantsToStopRiding() && this.isPassenger()) {
this.stopRiding();
@ -89,7 +90,7 @@
super.rideTick();
this.oBob = this.bob;
this.bob = 0.0F;
@@ -505,7 +538,8 @@
@@ -505,7 +539,8 @@
if (this.level().getDifficulty() == EnumDifficulty.PEACEFUL && this.level().getGameRules().getBoolean(GameRules.RULE_NATURAL_REGENERATION)) {
if (this.getHealth() < this.getMaxHealth() && this.tickCount % 20 == 0) {
@ -99,7 +100,7 @@
}
if (this.foodData.getSaturationLevel() < 20.0F && this.tickCount % 20 == 0) {
@@ -683,6 +717,13 @@
@@ -683,6 +718,13 @@
@Nullable
public EntityItem drop(ItemStack itemstack, boolean flag, boolean flag1) {
@ -113,7 +114,7 @@
if (itemstack.isEmpty()) {
return null;
} else {
@@ -717,6 +758,33 @@
@@ -717,6 +759,33 @@
entityitem.setDeltaMovement((double) (-f3 * f2 * 0.3F) + Math.cos((double) f5) * (double) f6, (double) (-f1 * 0.3F + 0.1F + (this.random.nextFloat() - this.random.nextFloat()) * 0.1F), (double) (f4 * f2 * 0.3F) + Math.sin((double) f5) * (double) f6);
}
@ -147,7 +148,7 @@
return entityitem;
}
}
@@ -803,7 +871,7 @@
@@ -803,7 +872,7 @@
}
if (nbttagcompound.contains("LastDeathLocation", 10)) {
@ -156,7 +157,7 @@
Logger logger = EntityHuman.LOGGER;
Objects.requireNonNull(logger);
@@ -811,7 +879,7 @@
@@ -811,7 +880,7 @@
}
if (nbttagcompound.contains("current_explosion_impact_pos", 9)) {
@ -165,7 +166,7 @@
Logger logger1 = EntityHuman.LOGGER;
Objects.requireNonNull(logger1);
@@ -848,7 +916,7 @@
@@ -848,7 +917,7 @@
}
this.getLastDeathLocation().flatMap((globalpos) -> {
@ -174,7 +175,7 @@
Logger logger = EntityHuman.LOGGER;
Objects.requireNonNull(logger);
@@ -881,12 +949,12 @@
@@ -881,12 +950,12 @@
return false;
} else {
if (!this.level().isClientSide) {
@ -189,7 +190,7 @@
}
if (this.level().getDifficulty() == EnumDifficulty.EASY) {
@@ -898,7 +966,13 @@
@@ -898,7 +967,13 @@
}
}
@ -204,7 +205,7 @@
}
}
}
@@ -918,10 +992,29 @@
@@ -918,10 +993,29 @@
}
public boolean canHarmPlayer(EntityHuman entityhuman) {
@ -237,22 +238,22 @@
}
@Override
@@ -961,8 +1054,13 @@
@@ -961,8 +1055,13 @@
}
}
+ // CraftBukkit start
@Override
- protected void actuallyHurt(DamageSource damagesource, float f) {
+ protected boolean actuallyHurt(DamageSource damagesource, float f) { // void -> boolean
+ protected boolean actuallyHurt(DamageSource damagesource, float f, EntityDamageEvent event) { // void -> boolean
+ if (true) {
+ return super.actuallyHurt(damagesource, f);
+ return super.actuallyHurt(damagesource, f, event);
+ }
+ // CraftBukkit end
if (!this.isInvulnerableTo(damagesource)) {
f = this.getDamageAfterArmorAbsorb(damagesource, f);
f = this.getDamageAfterMagicAbsorb(damagesource, f);
@@ -977,7 +1075,7 @@
@@ -977,7 +1076,7 @@
}
if (f != 0.0F) {
@ -261,7 +262,7 @@
this.getCombatTracker().recordDamage(damagesource, f);
this.setHealth(this.getHealth() - f);
if (f < 3.4028235E37F) {
@@ -987,6 +1085,7 @@
@@ -987,6 +1086,7 @@
this.gameEvent(GameEvent.ENTITY_DAMAGE);
}
}
@ -269,7 +270,7 @@
}
public boolean isTextFilteringEnabled() {
@@ -1139,10 +1238,15 @@
@@ -1139,10 +1239,15 @@
f *= 0.2F + f2 * f2 * 0.8F;
f1 *= f2;
@ -286,7 +287,7 @@
if (iprojectile.deflect(ProjectileDeflection.AIM_DEFLECT, this, this, true)) {
this.level().playSound((EntityHuman) null, this.getX(), this.getY(), this.getZ(), SoundEffects.PLAYER_ATTACK_NODAMAGE, this.getSoundSource());
return;
@@ -1218,8 +1322,11 @@
@@ -1218,8 +1323,11 @@
if (entityliving2 != this && entityliving2 != entity && !this.isAlliedTo((Entity) entityliving2) && (!(entityliving2 instanceof EntityArmorStand) || !((EntityArmorStand) entityliving2).isMarker()) && this.distanceToSqr((Entity) entityliving2) < 9.0D) {
float f7 = this.getEnchantedDamage(entityliving2, f6, damagesource) * f2;
@ -300,7 +301,7 @@
World world = this.level();
if (world instanceof WorldServer) {
@@ -1235,9 +1342,26 @@
@@ -1235,9 +1343,26 @@
}
if (entity instanceof EntityPlayer && entity.hurtMarked) {
@ -327,7 +328,7 @@
}
if (flag2) {
@@ -1303,9 +1427,14 @@
@@ -1303,9 +1428,14 @@
}
}
@ -343,7 +344,7 @@
}
}
@@ -1346,7 +1475,14 @@
@@ -1346,7 +1476,14 @@
@Override
public void remove(Entity.RemovalReason entity_removalreason) {
@ -359,7 +360,7 @@
this.inventoryMenu.removed(this);
if (this.containerMenu != null && this.hasContainerOpen()) {
this.doCloseContainer();
@@ -1382,6 +1518,12 @@
@@ -1382,6 +1519,12 @@
}
public Either<EntityHuman.EnumBedResult, Unit> startSleepInBed(BlockPosition blockposition) {
@ -372,7 +373,7 @@
this.startSleeping(blockposition);
this.sleepCounter = 0;
return Either.right(Unit.INSTANCE);
@@ -1444,9 +1586,9 @@
@@ -1444,9 +1587,9 @@
super.jumpFromGround();
this.awardStat(StatisticList.JUMP);
if (this.isSprinting()) {
@ -384,7 +385,7 @@
}
}
@@ -1473,7 +1615,11 @@
@@ -1473,7 +1616,11 @@
this.setDeltaMovement(vec3d2.x, d0 * 0.6D, vec3d2.z);
this.resetFallDistance();
@ -397,7 +398,7 @@
} else {
super.travel(vec3d);
}
@@ -1547,12 +1693,24 @@
@@ -1547,12 +1694,24 @@
}
public void startFallFlying() {
@ -423,7 +424,7 @@
}
@Override
@@ -1667,10 +1825,21 @@
@@ -1667,10 +1826,21 @@
return this.experienceLevel >= 30 ? 112 + (this.experienceLevel - 30) * 9 : (this.experienceLevel >= 15 ? 37 + (this.experienceLevel - 15) * 5 : 7 + this.experienceLevel * 2);
}
@ -446,7 +447,7 @@
}
}
@@ -1756,13 +1925,20 @@
@@ -1756,13 +1926,20 @@
@Override
public void setItemSlot(EnumItemSlot enumitemslot, ItemStack itemstack) {
@ -470,7 +471,7 @@
}
}
@@ -1806,26 +1982,31 @@
@@ -1806,26 +1983,31 @@
protected void removeEntitiesOnShoulder() {
if (this.timeEntitySatOnShoulder + 20L < this.level().getGameTime()) {
@ -510,7 +511,7 @@
}
@Override
@@ -2040,7 +2221,7 @@
@@ -2040,7 +2222,7 @@
@Override
public ItemStack eat(World world, ItemStack itemstack, FoodInfo foodinfo) {

View file

@ -1067,11 +1067,15 @@ public class CraftEventFactory {
private static final Function<? super Double, Double> ZERO = Functions.constant(-0.0);
public static EntityDamageEvent handleLivingEntityDamageEvent(Entity damagee, DamageSource source, double rawDamage, double hardHatModifier, double blockingModifier, double armorModifier, double resistanceModifier, double magicModifier, double absorptionModifier, Function<Double, Double> hardHat, Function<Double, Double> blocking, Function<Double, Double> armor, Function<Double, Double> resistance, Function<Double, Double> magic, Function<Double, Double> absorption) {
public static EntityDamageEvent handleLivingEntityDamageEvent(Entity damagee, DamageSource source, double rawDamage, double freezingModifier, double hardHatModifier, double blockingModifier, double armorModifier, double resistanceModifier, double magicModifier, double absorptionModifier, Function<Double, Double> freezing, Function<Double, Double> hardHat, Function<Double, Double> blocking, Function<Double, Double> armor, Function<Double, Double> resistance, Function<Double, Double> magic, Function<Double, Double> absorption) {
Map<DamageModifier, Double> modifiers = new EnumMap<>(DamageModifier.class);
Map<DamageModifier, Function<? super Double, Double>> modifierFunctions = new EnumMap<>(DamageModifier.class);
modifiers.put(DamageModifier.BASE, rawDamage);
modifierFunctions.put(DamageModifier.BASE, ZERO);
if (source.is(DamageTypes.FREEZE)) {
modifiers.put(DamageModifier.FREEZING, freezingModifier);
modifierFunctions.put(DamageModifier.FREEZING, freezing);
}
if (source.is(DamageTypes.FALLING_BLOCK) || source.is(DamageTypes.FALLING_ANVIL)) {
modifiers.put(DamageModifier.HARD_HAT, hardHatModifier);
modifierFunctions.put(DamageModifier.HARD_HAT, hardHat);