Java Code Examples for com.nukkitx.nbt.NbtUtils#createNetworkReader()

The following examples show how to use com.nukkitx.nbt.NbtUtils#createNetworkReader() . 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: UpdateTradeSerializer_v340.java    From Protocol with Apache License 2.0 6 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, UpdateTradePacket packet) {
    packet.setWindowId(buffer.readUnsignedByte());
    packet.setWindowType(buffer.readUnsignedByte());
    packet.setUnknownInt(VarInts.readInt(buffer));
    packet.setScreen2(VarInts.readInt(buffer) >= 40);
    packet.setTradeTier(VarInts.readInt(buffer));
    packet.setWilling(buffer.readBoolean());
    packet.setTraderUniqueEntityId(VarInts.readLong(buffer));
    packet.setPlayerUniqueEntityId(VarInts.readLong(buffer));
    packet.setDisplayName(BedrockUtils.readString(buffer));
    try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) {
        packet.setOffers(reader.readTag());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example 2
Source File: UpdateTradeSerializer_v291.java    From Protocol with Apache License 2.0 6 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, UpdateTradePacket packet) {
    packet.setWindowId(buffer.readUnsignedByte());
    packet.setWindowType(buffer.readUnsignedByte());
    packet.setUnknownInt(VarInts.readInt(buffer));
    packet.setScreen2(VarInts.readInt(buffer) >= 40);
    packet.setWilling(buffer.readBoolean());
    packet.setTraderUniqueEntityId(VarInts.readLong(buffer));
    packet.setPlayerUniqueEntityId(VarInts.readLong(buffer));
    packet.setDisplayName(BedrockUtils.readString(buffer));
    try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) {
        packet.setOffers(reader.readTag());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example 3
Source File: UpdateTradeSerializer_v361.java    From Protocol with Apache License 2.0 6 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, UpdateTradePacket packet) {
    packet.setWindowId(buffer.readUnsignedByte());
    packet.setWindowType(buffer.readUnsignedByte());
    packet.setUnknownInt(VarInts.readInt(buffer));
    packet.setTradeTier(VarInts.readInt(buffer));
    packet.setWilling(buffer.readBoolean());
    packet.setTraderUniqueEntityId(VarInts.readLong(buffer));
    packet.setPlayerUniqueEntityId(VarInts.readLong(buffer));
    packet.setDisplayName(BedrockUtils.readString(buffer));
    packet.setScreen2(buffer.readBoolean());
    packet.setWilling(buffer.readBoolean());
    try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) {
        packet.setOffers(reader.readTag());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example 4
Source File: StructureTemplateDataExportResponseSerializer_v361.java    From Protocol with Apache License 2.0 6 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, StructureTemplateDataExportResponsePacket packet) {
    packet.setName(BedrockUtils.readString(buffer));

    boolean save = buffer.readBoolean();
    packet.setSave(save);

    if (save) {
        try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) {
            Tag<?> tag = reader.readTag();
            if (tag instanceof CompoundTag) {
                packet.setTag((CompoundTag) tag);
            } else {
                throw new IllegalArgumentException("Tag received was not a CompoundTag");
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
 
Example 5
Source File: UpdateTradeSerializer_v332.java    From Protocol with Apache License 2.0 6 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, UpdateTradePacket packet) {
    packet.setWindowId(buffer.readUnsignedByte());
    packet.setWindowType(buffer.readUnsignedByte());
    packet.setUnknownInt(VarInts.readInt(buffer));
    packet.setScreen2(VarInts.readInt(buffer) >= 40);
    packet.setTradeTier(VarInts.readInt(buffer));
    packet.setWilling(buffer.readBoolean());
    packet.setTraderUniqueEntityId(VarInts.readLong(buffer));
    packet.setPlayerUniqueEntityId(VarInts.readLong(buffer));
    packet.setDisplayName(BedrockUtils.readString(buffer));
    try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) {
        packet.setOffers(reader.readTag());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example 6
Source File: StructureTemplateDataExportResponseSerializer_v388.java    From Protocol with Apache License 2.0 6 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, StructureTemplateDataExportResponsePacket packet) {
    packet.setName(BedrockUtils.readString(buffer));

    boolean save = buffer.readBoolean();
    packet.setSave(save);

    if (save) {
        try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) {
            Tag<?> tag = reader.readTag();
            if (tag instanceof CompoundTag) {
                packet.setTag((CompoundTag) tag);
            } else {
                throw new IllegalArgumentException("Tag received was not a CompoundTag");
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
 
Example 7
Source File: BiomeDefinitionListSerializer_v340.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, BiomeDefinitionListPacket packet) {
    try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) {
        packet.setTag(reader.readTag());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example 8
Source File: BiomeDefinitionListSerializer_v332.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, BiomeDefinitionListPacket packet) {
    try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) {
        packet.setTag(reader.readTag());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example 9
Source File: AvailableEntityIdentifiersSerializer_v332.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, AvailableEntityIdentifiersPacket packet) {
    try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) {
        packet.setTag(reader.readTag());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example 10
Source File: BlockEntityDataSerializer_v388.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, BlockEntityDataPacket packet) {
    packet.setBlockPosition(BedrockUtils.readBlockPosition(buffer));
    try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) {
        packet.setData(reader.readTag());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example 11
Source File: UpdateEquipSerializer_v361.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, UpdateEquipPacket packet) {
    packet.setWindowId(buffer.readUnsignedByte());
    packet.setWindowType(buffer.readUnsignedByte());
    packet.setUnknown0(VarInts.readInt(buffer));
    packet.setUniqueEntityId(VarInts.readLong(buffer));
    try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) {
        packet.setTag(reader.readTag());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example 12
Source File: LevelEventGenericSerializer_v361.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, LevelEventGenericPacket packet) {
    packet.setEventId(VarInts.readInt(buffer));
    try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) {
        packet.setTag(reader.readTag());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example 13
Source File: BlockEntityDataSerializer_v340.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, BlockEntityDataPacket packet) {
    packet.setBlockPosition(BedrockUtils.readBlockPosition(buffer));
    try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) {
        packet.setData(reader.readTag());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example 14
Source File: BlockEntityDataSerializer_v313.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, BlockEntityDataPacket packet) {
    packet.setBlockPosition(BedrockUtils.readBlockPosition(buffer));
    try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) {
        packet.setData(reader.readTag());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example 15
Source File: BlockEntityDataSerializer_v354.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, BlockEntityDataPacket packet) {
    packet.setBlockPosition(BedrockUtils.readBlockPosition(buffer));
    try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) {
        packet.setData(reader.readTag());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example 16
Source File: BiomeDefinitionListSerializer_v354.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, BiomeDefinitionListPacket packet) {
    try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) {
        packet.setTag(reader.readTag());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example 17
Source File: AvailableEntityIdentifiersSerializer_v354.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, AvailableEntityIdentifiersPacket packet) {
    try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) {
        packet.setTag(reader.readTag());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example 18
Source File: UpdateEquipSerializer_v291.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, UpdateEquipPacket packet) {
    packet.setWindowId(buffer.readUnsignedByte());
    packet.setWindowType(buffer.readUnsignedByte());
    packet.setUnknown0(VarInts.readInt(buffer));
    packet.setUniqueEntityId(VarInts.readLong(buffer));
    try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) {
        packet.setTag(reader.readTag());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example 19
Source File: BiomeDefinitionListSerializer_v313.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, BiomeDefinitionListPacket packet) {
    try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) {
        packet.setTag(reader.readTag());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example 20
Source File: StartGameSerializer_v388.java    From Protocol with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void deserialize(ByteBuf buffer, StartGamePacket packet) {
    packet.setUniqueEntityId(VarInts.readLong(buffer));
    packet.setRuntimeEntityId(VarInts.readUnsignedLong(buffer));
    packet.setPlayerGamemode(VarInts.readInt(buffer));
    packet.setPlayerPosition(BedrockUtils.readVector3f(buffer));
    packet.setRotation(BedrockUtils.readVector2f(buffer));
    // Level settings start
    packet.setSeed(VarInts.readInt(buffer));
    packet.setDimensionId(VarInts.readInt(buffer));
    packet.setGeneratorId(VarInts.readInt(buffer));
    packet.setLevelGamemode(VarInts.readInt(buffer));
    packet.setDifficulty(VarInts.readInt(buffer));
    packet.setDefaultSpawn(BedrockUtils.readBlockPosition(buffer));
    packet.setAchievementsDisabled(buffer.readBoolean());
    packet.setTime(VarInts.readInt(buffer));
    packet.setEduEditionOffers(VarInts.readInt(buffer));
    packet.setEduFeaturesEnabled(buffer.readBoolean());
    packet.setRainLevel(buffer.readFloatLE());
    packet.setLightningLevel(buffer.readFloatLE());
    packet.setPlatformLockedContentConfirmed(buffer.readBoolean());
    packet.setMultiplayerGame(buffer.readBoolean());
    packet.setBroadcastingToLan(buffer.readBoolean());
    packet.setXblBroadcastMode(GamePublishSetting.byId(VarInts.readInt(buffer)));
    packet.setPlatformBroadcastMode(GamePublishSetting.byId(VarInts.readInt(buffer)));
    packet.setCommandsEnabled(buffer.readBoolean());
    packet.setTexturePacksRequired(buffer.readBoolean());
    BedrockUtils.readArray(buffer, packet.getGamerules(), BedrockUtils::readGameRule);
    packet.setBonusChestEnabled(buffer.readBoolean());
    packet.setStartingWithMap(buffer.readBoolean());
    packet.setDefaultPlayerPermission(PLAYER_PERMISSIONS[VarInts.readInt(buffer)]);
    packet.setServerChunkTickRange(buffer.readIntLE());
    packet.setBehaviorPackLocked(buffer.readBoolean());
    packet.setResourcePackLocked(buffer.readBoolean());
    packet.setFromLockedWorldTemplate(buffer.readBoolean());
    packet.setUsingMsaGamertagsOnly(buffer.readBoolean());
    packet.setFromWorldTemplate(buffer.readBoolean());
    packet.setWorldTemplateOptionLocked(buffer.readBoolean());
    packet.setOnlySpawningV1Villagers(buffer.readBoolean());
    packet.setVanillaVersion(BedrockUtils.readString(buffer));
    // Level settings end
    packet.setLevelId(BedrockUtils.readString(buffer));
    packet.setWorldName(BedrockUtils.readString(buffer));
    packet.setPremiumWorldTemplateId(BedrockUtils.readString(buffer));
    packet.setTrial(buffer.readBoolean());
    packet.setMovementServerAuthoritative(buffer.readBoolean());
    packet.setCurrentTick(buffer.readLongLE());
    packet.setEnchantmentSeed(VarInts.readInt(buffer));

    try (NBTInputStream stream = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) {
        packet.setBlockPalette((ListTag<CompoundTag>) stream.readTag());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    BedrockUtils.readArray(buffer, packet.getItemEntries(), buf -> {
        String identifier = BedrockUtils.readString(buf);
        short id = buf.readShortLE();
        return new StartGamePacket.ItemEntry(identifier, id);
    });

    packet.setMultiplayerCorrelationId(BedrockUtils.readString(buffer));
}