mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Fix player movement not being visible, movement bugs and laggy entities
(Addresses #74, #109)
This commit is contained in:
parent
e6d166d4d4
commit
ee85abf34c
10 changed files with 97 additions and 91 deletions
|
@ -65,7 +65,6 @@ public class Entity {
|
|||
protected Vector3f rotation;
|
||||
|
||||
protected float scale = 1;
|
||||
protected boolean movePending;
|
||||
|
||||
protected EntityType entityType;
|
||||
|
||||
|
@ -79,14 +78,14 @@ public class Entity {
|
|||
this.entityId = entityId;
|
||||
this.geyserId = geyserId;
|
||||
this.entityType = entityType;
|
||||
this.position = position;
|
||||
this.motion = motion;
|
||||
this.rotation = rotation;
|
||||
|
||||
this.valid = false;
|
||||
this.movePending = false;
|
||||
this.dimension = 0;
|
||||
|
||||
setPosition(position);
|
||||
|
||||
metadata.put(EntityData.SCALE, 1f);
|
||||
metadata.put(EntityData.MAX_AIR, (short) 400);
|
||||
metadata.put(EntityData.AIR, (short) 0);
|
||||
|
@ -132,25 +131,40 @@ public class Entity {
|
|||
return true;
|
||||
}
|
||||
|
||||
public void moveRelative(double relX, double relY, double relZ, float yaw, float pitch) {
|
||||
moveRelative(relX, relY, relZ, Vector3f.from(yaw, pitch, yaw));
|
||||
public void moveRelative(GeyserSession session, double relX, double relY, double relZ, float yaw, float pitch, boolean isOnGround) {
|
||||
moveRelative(session, relX, relY, relZ, Vector3f.from(yaw, pitch, yaw), isOnGround);
|
||||
}
|
||||
|
||||
public void moveRelative(double relX, double relY, double relZ, Vector3f rotation) {
|
||||
public void moveRelative(GeyserSession session, double relX, double relY, double relZ, Vector3f rotation, boolean isOnGround) {
|
||||
setRotation(rotation);
|
||||
this.position = Vector3f.from(position.getX() + relX, position.getY() + relY, position.getZ() + relZ);
|
||||
this.movePending = true;
|
||||
|
||||
MoveEntityAbsolutePacket moveEntityPacket = new MoveEntityAbsolutePacket();
|
||||
moveEntityPacket.setRuntimeEntityId(geyserId);
|
||||
moveEntityPacket.setPosition(position);
|
||||
moveEntityPacket.setRotation(getBedrockRotation());
|
||||
moveEntityPacket.setOnGround(isOnGround);
|
||||
moveEntityPacket.setTeleported(false);
|
||||
|
||||
session.getUpstream().sendPacket(moveEntityPacket);
|
||||
}
|
||||
|
||||
public void moveAbsolute(Vector3f position, float yaw, float pitch) {
|
||||
moveAbsolute(position, Vector3f.from(yaw, pitch, yaw));
|
||||
public void moveAbsolute(GeyserSession session, Vector3f position, float yaw, float pitch, boolean isOnGround) {
|
||||
moveAbsolute(session, position, Vector3f.from(yaw, pitch, yaw), isOnGround);
|
||||
}
|
||||
|
||||
public void moveAbsolute(Vector3f position, Vector3f rotation) {
|
||||
public void moveAbsolute(GeyserSession session, Vector3f position, Vector3f rotation, boolean isOnGround) {
|
||||
setPosition(position);
|
||||
setRotation(rotation);
|
||||
|
||||
this.movePending = true;
|
||||
MoveEntityAbsolutePacket moveEntityPacket = new MoveEntityAbsolutePacket();
|
||||
moveEntityPacket.setRuntimeEntityId(geyserId);
|
||||
moveEntityPacket.setPosition(position);
|
||||
moveEntityPacket.setRotation(getBedrockRotation());
|
||||
moveEntityPacket.setOnGround(isOnGround);
|
||||
moveEntityPacket.setTeleported(false);
|
||||
|
||||
session.getUpstream().sendPacket(moveEntityPacket);
|
||||
}
|
||||
|
||||
public void updateBedrockAttributes(GeyserSession session) {
|
||||
|
@ -216,14 +230,6 @@ public class Entity {
|
|||
session.getUpstream().sendPacket(entityDataPacket);
|
||||
}
|
||||
|
||||
public void setPosition(Vector3f position) {
|
||||
if (is(PlayerEntity.class)) {
|
||||
this.position = position.add(0, entityType.getOffset(), 0);
|
||||
return;
|
||||
}
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
/**
|
||||
* x = Pitch, y = HeadYaw, z = Yaw
|
||||
*/
|
||||
|
|
|
@ -30,6 +30,7 @@ import com.nukkitx.math.vector.Vector3f;
|
|||
import com.nukkitx.protocol.bedrock.data.CommandPermission;
|
||||
import com.nukkitx.protocol.bedrock.data.PlayerPermission;
|
||||
import com.nukkitx.protocol.bedrock.packet.AddPlayerPacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.PlayerListPacket;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
@ -115,4 +116,38 @@ public class PlayerEntity extends LivingEntity {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveAbsolute(GeyserSession session, Vector3f position, Vector3f rotation, boolean isOnGround) {
|
||||
setPosition(position);
|
||||
setRotation(rotation);
|
||||
|
||||
MovePlayerPacket movePlayerPacket = new MovePlayerPacket();
|
||||
movePlayerPacket.setRuntimeEntityId(geyserId);
|
||||
movePlayerPacket.setPosition(this.position);
|
||||
movePlayerPacket.setRotation(getBedrockRotation());
|
||||
movePlayerPacket.setOnGround(isOnGround);
|
||||
movePlayerPacket.setMode(MovePlayerPacket.Mode.NORMAL);
|
||||
|
||||
session.getUpstream().sendPacket(movePlayerPacket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveRelative(GeyserSession session, double relX, double relY, double relZ, Vector3f rotation, boolean isOnGround) {
|
||||
setRotation(rotation);
|
||||
this.position = Vector3f.from(position.getX() + relX, position.getY() + relY, position.getZ() + relZ);
|
||||
|
||||
MovePlayerPacket movePlayerPacket = new MovePlayerPacket();
|
||||
movePlayerPacket.setRuntimeEntityId(geyserId);
|
||||
movePlayerPacket.setPosition(position);
|
||||
movePlayerPacket.setRotation(getBedrockRotation());
|
||||
movePlayerPacket.setOnGround(isOnGround);
|
||||
movePlayerPacket.setMode(MovePlayerPacket.Mode.NORMAL);
|
||||
session.getUpstream().sendPacket(movePlayerPacket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPosition(Vector3f position) {
|
||||
this.position = position.add(0, entityType.getOffset(), 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,7 +55,6 @@ public class EntityCache {
|
|||
}
|
||||
|
||||
public void spawnEntity(Entity entity) {
|
||||
entity.moveAbsolute(entity.getPosition(), entity.getRotation().getX(), entity.getRotation().getY());
|
||||
cacheEntity(entity);
|
||||
entity.spawnEntity(session);
|
||||
}
|
||||
|
|
|
@ -61,8 +61,7 @@ public class BedrockMovePlayerTranslator extends PacketTranslator<MovePlayerPack
|
|||
return;
|
||||
}
|
||||
|
||||
double javaY = packet.getPosition().getY() - EntityType.PLAYER.getOffset();
|
||||
|
||||
double javaY = Math.ceil((packet.getPosition().getY() - EntityType.PLAYER.getOffset()) * 2) / 2;
|
||||
ClientPlayerPositionRotationPacket playerPositionRotationPacket = new ClientPlayerPositionRotationPacket(
|
||||
packet.isOnGround(), packet.getPosition().getX(), javaY,
|
||||
packet.getPosition().getZ(), packet.getRotation().getY(), packet.getRotation().getX()
|
||||
|
@ -70,8 +69,8 @@ public class BedrockMovePlayerTranslator extends PacketTranslator<MovePlayerPack
|
|||
|
||||
// head yaw, pitch, head yaw
|
||||
Vector3f rotation = Vector3f.from(packet.getRotation().getY(), packet.getRotation().getX(), packet.getRotation().getY());
|
||||
|
||||
entity.moveAbsolute(packet.getPosition().sub(0, EntityType.PLAYER.getOffset(), 0), rotation);
|
||||
entity.setPosition(packet.getPosition().sub(0, EntityType.PLAYER.getOffset(), 0));
|
||||
entity.setRotation(rotation);
|
||||
|
||||
/*
|
||||
boolean colliding = false;
|
||||
|
@ -124,8 +123,6 @@ public class BedrockMovePlayerTranslator extends PacketTranslator<MovePlayerPack
|
|||
movePlayerPacket.setPosition(entity.getPosition());
|
||||
movePlayerPacket.setRotation(entity.getBedrockRotation());
|
||||
movePlayerPacket.setMode(MovePlayerPacket.Mode.RESET);
|
||||
movePlayerPacket.setOnGround(true);
|
||||
entity.setMovePending(false);
|
||||
session.getUpstream().sendPacket(movePlayerPacket);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,9 @@ package org.geysermc.connector.network.translators.java.entity;
|
|||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityHeadLookPacket;
|
||||
import com.nukkitx.math.vector.Vector3f;
|
||||
import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket;
|
||||
import org.geysermc.connector.entity.Entity;
|
||||
import org.geysermc.connector.entity.type.EntityType;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||
|
||||
|
@ -45,12 +47,19 @@ public class JavaEntityHeadLookTranslator extends PacketTranslator<ServerEntityH
|
|||
|
||||
entity.setRotation(Vector3f.from(entity.getRotation().getX(), entity.getRotation().getY(), packet.getHeadYaw()));
|
||||
|
||||
MoveEntityAbsolutePacket moveEntityAbsolutePacket = new MoveEntityAbsolutePacket();
|
||||
moveEntityAbsolutePacket.setRuntimeEntityId(entity.getGeyserId());
|
||||
moveEntityAbsolutePacket.setPosition(entity.getPosition());
|
||||
moveEntityAbsolutePacket.setRotation(entity.getBedrockRotation());
|
||||
moveEntityAbsolutePacket.setOnGround(true);
|
||||
|
||||
session.getUpstream().sendPacket(moveEntityAbsolutePacket);
|
||||
if (entity.getEntityType() != EntityType.PLAYER) {
|
||||
MoveEntityAbsolutePacket moveEntityAbsolutePacket = new MoveEntityAbsolutePacket();
|
||||
moveEntityAbsolutePacket.setRuntimeEntityId(entity.getGeyserId());
|
||||
moveEntityAbsolutePacket.setPosition(entity.getPosition());
|
||||
moveEntityAbsolutePacket.setRotation(entity.getBedrockRotation());
|
||||
session.getUpstream().sendPacket(moveEntityAbsolutePacket);
|
||||
} else {
|
||||
MovePlayerPacket movePlayerPacket = new MovePlayerPacket();
|
||||
movePlayerPacket.setRuntimeEntityId(entity.getGeyserId());
|
||||
movePlayerPacket.setPosition(entity.getPosition());
|
||||
movePlayerPacket.setRotation(entity.getBedrockRotation());
|
||||
movePlayerPacket.setMode(MovePlayerPacket.Mode.ROTATION);
|
||||
session.getUpstream().sendPacket(movePlayerPacket);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,18 +41,6 @@ public class JavaEntityPositionRotationTranslator extends PacketTranslator<Serve
|
|||
}
|
||||
if (entity == null) return;
|
||||
|
||||
entity.moveRelative(packet.getMoveX(), packet.getMoveY(), packet.getMoveZ(), packet.getYaw(), packet.getPitch());
|
||||
|
||||
if (entity.isMovePending()) {
|
||||
MoveEntityAbsolutePacket moveEntityPacket = new MoveEntityAbsolutePacket();
|
||||
moveEntityPacket.setRuntimeEntityId(entity.getGeyserId());
|
||||
moveEntityPacket.setPosition(entity.getPosition());
|
||||
moveEntityPacket.setRotation(entity.getBedrockRotation());
|
||||
moveEntityPacket.setOnGround(packet.isOnGround());
|
||||
moveEntityPacket.setTeleported(false);
|
||||
entity.setMovePending(false);
|
||||
|
||||
session.getUpstream().sendPacket(moveEntityPacket);
|
||||
}
|
||||
entity.moveRelative(session, packet.getMoveX(), packet.getMoveY(), packet.getMoveZ(), packet.getYaw(), packet.getPitch(), packet.isOnGround());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
package org.geysermc.connector.network.translators.java.entity;
|
||||
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionPacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket;
|
||||
|
||||
import org.geysermc.connector.entity.Entity;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||
|
@ -41,18 +41,6 @@ public class JavaEntityPositionTranslator extends PacketTranslator<ServerEntityP
|
|||
}
|
||||
if (entity == null) return;
|
||||
|
||||
entity.moveRelative(packet.getMoveX(), packet.getMoveY(), packet.getMoveZ(), entity.getRotation());
|
||||
|
||||
if (entity.isMovePending()) {
|
||||
MoveEntityAbsolutePacket moveEntityPacket = new MoveEntityAbsolutePacket();
|
||||
moveEntityPacket.setRuntimeEntityId(entity.getGeyserId());
|
||||
moveEntityPacket.setPosition(entity.getPosition());
|
||||
moveEntityPacket.setRotation(entity.getBedrockRotation());
|
||||
moveEntityPacket.setOnGround(packet.isOnGround());
|
||||
moveEntityPacket.setTeleported(false);
|
||||
entity.setMovePending(false);
|
||||
|
||||
session.getUpstream().sendPacket(moveEntityPacket);
|
||||
}
|
||||
entity.moveRelative(session, packet.getMoveX(), packet.getMoveY(), packet.getMoveZ(), entity.getRotation(), packet.isOnGround());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,9 @@ package org.geysermc.connector.network.translators.java.entity;
|
|||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityRotationPacket;
|
||||
import com.nukkitx.math.vector.Vector3f;
|
||||
import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket;
|
||||
import org.geysermc.connector.entity.Entity;
|
||||
import org.geysermc.connector.entity.type.EntityType;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||
|
||||
|
@ -45,14 +47,20 @@ public class JavaEntityRotationTranslator extends PacketTranslator<ServerEntityR
|
|||
// entity.moveRelative(packet.getMovementX(), packet.getMovementY(), packet.getMovementZ(), packet.getYaw(), packet.getPitch());
|
||||
entity.setRotation(Vector3f.from(packet.getYaw(), packet.getPitch(), packet.getYaw()));
|
||||
|
||||
if (entity.isMovePending()) {
|
||||
if (entity.getEntityType() != EntityType.PLAYER) {
|
||||
MoveEntityAbsolutePacket moveEntityAbsolutePacket = new MoveEntityAbsolutePacket();
|
||||
moveEntityAbsolutePacket.setRuntimeEntityId(entity.getGeyserId());
|
||||
moveEntityAbsolutePacket.setPosition(entity.getPosition());
|
||||
moveEntityAbsolutePacket.setRotation(entity.getBedrockRotation());
|
||||
entity.setMovePending(false);
|
||||
|
||||
session.getUpstream().sendPacket(moveEntityAbsolutePacket);
|
||||
} else {
|
||||
MovePlayerPacket movePlayerPacket = new MovePlayerPacket();
|
||||
movePlayerPacket.setRuntimeEntityId(entity.getGeyserId());
|
||||
movePlayerPacket.setPosition(entity.getPosition());
|
||||
movePlayerPacket.setRotation(entity.getBedrockRotation());
|
||||
movePlayerPacket.setOnGround(packet.isOnGround());
|
||||
movePlayerPacket.setMode(MovePlayerPacket.Mode.ROTATION);
|
||||
session.getUpstream().sendPacket(movePlayerPacket);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ package org.geysermc.connector.network.translators.java.entity;
|
|||
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityTeleportPacket;
|
||||
import com.nukkitx.math.vector.Vector3f;
|
||||
import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket;
|
||||
|
||||
import org.geysermc.connector.entity.Entity;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||
|
@ -42,18 +42,6 @@ public class JavaEntityTeleportTranslator extends PacketTranslator<ServerEntityT
|
|||
}
|
||||
if (entity == null) return;
|
||||
|
||||
entity.moveAbsolute(Vector3f.from(packet.getX(), packet.getY(), packet.getZ()), packet.getYaw(), packet.getPitch());
|
||||
|
||||
if (entity.isMovePending()) {
|
||||
MoveEntityAbsolutePacket moveEntityPacket = new MoveEntityAbsolutePacket();
|
||||
moveEntityPacket.setRuntimeEntityId(entity.getGeyserId());
|
||||
moveEntityPacket.setPosition(entity.getPosition());
|
||||
moveEntityPacket.setRotation(entity.getBedrockRotation());
|
||||
moveEntityPacket.setOnGround(packet.isOnGround());
|
||||
moveEntityPacket.setTeleported(true);
|
||||
entity.setMovePending(false);
|
||||
|
||||
session.getUpstream().sendPacket(moveEntityPacket);
|
||||
}
|
||||
entity.moveAbsolute(session, Vector3f.from(packet.getX(), packet.getY(), packet.getZ()), packet.getYaw(), packet.getPitch(), packet.isOnGround());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,8 @@ public class JavaPlayerPositionRotationTranslator extends PacketTranslator<Serve
|
|||
|
||||
if (!session.isSpawned()) {
|
||||
Vector3f pos = Vector3f.from(packet.getX(), packet.getY() + EntityType.PLAYER.getOffset() + 0.1f, packet.getZ());
|
||||
entity.moveAbsolute(pos, packet.getYaw(), packet.getPitch());
|
||||
entity.setPosition(pos);
|
||||
entity.setRotation(Vector3f.from(packet.getYaw(), packet.getPitch(), packet.getYaw()));
|
||||
|
||||
RespawnPacket respawnPacket = new RespawnPacket();
|
||||
respawnPacket.setRuntimeEntityId(0);
|
||||
|
@ -73,8 +74,6 @@ public class JavaPlayerPositionRotationTranslator extends PacketTranslator<Serve
|
|||
movePlayerPacket.setPosition(pos);
|
||||
movePlayerPacket.setRotation(Vector3f.from(packet.getPitch(), packet.getYaw(), 0));
|
||||
movePlayerPacket.setMode(MovePlayerPacket.Mode.RESET);
|
||||
movePlayerPacket.setOnGround(true);
|
||||
entity.setMovePending(false);
|
||||
|
||||
session.getUpstream().sendPacket(movePlayerPacket);
|
||||
session.setSpawned(true);
|
||||
|
@ -83,17 +82,6 @@ public class JavaPlayerPositionRotationTranslator extends PacketTranslator<Serve
|
|||
return;
|
||||
}
|
||||
|
||||
entity.moveAbsolute(Vector3f.from(packet.getX(), packet.getY() + EntityType.PLAYER.getOffset() + 0.1f, packet.getZ()), packet.getYaw(), packet.getPitch());
|
||||
|
||||
MovePlayerPacket movePlayerPacket = new MovePlayerPacket();
|
||||
movePlayerPacket.setRuntimeEntityId(entity.getGeyserId());
|
||||
movePlayerPacket.setPosition(Vector3f.from(packet.getX(), packet.getY() + EntityType.PLAYER.getOffset() + 0.01f, packet.getZ()));
|
||||
movePlayerPacket.setRotation(Vector3f.from(packet.getPitch(), packet.getYaw(), 0));
|
||||
movePlayerPacket.setMode(MovePlayerPacket.Mode.NORMAL);
|
||||
movePlayerPacket.setOnGround(true);
|
||||
entity.setMovePending(false);
|
||||
|
||||
session.getUpstream().sendPacket(movePlayerPacket);
|
||||
session.setSpawned(true);
|
||||
|
||||
ClientTeleportConfirmPacket teleportConfirmPacket = new ClientTeleportConfirmPacket(packet.getTeleportId());
|
||||
|
|
Loading…
Reference in a new issue