3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-20 06:50:09 +01:00

Fix player movement not being visible, movement bugs and laggy entities

(Addresses #74, #109)
Dieser Commit ist enthalten in:
RednedEpic 2020-02-15 17:39:34 -06:00
Ursprung e6d166d4d4
Commit ee85abf34c
10 geänderte Dateien mit 97 neuen und 91 gelöschten Zeilen

Datei anzeigen

@ -65,7 +65,6 @@ public class Entity {
protected Vector3f rotation; protected Vector3f rotation;
protected float scale = 1; protected float scale = 1;
protected boolean movePending;
protected EntityType entityType; protected EntityType entityType;
@ -79,14 +78,14 @@ public class Entity {
this.entityId = entityId; this.entityId = entityId;
this.geyserId = geyserId; this.geyserId = geyserId;
this.entityType = entityType; this.entityType = entityType;
this.position = position;
this.motion = motion; this.motion = motion;
this.rotation = rotation; this.rotation = rotation;
this.valid = false; this.valid = false;
this.movePending = false;
this.dimension = 0; this.dimension = 0;
setPosition(position);
metadata.put(EntityData.SCALE, 1f); metadata.put(EntityData.SCALE, 1f);
metadata.put(EntityData.MAX_AIR, (short) 400); metadata.put(EntityData.MAX_AIR, (short) 400);
metadata.put(EntityData.AIR, (short) 0); metadata.put(EntityData.AIR, (short) 0);
@ -132,25 +131,40 @@ public class Entity {
return true; return true;
} }
public void moveRelative(double relX, double relY, double relZ, float yaw, float pitch) { public void moveRelative(GeyserSession session, double relX, double relY, double relZ, float yaw, float pitch, boolean isOnGround) {
moveRelative(relX, relY, relZ, Vector3f.from(yaw, pitch, yaw)); 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); setRotation(rotation);
this.position = Vector3f.from(position.getX() + relX, position.getY() + relY, position.getZ() + relZ); 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) { public void moveAbsolute(GeyserSession session, Vector3f position, float yaw, float pitch, boolean isOnGround) {
moveAbsolute(position, Vector3f.from(yaw, pitch, yaw)); 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); setPosition(position);
setRotation(rotation); 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) { public void updateBedrockAttributes(GeyserSession session) {
@ -216,14 +230,6 @@ public class Entity {
session.getUpstream().sendPacket(entityDataPacket); 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 * x = Pitch, y = HeadYaw, z = Yaw
*/ */

Datei anzeigen

@ -30,6 +30,7 @@ import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.CommandPermission; import com.nukkitx.protocol.bedrock.data.CommandPermission;
import com.nukkitx.protocol.bedrock.data.PlayerPermission; import com.nukkitx.protocol.bedrock.data.PlayerPermission;
import com.nukkitx.protocol.bedrock.packet.AddPlayerPacket; import com.nukkitx.protocol.bedrock.packet.AddPlayerPacket;
import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket;
import com.nukkitx.protocol.bedrock.packet.PlayerListPacket; import com.nukkitx.protocol.bedrock.packet.PlayerListPacket;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; 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);
}
} }

Datei anzeigen

@ -55,7 +55,6 @@ public class EntityCache {
} }
public void spawnEntity(Entity entity) { public void spawnEntity(Entity entity) {
entity.moveAbsolute(entity.getPosition(), entity.getRotation().getX(), entity.getRotation().getY());
cacheEntity(entity); cacheEntity(entity);
entity.spawnEntity(session); entity.spawnEntity(session);
} }

Datei anzeigen

