mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-03 23:17:48 +01:00
Merge remote-tracking branch 'Kebab11noel/position-cleanup' into position-cleanup
This commit is contained in:
commit
7a6763f73f
@ -138,7 +138,7 @@ public class Entity implements Viewable, Tickable, EventHandler, DataContainer,
|
|||||||
*/
|
*/
|
||||||
private final Object entityTypeLock = new Object();
|
private final Object entityTypeLock = new Object();
|
||||||
|
|
||||||
private final boolean isNettyClient;
|
protected boolean isNettyClient;
|
||||||
|
|
||||||
public Entity(@NotNull EntityType entityType, @NotNull UUID uuid) {
|
public Entity(@NotNull EntityType entityType, @NotNull UUID uuid) {
|
||||||
this.id = generateId();
|
this.id = generateId();
|
||||||
@ -154,8 +154,6 @@ public class Entity implements Viewable, Tickable, EventHandler, DataContainer,
|
|||||||
|
|
||||||
setAutoViewable(true);
|
setAutoViewable(true);
|
||||||
|
|
||||||
isNettyClient = PlayerUtils.isNettyClient(this);
|
|
||||||
|
|
||||||
Entity.ENTITY_BY_ID.put(id, this);
|
Entity.ENTITY_BY_ID.put(id, this);
|
||||||
Entity.ENTITY_BY_UUID.put(uuid, this);
|
Entity.ENTITY_BY_UUID.put(uuid, this);
|
||||||
}
|
}
|
||||||
@ -497,7 +495,7 @@ public class Entity implements Viewable, Tickable, EventHandler, DataContainer,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sendPositionUpdate();
|
sendPositionUpdate(true);
|
||||||
|
|
||||||
// Entity tick
|
// Entity tick
|
||||||
{
|
{
|
||||||
@ -692,8 +690,10 @@ public class Entity implements Viewable, Tickable, EventHandler, DataContainer,
|
|||||||
* </ol>
|
* </ol>
|
||||||
* In case of a player's position and/or view change an additional {@link PlayerPositionAndLookPacket}
|
* In case of a player's position and/or view change an additional {@link PlayerPositionAndLookPacket}
|
||||||
* is sent to self.
|
* is sent to self.
|
||||||
|
*
|
||||||
|
* @param notFromListener {@code true} if the client triggered this action
|
||||||
*/
|
*/
|
||||||
protected void sendPositionUpdate() {
|
protected 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());
|
||||||
@ -710,7 +710,7 @@ public class Entity implements Viewable, Tickable, EventHandler, DataContainer,
|
|||||||
sendPacketToViewers(positionAndRotationPacket);
|
sendPacketToViewers(positionAndRotationPacket);
|
||||||
|
|
||||||
// Fix head rotation
|
// Fix head rotation
|
||||||
EntityHeadLookPacket entityHeadLookPacket = new EntityHeadLookPacket();
|
final EntityHeadLookPacket entityHeadLookPacket = new EntityHeadLookPacket();
|
||||||
entityHeadLookPacket.entityId = getEntityId();
|
entityHeadLookPacket.entityId = getEntityId();
|
||||||
entityHeadLookPacket.yaw = position.getYaw();
|
entityHeadLookPacket.yaw = position.getYaw();
|
||||||
sendPacketToViewersAndSelf(entityHeadLookPacket);
|
sendPacketToViewersAndSelf(entityHeadLookPacket);
|
||||||
@ -719,18 +719,29 @@ public class Entity implements Viewable, Tickable, EventHandler, DataContainer,
|
|||||||
.getPacket(getEntityId(), position, lastSyncedPosition, onGround);
|
.getPacket(getEntityId(), position, lastSyncedPosition, onGround);
|
||||||
sendPacketToViewers(entityPositionPacket);
|
sendPacketToViewers(entityPositionPacket);
|
||||||
} else if (viewChange) {
|
} else if (viewChange) {
|
||||||
setView(position.getYaw(), position.getPitch());
|
final EntityRotationPacket entityRotationPacket = new EntityRotationPacket();
|
||||||
/*
|
entityRotationPacket.entityId = getEntityId();
|
||||||
#setView indirectly sets last sync field and it appears that EntityRotation packet
|
entityRotationPacket.yaw = position.getYaw();
|
||||||
can be used for players as well, so it's safe to return
|
entityRotationPacket.pitch = position.getPitch();
|
||||||
*/
|
entityRotationPacket.onGround = onGround;
|
||||||
return;
|
|
||||||
|
final EntityHeadLookPacket entityHeadLookPacket = new EntityHeadLookPacket();
|
||||||
|
entityHeadLookPacket.entityId = getEntityId();
|
||||||
|
entityHeadLookPacket.yaw = position.getYaw();
|
||||||
|
|
||||||
|
if (notFromListener) {
|
||||||
|
sendPacketToViewersAndSelf(entityHeadLookPacket);
|
||||||
|
sendPacketToViewersAndSelf(entityRotationPacket);
|
||||||
|
} else {
|
||||||
|
sendPacketToViewers(entityHeadLookPacket);
|
||||||
|
sendPacketToViewers(entityRotationPacket);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Nothing changed, return
|
// Nothing changed, return
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isNettyClient) {
|
if (isNettyClient && notFromListener) {
|
||||||
final PlayerPositionAndLookPacket playerPositionAndLookPacket = new PlayerPositionAndLookPacket();
|
final PlayerPositionAndLookPacket playerPositionAndLookPacket = new PlayerPositionAndLookPacket();
|
||||||
playerPositionAndLookPacket.flags = 0b111;
|
playerPositionAndLookPacket.flags = 0b111;
|
||||||
playerPositionAndLookPacket.position = position.clone().subtract(lastSyncedPosition.getX(), lastSyncedPosition.getY(), lastSyncedPosition.getZ());
|
playerPositionAndLookPacket.position = position.clone().subtract(lastSyncedPosition.getX(), lastSyncedPosition.getY(), lastSyncedPosition.getZ());
|
||||||
@ -1345,9 +1356,8 @@ public class Entity implements Viewable, Tickable, EventHandler, DataContainer,
|
|||||||
position.setX(x);
|
position.setX(x);
|
||||||
position.setY(y);
|
position.setY(y);
|
||||||
position.setZ(z);
|
position.setZ(z);
|
||||||
lastSyncedPosition.setX(x);
|
|
||||||
lastSyncedPosition.setY(y);
|
sendPositionUpdate(false);
|
||||||
lastSyncedPosition.setZ(z);
|
|
||||||
|
|
||||||
if (hasPassenger()) {
|
if (hasPassenger()) {
|
||||||
for (Entity passenger : getPassengers()) {
|
for (Entity passenger : getPassengers()) {
|
||||||
@ -1406,8 +1416,8 @@ public class Entity implements Viewable, Tickable, EventHandler, DataContainer,
|
|||||||
this.lastPosition.setPitch(position.getPitch());
|
this.lastPosition.setPitch(position.getPitch());
|
||||||
position.setYaw(yaw);
|
position.setYaw(yaw);
|
||||||
position.setPitch(pitch);
|
position.setPitch(pitch);
|
||||||
this.lastSyncedPosition.setYaw(yaw);
|
|
||||||
this.lastSyncedPosition.setPitch(pitch);
|
sendPositionUpdate(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,6 +68,7 @@ import net.minestom.server.utils.chunk.ChunkUtils;
|
|||||||
import net.minestom.server.utils.entity.EntityUtils;
|
import net.minestom.server.utils.entity.EntityUtils;
|
||||||
import net.minestom.server.utils.instance.InstanceUtils;
|
import net.minestom.server.utils.instance.InstanceUtils;
|
||||||
import net.minestom.server.utils.inventory.PlayerInventoryUtils;
|
import net.minestom.server.utils.inventory.PlayerInventoryUtils;
|
||||||
|
import net.minestom.server.utils.player.PlayerUtils;
|
||||||
import net.minestom.server.utils.time.Cooldown;
|
import net.minestom.server.utils.time.Cooldown;
|
||||||
import net.minestom.server.utils.time.TimeUnit;
|
import net.minestom.server.utils.time.TimeUnit;
|
||||||
import net.minestom.server.utils.time.UpdateOption;
|
import net.minestom.server.utils.time.UpdateOption;
|
||||||
@ -180,6 +181,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
|||||||
super(EntityType.PLAYER, uuid);
|
super(EntityType.PLAYER, uuid);
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.playerConnection = playerConnection;
|
this.playerConnection = playerConnection;
|
||||||
|
this.isNettyClient = PlayerUtils.isNettyClient(this);
|
||||||
|
|
||||||
setBoundingBox(0.6f, 1.8f, 0.6f);
|
setBoundingBox(0.6f, 1.8f, 0.6f);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user