Made #sendPositionUpdate(boolean) protected

This commit is contained in:
Németh Noel 2021-05-02 00:05:48 +02:00
parent f4c55dd4b2
commit 818251331f
3 changed files with 20 additions and 17 deletions

View File

@ -267,7 +267,6 @@ public class Entity implements Viewable, Tickable, EventHandler, DataContainer,
final ChunkCallback endCallback = (chunk) -> { final ChunkCallback endCallback = (chunk) -> {
refreshPosition(teleportPosition); refreshPosition(teleportPosition);
refreshView(teleportPosition.getYaw(), teleportPosition.getPitch());
synchronizePosition(); synchronizePosition();
@ -552,7 +551,7 @@ public class Entity implements Viewable, Tickable, EventHandler, DataContainer,
} }
// Apply the position if changed // Apply the position if changed
if (!newPosition.isSimilar(position)) { if (!finalVelocityPosition.isSimilar(position)) {
refreshPosition(finalVelocityPosition); refreshPosition(finalVelocityPosition);
} }
@ -692,8 +691,7 @@ public class Entity implements Viewable, Tickable, EventHandler, DataContainer,
* *
* @param notFromListener {@code false} if the client triggered this action * @param notFromListener {@code false} if the client triggered this action
*/ */
@ApiStatus.Internal protected void sendPositionUpdate(final boolean notFromListener) {
public void sendPositionUpdate(final boolean notFromListener) {
final boolean viewChange = !position.hasSimilarView(lastSyncedPosition); final boolean viewChange = !position.hasSimilarView(lastSyncedPosition);
final double distanceX = Math.abs(position.getX()-lastSyncedPosition.getX()); final double distanceX = Math.abs(position.getX()-lastSyncedPosition.getX());
final double distanceY = Math.abs(position.getY()-lastSyncedPosition.getY()); final double distanceY = Math.abs(position.getY()-lastSyncedPosition.getY());
@ -1352,7 +1350,7 @@ public class Entity implements Viewable, Tickable, EventHandler, DataContainer,
* @param y new position Y * @param y new position Y
* @param z new position Z * @param z new position Z
*/ */
public void refreshPosition(double x, double y, double z) { private void refreshPosition(double x, double y, double z) {
position.setX(x); position.setX(x);
position.setY(y); position.setY(y);
position.setZ(z); position.setZ(z);
@ -1394,11 +1392,20 @@ public class Entity implements Viewable, Tickable, EventHandler, DataContainer,
} }
/** /**
* @param position the new position * Updates internal fields and sends updates
*
* @param position the new position
*
* @see #refreshPosition(double, double, double) * @see #refreshPosition(double, double, double)
* @see #refreshView(float, float)
* @see #sendPositionUpdate(boolean)
*/ */
public void refreshPosition(@NotNull Position position) { @ApiStatus.Internal
refreshPosition(position.getX(), position.getY(), position.getZ()); public void refreshPosition(@NotNull final Position position) {
if (!position.isSimilar(this.position))
refreshPosition(position.getX(), position.getY(), position.getZ());
refreshView(position.getYaw(), position.getPitch());
sendPositionUpdate(false);
} }
/** /**
@ -1409,9 +1416,9 @@ public class Entity implements Viewable, Tickable, EventHandler, DataContainer,
* @param yaw the yaw * @param yaw the yaw
* @param pitch the pitch * @param pitch the pitch
*/ */
public void refreshView(float yaw, float pitch) { private void refreshView(final float yaw, final float pitch) {
this.lastPosition.setYaw(position.getYaw()); lastPosition.setYaw(position.getYaw());
this.lastPosition.setPitch(position.getPitch()); lastPosition.setPitch(position.getPitch());
position.setYaw(yaw); position.setYaw(yaw);
position.setPitch(pitch); position.setPitch(pitch);
} }

View File

@ -87,10 +87,8 @@ public class PlayerPositionListener {
player.teleport(newPosition); player.teleport(newPosition);
} }
// Change the internal data // Change the internal data
player.refreshPosition(newPosition.getX(), newPosition.getY(), newPosition.getZ()); player.refreshPosition(newPosition);
player.refreshView(newPosition.getYaw(), newPosition.getPitch());
player.refreshOnGround(onGround); player.refreshOnGround(onGround);
player.sendPositionUpdate(false);
} else { } else {
player.teleport(player.getPosition()); player.teleport(player.getPosition());
} }

View File

@ -23,10 +23,8 @@ public class PlayerVehicleListener {
if (vehicle == null) if (vehicle == null)
return; return;
final Position newPosition = new Position((float) packet.x, (float) packet.y, (float) packet.z); final Position newPosition = new Position((float) packet.x, (float) packet.y, (float) packet.z, packet.yaw, packet.pitch);
vehicle.refreshPosition(newPosition); vehicle.refreshPosition(newPosition);
vehicle.refreshView(packet.yaw, packet.pitch);
vehicle.askSynchronization();
// This packet causes weird screen distortion // This packet causes weird screen distortion
/*VehicleMovePacket vehicleMovePacket = new VehicleMovePacket(); /*VehicleMovePacket vehicleMovePacket = new VehicleMovePacket();