com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket Java Examples

The following examples show how to use com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket. 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: JavaJoinGameTranslator.java    From Geyser with MIT License 5 votes vote down vote up
@Override
public void translate(ServerJoinGamePacket packet, GeyserSession session) {
    PlayerEntity entity = session.getPlayerEntity();
    entity.setEntityId(packet.getEntityId());

    AdventureSettingsPacket bedrockPacket = new AdventureSettingsPacket();
    bedrockPacket.setUniqueEntityId(session.getPlayerEntity().getGeyserId());
    bedrockPacket.setPlayerPermission(PlayerPermission.MEMBER);
    session.sendUpstreamPacket(bedrockPacket);

    PlayStatusPacket playStatus = new PlayStatusPacket();
    playStatus.setStatus(PlayStatusPacket.Status.LOGIN_SUCCESS);
    // session.sendPacket(playStatus);

    SetPlayerGameTypePacket playerGameTypePacket = new SetPlayerGameTypePacket();
    playerGameTypePacket.setGamemode(packet.getGameMode().ordinal());
    session.sendUpstreamPacket(playerGameTypePacket);
    session.setGameMode(packet.getGameMode());

    SetEntityDataPacket entityDataPacket = new SetEntityDataPacket();
    entityDataPacket.setRuntimeEntityId(entity.getGeyserId());
    entityDataPacket.getMetadata().putAll(entity.getMetadata());
    session.sendUpstreamPacket(entityDataPacket);

    session.setRenderDistance(packet.getViewDistance());

    // We need to send our skin parts to the server otherwise java sees us with no hat, jacket etc
    String locale = session.getClientData().getLanguageCode();
    List<SkinPart> skinParts = Arrays.asList(SkinPart.values());
    ClientSettingsPacket clientSettingsPacket = new ClientSettingsPacket(locale, (byte) session.getRenderDistance(), ChatVisibility.FULL, true, skinParts, Hand.MAIN_HAND);
    session.sendDownstreamPacket(clientSettingsPacket);

    if (DimensionUtils.javaToBedrock(packet.getDimension()) != entity.getDimension()) {
        DimensionUtils.switchDimension(session, packet.getDimension());
    }
}
 
Example #2
Source File: BedrockMovePlayerTranslator.java    From Geyser with MIT License 5 votes vote down vote up
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 #3
Source File: JavaPlayerAbilitiesTranslator.java    From Geyser with MIT License 5 votes vote down vote up
@Override
public void translate(ServerPlayerAbilitiesPacket packet, GeyserSession session) {
    Entity entity = session.getPlayerEntity();
    if (entity == null)
        return;

    EntityDataMap metadata = entity.getMetadata();
    metadata.getFlags().setFlag(EntityFlag.CAN_FLY, packet.isCanFly());

    SetEntityDataPacket entityDataPacket = new SetEntityDataPacket();
    entityDataPacket.setRuntimeEntityId(entity.getGeyserId());
    entityDataPacket.getMetadata().putAll(metadata);
    session.sendUpstreamPacket(entityDataPacket);

    Set<AdventureSettingsPacket.Flag> playerFlags = new ObjectOpenHashSet<>();
    playerFlags.add(AdventureSettingsPacket.Flag.AUTO_JUMP);
    if (packet.isCanFly())
        playerFlags.add(AdventureSettingsPacket.Flag.MAY_FLY);

    if (packet.isFlying())
        playerFlags.add(AdventureSettingsPacket.Flag.FLYING);

    AdventureSettingsPacket adventureSettingsPacket = new AdventureSettingsPacket();
    adventureSettingsPacket.setPlayerPermission(PlayerPermission.MEMBER);
    // Required or the packet simply is not sent
    adventureSettingsPacket.setCommandPermission(CommandPermission.NORMAL);
    adventureSettingsPacket.setUniqueEntityId(entity.getGeyserId());
    adventureSettingsPacket.getFlags().addAll(playerFlags);
    session.sendUpstreamPacket(adventureSettingsPacket);
}
 
Example #4
Source File: SetEntityDataSerializer_v291.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, SetEntityDataPacket packet) {
    packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer));
    BedrockUtils.readEntityData(buffer, packet.getMetadata());
}
 
Example #5
Source File: SetEntityDataSerializer_v291.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, SetEntityDataPacket packet) {
    VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId());
    BedrockUtils.writeEntityData(buffer, packet.getMetadata());
}
 
Example #6
Source File: SetEntityDataSerializer_v332.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, SetEntityDataPacket packet) {
    packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer));
    BedrockUtils.readEntityData(buffer, packet.getMetadata());
}
 
Example #7
Source File: SetEntityDataSerializer_v332.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, SetEntityDataPacket packet) {
    VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId());
    BedrockUtils.writeEntityData(buffer, packet.getMetadata());
}
 
Example #8
Source File: SetEntityDataSerializer_v361.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, SetEntityDataPacket packet) {
    packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer));
    BedrockUtils.readEntityData(buffer, packet.getMetadata());
}
 
Example #9
Source File: SetEntityDataSerializer_v361.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, SetEntityDataPacket packet) {
    VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId());
    BedrockUtils.writeEntityData(buffer, packet.getMetadata());
}
 
Example #10
Source File: SetEntityDataSerializer_v313.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, SetEntityDataPacket packet) {
    packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer));
    BedrockUtils.readEntityData(buffer, packet.getMetadata());
}
 
Example #11
Source File: SetEntityDataSerializer_v313.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, SetEntityDataPacket packet) {
    VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId());
    BedrockUtils.writeEntityData(buffer, packet.getMetadata());
}
 
Example #12
Source File: SetEntityDataSerializer_v340.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, SetEntityDataPacket packet) {
    packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer));
    BedrockUtils.readEntityData(buffer, packet.getMetadata());
}
 
Example #13
Source File: SetEntityDataSerializer_v340.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, SetEntityDataPacket packet) {
    VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId());
    BedrockUtils.writeEntityData(buffer, packet.getMetadata());
}
 
Example #14
Source File: SetEntityDataSerializer_v388.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, SetEntityDataPacket packet) {
    packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer));
    BedrockUtils.readEntityData(buffer, packet.getMetadata());
}
 
Example #15
Source File: SetEntityDataSerializer_v388.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, SetEntityDataPacket packet) {
    VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId());
    BedrockUtils.writeEntityData(buffer, packet.getMetadata());
}
 
Example #16
Source File: SetEntityDataSerializer_v354.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, SetEntityDataPacket packet) {
    packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer));
    BedrockUtils.readEntityData(buffer, packet.getMetadata());
}
 
Example #17
Source File: SetEntityDataSerializer_v354.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, SetEntityDataPacket packet) {
    VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId());
    BedrockUtils.writeEntityData(buffer, packet.getMetadata());
}