Update head rotation in missing places

In certain areas the player's head rotation could be desynced when teleported/moved.
This is because bukkit uses a separate head rotation field for yaw.
This issue only applies to players.
This commit is contained in:
Owen1212055 2021-06-21 21:55:23 -04:00
parent 5c4d5afef1
commit 8c5582489a

View file

@ -18,7 +18,7 @@
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.FenceGateBlock;
@@ -138,9 +138,142 @@
@@ -138,8 +138,141 @@
import net.minecraft.world.scores.ScoreHolder;
import net.minecraft.world.scores.Team;
import org.slf4j.Logger;
@ -61,7 +61,7 @@
+// CraftBukkit end
public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess, ScoreHolder {
+
+ // CraftBukkit start
+ private static final int CURRENT_LEVEL = 2;
+ public boolean preserveMotion = true; // Paper - Fix Entity Teleportation and cancel velocity if teleported; keep initial motion on first setPositionRotation
@ -157,10 +157,9 @@
+ return Entity.TOTAL_AIR_SUPPLY;
+ }
+ // CraftBukkit end
+
private static final Logger LOGGER = LogUtils.getLogger();
public static final String ID_TAG = "id";
public static final String PASSENGERS_TAG = "Passengers";
@@ -224,7 +357,7 @@
private static final EntityDataAccessor<Boolean> DATA_CUSTOM_NAME_VISIBLE = SynchedEntityData.defineId(Entity.class, EntityDataSerializers.BOOLEAN);
private static final EntityDataAccessor<Boolean> DATA_SILENT = SynchedEntityData.defineId(Entity.class, EntityDataSerializers.BOOLEAN);
@ -519,10 +518,13 @@
}
public boolean isFree(double offsetX, double offsetY, double offsetZ) {
@@ -750,6 +1053,28 @@
}
}
@@ -747,8 +1050,30 @@
if (movement.y != vec3d1.y) {
block.updateEntityMovementAfterFallOn(this.level(), this);
+ }
+ }
+
+ // CraftBukkit start
+ if (this.horizontalCollision && this.getBukkitEntity() instanceof Vehicle) {
+ Vehicle vehicle = (Vehicle) this.getBukkitEntity();
@ -541,14 +543,13 @@
+ if (!bl.getType().isAir()) {
+ VehicleBlockCollisionEvent event = new VehicleBlockCollisionEvent(vehicle, bl);
+ this.level.getCraftServer().getPluginManager().callEvent(event);
+ }
+ }
}
}
+ // CraftBukkit end
+
if (!this.level().isClientSide() || this.isControlledByLocalInstance()) {
Entity.MovementEmission entity_movementemission = this.getMovementEmission();
@@ -1131,8 +1456,22 @@
@@ -1131,7 +1456,21 @@
protected SoundEvent getSwimHighSpeedSplashSound() {
return SoundEvents.GENERIC_SPLASH;
@ -557,21 +558,28 @@
+ // CraftBukkit start - Add delegate methods
+ public SoundEvent getSwimSound0() {
+ return this.getSwimSound();
}
+ }
+
+ public SoundEvent getSwimSplashSound0() {
+ return this.getSwimSplashSound();
+ }
+
+ public SoundEvent getSwimHighSpeedSplashSound0() {
+ return this.getSwimHighSpeedSplashSound();
+ }
}
+ // CraftBukkit end
+
public void recordMovementThroughBlocks(Vec3 oldPos, Vec3 newPos) {
this.movementThisTick.add(new Entity.Movement(oldPos, newPos));
@@ -1599,6 +1938,7 @@
this.setXRot(Mth.clamp(pitch, -90.0F, 90.0F) % 360.0F);
this.yRotO = this.getYRot();
this.xRotO = this.getXRot();
+ this.setYHeadRot(yaw); // Paper - Update head rotation
}
@@ -1609,6 +1948,7 @@
public void absMoveTo(double x, double y, double z) {
@@ -1609,6 +1949,7 @@
this.yo = y;
this.zo = d4;
this.setPos(d3, y, d4);
@ -579,7 +587,7 @@
}
public void moveTo(Vec3 pos) {
@@ -1628,6 +1968,13 @@
@@ -1628,11 +1969,19 @@
}
public void moveTo(double x, double y, double z, float yaw, float pitch) {
@ -593,7 +601,13 @@
this.setPosRaw(x, y, z);
this.setYRot(yaw);
this.setXRot(pitch);
@@ -1701,6 +2048,7 @@
this.setOldPosAndRot();
this.reapplyPosition();
+ this.setYHeadRot(yaw); // Paper - Update head rotation
}
public final void setOldPosAndRot() {
@@ -1701,6 +2050,7 @@
public void push(Entity entity) {
if (!this.isPassengerOfSameVehicle(entity)) {
if (!entity.noPhysics && !this.noPhysics) {
@ -601,7 +615,7 @@
double d0 = entity.getX() - this.getX();
double d1 = entity.getZ() - this.getZ();
double d2 = Mth.absMax(d0, d1);
@@ -1737,7 +2085,21 @@
@@ -1737,7 +2087,21 @@
}
public void push(double deltaX, double deltaY, double deltaZ) {
@ -624,7 +638,7 @@
this.hasImpulse = true;
}
@@ -1858,9 +2220,21 @@
@@ -1858,9 +2222,21 @@
}
public boolean isPushable() {
@ -646,7 +660,7 @@
public void awardKillScore(Entity entityKilled, DamageSource damageSource) {
if (entityKilled instanceof ServerPlayer) {
CriteriaTriggers.ENTITY_KILLED_PLAYER.trigger((ServerPlayer) entityKilled, this, damageSource);
@@ -1889,74 +2263,133 @@
@@ -1889,74 +2265,133 @@
}
public boolean saveAsPassenger(CompoundTag nbt) {
@ -803,7 +817,7 @@
}
ListTag nbttaglist;
@@ -1972,10 +2405,10 @@
@@ -1972,10 +2407,10 @@
nbttaglist.add(StringTag.valueOf(s));
}
@ -816,7 +830,7 @@
if (this.isVehicle()) {
nbttaglist = new ListTag();
iterator = this.getPassengers().iterator();
@@ -1984,17 +2417,41 @@
@@ -1984,17 +2419,41 @@
Entity entity = (Entity) iterator.next();
CompoundTag nbttagcompound1 = new CompoundTag();
@ -861,7 +875,7 @@
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Saving entity NBT");
CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Entity being saved");
@@ -2079,7 +2536,69 @@
@@ -2079,7 +2538,69 @@
}
} else {
throw new IllegalStateException("Entity has invalid position");
@ -931,7 +945,7 @@
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Loading entity NBT");
CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Entity being loaded");
@@ -2101,6 +2620,12 @@
@@ -2101,6 +2622,12 @@
return entitytypes.canSerialize() && minecraftkey != null ? minecraftkey.toString() : null;
}
@ -944,7 +958,7 @@
protected abstract void readAdditionalSaveData(CompoundTag nbt);
protected abstract void addAdditionalSaveData(CompoundTag nbt);
@@ -2153,9 +2678,23 @@
@@ -2153,9 +2680,23 @@
if (stack.isEmpty()) {
return null;
} else {
@ -969,7 +983,7 @@
world.addFreshEntity(entityitem);
return entityitem;
}
@@ -2184,7 +2723,16 @@
@@ -2184,7 +2725,16 @@
if (this.isAlive() && this instanceof Leashable leashable) {
if (leashable.getLeashHolder() == player) {
if (!this.level().isClientSide()) {
@ -987,7 +1001,7 @@
leashable.removeLeash();
} else {
leashable.dropLeash();
@@ -2200,6 +2748,13 @@
@@ -2200,6 +2750,13 @@
if (itemstack.is(Items.LEAD) && leashable.canHaveALeashAttachedToIt()) {
if (!this.level().isClientSide()) {
@ -1001,7 +1015,7 @@
leashable.setLeashedTo(player, true);
}
@@ -2265,7 +2820,7 @@
@@ -2265,7 +2822,7 @@
}
public boolean showVehicleHealth() {
@ -1010,7 +1024,7 @@
}
public boolean startRiding(Entity entity, boolean force) {
@@ -2273,7 +2828,7 @@
@@ -2273,7 +2830,7 @@
return false;
} else if (!entity.couldAcceptPassenger()) {
return false;
@ -1019,7 +1033,7 @@
return false;
} else {
for (Entity entity1 = entity; entity1.vehicle != null; entity1 = entity1.vehicle) {
@@ -2285,11 +2840,32 @@
@@ -2285,11 +2842,32 @@
if (!force && (!this.canRide(entity) || !entity.canAddPassenger(this))) {
return false;
} else {
@ -1053,7 +1067,7 @@
this.vehicle = entity;
this.vehicle.addPassenger(this);
entity.getIndirectPassengersStream().filter((entity2) -> {
@@ -2314,19 +2890,30 @@
@@ -2314,19 +2892,30 @@
}
public void removeVehicle() {
@ -1086,7 +1100,7 @@
protected void addPassenger(Entity passenger) {
if (passenger.getVehicle() != this) {
throw new IllegalStateException("Use x.startRiding(y), not y.addPassenger(x)");
@@ -2349,21 +2936,53 @@
@@ -2349,21 +2938,53 @@
}
}
@ -1146,7 +1160,7 @@
}
protected boolean canAddPassenger(Entity passenger) {
@@ -2464,7 +3083,7 @@
@@ -2464,7 +3085,7 @@
if (teleporttransition != null) {
ServerLevel worldserver1 = teleporttransition.newLevel();
@ -1155,7 +1169,7 @@
this.teleport(teleporttransition);
}
}
@@ -2547,7 +3166,7 @@
@@ -2547,7 +3168,7 @@
}
public boolean isCrouching() {
@ -1164,7 +1178,7 @@
}
public boolean isSprinting() {
@@ -2563,7 +3182,7 @@
@@ -2563,7 +3184,7 @@
}
public boolean isVisuallySwimming() {
@ -1173,7 +1187,7 @@
}
public boolean isVisuallyCrawling() {
@@ -2571,6 +3190,13 @@
@@ -2571,6 +3192,13 @@
}
public void setSwimming(boolean swimming) {
@ -1187,7 +1201,7 @@
this.setSharedFlag(4, swimming);
}
@@ -2609,6 +3235,7 @@
@@ -2609,6 +3237,7 @@
@Nullable
public PlayerTeam getTeam() {
@ -1195,7 +1209,7 @@
return this.level().getScoreboard().getPlayersTeam(this.getScoreboardName());
}
@@ -2624,8 +3251,12 @@
@@ -2624,8 +3253,12 @@
return this.getTeam() != null ? this.getTeam().isAlliedTo(team) : false;
}
@ -1209,7 +1223,7 @@
}
public boolean getSharedFlag(int index) {
@@ -2644,7 +3275,7 @@
@@ -2644,7 +3277,7 @@
}
public int getMaxAirSupply() {
@ -1218,7 +1232,7 @@
}
public int getAirSupply() {
@@ -2652,7 +3283,18 @@
@@ -2652,7 +3285,18 @@
}
public void setAirSupply(int air) {
@ -1238,7 +1252,7 @@
}
public int getTicksFrozen() {
@@ -2679,11 +3321,40 @@
@@ -2679,11 +3323,40 @@
public void thunderHit(ServerLevel world, LightningBolt lightning) {
this.setRemainingFireTicks(this.remainingFireTicks + 1);
@ -1281,7 +1295,7 @@
}
public void onAboveBubbleCol(boolean drag) {
@@ -2713,7 +3384,7 @@
@@ -2713,7 +3386,7 @@
this.resetFallDistance();
}
@ -1290,7 +1304,7 @@
return true;
}
@@ -2818,7 +3489,7 @@
@@ -2818,7 +3491,7 @@
public String toString() {
String s = this.level() == null ? "~NULL~" : this.level().toString();
@ -1299,7 +1313,7 @@
}
public final boolean isInvulnerableToBase(DamageSource damageSource) {
@@ -2850,8 +3521,57 @@
@@ -2850,8 +3523,57 @@
public Entity teleport(TeleportTransition teleportTarget) {
Level world = this.level();
@ -1357,7 +1371,7 @@
ServerLevel worldserver1 = teleportTarget.newLevel();
boolean flag = worldserver1.dimension() != worldserver.dimension();
@@ -2918,10 +3638,19 @@
@@ -2918,10 +3640,19 @@
gameprofilerfiller.pop();
return null;
} else {
@ -1378,7 +1392,7 @@
Iterator iterator1 = list1.iterator();
while (iterator1.hasNext()) {
@@ -2947,7 +3676,7 @@
@@ -2947,7 +3678,7 @@
}
private void sendTeleportTransitionToRidingPlayers(TeleportTransition teleportTarget) {
@ -1387,7 +1401,7 @@
Iterator iterator = this.getIndirectPassengers().iterator();
while (iterator.hasNext()) {
@@ -2995,9 +3724,17 @@
@@ -2995,22 +3726,45 @@
}
protected void removeAfterChangingDimensions() {
@ -1408,10 +1422,11 @@
}
}
@@ -3006,11 +3743,26 @@
return PortalShape.getRelativePosition(portalRect, portalAxis, this.position(), this.getDimensions(this.getPose()));
}
public Vec3 getRelativePortalPosition(Direction.Axis portalAxis, BlockUtil.FoundRectangle portalRect) {
return PortalShape.getRelativePosition(portalRect, portalAxis, this.position(), this.getDimensions(this.getPose()));
+ }
+
+ // CraftBukkit start
+ public CraftPortalEvent callPortalEvent(Entity entity, Location exit, PlayerTeleportEvent.TeleportCause cause, int searchRadius, int creationRadius) {
+ org.bukkit.entity.Entity bukkitEntity = entity.getBukkitEntity();
@ -1423,9 +1438,9 @@
+ return null;
+ }
+ return new CraftPortalEvent(event);
+ }
}
+ // CraftBukkit end
+
public boolean canUsePortal(boolean allowVehicles) {
return (allowVehicles || !this.isPassenger()) && this.isAlive();
}
@ -1435,7 +1450,7 @@
if (from.dimension() == Level.END && to.dimension() == Level.OVERWORLD) {
Iterator iterator = this.getPassengers().iterator();
@@ -3134,10 +3886,16 @@
@@ -3134,10 +3888,16 @@
return (Boolean) this.entityData.get(Entity.DATA_CUSTOM_NAME_VISIBLE);
}
@ -1455,7 +1470,7 @@
return entity != null;
}
@@ -3187,7 +3945,7 @@
@@ -3187,7 +3947,7 @@
/** @deprecated */
@Deprecated
protected void fixupDimensions() {
@ -1464,7 +1479,7 @@
EntityDimensions entitysize = this.getDimensions(entitypose);
this.dimensions = entitysize;
@@ -3196,7 +3954,7 @@
@@ -3196,7 +3956,7 @@
public void refreshDimensions() {
EntityDimensions entitysize = this.dimensions;
@ -1473,7 +1488,7 @@
EntityDimensions entitysize1 = this.getDimensions(entitypose);
this.dimensions = entitysize1;
@@ -3258,10 +4016,29 @@
@@ -3258,10 +4018,29 @@
}
public final void setBoundingBox(AABB boundingBox) {
@ -1505,7 +1520,7 @@
return this.getDimensions(pose).eyeHeight();
}
@@ -3335,7 +4112,7 @@
@@ -3335,7 +4114,7 @@
}
@Nullable
@ -1514,7 +1529,7 @@
return null;
}
@@ -3373,20 +4150,34 @@
@@ -3373,20 +4152,34 @@
}
private Stream<Entity> getIndirectPassengersStream() {
@ -1549,7 +1564,7 @@
return () -> {
return this.getIndirectPassengersStream().iterator();
};
@@ -3399,6 +4190,7 @@
@@ -3399,6 +4192,7 @@
}
public boolean hasExactlyOnePlayerPassenger() {
@ -1557,7 +1572,7 @@
return this.countPlayerPassengers() == 1;
}
@@ -3435,7 +4227,7 @@
@@ -3435,7 +4229,7 @@
}
public boolean isControlledByLocalInstance() {
@ -1566,7 +1581,7 @@
if (entityliving instanceof Player entityhuman) {
return entityhuman.isLocalPlayer();
@@ -3445,7 +4237,7 @@
@@ -3445,7 +4239,7 @@
}
public boolean isControlledByClient() {
@ -1575,7 +1590,7 @@
return entityliving != null && entityliving.isControlledByClient();
}
@@ -3463,7 +4255,7 @@
@@ -3463,7 +4257,7 @@
return new Vec3((double) f1 * d2 / (double) f3, 0.0D, (double) f2 * d2 / (double) f3);
}
@ -1584,7 +1599,7 @@
return new Vec3(this.getX(), this.getBoundingBox().maxY, this.getZ());
}
@@ -3488,9 +4280,38 @@
@@ -3488,9 +4282,38 @@
public int getFireImmuneTicks() {
return 1;
}
@ -1624,7 +1639,7 @@
}
public void lookAt(EntityAnchorArgument.Anchor anchorPoint, Vec3 target) {
@@ -3551,6 +4372,11 @@
@@ -3551,6 +4374,11 @@
vec3d = vec3d.add(vec3d1);
++k1;
}
@ -1636,7 +1651,7 @@
}
}
}
@@ -3613,7 +4439,7 @@
@@ -3613,7 +4441,7 @@
return new ClientboundAddEntityPacket(this, entityTrackerEntry);
}
@ -1645,7 +1660,7 @@
return this.type.getDimensions();
}
@@ -3714,7 +4540,39 @@
@@ -3714,7 +4542,39 @@
return this.getZ((2.0D * this.random.nextDouble() - 1.0D) * widthScale);
}
@ -1685,7 +1700,7 @@
if (this.position.x != x || this.position.y != y || this.position.z != z) {
this.position = new Vec3(x, y, z);
int i = Mth.floor(x);
@@ -3732,6 +4590,12 @@
@@ -3732,6 +4592,12 @@
this.levelCallback.onMove();
}
@ -1698,7 +1713,7 @@
}
public void checkDespawn() {}
@@ -3818,8 +4682,16 @@
@@ -3818,8 +4684,16 @@
@Override
public final void setRemoved(Entity.RemovalReason reason) {
@ -1716,7 +1731,7 @@
}
if (this.removalReason.shouldDestroy()) {
@@ -3827,8 +4699,8 @@
@@ -3827,8 +4701,8 @@
}
this.getPassengers().forEach(Entity::stopRiding);
@ -1727,7 +1742,7 @@
}
public void unsetRemoved() {
@@ -3887,7 +4759,7 @@
@@ -3887,7 +4761,7 @@
}
public Vec3 getKnownMovement() {
@ -1736,7 +1751,7 @@
if (entityliving instanceof Player entityhuman) {
if (this.isAlive()) {
@@ -3962,4 +4834,14 @@
@@ -3962,4 +4836,14 @@
void accept(Entity entity, double x, double y, double z);
}