@ -61,8 +61,7 @@ public class BedrockMovePlayerTranslator extends PacketTranslator<MovePlayerPack
return; 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( ClientPlayerPositionRotationPacket playerPositionRotationPacket = new ClientPlayerPositionRotationPacket(
packet.isOnGround(), packet.getPosition().getX(), javaY, packet.isOnGround(), packet.getPosition().getX(), javaY,
packet.getPosition().getZ(), packet.getRotation().getY(), packet.getRotation().getX() packet.getPosition().getZ(), packet.getRotation().getY(), packet.getRotation().getX()
@ -70,8 +69,8 @@ public class BedrockMovePlayerTranslator extends PacketTranslator<MovePlayerPack
// head yaw, pitch, head yaw // head yaw, pitch, head yaw
Vector3f rotation = Vector3f.from(packet.getRotation().getY(), packet.getRotation().getX(), packet.getRotation().getY()); Vector3f rotation = Vector3f.from(packet.getRotation().getY(), packet.getRotation().getX(), packet.getRotation().getY());
entity.setPosition(packet.getPosition().sub(0, EntityType.PLAYER.getOffset(), 0));
entity.moveAbsolute(packet.getPosition().sub(0, EntityType.PLAYER.getOffset(), 0), rotation); entity.setRotation(rotation);
/* /*
boolean colliding = false; boolean colliding = false;
@ -124,8 +123,6 @@ public class BedrockMovePlayerTranslator extends PacketTranslator<MovePlayerPack
movePlayerPacket.setPosition(entity.getPosition()); movePlayerPacket.setPosition(entity.getPosition());
movePlayerPacket.setRotation(entity.getBedrockRotation()); movePlayerPacket.setRotation(entity.getBedrockRotation());
movePlayerPacket.setMode(MovePlayerPacket.Mode.RESET); movePlayerPacket.setMode(MovePlayerPacket.Mode.RESET);
movePlayerPacket.setOnGround(true);
entity.setMovePending(false);
session.getUpstream().sendPacket(movePlayerPacket); session.getUpstream().sendPacket(movePlayerPacket);
} }
} }

Datei anzeigen

@ -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.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityHeadLookPacket;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket; 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.Entity;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator; 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())); entity.setRotation(Vector3f.from(entity.getRotation().getX(), entity.getRotation().getY(), packet.getHeadYaw()));
MoveEntityAbsolutePacket moveEntityAbsolutePacket = new MoveEntityAbsolutePacket(); if (entity.getEntityType() != EntityType.PLAYER) {
moveEntityAbsolutePacket.setRuntimeEntityId(entity.getGeyserId()); MoveEntityAbsolutePacket moveEntityAbsolutePacket = new MoveEntityAbsolutePacket();
moveEntityAbsolutePacket.setPosition(entity.getPosition()); moveEntityAbsolutePacket.setRuntimeEntityId(entity.getGeyserId());
moveEntityAbsolutePacket.setRotation(entity.getBedrockRotation()); moveEntityAbsolutePacket.setPosition(entity.getPosition());
moveEntityAbsolutePacket.setOnGround(true); moveEntityAbsolutePacket.setRotation(entity.getBedrockRotation());
session.getUpstream().sendPacket(moveEntityAbsolutePacket);
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);
}
} }
} }

Datei anzeigen

@ -41,18 +41,6 @@ public class JavaEntityPositionRotationTranslator extends PacketTranslator<Serve
} }
if (entity == null) return; if (entity == null) return;
entity.moveRelative(packet.getMoveX(), packet.getMoveY(), packet.getMoveZ(), packet.getYaw(), packet.getPitch()); entity.moveRelative(session, packet.getMoveX(), packet.getMoveY(), packet.getMoveZ(), packet.getYaw(), packet.getPitch(), packet.isOnGround());
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);
}
} }
} }

Datei anzeigen

@ -26,7 +26,7 @@
package org.geysermc.connector.network.translators.java.entity; package org.geysermc.connector.network.translators.java.entity;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityPositionPacket; 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.entity.Entity;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.PacketTranslator;
@ -41,18 +41,6 @@ public class JavaEntityPositionTranslator extends PacketTranslator<ServerEntityP
} }
if (entity == null) return; if (entity == null) return;
entity.moveRelative(packet.getMoveX(), packet.getMoveY(), packet.getMoveZ(), entity.getRotation()); entity.moveRelative(session, packet.getMoveX(), packet.getMoveY(), packet.getMoveZ(), entity.getRotation(), packet.isOnGround());
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);
}
} }
} }

Datei anzeigen

@ -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.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityRotationPacket;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket; 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.Entity;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator; 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.moveRelative(packet.getMovementX(), packet.getMovementY(), packet.getMovementZ(), packet.getYaw(), packet.getPitch());
entity.setRotation(Vector3f.from(packet.getYaw(), packet.getPitch(), packet.getYaw())); entity.setRotation(Vector3f.from(packet.getYaw(), packet.getPitch(), packet.getYaw()));
if (entity.isMovePending()) { if (entity.getEntityType() != EntityType.PLAYER) {
MoveEntityAbsolutePacket moveEntityAbsolutePacket = new MoveEntityAbsolutePacket(); MoveEntityAbsolutePacket moveEntityAbsolutePacket = new MoveEntityAbsolutePacket();
moveEntityAbsolutePacket.setRuntimeEntityId(entity.getGeyserId()); moveEntityAbsolutePacket.setRuntimeEntityId(entity.getGeyserId());
moveEntityAbsolutePacket.setPosition(entity.getPosition()); moveEntityAbsolutePacket.setPosition(entity.getPosition());
moveEntityAbsolutePacket.setRotation(entity.getBedrockRotation()); moveEntityAbsolutePacket.setRotation(entity.getBedrockRotation());
entity.setMovePending(false);
session.getUpstream().sendPacket(moveEntityAbsolutePacket); 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);
} }
} }
} }

Datei anzeigen

@ -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.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityTeleportPacket;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket;
import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.PacketTranslator;
@ -42,18 +42,6 @@ public class JavaEntityTeleportTranslator extends PacketTranslator<ServerEntityT
} }
if (entity == null) return; if (entity == null) return;
entity.moveAbsolute(Vector3f.from(packet.getX(), packet.getY(), packet.getZ()), packet.getYaw(), packet.getPitch()); entity.moveAbsolute(session, Vector3f.from(packet.getX(), packet.getY(), packet.getZ()), packet.getYaw(), packet.getPitch(), packet.isOnGround());
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);
}
} }
} }

Datei anzeigen

@ -49,7 +49,8 @@ public class JavaPlayerPositionRotationTranslator extends PacketTranslator<Serve
if (!session.isSpawned()) { if (!session.isSpawned()) {
Vector3f pos = Vector3f.from(packet.getX(), packet.getY() + EntityType.PLAYER.getOffset() + 0.1f, packet.getZ()); 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 respawnPacket = new RespawnPacket();
respawnPacket.setRuntimeEntityId(0); respawnPacket.setRuntimeEntityId(0);
@ -73,8 +74,6 @@ public class JavaPlayerPositionRotationTranslator extends PacketTranslator<Serve
movePlayerPacket.setPosition(pos); movePlayerPacket.setPosition(pos);
movePlayerPacket.setRotation(Vector3f.from(packet.getPitch(), packet.getYaw(), 0)); movePlayerPacket.setRotation(Vector3f.from(packet.getPitch(), packet.getYaw(), 0));
movePlayerPacket.setMode(MovePlayerPacket.Mode.RESET); movePlayerPacket.setMode(MovePlayerPacket.Mode.RESET);
movePlayerPacket.setOnGround(true);
entity.setMovePending(false);
session.getUpstream().sendPacket(movePlayerPacket); session.getUpstream().sendPacket(movePlayerPacket);
session.setSpawned(true); session.setSpawned(true);
@ -83,17 +82,6 @@ public class JavaPlayerPositionRotationTranslator extends PacketTranslator<Serve
return; 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); session.setSpawned(true);
ClientTeleportConfirmPacket teleportConfirmPacket = new ClientTeleportConfirmPacket(packet.getTeleportId()); ClientTeleportConfirmPacket teleportConfirmPacket = new ClientTeleportConfirmPacket(packet.getTeleportId());