Update to Minecraft 1.20

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot
2023-06-08 01:30:00 +10:00
parent bac55e67d6
commit 9d740b84b0
269 changed files with 2605 additions and 2568 deletions

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/world/entity/player/EntityHuman.java
+++ b/net/minecraft/world/entity/player/EntityHuman.java
@@ -117,6 +117,20 @@
@@ -118,6 +118,20 @@
import net.minecraft.world.scores.ScoreboardTeamBase;
import org.slf4j.Logger;
@@ -21,7 +21,7 @@
public abstract class EntityHuman extends EntityLiving {
private static final Logger LOGGER = LogUtils.getLogger();
@@ -130,7 +144,8 @@
@@ -131,7 +145,8 @@
public static final float SWIMMING_BB_HEIGHT = 0.6F;
public static final float DEFAULT_EYE_HEIGHT = 1.62F;
public static final EntitySize STANDING_DIMENSIONS = EntitySize.scalable(0.6F, 1.8F);
@@ -31,7 +31,7 @@
private static final int FLY_ACHIEVEMENT_SPEED = 25;
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);
@@ -140,10 +155,10 @@
@@ -141,10 +156,10 @@
protected static final DataWatcherObject<NBTTagCompound> DATA_SHOULDER_RIGHT = DataWatcher.defineId(EntityHuman.class, DataWatcherRegistry.COMPOUND_TAG);
private long timeEntitySatOnShoulder;
private final PlayerInventory inventory = new PlayerInventory(this);
@@ -44,7 +44,7 @@
protected int jumpTriggerTime;
public float oBob;
public float bob;
@@ -172,6 +187,16 @@
@@ -173,6 +188,16 @@
public EntityFishingHook fishing;
protected float hurtDir;
@@ -61,7 +61,7 @@
public EntityHuman(World world, BlockPosition blockposition, float f, GameProfile gameprofile) {
super(EntityTypes.PLAYER, world);
this.lastItemInMainHand = ItemStack.EMPTY;
@@ -311,7 +336,7 @@
@@ -312,7 +337,7 @@
ItemStack itemstack = this.getItemBySlot(EnumItemSlot.HEAD);
if (itemstack.is(Items.TURTLE_HELMET) && !this.isEyeInFluid(TagsFluid.WATER)) {
@@ -70,9 +70,9 @@
}
}
@@ -477,8 +502,14 @@
@@ -478,8 +503,14 @@
public void rideTick() {
if (!this.level.isClientSide && this.wantsToStopRiding() && this.isPassenger()) {
if (!this.level().isClientSide && this.wantsToStopRiding() && this.isPassenger()) {
this.stopRiding();
- this.setShiftKeyDown(false);
- } else {
@@ -87,9 +87,9 @@
double d0 = this.getX();
double d1 = this.getY();
double d2 = this.getZ();
@@ -505,7 +536,8 @@
@@ -506,7 +537,8 @@
if (this.level.getDifficulty() == EnumDifficulty.PEACEFUL && this.level.getGameRules().getBoolean(GameRules.RULE_NATURAL_REGENERATION)) {
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.
@@ -97,7 +97,7 @@
}
if (this.foodData.needsFood() && this.tickCount % 10 == 0) {
@@ -664,6 +696,13 @@
@@ -665,6 +697,13 @@
@Nullable
public EntityItem drop(ItemStack itemstack, boolean flag, boolean flag1) {
@@ -111,7 +111,7 @@
if (itemstack.isEmpty()) {
return null;
} else {
@@ -698,6 +737,33 @@
@@ -699,6 +738,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);
}
@@ -123,7 +123,7 @@
+ Item drop = (Item) entityitem.getBukkitEntity();
+
+ PlayerDropItemEvent event = new PlayerDropItemEvent(player, drop);
+ this.level.getCraftServer().getPluginManager().callEvent(event);
+ this.level().getCraftServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ org.bukkit.inventory.ItemStack cur = player.getInventory().getItemInHand();
@@ -145,7 +145,7 @@
return entityitem;
}
}
@@ -788,7 +854,7 @@
@@ -789,7 +855,7 @@
}
if (nbttagcompound.contains("LastDeathLocation", 10)) {
@@ -154,7 +154,7 @@
Logger logger = EntityHuman.LOGGER;
Objects.requireNonNull(logger);
@@ -821,7 +887,7 @@
@@ -822,7 +888,7 @@
}
this.getLastDeathLocation().flatMap((globalpos) -> {
@@ -163,22 +163,22 @@
Logger logger = EntityHuman.LOGGER;
Objects.requireNonNull(logger);
@@ -848,12 +914,12 @@
@@ -849,12 +915,12 @@
return false;
} else {
if (!this.level.isClientSide) {
if (!this.level().isClientSide) {
- this.removeEntitiesOnShoulder();
+ // this.removeEntitiesOnShoulder(); // CraftBukkit - moved down
}
if (damagesource.scalesWithDifficulty()) {
if (this.level.getDifficulty() == EnumDifficulty.PEACEFUL) {
if (this.level().getDifficulty() == EnumDifficulty.PEACEFUL) {
- f = 0.0F;
+ return false; // CraftBukkit - f = 0.0f -> return false
}
if (this.level.getDifficulty() == EnumDifficulty.EASY) {
@@ -865,7 +931,13 @@
if (this.level().getDifficulty() == EnumDifficulty.EASY) {
@@ -866,7 +932,13 @@
}
}
@@ -193,7 +193,7 @@
}
}
}
@@ -885,10 +957,29 @@
@@ -886,10 +958,29 @@
}
public boolean canHarmPlayer(EntityHuman entityhuman) {
@@ -210,8 +210,8 @@
+ }
+ } else {
+ // This should never be called, but is implemented anyway
+ org.bukkit.OfflinePlayer thisPlayer = entityhuman.level.getCraftServer().getOfflinePlayer(entityhuman.getScoreboardName());
+ team = entityhuman.level.getCraftServer().getScoreboardManager().getMainScoreboard().getPlayerTeam(thisPlayer);
+ org.bukkit.OfflinePlayer thisPlayer = entityhuman.level().getCraftServer().getOfflinePlayer(entityhuman.getScoreboardName());
+ team = entityhuman.level().getCraftServer().getScoreboardManager().getMainScoreboard().getPlayerTeam(thisPlayer);
+ if (team == null || team.allowFriendlyFire()) {
+ return true;
+ }
@@ -221,12 +221,12 @@
+ if (this instanceof EntityPlayer) {
+ return !team.hasPlayer(((EntityPlayer) this).getBukkitEntity());
+ }
+ return !team.hasPlayer(this.level.getCraftServer().getOfflinePlayer(this.getScoreboardName()));
+ return !team.hasPlayer(this.level().getCraftServer().getOfflinePlayer(this.getScoreboardName()));
+ // CraftBukkit end
}
@Override
@@ -930,8 +1021,13 @@
@@ -931,8 +1022,13 @@
}
}
@@ -241,17 +241,17 @@
if (!this.isInvulnerableTo(damagesource)) {
f = this.getDamageAfterArmorAbsorb(damagesource, f);
f = this.getDamageAfterMagicAbsorb(damagesource, f);
@@ -946,7 +1042,7 @@
@@ -947,7 +1043,7 @@
}
if (f != 0.0F) {
- this.causeFoodExhaustion(damagesource.getFoodExhaustion());
+ this.causeFoodExhaustion(damagesource.getFoodExhaustion(), EntityExhaustionEvent.ExhaustionReason.DAMAGED); // CraftBukkit - EntityExhaustionEvent
float f3 = this.getHealth();
this.getCombatTracker().recordDamage(damagesource, f3, f);
this.getCombatTracker().recordDamage(damagesource, f);
this.setHealth(this.getHealth() - f);
if (f < 3.4028235E37F) {
@@ -957,6 +1053,7 @@
this.gameEvent(GameEvent.ENTITY_DAMAGE);
}
}
+ return false; // CraftBukkit
@@ -308,7 +308,7 @@
+ org.bukkit.util.Vector velocity = CraftVector.toBukkit(vec3d);
+
+ PlayerVelocityEvent event = new PlayerVelocityEvent(player, velocity.clone());
+ level.getCraftServer().getPluginManager().callEvent(event);
+ this.level().getCraftServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ cancelled = true;
@@ -340,7 +340,7 @@
+ // CraftBukkit end
}
if (this.level instanceof WorldServer && f5 > 2.0F) {
if (this.level() instanceof WorldServer && f5 > 2.0F) {
@@ -1256,12 +1387,17 @@
}
}
@@ -348,7 +348,7 @@
- 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);
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();
}
@@ -373,7 +373,7 @@
this.startSleeping(blockposition);
this.sleepCounter = 0;
return Either.right(Unit.INSTANCE);
@@ -1422,9 +1564,9 @@
@@ -1425,9 +1567,9 @@
super.jumpFromGround();
this.awardStat(StatisticList.JUMP);
if (this.isSprinting()) {
@@ -385,7 +385,7 @@
}
}
@@ -1454,7 +1596,11 @@
@@ -1457,7 +1599,11 @@
this.setDeltaMovement(vec3d2.x, d3 * 0.6D, vec3d2.z);
this.resetFallDistance();
@@ -398,7 +398,7 @@
} else {
super.travel(vec3d);
}
@@ -1489,19 +1635,19 @@
@@ -1492,19 +1638,19 @@
i = Math.round((float) Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2) * 100.0F);
if (i > 0) {
this.awardStat(StatisticList.SWIM_ONE_CM, i);
@@ -421,7 +421,7 @@
}
} else if (this.onClimbable()) {
if (d1 > 0.0D) {
@@ -1512,13 +1658,13 @@
@@ -1515,13 +1661,13 @@
if (i > 0) {
if (this.isSprinting()) {
this.awardStat(StatisticList.SPRINT_ONE_CM, i);
@@ -438,7 +438,7 @@
}
}
} else if (this.isFallFlying()) {
@@ -1584,12 +1730,24 @@
@@ -1587,12 +1733,24 @@
}
public void startFallFlying() {
@@ -464,7 +464,7 @@
}
@Override
@@ -1680,10 +1838,21 @@
@@ -1706,10 +1864,21 @@
return this.experienceLevel >= 30 ? 112 + (this.experienceLevel - 30) * 9 : (this.experienceLevel >= 15 ? 37 + (this.experienceLevel - 15) * 5 : 7 + this.experienceLevel * 2);
}
@@ -476,7 +476,7 @@
+ public void causeFoodExhaustion(float f, EntityExhaustionEvent.ExhaustionReason reason) {
+ // CraftBukkit end
if (!this.abilities.invulnerable) {
if (!this.level.isClientSide) {
if (!this.level().isClientSide) {
- this.foodData.addExhaustion(f);
+ // CraftBukkit start
+ EntityExhaustionEvent event = CraftEventFactory.callPlayerExhaustionEvent(this, reason, f);
@@ -487,7 +487,7 @@
}
}
@@ -1769,13 +1938,20 @@
@@ -1795,13 +1964,20 @@
@Override
public void setItemSlot(EnumItemSlot enumitemslot, ItemStack itemstack) {
@@ -511,19 +511,19 @@
}
}
@@ -1814,26 +1990,31 @@
@@ -1840,26 +2016,31 @@
protected void removeEntitiesOnShoulder() {
if (this.timeEntitySatOnShoulder + 20L < this.level.getGameTime()) {
if (this.timeEntitySatOnShoulder + 20L < this.level().getGameTime()) {
- this.respawnEntityOnShoulder(this.getShoulderEntityLeft());
- this.setShoulderEntityLeft(new NBTTagCompound());
- this.respawnEntityOnShoulder(this.getShoulderEntityRight());
- this.setShoulderEntityRight(new NBTTagCompound());
+ // CraftBukkit start
+ if (this.spawnEntityFromShoulder(this.getShoulderEntityLeft())) {
+ if (this.respawnEntityOnShoulder(this.getShoulderEntityLeft())) {
+ this.setShoulderEntityLeft(new NBTTagCompound());
+ }
+ if (this.spawnEntityFromShoulder(this.getShoulderEntityRight())) {
+ if (this.respawnEntityOnShoulder(this.getShoulderEntityRight())) {
+ this.setShoulderEntityRight(new NBTTagCompound());
+ }
+ // CraftBukkit end
@@ -532,18 +532,18 @@
}
- private void respawnEntityOnShoulder(NBTTagCompound nbttagcompound) {
+ private boolean spawnEntityFromShoulder(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
+ 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
if (entity instanceof EntityTameableAnimal) {
((EntityTameableAnimal) entity).setOwnerUUID(this.uuid);
}
entity.setPos(this.getX(), this.getY() + 0.699999988079071D, this.getZ());
- ((WorldServer) this.level).addWithUUID(entity);
- ((WorldServer) this.level()).addWithUUID(entity);
- });
+ return ((WorldServer) this.level).addWithUUID(entity, CreatureSpawnEvent.SpawnReason.SHOULDER_ENTITY); // CraftBukkit
+ return ((WorldServer) this.level()).addWithUUID(entity, CreatureSpawnEvent.SpawnReason.SHOULDER_ENTITY); // CraftBukkit
+ }).orElse(true); // CraftBukkit
}