com.nukkitx.protocol.bedrock.packet.MovePlayerPacket Java Examples
The following examples show how to use
com.nukkitx.protocol.bedrock.packet.MovePlayerPacket.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BedrockMovePlayerTranslator.java From Geyser with MIT License | 6 votes |
public boolean isValidMove(GeyserSession session, MovePlayerPacket.Mode mode, Vector3f currentPosition, Vector3f newPosition) { if (mode != MovePlayerPacket.Mode.NORMAL) return true; double xRange = newPosition.getX() - currentPosition.getX(); double yRange = newPosition.getY() - currentPosition.getY(); double zRange = newPosition.getZ() - currentPosition.getZ(); if (xRange < 0) xRange = -xRange; if (yRange < 0) yRange = -yRange; if (zRange < 0) zRange = -zRange; if ((xRange + yRange + zRange) > 100) { session.getConnector().getLogger().debug(ChatColor.RED + session.getName() + " moved too quickly." + " current position: " + currentPosition + ", new position: " + newPosition); return false; } return true; }
Example #2
Source File: MovePlayerSerializer_v291.java From Protocol with Apache License 2.0 | 5 votes |
@Override public void deserialize(ByteBuf buffer, MovePlayerPacket packet) { packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); packet.setPosition(BedrockUtils.readVector3f(buffer)); packet.setRotation(BedrockUtils.readVector3f(buffer)); packet.setMode(Mode.values()[buffer.readByte()]); packet.setOnGround(buffer.readBoolean()); packet.setRidingRuntimeEntityId(VarInts.readUnsignedLong(buffer)); if (packet.getMode() == Mode.TELEPORT) { packet.setTeleportationCause(TeleportationCause.byId(buffer.readIntLE())); packet.setEntityType(buffer.readIntLE()); } }
Example #3
Source File: MovePlayerSerializer_v291.java From Protocol with Apache License 2.0 | 5 votes |
@Override public void serialize(ByteBuf buffer, MovePlayerPacket packet) { VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); BedrockUtils.writeVector3f(buffer, packet.getPosition()); BedrockUtils.writeVector3f(buffer, packet.getRotation()); buffer.writeByte(packet.getMode().ordinal()); buffer.writeBoolean(packet.isOnGround()); VarInts.writeUnsignedLong(buffer, packet.getRidingRuntimeEntityId()); if (packet.getMode() == Mode.TELEPORT) { buffer.writeIntLE(packet.getTeleportationCause().ordinal()); buffer.writeIntLE(packet.getEntityType()); } }
Example #4
Source File: MovePlayerSerializer_v332.java From Protocol with Apache License 2.0 | 5 votes |
@Override public void deserialize(ByteBuf buffer, MovePlayerPacket packet) { packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); packet.setPosition(BedrockUtils.readVector3f(buffer)); packet.setRotation(BedrockUtils.readVector3f(buffer)); packet.setMode(Mode.values()[buffer.readByte()]); packet.setOnGround(buffer.readBoolean()); packet.setRidingRuntimeEntityId(VarInts.readUnsignedLong(buffer)); if (packet.getMode() == Mode.TELEPORT) { packet.setTeleportationCause(TeleportationCause.byId(buffer.readIntLE())); packet.setEntityType(buffer.readIntLE()); } }
Example #5
Source File: MovePlayerSerializer_v332.java From Protocol with Apache License 2.0 | 5 votes |
@Override public void serialize(ByteBuf buffer, MovePlayerPacket packet) { VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); BedrockUtils.writeVector3f(buffer, packet.getPosition()); BedrockUtils.writeVector3f(buffer, packet.getRotation()); buffer.writeByte(packet.getMode().ordinal()); buffer.writeBoolean(packet.isOnGround()); VarInts.writeUnsignedLong(buffer, packet.getRidingRuntimeEntityId()); if (packet.getMode() == Mode.TELEPORT) { buffer.writeIntLE(packet.getTeleportationCause().ordinal()); buffer.writeIntLE(packet.getEntityType()); } }
Example #6
Source File: MovePlayerSerializer_v361.java From Protocol with Apache License 2.0 | 5 votes |
@Override public void deserialize(ByteBuf buffer, MovePlayerPacket packet) { packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); packet.setPosition(BedrockUtils.readVector3f(buffer)); packet.setRotation(BedrockUtils.readVector3f(buffer)); packet.setMode(Mode.values()[buffer.readByte()]); packet.setOnGround(buffer.readBoolean()); packet.setRidingRuntimeEntityId(VarInts.readUnsignedLong(buffer)); if (packet.getMode() == Mode.TELEPORT) { packet.setTeleportationCause(TeleportationCause.byId(buffer.readIntLE())); packet.setEntityType(buffer.readIntLE()); } }
Example #7
Source File: MovePlayerSerializer_v361.java From Protocol with Apache License 2.0 | 5 votes |
@Override public void serialize(ByteBuf buffer, MovePlayerPacket packet) { VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); BedrockUtils.writeVector3f(buffer, packet.getPosition()); BedrockUtils.writeVector3f(buffer, packet.getRotation()); buffer.writeByte(packet.getMode().ordinal()); buffer.writeBoolean(packet.isOnGround()); VarInts.writeUnsignedLong(buffer, packet.getRidingRuntimeEntityId()); if (packet.getMode() == Mode.TELEPORT) { buffer.writeIntLE(packet.getTeleportationCause().ordinal()); buffer.writeIntLE(packet.getEntityType()); } }
Example #8
Source File: MovePlayerSerializer_v313.java From Protocol with Apache License 2.0 | 5 votes |
@Override public void deserialize(ByteBuf buffer, MovePlayerPacket packet) { packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); packet.setPosition(BedrockUtils.readVector3f(buffer)); packet.setRotation(BedrockUtils.readVector3f(buffer)); packet.setMode(Mode.values()[buffer.readByte()]); packet.setOnGround(buffer.readBoolean()); packet.setRidingRuntimeEntityId(VarInts.readUnsignedLong(buffer)); if (packet.getMode() == Mode.TELEPORT) { packet.setTeleportationCause(TeleportationCause.byId(buffer.readIntLE())); packet.setEntityType(buffer.readIntLE()); } }
Example #9
Source File: MovePlayerSerializer_v313.java From Protocol with Apache License 2.0 | 5 votes |
@Override public void serialize(ByteBuf buffer, MovePlayerPacket packet) { VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); BedrockUtils.writeVector3f(buffer, packet.getPosition()); BedrockUtils.writeVector3f(buffer, packet.getRotation()); buffer.writeByte(packet.getMode().ordinal()); buffer.writeBoolean(packet.isOnGround()); VarInts.writeUnsignedLong(buffer, packet.getRidingRuntimeEntityId()); if (packet.getMode() == Mode.TELEPORT) { buffer.writeIntLE(packet.getTeleportationCause().ordinal()); buffer.writeIntLE(packet.getEntityType()); } }
Example #10
Source File: MovePlayerSerializer_v340.java From Protocol with Apache License 2.0 | 5 votes |
@Override public void deserialize(ByteBuf buffer, MovePlayerPacket packet) { packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); packet.setPosition(BedrockUtils.readVector3f(buffer)); packet.setRotation(BedrockUtils.readVector3f(buffer)); packet.setMode(Mode.values()[buffer.readByte()]); packet.setOnGround(buffer.readBoolean()); packet.setRidingRuntimeEntityId(VarInts.readUnsignedLong(buffer)); if (packet.getMode() == Mode.TELEPORT) { packet.setTeleportationCause(TeleportationCause.byId(buffer.readIntLE())); packet.setEntityType(buffer.readIntLE()); } }
Example #11
Source File: MovePlayerSerializer_v340.java From Protocol with Apache License 2.0 | 5 votes |
@Override public void serialize(ByteBuf buffer, MovePlayerPacket packet) { VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); BedrockUtils.writeVector3f(buffer, packet.getPosition()); BedrockUtils.writeVector3f(buffer, packet.getRotation()); buffer.writeByte(packet.getMode().ordinal()); buffer.writeBoolean(packet.isOnGround()); VarInts.writeUnsignedLong(buffer, packet.getRidingRuntimeEntityId()); if (packet.getMode() == Mode.TELEPORT) { buffer.writeIntLE(packet.getTeleportationCause().ordinal()); buffer.writeIntLE(packet.getEntityType()); } }
Example #12
Source File: MovePlayerSerializer_v388.java From Protocol with Apache License 2.0 | 5 votes |
@Override public void deserialize(ByteBuf buffer, MovePlayerPacket packet) { packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); packet.setPosition(BedrockUtils.readVector3f(buffer)); packet.setRotation(BedrockUtils.readVector3f(buffer)); packet.setMode(Mode.values()[buffer.readByte()]); packet.setOnGround(buffer.readBoolean()); packet.setRidingRuntimeEntityId(VarInts.readUnsignedLong(buffer)); if (packet.getMode() == Mode.TELEPORT) { packet.setTeleportationCause(TeleportationCause.byId(buffer.readIntLE())); packet.setEntityType(buffer.readIntLE()); } }
Example #13
Source File: MovePlayerSerializer_v388.java From Protocol with Apache License 2.0 | 5 votes |
@Override public void serialize(ByteBuf buffer, MovePlayerPacket packet) { VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); BedrockUtils.writeVector3f(buffer, packet.getPosition()); BedrockUtils.writeVector3f(buffer, packet.getRotation()); buffer.writeByte(packet.getMode().ordinal()); buffer.writeBoolean(packet.isOnGround()); VarInts.writeUnsignedLong(buffer, packet.getRidingRuntimeEntityId()); if (packet.getMode() == Mode.TELEPORT) { buffer.writeIntLE(packet.getTeleportationCause().ordinal()); buffer.writeIntLE(packet.getEntityType()); } }
Example #14
Source File: MovePlayerSerializer_v354.java From Protocol with Apache License 2.0 | 5 votes |
@Override public void deserialize(ByteBuf buffer, MovePlayerPacket packet) { packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer)); packet.setPosition(BedrockUtils.readVector3f(buffer)); packet.setRotation(BedrockUtils.readVector3f(buffer)); packet.setMode(Mode.values()[buffer.readByte()]); packet.setOnGround(buffer.readBoolean()); packet.setRidingRuntimeEntityId(VarInts.readUnsignedLong(buffer)); if (packet.getMode() == Mode.TELEPORT) { packet.setTeleportationCause(TeleportationCause.byId(buffer.readIntLE())); packet.setEntityType(buffer.readIntLE()); } }
Example #15
Source File: MovePlayerSerializer_v354.java From Protocol with Apache License 2.0 | 5 votes |
@Override public void serialize(ByteBuf buffer, MovePlayerPacket packet) { VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId()); BedrockUtils.writeVector3f(buffer, packet.getPosition()); BedrockUtils.writeVector3f(buffer, packet.getRotation()); buffer.writeByte(packet.getMode().ordinal()); buffer.writeBoolean(packet.isOnGround()); VarInts.writeUnsignedLong(buffer, packet.getRidingRuntimeEntityId()); if (packet.getMode() == Mode.TELEPORT) { buffer.writeIntLE(packet.getTeleportationCause().ordinal()); buffer.writeIntLE(packet.getEntityType()); } }
Example #16
Source File: BedrockMovePlayerTranslator.java From Geyser with MIT License | 5 votes |
public void recalculatePosition(GeyserSession session, Entity entity, Vector3f currentPosition) { // Gravity might need to be reset... SetEntityDataPacket entityDataPacket = new SetEntityDataPacket(); entityDataPacket.setRuntimeEntityId(entity.getGeyserId()); entityDataPacket.getMetadata().putAll(entity.getMetadata()); session.sendUpstreamPacket(entityDataPacket); MovePlayerPacket movePlayerPacket = new MovePlayerPacket(); movePlayerPacket.setRuntimeEntityId(entity.getGeyserId()); movePlayerPacket.setPosition(entity.getPosition()); movePlayerPacket.setRotation(entity.getBedrockRotation()); movePlayerPacket.setMode(MovePlayerPacket.Mode.RESET); session.sendUpstreamPacket(movePlayerPacket); }
Example #17
Source File: BedrockMovePlayerTranslator.java From Geyser with MIT License | 4 votes |
@Override public void translate(MovePlayerPacket packet, GeyserSession session) { PlayerEntity entity = session.getPlayerEntity(); if (entity == null || !session.isSpawned() || session.getPendingDimSwitches().get() > 0) return; if (!session.getUpstream().isInitialized()) { MoveEntityAbsolutePacket moveEntityBack = new MoveEntityAbsolutePacket(); moveEntityBack.setRuntimeEntityId(entity.getGeyserId()); moveEntityBack.setPosition(entity.getPosition()); moveEntityBack.setRotation(entity.getBedrockRotation()); moveEntityBack.setTeleported(true); moveEntityBack.setOnGround(true); session.sendUpstreamPacketImmediately(moveEntityBack); return; } // We need to parse the float as a string since casting a float to a double causes us to // lose precision and thus, causes players to get stuck when walking near walls double javaY = packet.getPosition().getY() - EntityType.PLAYER.getOffset(); if (packet.isOnGround()) javaY = Math.ceil(javaY * 2) / 2; Vector3d position = Vector3d.from(Double.parseDouble(Float.toString(packet.getPosition().getX())), javaY, Double.parseDouble(Float.toString(packet.getPosition().getZ()))); if(!session.confirmTeleport(position)){ return; } if (!isValidMove(session, packet.getMode(), entity.getPosition(), packet.getPosition())) { session.getConnector().getLogger().debug("Recalculating position..."); recalculatePosition(session, entity, entity.getPosition()); return; } ClientPlayerPositionRotationPacket playerPositionRotationPacket = new ClientPlayerPositionRotationPacket( packet.isOnGround(), position.getX(), position.getY(), position.getZ(), packet.getRotation().getY(), packet.getRotation().getX() ); // head yaw, pitch, head yaw Vector3f rotation = Vector3f.from(packet.getRotation().getY(), packet.getRotation().getX(), packet.getRotation().getY()); entity.setPosition(packet.getPosition().sub(0, EntityType.PLAYER.getOffset(), 0)); entity.setRotation(rotation); entity.setOnGround(packet.isOnGround()); /* boolean colliding = false; Position position = new Position((int) packet.getPosition().getX(), (int) Math.ceil(javaY * 2) / 2, (int) packet.getPosition().getZ()); BlockEntry block = session.getChunkCache().getBlockAt(position); if (!block.getJavaIdentifier().contains("air")) colliding = true; if (!colliding) */ session.sendDownstreamPacket(playerPositionRotationPacket); }