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

The following examples show how to use com.nukkitx.protocol.bedrock.packet.SetPlayerGameTypePacket. 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: JavaRespawnTranslator.java    From Geyser with MIT License 5 votes vote down vote up
@Override
public void translate(ServerRespawnPacket packet, GeyserSession session) {
    Entity entity = session.getPlayerEntity();
    if (entity == null)
        return;

    float maxHealth = entity.getAttributes().containsKey(AttributeType.MAX_HEALTH) ? entity.getAttributes().get(AttributeType.MAX_HEALTH).getValue() : 20f;
    // Max health must be divisible by two in bedrock
    entity.getAttributes().put(AttributeType.HEALTH, AttributeType.HEALTH.getAttribute(maxHealth, (maxHealth % 2 == 1 ? maxHealth + 1 : maxHealth)));

    session.getInventoryCache().setOpenInventory(null);

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

    LevelEventPacket stopRainPacket = new LevelEventPacket();
    stopRainPacket.setType(LevelEventType.STOP_RAIN);
    stopRainPacket.setData(ThreadLocalRandom.current().nextInt(50000) + 10000);
    stopRainPacket.setPosition(Vector3f.ZERO);
    session.sendUpstreamPacket(stopRainPacket);

    if (entity.getDimension() != DimensionUtils.javaToBedrock(packet.getDimension())) {
        DimensionUtils.switchDimension(session, packet.getDimension());
    } else {
        if (session.isManyDimPackets()) { //reloading world
            int fakeDim = entity.getDimension() == 0 ? -1 : 0;
            DimensionUtils.switchDimension(session, fakeDim);
            DimensionUtils.switchDimension(session, packet.getDimension());
        } else {
            // Handled in JavaPlayerPositionRotationTranslator
            session.setSpawned(false);
        }
    }
}
 
Example #2
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 #3
Source File: SetPlayerGameTypeSerializer_v354.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, SetPlayerGameTypePacket packet) {
    VarInts.writeInt(buffer, packet.getGamemode());
}
 
Example #4
Source File: SetPlayerGameTypeSerializer_v354.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, SetPlayerGameTypePacket packet) {
    packet.setGamemode(VarInts.readInt(buffer));
}
 
Example #5
Source File: SetPlayerGameTypeSerializer_v388.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, SetPlayerGameTypePacket packet) {
    VarInts.writeInt(buffer, packet.getGamemode());
}
 
Example #6
Source File: SetPlayerGameTypeSerializer_v388.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, SetPlayerGameTypePacket packet) {
    packet.setGamemode(VarInts.readInt(buffer));
}
 
Example #7
Source File: SetPlayerGameTypeSerializer_v340.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, SetPlayerGameTypePacket packet) {
    VarInts.writeInt(buffer, packet.getGamemode());
}
 
Example #8
Source File: SetPlayerGameTypeSerializer_v340.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, SetPlayerGameTypePacket packet) {
    packet.setGamemode(VarInts.readInt(buffer));
}
 
Example #9
Source File: SetPlayerGameTypeSerializer_v313.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, SetPlayerGameTypePacket packet) {
    VarInts.writeInt(buffer, packet.getGamemode());
}
 
Example #10
Source File: SetPlayerGameTypeSerializer_v313.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, SetPlayerGameTypePacket packet) {
    packet.setGamemode(VarInts.readInt(buffer));
}
 
Example #11
Source File: SetPlayerGameTypeSerializer_v361.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, SetPlayerGameTypePacket packet) {
    VarInts.writeInt(buffer, packet.getGamemode());
}
 
Example #12
Source File: SetPlayerGameTypeSerializer_v361.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, SetPlayerGameTypePacket packet) {
    packet.setGamemode(VarInts.readInt(buffer));
}
 
Example #13
Source File: SetPlayerGameTypeSerializer_v332.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, SetPlayerGameTypePacket packet) {
    VarInts.writeInt(buffer, packet.getGamemode());
}
 
Example #14
Source File: SetPlayerGameTypeSerializer_v332.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, SetPlayerGameTypePacket packet) {
    packet.setGamemode(VarInts.readInt(buffer));
}
 
Example #15
Source File: SetPlayerGameTypeSerializer_v291.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, SetPlayerGameTypePacket packet) {
    VarInts.writeInt(buffer, packet.getGamemode());
}
 
Example #16
Source File: SetPlayerGameTypeSerializer_v291.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, SetPlayerGameTypePacket packet) {
    packet.setGamemode(VarInts.readInt(buffer));
}