Java Code Examples for com.nukkitx.network.VarInts#writeInt()

The following examples show how to use com.nukkitx.network.VarInts#writeInt() . 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: BedrockUtils.java    From Protocol with Apache License 2.0 6 votes vote down vote up
public static void writeInventorySource(ByteBuf buffer, InventorySource inventorySource) {
    Preconditions.checkNotNull(buffer, "buffer");
    Preconditions.checkNotNull(inventorySource, "inventorySource");

    VarInts.writeUnsignedInt(buffer, inventorySource.getType().id());

    switch (inventorySource.getType()) {
        case CONTAINER:
        case UNTRACKED_INTERACTION_UI:
        case NON_IMPLEMENTED_TODO:
            VarInts.writeInt(buffer, inventorySource.getContainerId());
            break;
        case WORLD_INTERACTION:
            VarInts.writeUnsignedInt(buffer, inventorySource.getFlag().ordinal());
            break;
    }
}
 
Example 2
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 5 votes vote down vote up
public static void writeVector3i(ByteBuf buffer, Vector3i vector3i) {
    Preconditions.checkNotNull(buffer, "buffer");
    Preconditions.checkNotNull(vector3i, "vector3i");
    VarInts.writeInt(buffer, vector3i.getX());
    VarInts.writeInt(buffer, vector3i.getY());
    VarInts.writeInt(buffer, vector3i.getZ());
}
 
Example 3
Source File: LevelSoundEvent1Serializer_v332.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, LevelSoundEvent1Packet packet) {
    VarInts.writeInt(buffer, SOUNDS.get(packet.getSound()));
    BedrockUtils.writeVector3f(buffer, packet.getPosition());
    VarInts.writeInt(buffer, packet.getExtraData());
    VarInts.writeInt(buffer, packet.getPitch());
    buffer.writeBoolean(packet.isBabySound());
    buffer.writeBoolean(packet.isRelativeVolumeDisabled());
}
 
Example 4
Source File: AnimateSerializer_v361.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, AnimatePacket packet) {
    Action action = packet.getAction();
    VarInts.writeInt(buffer, types.get(action));
    VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId());
    if (action == Action.ROW_LEFT || action == Action.ROW_RIGHT) {
        buffer.writeFloatLE(packet.getRowingTime());
    }
}
 
Example 5
Source File: LevelSoundEvent1Serializer_v361.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, LevelSoundEvent1Packet packet) {
    VarInts.writeInt(buffer, SOUNDS.get(packet.getSound()));
    BedrockUtils.writeVector3f(buffer, packet.getPosition());
    VarInts.writeInt(buffer, packet.getExtraData());
    VarInts.writeInt(buffer, packet.getPitch());
    buffer.writeBoolean(packet.isBabySound());
    buffer.writeBoolean(packet.isRelativeVolumeDisabled());
}
 
Example 6
Source File: SetDisplayObjectiveSerializer_v291.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, SetDisplayObjectivePacket packet) {
    BedrockUtils.writeString(buffer, packet.getDisplaySlot());
    BedrockUtils.writeString(buffer, packet.getObjectiveId());
    BedrockUtils.writeString(buffer, packet.getDisplayName());
    BedrockUtils.writeString(buffer, packet.getCriteria());
    VarInts.writeInt(buffer, packet.getSortOrder());
}
 
Example 7
Source File: PlayerActionSerializer_v388.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, PlayerActionPacket packet) {
    VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId());
    VarInts.writeInt(buffer, packet.getAction().ordinal());
    BedrockUtils.writeBlockPosition(buffer, packet.getBlockPosition());
    VarInts.writeInt(buffer, packet.getFace());
}
 
Example 8
Source File: BedrockUtils.java    From Protocol with Apache License 2.0 5 votes vote down vote up
public static void writeVector3i(ByteBuf buffer, Vector3i vector3i) {
    Preconditions.checkNotNull(buffer, "buffer");
    Preconditions.checkNotNull(vector3i, "vector3i");
    VarInts.writeInt(buffer, vector3i.getX());
    VarInts.writeInt(buffer, vector3i.getY());
    VarInts.writeInt(buffer, vector3i.getZ());
}
 
