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

@@ -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) {