Update to Minecraft 1.21.2

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot
2024-10-23 02:15:00 +11:00
parent 2c4beb962b
commit d3a23f42c3
522 changed files with 8501 additions and 6477 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,23 @@
@@ -119,6 +119,19 @@
import net.minecraft.world.scores.ScoreboardTeam;
import org.slf4j.Logger;
@@ -9,22 +9,18 @@
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.util.CraftVector;
+import org.bukkit.entity.Item;
+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;
+import org.bukkit.event.player.PlayerDropItemEvent;
+import org.bukkit.event.player.PlayerVelocityEvent;
+// CraftBukkit end
+
public abstract class EntityHuman extends EntityLiving {
private static final Logger LOGGER = LogUtils.getLogger();
@@ -135,7 +152,8 @@
@@ -139,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));
@@ -34,7 +30,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 +162,10 @@
@@ -148,7 +162,7 @@
protected static final DataWatcherObject<NBTTagCompound> DATA_SHOULDER_RIGHT = DataWatcher.defineId(EntityHuman.class, DataWatcherRegistry.COMPOUND_TAG);
private long timeEntitySatOnShoulder;
final PlayerInventory inventory = new PlayerInventory(this);
@@ -42,12 +38,8 @@
+ protected InventoryEnderChest enderChestInventory = new InventoryEnderChest(this); // CraftBukkit - add "this" to constructor
public final ContainerPlayer inventoryMenu;
public Container containerMenu;
- protected FoodMetaData foodData = new FoodMetaData();
+ protected FoodMetaData foodData = new FoodMetaData(this); // CraftBukkit - add "this" to constructor
protected int jumpTriggerTime;
public float oBob;
public float bob;
@@ -182,6 +200,16 @@
protected FoodMetaData foodData = new FoodMetaData();
@@ -186,6 +200,16 @@
private boolean ignoreFallDamageFromCurrentImpulse;
private int currentImpulseContextResetGraceTime;
@@ -64,16 +56,16 @@
public EntityHuman(World world, BlockPosition blockposition, float f, GameProfile gameprofile) {
super(EntityTypes.PLAYER, world);
this.lastItemInMainHand = ItemStack.EMPTY;
@@ -330,7 +358,7 @@
ItemStack itemstack = this.getItemBySlot(EnumItemSlot.HEAD);
if (itemstack.is(Items.TURTLE_HELMET) && !this.isEyeInFluid(TagsFluid.WATER)) {
- this.addEffect(new MobEffect(MobEffects.WATER_BREATHING, 200, 0, false, false, true));
+ this.addEffect(new MobEffect(MobEffects.WATER_BREATHING, 200, 0, false, false, true), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.TURTLE_HELMET); // CraftBukkit
}
@@ -350,7 +374,7 @@
}
@@ -482,8 +510,14 @@
private void turtleHelmetTick() {
- this.addEffect(new MobEffect(MobEffects.WATER_BREATHING, 200, 0, false, false, true));
+ this.addEffect(new MobEffect(MobEffects.WATER_BREATHING, 200, 0, false, false, true), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.TURTLE_HELMET); // CraftBukkit
}
private boolean isEquipped(Item item) {
@@ -520,8 +544,14 @@
public void rideTick() {
if (!this.level().isClientSide && this.wantsToStopRiding() && this.isPassenger()) {
this.stopRiding();
@@ -90,17 +82,7 @@
super.rideTick();
this.oBob = this.bob;
this.bob = 0.0F;
@@ -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) {
- this.heal(1.0F);
+ // CraftBukkit - added regain reason of "REGEN" for filtering purposes.
+ this.heal(1.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.REGEN);
}
if (this.foodData.getSaturationLevel() < 20.0F && this.tickCount % 20 == 0) {
@@ -683,6 +718,13 @@
@@ -716,6 +746,13 @@
@Nullable
public EntityItem drop(ItemStack itemstack, boolean flag, boolean flag1) {
@@ -111,44 +93,10 @@
+ @Nullable
+ public EntityItem drop(ItemStack itemstack, boolean flag, boolean flag1, boolean callEvent) {
+ // CraftBukkit end
if (itemstack.isEmpty()) {
return null;
} else {
@@ -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);
}
+ // CraftBukkit start - fire PlayerDropItemEvent
+ if (!callEvent) { // SPIGOT-2942: Add boolean to call event
+ return entityitem;
+ }
+ Player player = (Player) this.getBukkitEntity();
+ Item drop = (Item) entityitem.getBukkitEntity();
+
+ PlayerDropItemEvent event = new PlayerDropItemEvent(player, drop);
+ this.level().getCraftServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ org.bukkit.inventory.ItemStack cur = player.getInventory().getItemInHand();
+ if (flag1 && (cur == null || cur.getAmount() == 0)) {
+ // The complete stack was dropped
+ player.getInventory().setItemInHand(drop.getItemStack());
+ } else if (flag1 && cur.isSimilar(drop.getItemStack()) && cur.getAmount() < cur.getMaxStackSize() && drop.getItemStack().getAmount() == 1) {
+ // Only one item is dropped
+ cur.setAmount(cur.getAmount() + 1);
+ player.getInventory().setItemInHand(cur);
+ } else {
+ // Fallback
+ player.getInventory().addItem(drop.getItemStack());
+ }
+ return null;
+ }
+ // CraftBukkit end
+
return entityitem;
if (!itemstack.isEmpty() && this.level().isClientSide) {
this.swing(EnumHand.MAIN_HAND);
}
}
@@ -803,7 +872,7 @@
@@ -806,7 +843,7 @@
}
if (nbttagcompound.contains("LastDeathLocation", 10)) {
@@ -157,7 +105,7 @@
Logger logger = EntityHuman.LOGGER;
Objects.requireNonNull(logger);
@@ -811,7 +880,7 @@
@@ -814,7 +851,7 @@
}
if (nbttagcompound.contains("current_explosion_impact_pos", 9)) {
@@ -166,7 +114,7 @@
Logger logger1 = EntityHuman.LOGGER;
Objects.requireNonNull(logger1);
@@ -848,7 +917,7 @@
@@ -851,7 +888,7 @@
}
this.getLastDeathLocation().flatMap((globalpos) -> {
@@ -175,28 +123,26 @@
Logger logger = EntityHuman.LOGGER;
Objects.requireNonNull(logger);
@@ -881,12 +950,12 @@
@@ -883,10 +920,10 @@
if (this.isDeadOrDying()) {
return false;
} else {
if (!this.level().isClientSide) {
- this.removeEntitiesOnShoulder();
+ // this.removeEntitiesOnShoulder(); // CraftBukkit - moved down
}
- this.removeEntitiesOnShoulder();
+ // this.removeEntitiesOnShoulder(); // CraftBukkit - moved down
if (damagesource.scalesWithDifficulty()) {
if (this.level().getDifficulty() == EnumDifficulty.PEACEFUL) {
if (worldserver.getDifficulty() == EnumDifficulty.PEACEFUL) {
- f = 0.0F;
+ return false; // CraftBukkit - f = 0.0f -> return false
}
if (this.level().getDifficulty() == EnumDifficulty.EASY) {
@@ -898,7 +967,13 @@
if (worldserver.getDifficulty() == EnumDifficulty.EASY) {
@@ -898,7 +935,13 @@
}
}
- return f == 0.0F ? false : super.hurt(damagesource, f);
- return f == 0.0F ? false : super.hurtServer(worldserver, damagesource, f);
+ // CraftBukkit start - Don't filter out 0 damage
+ boolean damaged = super.hurt(damagesource, f);
+ boolean damaged = super.hurtServer(worldserver, damagesource, f);
+ if (damaged) {
+ this.removeEntitiesOnShoulder();
+ }
@@ -205,7 +151,7 @@
}
}
}
@@ -918,10 +993,29 @@
@@ -920,10 +963,29 @@
}
public boolean canHarmPlayer(EntityHuman entityhuman) {
@@ -238,22 +184,22 @@
}
@Override
@@ -961,8 +1055,13 @@
@@ -963,8 +1025,13 @@
}
}
+ // CraftBukkit start
@Override
- protected void actuallyHurt(DamageSource damagesource, float f) {
+ protected boolean actuallyHurt(DamageSource damagesource, float f, EntityDamageEvent event) { // void -> boolean
- protected void actuallyHurt(WorldServer worldserver, DamageSource damagesource, float f) {
+ protected boolean actuallyHurt(WorldServer worldserver, DamageSource damagesource, float f, EntityDamageEvent event) { // void -> boolean
+ if (true) {
+ return super.actuallyHurt(damagesource, f, event);
+ return super.actuallyHurt(worldserver, damagesource, f, event);
+ }
+ // CraftBukkit end
if (!this.isInvulnerableTo(damagesource)) {
if (!this.isInvulnerableTo(worldserver, damagesource)) {
f = this.getDamageAfterArmorAbsorb(damagesource, f);
f = this.getDamageAfterMagicAbsorb(damagesource, f);
@@ -977,7 +1076,7 @@
@@ -979,7 +1046,7 @@
}
if (f != 0.0F) {
@@ -262,7 +208,7 @@
this.getCombatTracker().recordDamage(damagesource, f);
this.setHealth(this.getHealth() - f);
if (f < 3.4028235E37F) {
@@ -987,6 +1086,7 @@
@@ -989,6 +1056,7 @@
this.gameEvent(GameEvent.ENTITY_DAMAGE);
}
}
@@ -270,7 +216,7 @@
}
public boolean isTextFilteringEnabled() {
@@ -1139,10 +1239,15 @@
@@ -1141,10 +1209,15 @@
f *= 0.2F + f2 * f2 * 0.8F;
f1 *= f2;
@@ -287,12 +233,12 @@
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 +1323,13 @@
@@ -1220,8 +1293,13 @@
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;
+ // CraftBukkit start - Only apply knockback if the damage hits
+ if (!entityliving2.hurt(this.damageSources().playerAttack(this).sweep(), f7)) {
+ if (!entityliving2.hurtServer((WorldServer) this.level(), this.damageSources().playerAttack(this).sweep(), f7)) {
+ continue;
+ }
+ // CraftBukkit end
@@ -302,7 +248,7 @@
World world = this.level();
if (world instanceof WorldServer) {
@@ -1235,9 +1345,26 @@
@@ -1237,9 +1315,26 @@
}
if (entity instanceof EntityPlayer && entity.hurtMarked) {
@@ -329,7 +275,7 @@
}
if (flag2) {
@@ -1303,9 +1430,14 @@
@@ -1305,9 +1400,14 @@
}
}
@@ -345,7 +291,7 @@
}
}
@@ -1346,7 +1478,14 @@
@@ -1348,7 +1448,14 @@
@Override
public void remove(Entity.RemovalReason entity_removalreason) {
@@ -361,7 +307,7 @@
this.inventoryMenu.removed(this);
if (this.containerMenu != null && this.hasContainerOpen()) {
this.doCloseContainer();
@@ -1382,6 +1521,12 @@
@@ -1388,6 +1495,12 @@
}
public Either<EntityHuman.EnumBedResult, Unit> startSleepInBed(BlockPosition blockposition) {
@@ -374,32 +320,7 @@
this.startSleeping(blockposition);
this.sleepCounter = 0;
return Either.right(Unit.INSTANCE);
@@ -1444,9 +1589,9 @@
super.jumpFromGround();
this.awardStat(StatisticList.JUMP);
if (this.isSprinting()) {
- this.causeFoodExhaustion(0.2F);
+ this.causeFoodExhaustion(0.2F, EntityExhaustionEvent.ExhaustionReason.JUMP_SPRINT); // CraftBukkit - EntityExhaustionEvent
} else {
- this.causeFoodExhaustion(0.05F);
+ this.causeFoodExhaustion(0.05F, EntityExhaustionEvent.ExhaustionReason.JUMP); // CraftBukkit - EntityExhaustionEvent
}
}
@@ -1473,7 +1618,11 @@
this.setDeltaMovement(vec3d2.x, d0 * 0.6D, vec3d2.z);
this.resetFallDistance();
- this.setSharedFlag(7, false);
+ // CraftBukkit start
+ if (getSharedFlag(7) && !org.bukkit.craftbukkit.event.CraftEventFactory.callToggleGlideEvent(this, false).isCancelled()) {
+ this.setSharedFlag(7, false);
+ }
+ // CraftBukkit end
} else {
super.travel(vec3d);
}
@@ -1547,12 +1696,24 @@
@@ -1542,12 +1655,24 @@
}
public void startFallFlying() {
@@ -425,7 +346,7 @@
}
@Override
@@ -1667,10 +1828,21 @@
@@ -1662,10 +1787,21 @@
return this.experienceLevel >= 30 ? 112 + (this.experienceLevel - 30) * 9 : (this.experienceLevel >= 15 ? 37 + (this.experienceLevel - 15) * 5 : 7 + this.experienceLevel * 2);
}
@@ -448,7 +369,7 @@
}
}
@@ -1756,13 +1928,20 @@
@@ -1745,13 +1881,20 @@
@Override
public void setItemSlot(EnumItemSlot enumitemslot, ItemStack itemstack) {
@@ -472,7 +393,7 @@
}
}
@@ -1806,26 +1985,31 @@
@@ -1795,26 +1938,31 @@
protected void removeEntitiesOnShoulder() {
if (this.timeEntitySatOnShoulder + 20L < this.level().getGameTime()) {
@@ -495,8 +416,8 @@
- private void respawnEntityOnShoulder(NBTTagCompound nbttagcompound) {
+ private boolean respawnEntityOnShoulder(NBTTagCompound nbttagcompound) { // CraftBukkit void->boolean
if (!this.level().isClientSide && !nbttagcompound.isEmpty()) {
- EntityTypes.create(nbttagcompound, this.level()).ifPresent((entity) -> {
+ return EntityTypes.create(nbttagcompound, this.level()).map((entity) -> { // CraftBukkit
- EntityTypes.create(nbttagcompound, this.level(), EntitySpawnReason.LOAD).ifPresent((entity) -> {
+ return EntityTypes.create(nbttagcompound, this.level(), EntitySpawnReason.LOAD).map((entity) -> { // CraftBukkit
if (entity instanceof EntityTameableAnimal) {
((EntityTameableAnimal) entity).setOwnerUUID(this.uuid);
}
@@ -512,12 +433,3 @@
}
@Override
@@ -2040,7 +2224,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) {

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/world/entity/player/PlayerInventory.java
+++ b/net/minecraft/world/entity/player/PlayerInventory.java
@@ -23,6 +23,13 @@
@@ -24,6 +24,13 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.state.IBlockData;
@@ -14,7 +14,7 @@
public class PlayerInventory implements IInventory, INamableTileEntity {
public static final int POP_TIME_DURATION = 5;
@@ -40,6 +47,54 @@
@@ -39,6 +46,54 @@
public final EntityHuman player;
private int timesChanged;
@@ -69,7 +69,7 @@
public PlayerInventory(EntityHuman entityhuman) {
this.items = NonNullList.withSize(36, ItemStack.EMPTY);
this.armor = NonNullList.withSize(4, ItemStack.EMPTY);
@@ -60,6 +115,28 @@
@@ -59,6 +114,28 @@
return !itemstack.isEmpty() && ItemStack.isSameItemSameComponents(itemstack, itemstack1) && itemstack.isStackable() && itemstack.getCount() < this.getMaxStackSize(itemstack);
}