Update to Minecraft 1.21

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot
2024-06-14 01:05:00 +10:00
parent 7c6204e1a9
commit eed041d629
255 changed files with 3585 additions and 3261 deletions

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/world/entity/player/EntityHuman.java
+++ b/net/minecraft/world/entity/player/EntityHuman.java
@@ -116,6 +116,22 @@
@@ -115,6 +115,22 @@
import net.minecraft.world.scores.ScoreboardTeam;
import org.slf4j.Logger;
@@ -24,7 +24,7 @@
private static final Logger LOGGER = LogUtils.getLogger();
@@ -135,7 +151,8 @@
public static final float DEFAULT_EYE_HEIGHT = 1.62F;
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));
- private static final Map<EntityPose, EntitySize> POSES = ImmutableMap.builder().put(EntityPose.STANDING, EntityHuman.STANDING_DIMENSIONS).put(EntityPose.SLEEPING, EntityHuman.SLEEPING_DIMENSIONS).put(EntityPose.FALL_FLYING, EntitySize.scalable(0.6F, 0.6F).withEyeHeight(0.4F)).put(EntityPose.SWIMMING, EntitySize.scalable(0.6F, 0.6F).withEyeHeight(0.4F)).put(EntityPose.SPIN_ATTACK, EntitySize.scalable(0.6F, 0.6F).withEyeHeight(0.4F)).put(EntityPose.CROUCHING, EntitySize.scalable(0.6F, 1.5F).withEyeHeight(1.27F).withAttachments(EntityAttachments.builder().attach(EntityAttachment.VEHICLE, EntityHuman.DEFAULT_VEHICLE_ATTACHMENT))).put(EntityPose.DYING, EntitySize.fixed(0.2F, 0.2F).withEyeHeight(1.62F)).build();
@@ -46,9 +46,9 @@
protected int jumpTriggerTime;
public float oBob;
public float bob;
@@ -181,6 +198,16 @@
public Entity currentExplosionCause;
public boolean ignoreFallDamageFromCurrentImpulse;
@@ -182,6 +199,16 @@
private boolean ignoreFallDamageFromCurrentImpulse;
private int currentImpulseContextResetGraceTime;
+ // CraftBukkit start
+ public boolean fauxSleeping;
@@ -63,7 +63,7 @@
public EntityHuman(World world, BlockPosition blockposition, float f, GameProfile gameprofile) {
super(EntityTypes.PLAYER, world);
this.lastItemInMainHand = ItemStack.EMPTY;
@@ -325,7 +352,7 @@
@@ -330,7 +357,7 @@
ItemStack itemstack = this.getItemBySlot(EnumItemSlot.HEAD);
if (itemstack.is(Items.TURTLE_HELMET) && !this.isEyeInFluid(TagsFluid.WATER)) {
@@ -98,8 +98,8 @@
+ this.heal(1.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.REGEN);
}
if (this.foodData.needsFood() && this.tickCount % 10 == 0) {
@@ -665,6 +699,13 @@
if (this.foodData.getSaturationLevel() < 20.0F && this.tickCount % 20 == 0) {
@@ -683,6 +717,13 @@
@Nullable
public EntityItem drop(ItemStack itemstack, boolean flag, boolean flag1) {
@@ -113,7 +113,7 @@
if (itemstack.isEmpty()) {
return null;
} else {
@@ -699,6 +740,33 @@
@@ -717,6 +758,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 +147,7 @@
return entityitem;
}
}
@@ -790,7 +858,7 @@
@@ -803,7 +871,7 @@
}
if (nbttagcompound.contains("LastDeathLocation", 10)) {
@@ -156,7 +156,7 @@
Logger logger = EntityHuman.LOGGER;
Objects.requireNonNull(logger);
@@ -798,7 +866,7 @@
@@ -811,7 +879,7 @@
}
if (nbttagcompound.contains("current_explosion_impact_pos", 9)) {
@@ -165,7 +165,7 @@
Logger logger1 = EntityHuman.LOGGER;
Objects.requireNonNull(logger1);
@@ -834,7 +902,7 @@
@@ -848,7 +916,7 @@
}
this.getLastDeathLocation().flatMap((globalpos) -> {
@@ -174,7 +174,7 @@
Logger logger = EntityHuman.LOGGER;
Objects.requireNonNull(logger);
@@ -866,12 +934,12 @@
@@ -881,12 +949,12 @@
return false;
} else {
if (!this.level().isClientSide) {
@@ -189,7 +189,7 @@
}
if (this.level().getDifficulty() == EnumDifficulty.EASY) {
@@ -883,7 +951,13 @@
@@ -898,7 +966,13 @@
}
}
@@ -204,7 +204,7 @@
}
}
}
@@ -903,10 +977,29 @@
@@ -918,10 +992,29 @@
}
public boolean canHarmPlayer(EntityHuman entityhuman) {
@@ -237,7 +237,7 @@
}
@Override
@@ -946,8 +1039,13 @@
@@ -961,8 +1054,13 @@
}
}
@@ -252,7 +252,7 @@
if (!this.isInvulnerableTo(damagesource)) {
f = this.getDamageAfterArmorAbsorb(damagesource, f);
f = this.getDamageAfterMagicAbsorb(damagesource, f);
@@ -962,7 +1060,7 @@
@@ -977,7 +1075,7 @@
}
if (f != 0.0F) {
@@ -261,15 +261,15 @@
this.getCombatTracker().recordDamage(damagesource, f);
this.setHealth(this.getHealth() - f);
if (f < 3.4028235E37F) {
@@ -972,6 +1070,7 @@
@@ -987,6 +1085,7 @@
this.gameEvent(GameEvent.ENTITY_DAMAGE);
}
}
+ return false; // CraftBukkit
}
@Override
@@ -1127,10 +1226,16 @@
public boolean isTextFilteringEnabled() {
@@ -1139,10 +1238,15 @@
f *= 0.2F + f2 * f2 * 0.8F;
f1 *= f2;
@@ -279,118 +279,71 @@
IProjectile iprojectile = (IProjectile) entity;
+ // CraftBukkit start
+ DamageSource damagesource = this.damageSources().playerAttack(this);
+ if (CraftEventFactory.handleNonLivingEntityDamageEvent(entity, damagesource, f1, false)) {
+ return;
+ }
+ // CraftBukkit end
iprojectile.deflect(ProjectileDeflection.AIM_DEFLECT, this, this, true);
} else {
if (f > 0.0F || f1 > 0.0F) {
@@ -1171,8 +1276,15 @@
if (entity instanceof EntityLiving) {
f3 = ((EntityLiving) entity).getHealth();
if (j > 0 && !entity.isOnFire()) {
- flag4 = true;
- entity.igniteForSeconds(1);
+ // CraftBukkit start - Call a combust event when somebody hits with a fire enchanted item
+ EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), entity.getBukkitEntity(), 1);
+ org.bukkit.Bukkit.getPluginManager().callEvent(combustEvent);
+
+ if (!combustEvent.isCancelled()) {
+ flag4 = true;
+ entity.igniteForSeconds(combustEvent.getDuration(), false);
+ }
+ // CraftBukkit end
}
}
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 @@
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;
@@ -1182,7 +1294,7 @@
if (flag5) {
if (i > 0) {
if (entity instanceof EntityLiving) {
- ((EntityLiving) entity).knockback((double) ((float) i * 0.5F), (double) MathHelper.sin(this.getYRot() * 0.017453292F), (double) (-MathHelper.cos(this.getYRot() * 0.017453292F)));
+ ((EntityLiving) entity).knockback((double) ((float) i * 0.5F), (double) MathHelper.sin(this.getYRot() * 0.017453292F), (double) (-MathHelper.cos(this.getYRot() * 0.017453292F)), this, EntityKnockbackEvent.KnockbackCause.ENTITY_ATTACK); // CraftBukkit
} else {
entity.push((double) (-MathHelper.sin(this.getYRot() * 0.017453292F) * (float) i * 0.5F), 0.1D, (double) (MathHelper.cos(this.getYRot() * 0.017453292F) * (float) i * 0.5F));
}
@@ -1200,8 +1312,11 @@
EntityLiving entityliving = (EntityLiving) iterator.next();
if (entityliving != this && entityliving != entity && !this.isAlliedTo((Entity) entityliving) && (!(entityliving instanceof EntityArmorStand) || !((EntityArmorStand) entityliving).isMarker()) && this.distanceToSqr((Entity) entityliving) < 9.0D) {
- entityliving.knockback(0.4000000059604645D, (double) MathHelper.sin(this.getYRot() * 0.017453292F), (double) (-MathHelper.cos(this.getYRot() * 0.017453292F)));
- entityliving.hurt(this.damageSources().playerAttack(this), f4);
+ // CraftBukkit start - Only apply knockback if the damage hits
+ if (entityliving.hurt(this.damageSources().playerAttack(this).sweep(), f4)) {
+ entityliving.knockback(0.4000000059604645D, (double) MathHelper.sin(this.getYRot() * 0.017453292F), (double) (-MathHelper.cos(this.getYRot() * 0.017453292F)), this, EntityKnockbackEvent.KnockbackCause.SWEEP_ATTACK); // CraftBukkit
+ }
+ // CraftBukkit end
}
}
@@ -1210,9 +1325,26 @@
}
if (entity instanceof EntityPlayer && entity.hurtMarked) {
+ // CraftBukkit start - Add Velocity Event
+ boolean cancelled = false;
+ Player player = (Player) entity.getBukkitEntity();
+ org.bukkit.util.Vector velocity = CraftVector.toBukkit(vec3d);
+
+ PlayerVelocityEvent event = new PlayerVelocityEvent(player, velocity.clone());
+ this.level().getCraftServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ cancelled = true;
+ } else if (!velocity.equals(event.getVelocity())) {
+ player.setVelocity(event.getVelocity());
+ }
+
+ if (!cancelled) {
((EntityPlayer) entity).connection.send(new PacketPlayOutEntityVelocity(entity));
entity.hurtMarked = false;
entity.setDeltaMovement(vec3d);
+ }
+ // CraftBukkit end
}
if (flag2) {
@@ -1257,7 +1389,14 @@
this.awardStat(StatisticList.DAMAGE_DEALT, Math.round(f5 * 10.0F));
if (j > 0) {
- entity.igniteForSeconds(j * 4);
+ // CraftBukkit start - Call a combust event when somebody hits with a fire enchanted item
+ EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), entity.getBukkitEntity(), j * 4);
+ org.bukkit.Bukkit.getPluginManager().callEvent(combustEvent);
+
+ if (!combustEvent.isCancelled()) {
+ entity.igniteForSeconds(combustEvent.getDuration(), false);
- entityliving2.knockback(0.4000000059604645D, (double) MathHelper.sin(this.getYRot() * 0.017453292F), (double) (-MathHelper.cos(this.getYRot() * 0.017453292F)));
- entityliving2.hurt(damagesource, f7);
+ // CraftBukkit start - Only apply knockback if the damage hits
+ if (entityliving2.hurt(this.damageSources().playerAttack(this).sweep(), f7)) {
+ entityliving2.knockback(0.4000000059604645D, (double) MathHelper.sin(this.getYRot() * 0.017453292F), (double) (-MathHelper.cos(this.getYRot() * 0.017453292F)), this, EntityKnockbackEvent.KnockbackCause.SWEEP_ATTACK); // CraftBukkit
+ }
+ // CraftBukkit end
}
World world = this.level();
if (this.level() instanceof WorldServer && f5 > 2.0F) {
@@ -1267,12 +1406,17 @@
}
}
if (world instanceof WorldServer) {
@@ -1235,9 +1342,26 @@
}
- this.causeFoodExhaustion(0.1F);
+ this.causeFoodExhaustion(0.1F, EntityExhaustionEvent.ExhaustionReason.ATTACK); // CraftBukkit - EntityExhaustionEvent
} else {
this.level().playSound((EntityHuman) null, this.getX(), this.getY(), this.getZ(), SoundEffects.PLAYER_ATTACK_NODAMAGE, this.getSoundSource(), 1.0F, 1.0F);
if (flag4) {
entity.clearFire();
}
+ // CraftBukkit start - resync on cancelled event
+ if (this instanceof EntityPlayer) {
+ ((EntityPlayer) this).getBukkitEntity().updateInventory();
if (entity instanceof EntityPlayer && entity.hurtMarked) {
+ // CraftBukkit start - Add Velocity Event
+ boolean cancelled = false;
+ Player player = (Player) entity.getBukkitEntity();
+ org.bukkit.util.Vector velocity = CraftVector.toBukkit(vec3d);
+
+ PlayerVelocityEvent event = new PlayerVelocityEvent(player, velocity.clone());
+ this.level().getCraftServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ cancelled = true;
+ } else if (!velocity.equals(event.getVelocity())) {
+ player.setVelocity(event.getVelocity());
+ }
+
+ if (!cancelled) {
((EntityPlayer) entity).connection.send(new PacketPlayOutEntityVelocity(entity));
entity.hurtMarked = false;
entity.setDeltaMovement(vec3d);
+ }
+ // CraftBukkit end
}
}
@@ -1310,7 +1454,14 @@
if (flag2) {
@@ -1303,9 +1427,14 @@
}
}
- this.causeFoodExhaustion(0.1F);
+ this.causeFoodExhaustion(0.1F, EntityExhaustionEvent.ExhaustionReason.ATTACK); // CraftBukkit - EntityExhaustionEvent
} else {
this.level().playSound((EntityHuman) null, this.getX(), this.getY(), this.getZ(), SoundEffects.PLAYER_ATTACK_NODAMAGE, this.getSoundSource(), 1.0F, 1.0F);
+ // CraftBukkit start - resync on cancelled event
+ if (this instanceof EntityPlayer) {
+ ((EntityPlayer) this).getBukkitEntity().updateInventory();
+ }
+ // CraftBukkit end
}
}
@@ -1346,7 +1475,14 @@
@Override
public void remove(Entity.RemovalReason entity_removalreason) {
@@ -406,7 +359,7 @@
this.inventoryMenu.removed(this);
if (this.containerMenu != null && this.hasContainerOpen()) {
this.doCloseContainer();
@@ -1346,6 +1497,12 @@
@@ -1382,6 +1518,12 @@
}
public Either<EntityHuman.EnumBedResult, Unit> startSleepInBed(BlockPosition blockposition) {
@@ -419,7 +372,7 @@
this.startSleeping(blockposition);
this.sleepCounter = 0;
return Either.right(Unit.INSTANCE);
@@ -1433,9 +1590,9 @@
@@ -1444,9 +1586,9 @@
super.jumpFromGround();
this.awardStat(StatisticList.JUMP);
if (this.isSprinting()) {
@@ -431,7 +384,7 @@
}
}
@@ -1462,7 +1619,11 @@
@@ -1473,7 +1615,11 @@
this.setDeltaMovement(vec3d2.x, d0 * 0.6D, vec3d2.z);
this.resetFallDistance();
@@ -444,7 +397,7 @@
} else {
super.travel(vec3d);
}
@@ -1522,12 +1683,24 @@
@@ -1547,12 +1693,24 @@
}
public void startFallFlying() {
@@ -470,7 +423,7 @@
}
@Override
@@ -1642,10 +1815,21 @@
@@ -1667,10 +1825,21 @@
return this.experienceLevel >= 30 ? 112 + (this.experienceLevel - 30) * 9 : (this.experienceLevel >= 15 ? 37 + (this.experienceLevel - 15) * 5 : 7 + this.experienceLevel * 2);
}
@@ -493,7 +446,7 @@
}
}
@@ -1731,13 +1915,20 @@
@@ -1756,13 +1925,20 @@
@Override
public void setItemSlot(EnumItemSlot enumitemslot, ItemStack itemstack) {
@@ -511,13 +464,13 @@
} else if (enumitemslot == EnumItemSlot.OFFHAND) {
- this.onEquipItem(enumitemslot, (ItemStack) this.inventory.offhand.set(0, itemstack), itemstack);
+ this.onEquipItem(enumitemslot, (ItemStack) this.inventory.offhand.set(0, itemstack), itemstack, silent); // CraftBukkit
} else if (enumitemslot.getType() == EnumItemSlot.Function.ARMOR) {
} else if (enumitemslot.getType() == EnumItemSlot.Function.HUMANOID_ARMOR) {
- this.onEquipItem(enumitemslot, (ItemStack) this.inventory.armor.set(enumitemslot.getIndex(), itemstack), itemstack);
+ this.onEquipItem(enumitemslot, (ItemStack) this.inventory.armor.set(enumitemslot.getIndex(), itemstack), itemstack, silent); // CraftBukkit
}
}
@@ -1781,26 +1972,31 @@
@@ -1806,26 +1982,31 @@
protected void removeEntitiesOnShoulder() {
if (this.timeEntitySatOnShoulder + 20L < this.level().getGameTime()) {
@@ -557,3 +510,12 @@
}
@Override
@@ -2040,7 +2221,7 @@
@Override
public ItemStack eat(World world, ItemStack itemstack, FoodInfo foodinfo) {
- this.getFoodData().eat(foodinfo);
+ this.getFoodData().eat(itemstack, foodinfo); // CraftBukkit
this.awardStat(StatisticList.ITEM_USED.get(itemstack.getItem()));
world.playSound((EntityHuman) null, this.getX(), this.getY(), this.getZ(), SoundEffects.PLAYER_BURP, SoundCategory.PLAYERS, 0.5F, world.random.nextFloat() * 0.1F + 0.9F);
if (this instanceof EntityPlayer) {