Example 9
Source File: AnimateSerializer_v332.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, AnimatePacket packet) {
    Action action = packet.getAction();
    VarInts.writeInt(buffer, types.get(action));
    VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId());
    if (action == Action.ROW_LEFT || action == Action.ROW_RIGHT) {
        buffer.writeFloatLE(packet.getRowingTime());
    }
}
 
Example 10
Source File: SetTimeSerializer_v313.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, SetTimePacket packet) {
    VarInts.writeInt(buffer, packet.getTime());
}
 
Example 11
Source File: SetDefaultGameTypeSerializer_v332.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, SetDefaultGameTypePacket packet) {
    VarInts.writeInt(buffer, packet.getGamemode());
}
 
Example 12
Source File: RequestChunkRadiusSerializer_v291.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, RequestChunkRadiusPacket packet) {
    VarInts.writeInt(buffer, packet.getRadius());
}
 
Example 13
Source File: RequestChunkRadiusSerializer_v332.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, RequestChunkRadiusPacket packet) {
    VarInts.writeInt(buffer, packet.getRadius());
}
 
Example 14
Source File: ClientboundMapItemDataSerializer_v291.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, ClientboundMapItemDataPacket packet) {
    VarInts.writeLong(buffer, packet.getUniqueMapId());

    int type = 0;
    int[] colors = packet.getColors();
    if (colors != null && colors.length > 0) {
        type |= 0x2;
    }
    List<MapDecoration> decorations = packet.getDecorations();
    List<MapTrackedObject> trackedObjects = packet.getTrackedObjects();
    if (!decorations.isEmpty() && !trackedObjects.isEmpty()) {
        type |= 0x4;
    }
    LongList trackedEntityIds = packet.getTrackedEntityIds();
    if (!trackedEntityIds.isEmpty()) {
        type |= 0x8;
    }

    VarInts.writeUnsignedInt(buffer, type);
    buffer.writeByte(packet.getDimensionId());

    if ((type & 0x8) != 0) {
        VarInts.writeUnsignedInt(buffer, trackedEntityIds.size());
        for (long trackedEntityId : trackedEntityIds) {
            VarInts.writeLong(buffer, trackedEntityId);
        }
    }

    if ((type & 0xe) != 0) {
        buffer.writeByte(packet.getScale());
    }

    if ((type & 0x4) != 0) {
        VarInts.writeUnsignedInt(buffer, trackedObjects.size());
        for (MapTrackedObject object : trackedObjects) {
            switch (object.getType()) {
                case BLOCK:
                    buffer.writeIntLE(object.getType().ordinal());
                    BedrockUtils.writeBlockPosition(buffer, object.getPosition());
                    break;
                case ENTITY:
                    buffer.writeIntLE(object.getType().ordinal());
                    VarInts.writeLong(buffer, object.getEntityId());
                    break;
            }
        }

        VarInts.writeUnsignedInt(buffer, decorations.size());
        for (MapDecoration decoration : decorations) {
            buffer.writeByte(decoration.getImage());
            buffer.writeByte(decoration.getRotation());
            buffer.writeByte(decoration.getXOffset());
            buffer.writeByte(decoration.getYOffset());
            BedrockUtils.writeString(buffer, decoration.getLabel());
            VarInts.writeUnsignedInt(buffer, decoration.getColor());
        }
    }

    if ((type & 0x2) != 0) {
        VarInts.writeInt(buffer, packet.getWidth());
        VarInts.writeInt(buffer, packet.getHeight());
        VarInts.writeInt(buffer, packet.getXOffset());
        VarInts.writeInt(buffer, packet.getYOffset());

        VarInts.writeUnsignedInt(buffer, colors.length);
        for (int color : colors) {
            VarInts.writeUnsignedInt(buffer, color);
        }
    }
}
 
Example 15
Source File: HurtArmorSerializer_v340.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, HurtArmorPacket packet) {
    VarInts.writeInt(buffer, packet.getHealth());
}
 
Example 16
Source File: SpawnExperienceOrbSerializer_v388.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, SpawnExperienceOrbPacket packet) {
    BedrockUtils.writeVector3f(buffer, packet.getPosition());
    VarInts.writeInt(buffer, packet.getAmount());
}
 
