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,15 +1,13 @@
--- a/net/minecraft/world/entity/EntityInsentient.java
+++ b/net/minecraft/world/entity/EntityInsentient.java
@@ -87,6 +87,20 @@
@@ -89,6 +89,18 @@
import net.minecraft.world.level.storage.loot.parameters.LootContextParameters;
import net.minecraft.world.phys.AxisAlignedBB;
+// CraftBukkit start
+import net.minecraft.server.level.EntityPlayer;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.entity.CraftLivingEntity;
+import org.bukkit.event.entity.CreatureSpawnEvent;
+import org.bukkit.event.entity.EntityCombustByEntityEvent;
+import org.bukkit.event.entity.EntityRemoveEvent;
+import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
+import org.bukkit.event.entity.EntityTargetEvent;
@@ -21,7 +19,7 @@
public abstract class EntityInsentient extends EntityLiving implements EquipmentUser, Leashable, Targeting {
private static final DataWatcherObject<Byte> DATA_MOB_FLAGS_ID = DataWatcher.defineId(EntityInsentient.class, DataWatcherRegistry.BYTE);
@@ -134,6 +148,8 @@
@@ -136,6 +148,8 @@
private BlockPosition restrictCenter;
private float restrictRadius;
@@ -30,7 +28,7 @@
protected EntityInsentient(EntityTypes<? extends EntityInsentient> entitytypes, World world) {
super(entitytypes, world);
this.handItems = NonNullList.withSize(2, ItemStack.EMPTY);
@@ -161,6 +177,12 @@
@@ -164,6 +178,12 @@
}
@@ -43,7 +41,7 @@
protected void registerGoals() {}
public static AttributeProvider.Builder createMobAttributes() {
@@ -265,11 +287,42 @@
@@ -268,11 +288,42 @@
@Nullable
protected final EntityLiving getTargetFromBrain() {
@@ -87,7 +85,7 @@
}
@Override
@@ -405,6 +458,12 @@
@@ -403,6 +454,12 @@
return null;
}
@@ -100,7 +98,7 @@
@Override
public void addAdditionalSaveData(NBTTagCompound nbttagcompound) {
super.addAdditionalSaveData(nbttagcompound);
@@ -478,16 +537,26 @@
@@ -476,16 +533,26 @@
nbttagcompound.putBoolean("NoAI", this.isNoAi());
}
@@ -112,7 +110,7 @@
super.readAdditionalSaveData(nbttagcompound);
+
+ // CraftBukkit start - If looting or persistence is false only use it if it was set after we started using it
if (nbttagcompound.contains("CanPickUpLoot", 1)) {
if (nbttagcompound.contains("CanPickUpLoot", 99)) {
- this.setCanPickUpLoot(nbttagcompound.getBoolean("CanPickUpLoot"));
+ boolean data = nbttagcompound.getBoolean("CanPickUpLoot");
+ if (isLevelAtLeast(nbttagcompound, 1) || data) {
@@ -129,7 +127,7 @@
NBTTagList nbttaglist;
NBTTagCompound nbttagcompound1;
int i;
@@ -541,6 +610,11 @@
@@ -539,6 +606,11 @@
}
this.setNoAi(nbttagcompound.getBoolean("NoAI"));
@@ -141,12 +139,12 @@
}
@Override
@@ -615,20 +689,26 @@
@@ -615,20 +687,26 @@
protected void pickUpItem(EntityItem entityitem) {
protected void pickUpItem(WorldServer worldserver, EntityItem entityitem) {
ItemStack itemstack = entityitem.getItem();
- ItemStack itemstack1 = this.equipItemIfPossible(itemstack.copy());
+ ItemStack itemstack1 = this.equipItemIfPossible(itemstack.copy(), entityitem); // CraftBukkit - add item
- ItemStack itemstack1 = this.equipItemIfPossible(worldserver, itemstack.copy());
+ ItemStack itemstack1 = this.equipItemIfPossible(worldserver, itemstack.copy(), entityitem); // CraftBukkit - add item
if (!itemstack1.isEmpty()) {
this.onItemPickup(entityitem);
@@ -160,17 +158,17 @@
}
public ItemStack equipItemIfPossible(ItemStack itemstack) {
public ItemStack equipItemIfPossible(WorldServer worldserver, ItemStack itemstack) {
+ // CraftBukkit start - add item
+ return this.equipItemIfPossible(itemstack, null);
+ return this.equipItemIfPossible(worldserver, itemstack, null);
+ }
+
+ public ItemStack equipItemIfPossible(ItemStack itemstack, EntityItem entityitem) {
+ public ItemStack equipItemIfPossible(WorldServer worldserver, ItemStack itemstack, EntityItem entityitem) {
+ // CraftBukkit end
EnumItemSlot enumitemslot = this.getEquipmentSlotForItem(itemstack);
ItemStack itemstack1 = this.getItemBySlot(enumitemslot);
boolean flag = this.canReplaceCurrentItem(itemstack, itemstack1);
@@ -639,11 +719,19 @@
boolean flag = this.canReplaceCurrentItem(itemstack, itemstack1, enumitemslot);
@@ -639,11 +717,19 @@
flag = itemstack1.isEmpty();
}
@@ -186,12 +184,12 @@
if (!itemstack1.isEmpty() && (double) Math.max(this.random.nextFloat() - 0.1F, 0.0F) < d0) {
+ this.forceDrops = true; // CraftBukkit
this.spawnAtLocation(itemstack1);
this.spawnAtLocation(worldserver, itemstack1);
+ this.forceDrops = false; // CraftBukkit
}
ItemStack itemstack2 = enumitemslot.limit(itemstack);
@@ -772,7 +860,7 @@
@@ -770,7 +856,7 @@
@Override
public void checkDespawn() {
if (this.level().getDifficulty() == EnumDifficulty.PEACEFUL && this.shouldDespawnInPeaceful()) {
@@ -200,7 +198,7 @@
} else if (!this.isPersistenceRequired() && !this.requiresCustomPersistence()) {
EntityHuman entityhuman = this.level().getNearestPlayer(this, -1.0D);
@@ -782,14 +870,14 @@
@@ -780,14 +866,14 @@
int j = i * i;
if (d0 > (double) j && this.removeWhenFarAway(d0)) {
@@ -217,15 +215,15 @@
} else if (d0 < (double) l) {
this.noActionTime = 0;
}
@@ -803,6 +891,7 @@
@@ -801,6 +887,7 @@
@Override
protected final void serverAiStep() {
++this.noActionTime;
+ if (!this.aware) return; // CraftBukkit
GameProfilerFiller gameprofilerfiller = this.level().getProfiler();
GameProfilerFiller gameprofilerfiller = Profiler.get();
gameprofilerfiller.push("sensing");
@@ -1354,7 +1443,7 @@
@@ -1340,7 +1427,7 @@
if (itemstack.getItem() instanceof ItemMonsterEgg) {
if (this.level() instanceof WorldServer) {
ItemMonsterEgg itemmonsteregg = (ItemMonsterEgg) itemstack.getItem();
@@ -234,51 +232,71 @@
optional.ifPresent((entityinsentient) -> {
this.onOffspringSpawnedFromEgg(entityhuman, entityinsentient);
@@ -1403,12 +1492,19 @@
@@ -1391,12 +1478,19 @@
return this.restrictRadius != -1.0F;
}
+ // CraftBukkit start
@Nullable
public <T extends EntityInsentient> T convertTo(EntityTypes<T> entitytypes, boolean flag) {
+ return this.convertTo(entitytypes, flag, EntityTransformEvent.TransformReason.UNKNOWN, CreatureSpawnEvent.SpawnReason.DEFAULT);
public <T extends EntityInsentient> T convertTo(EntityTypes<T> entitytypes, ConversionParams conversionparams, EntitySpawnReason entityspawnreason, ConversionParams.a<T> conversionparams_a) {
+ return this.convertTo(entitytypes, conversionparams, entityspawnreason, conversionparams_a, EntityTransformEvent.TransformReason.UNKNOWN, CreatureSpawnEvent.SpawnReason.DEFAULT);
+ }
+
+ @Nullable
+ public <T extends EntityInsentient> T convertTo(EntityTypes<T> entitytypes, boolean flag, EntityTransformEvent.TransformReason transformReason, CreatureSpawnEvent.SpawnReason spawnReason) {
+ public <T extends EntityInsentient> T convertTo(EntityTypes<T> entitytypes, ConversionParams conversionparams, EntitySpawnReason entityspawnreason, ConversionParams.a<T> conversionparams_a, EntityTransformEvent.TransformReason transformReason, CreatureSpawnEvent.SpawnReason spawnReason) {
+ // CraftBukkit end
if (this.isRemoved()) {
return null;
} else {
- T t0 = (EntityInsentient) entitytypes.create(this.level());
+ T t0 = entitytypes.create(this.level()); // CraftBukkit - decompile error
- T t0 = (EntityInsentient) entitytypes.create(this.level(), entityspawnreason);
+ T t0 = entitytypes.create(this.level(), EntitySpawnReason.CONVERSION); // CraftBukkit - decompile error
if (t0 == null) {
return null;
@@ -1442,7 +1538,12 @@
}
}
@@ -1405,14 +1499,24 @@
conversionparams_a.finalizeConversion(t0);
World world = this.level();
- this.level().addFreshEntity(t0);
+ // CraftBukkit start
+ if (transformReason == null) {
+ // Special handling for slime split and pig lightning
+ return t0;
+ }
+
+ if (CraftEventFactory.callEntityTransformEvent(this, t0, transformReason).isCancelled()) {
+ return null;
+ }
+ this.level().addFreshEntity(t0, spawnReason);
+ // CraftBukkit end
if (this.isPassenger()) {
Entity entity = this.getVehicle();
if (world instanceof WorldServer) {
WorldServer worldserver = (WorldServer) world;
@@ -1450,7 +1551,7 @@
t0.startRiding(entity, true);
- worldserver.addFreshEntity(t0);
+ worldserver.addFreshEntity(t0, spawnReason); // CraftBukkit
}
if (conversionparams.type().shouldDiscardAfterConversion()) {
- this.discard();
+ this.discard(EntityRemoveEvent.Cause.TRANSFORMATION); // CraftBukkit - add Bukkit remove cause
}
- this.discard();
+ this.discard(EntityRemoveEvent.Cause.TRANSFORMATION); // CraftBukkit - add Bukkit remove cause
return t0;
}
}
@@ -1492,6 +1593,7 @@
@@ -1422,7 +1526,14 @@
@Nullable
public <T extends EntityInsentient> T convertTo(EntityTypes<T> entitytypes, ConversionParams conversionparams, ConversionParams.a<T> conversionparams_a) {
- return this.convertTo(entitytypes, conversionparams, EntitySpawnReason.CONVERSION, conversionparams_a);
+ // CraftBukkit start
+ return this.convertTo(entitytypes, conversionparams, conversionparams_a, EntityTransformEvent.TransformReason.UNKNOWN, CreatureSpawnEvent.SpawnReason.DEFAULT);
+ }
+
+ @Nullable
+ public <T extends EntityInsentient> T convertTo(EntityTypes<T> entitytypes, ConversionParams conversionparams, ConversionParams.a<T> conversionparams_a, EntityTransformEvent.TransformReason transformReason, CreatureSpawnEvent.SpawnReason spawnReason) {
+ return this.convertTo(entitytypes, conversionparams, EntitySpawnReason.CONVERSION, conversionparams_a, transformReason, spawnReason);
+ // CraftBukkit end
}
@Nullable
@@ -1461,6 +1572,7 @@
boolean flag1 = super.startRiding(entity, flag);
if (flag1 && this.isLeashed()) {
@@ -286,10 +304,10 @@
this.dropLeash(true, true);
}
@@ -1578,7 +1680,7 @@
if (f1 > 0.0F && entity instanceof EntityLiving) {
EntityLiving entityliving = (EntityLiving) entity;
@@ -1545,7 +1657,7 @@
if (f1 > 0.0F && entity instanceof EntityLiving) {
entityliving = (EntityLiving) entity;
- entityliving.knockback((double) (f1 * 0.5F), (double) MathHelper.sin(this.getYRot() * 0.017453292F), (double) (-MathHelper.cos(this.getYRot() * 0.017453292F)));
+ entityliving.knockback((double) (f1 * 0.5F), (double) MathHelper.sin(this.getYRot() * 0.017453292F), (double) (-MathHelper.cos(this.getYRot() * 0.017453292F)), this, org.bukkit.event.entity.EntityKnockbackEvent.KnockbackCause.ENTITY_ATTACK); // CraftBukkit
this.setDeltaMovement(this.getDeltaMovement().multiply(0.6D, 1.0D, 0.6D));