mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Fix movement bugs *and* allow for teleportation
This commit is contained in:
parent
f52684f0dd
commit
9ffec0021c
3 changed files with 28 additions and 1 deletions
|
@ -100,6 +100,12 @@ public class GeyserSession implements Player {
|
|||
@Setter
|
||||
private GameMode gameMode = GameMode.SURVIVAL;
|
||||
|
||||
@Setter
|
||||
private boolean sprinting;
|
||||
|
||||
@Setter
|
||||
private boolean jumping;
|
||||
|
||||
@Setter
|
||||
private boolean switchingDimension = false;
|
||||
private boolean manyDimPackets = false;
|
||||
|
|
|
@ -40,6 +40,8 @@ import org.geysermc.connector.entity.Entity;
|
|||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket> {
|
||||
|
||||
@Override
|
||||
|
@ -72,10 +74,12 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
|
|||
case START_SPRINT:
|
||||
ClientPlayerStatePacket startSprintPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.START_SPRINTING);
|
||||
session.getDownstream().getSession().send(startSprintPacket);
|
||||
session.setSprinting(true);
|
||||
break;
|
||||
case STOP_SPRINT:
|
||||
ClientPlayerStatePacket stopSprintPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.STOP_SPRINTING);
|
||||
session.getDownstream().getSession().send(stopSprintPacket);
|
||||
session.setSprinting(false);
|
||||
break;
|
||||
case DROP_ITEM:
|
||||
ClientPlayerActionPacket dropItemPacket = new ClientPlayerActionPacket(PlayerAction.DROP_ITEM, position, BlockFace.values()[packet.getFace()]);
|
||||
|
@ -114,6 +118,12 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
|
|||
session.getUpstream().sendPacket(spawnPacket);
|
||||
entity.updateBedrockAttributes(session);
|
||||
break;
|
||||
case JUMP:
|
||||
session.setJumping(true);
|
||||
session.getConnector().getGeneralThreadPool().schedule(() -> {
|
||||
session.setJumping(false);
|
||||
}, 1, TimeUnit.SECONDS);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.Serv
|
|||
import com.nukkitx.math.vector.Vector3f;
|
||||
import com.nukkitx.protocol.bedrock.data.EntityEventType;
|
||||
import com.nukkitx.protocol.bedrock.packet.*;
|
||||
|
||||
import org.geysermc.connector.console.GeyserLogger;
|
||||
import org.geysermc.connector.entity.Entity;
|
||||
import org.geysermc.connector.entity.type.EntityType;
|
||||
|
@ -83,7 +84,17 @@ public class JavaPlayerPositionRotationTranslator extends PacketTranslator<Serve
|
|||
}
|
||||
|
||||
session.setSpawned(true);
|
||||
entity.moveAbsolute(session, Vector3f.from(packet.getX(), packet.getY() + EntityType.PLAYER.getOffset() + 0.1f, packet.getZ()), packet.getYaw(), packet.getPitch(), true);
|
||||
if (!packet.getRelative().isEmpty()) {
|
||||
entity.moveRelative(session, packet.getX(), packet.getY() + EntityType.PLAYER.getOffset() + 0.1f, packet.getZ(), packet.getYaw(), packet.getPitch(), true);
|
||||
} else {
|
||||
float xDis = Math.abs(entity.getPosition().getX() - (float) packet.getX());
|
||||
float yDis = entity.getPosition().getY() - (float) packet.getY();
|
||||
float zDis = Math.abs(entity.getPosition().getZ() - (float) packet.getZ());
|
||||
|
||||
if (xDis > 1.5 || (yDis < 1.45 || yDis > (session.isJumping() ? 4.3 : (session.isSprinting() ? 2.5 : 1.9))) || zDis > 1.5) {
|
||||
entity.moveAbsolute(session, Vector3f.from(packet.getX(), packet.getY() + 0.6f, packet.getZ()), packet.getYaw(), packet.getPitch(), true);
|
||||
}
|
||||
}
|
||||
|
||||
ClientTeleportConfirmPacket teleportConfirmPacket = new ClientTeleportConfirmPacket(packet.getTeleportId());
|
||||
session.getDownstream().getSession().send(teleportConfirmPacket);
|
||||
|
|
Loading…
Reference in a new issue