Example 17
Source File: StartGameSerializer_v388.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, StartGamePacket packet) {
    VarInts.writeLong(buffer, packet.getUniqueEntityId());
    VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId());
    VarInts.writeInt(buffer, packet.getPlayerGamemode());
    BedrockUtils.writeVector3f(buffer, packet.getPlayerPosition());
    BedrockUtils.writeVector2f(buffer, packet.getRotation());
    // Level settings start
    VarInts.writeInt(buffer, packet.getSeed());
    VarInts.writeInt(buffer, packet.getDimensionId());
    VarInts.writeInt(buffer, packet.getGeneratorId());
    VarInts.writeInt(buffer, packet.getLevelGamemode());
    VarInts.writeInt(buffer, packet.getDifficulty());
    BedrockUtils.writeBlockPosition(buffer, packet.getDefaultSpawn());
    buffer.writeBoolean(packet.isAchievementsDisabled());
    VarInts.writeInt(buffer, packet.getTime());
    VarInts.writeInt(buffer, packet.getEduEditionOffers());
    buffer.writeBoolean(packet.isEduFeaturesEnabled());
    buffer.writeFloatLE(packet.getRainLevel());
    buffer.writeFloatLE(packet.getLightningLevel());
    buffer.writeBoolean(packet.isPlatformLockedContentConfirmed());
    buffer.writeBoolean(packet.isMultiplayerGame());
    buffer.writeBoolean(packet.isBroadcastingToLan());
    VarInts.writeInt(buffer, packet.getXblBroadcastMode().ordinal());
    VarInts.writeInt(buffer, packet.getPlatformBroadcastMode().ordinal());
    buffer.writeBoolean(packet.isCommandsEnabled());
    buffer.writeBoolean(packet.isTexturePacksRequired());
    BedrockUtils.writeArray(buffer, packet.getGamerules(), BedrockUtils::writeGameRule);
    buffer.writeBoolean(packet.isBonusChestEnabled());
    buffer.writeBoolean(packet.isStartingWithMap());
    VarInts.writeInt(buffer, packet.getDefaultPlayerPermission().ordinal());
    buffer.writeIntLE(packet.getServerChunkTickRange());
    buffer.writeBoolean(packet.isBehaviorPackLocked());
    buffer.writeBoolean(packet.isResourcePackLocked());
    buffer.writeBoolean(packet.isFromLockedWorldTemplate());
    buffer.writeBoolean(packet.isUsingMsaGamertagsOnly());
    buffer.writeBoolean(packet.isFromWorldTemplate());
    buffer.writeBoolean(packet.isWorldTemplateOptionLocked());
    buffer.writeBoolean(packet.isOnlySpawningV1Villagers());
    BedrockUtils.writeString(buffer, packet.getVanillaVersion());

    // Level settings end
    BedrockUtils.writeString(buffer, packet.getLevelId());
    BedrockUtils.writeString(buffer, packet.getWorldName());
    BedrockUtils.writeString(buffer, packet.getPremiumWorldTemplateId());
    buffer.writeBoolean(packet.isTrial());
    buffer.writeBoolean(packet.isMovementServerAuthoritative());
    buffer.writeLongLE(packet.getCurrentTick());
    VarInts.writeInt(buffer, packet.getEnchantmentSeed());

    // cache palette for fast writing
    try (NBTOutputStream stream = NbtUtils.createNetworkWriter(new ByteBufOutputStream(buffer))) {
        stream.write(packet.getBlockPalette());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    BedrockUtils.writeArray(buffer, packet.getItemEntries(), (buf, entry) -> {
        BedrockUtils.writeString(buf, entry.getIdentifier());
        buf.writeShortLE(entry.getId());
    });

    BedrockUtils.writeString(buffer, packet.getMultiplayerCorrelationId());

}
 
Example 18
Source File: ShowCreditsSerializer_v291.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, ShowCreditsPacket packet) {
    VarInts.writeUnsignedLong(buffer, packet.getRuntimeEntityId());
    VarInts.writeInt(buffer, packet.getStatus().ordinal());
}
 
Example 19
Source File: SetLastHurtBySerializer_v313.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, SetLastHurtByPacket packet) {
    VarInts.writeInt(buffer, packet.getEntityTypeId());
}
 
Example 20
Source File: SetDefaultGameTypeSerializer_v361.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, SetDefaultGameTypePacket packet) {
    VarInts.writeInt(buffer, packet.getGamemode());
}