Java Code Examples for us.myles.ViaVersion.api.PacketWrapper#read()

The following examples show how to use us.myles.ViaVersion.api.PacketWrapper#read() . 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: TagRewriter.java    From ViaVersion with MIT License 6 votes vote down vote up
private void handle(PacketWrapper wrapper, IdRewriteFunction rewriteFunction, List<TagData> newTags) throws Exception {
    int tagsSize = wrapper.read(Type.VAR_INT);
    wrapper.write(Type.VAR_INT, newTags != null ? tagsSize + newTags.size() : tagsSize); // add new tags count

    for (int i = 0; i < tagsSize; i++) {
        wrapper.passthrough(Type.STRING);
        int[] ids = wrapper.passthrough(Type.VAR_INT_ARRAY_PRIMITIVE);
        if (rewriteFunction != null) {
            for (int j = 0; j < ids.length; j++) {
                ids[j] = rewriteFunction.rewrite(ids[j]);
            }
        }
    }

    // Send new tags if present
    if (newTags != null) {
        for (TagData tag : newTags) {
            wrapper.write(Type.STRING, tag.identifier);
            wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, tag.entries);
        }
    }
}
 
Example 2
Source File: BulkChunkTranslatorProvider.java    From ViaVersion with MIT License 5 votes vote down vote up
/**
 * Transforms a Bulk Chunk packet into Chunk Packets
 *
 * @param packet       The NMS Packet
 * @param clientChunks The ClientChunks object for the current player
 * @return A List of all the output packets
 * @throws Exception If there is an issue translating
 */
public List<Object> transformMapChunkBulk(Object packet, ClientChunks clientChunks) throws Exception {
    if (!(packet instanceof PacketWrapper))
        throw new IllegalArgumentException("The default packet has to be a PacketWrapper for transformMapChunkBulk, unexpected " + packet.getClass());

    List<Object> packets = new ArrayList<>();
    PacketWrapper wrapper = (PacketWrapper) packet;

    boolean skyLight = wrapper.read(Type.BOOLEAN);
    int count = wrapper.read(Type.VAR_INT);

    ChunkBulkSection[] metas = new ChunkBulkSection[count];
    for (int i = 0; i < count; i++) {
        metas[i] = ChunkBulkSection.read(wrapper, skyLight);
    }

    for (ChunkBulkSection meta : metas) {
        CustomByteType customByteType = new CustomByteType(meta.getLength());
        meta.setData(wrapper.read(customByteType));

        // Construct chunk packet
        PacketWrapper chunkPacket = new PacketWrapper(0x21, null, wrapper.user());
        chunkPacket.write(Type.INT, meta.getX());
        chunkPacket.write(Type.INT, meta.getZ());
        chunkPacket.write(Type.BOOLEAN, true); // Always ground-up
        chunkPacket.write(Type.UNSIGNED_SHORT, meta.getBitMask());
        chunkPacket.write(Type.VAR_INT, meta.getLength());
        chunkPacket.write(customByteType, meta.getData());

        clientChunks.getBulkChunks().add(ClientChunks.toLong(meta.getX(), meta.getZ())); // Store for later
        packets.add(chunkPacket);
    }

    return packets;
}
 
Example 3
Source File: ParticleMapping.java    From ViaBackwards with MIT License 5 votes vote down vote up
@Override
public int[] rewrite(Protocol1_12_2To1_13 protocol, PacketWrapper wrapper) throws Exception {
    float r = wrapper.read(Type.FLOAT);
    float g = wrapper.read(Type.FLOAT);
    float b = wrapper.read(Type.FLOAT);
    float scale = wrapper.read(Type.FLOAT);

    wrapper.set(Type.FLOAT, 3, r); // 5 - Offset X index=3
    wrapper.set(Type.FLOAT, 4, g); // 6 - Offset Y index=4
    wrapper.set(Type.FLOAT, 5, b); // 7 - Offset Z index=5
    wrapper.set(Type.FLOAT, 6, scale); // 8 - Particle Data index=6
    wrapper.set(Type.INT, 1, 0); // 9 - Particle Count index=1 enable rgb particle

    return null;
}
 
Example 4
Source File: TypeRemapper.java    From ViaVersion with MIT License 4 votes vote down vote up
@Override
public T read(PacketWrapper wrapper) throws Exception {
    return wrapper.read(type);
}