net.minecraft.nbt.NBTSizeTracker Java Examples

The following examples show how to use net.minecraft.nbt.NBTSizeTracker. 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: MCDataInput.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Reads a {@link CompoundNBT} from the stream.
 *
 * @return The {@link CompoundNBT}.
 */
@Nullable
default CompoundNBT readCompoundNBT() {
    if (!readBoolean()) {
        return null;
    } else {
        try {
            return CompressedStreamTools.read(toDataInput(), new NBTSizeTracker(2097152L));
        } catch (IOException e) {
            throw new EncoderException("Failed to read CompoundNBT from stream.", e);
        }
    }
}
 
Example #2
Source File: PacketSyncData.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void fromBytes(ByteBuf buf) {
    int size = buf.readInt();

    for (int i = 0; i < size; i++) {
        String key = StringHelper.readFromBuffer(buf);

        byte providerId = buf.readByte();
        AbstractData.AbstractDataProvider<? extends AbstractData> provider = AbstractData.Registry.getProvider(providerId);
        if(provider == null) {
            Gadomancy.log.warn("Provider for ID " + providerId + " doesn't exist! Skipping...");
            continue;
        }

        NBTTagCompound cmp;
        short compoundLength = buf.readShort();
        byte[] abyte = new byte[compoundLength];
        buf.readBytes(abyte);
        try {
            cmp = CompressedStreamTools.func_152457_a(abyte, new NBTSizeTracker(2097152L));
        } catch (IOException e) {
            Gadomancy.log.warn("Provider Compound of " + providerId + " threw an IOException! Skipping...");
            Gadomancy.log.warn("Exception message: " + e.getMessage());
            continue;
        }

        AbstractData dat = provider.provideNewInstance();
        dat.readRawFromPacket(cmp);

        data.put(key, dat);
    }
}
 
Example #3
Source File: ByteBufUtilsEU.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static NBTTagCompound readNBTTagCompoundFromBuffer(ByteBuf buf) throws IOException
{
    int i = buf.readerIndex();
    byte b0 = buf.readByte();

    if (b0 == 0)
    {
        return null;
    }
    else
    {
        buf.readerIndex(i);
        return CompressedStreamTools.read(new ByteBufInputStream(buf), new NBTSizeTracker(2097152L));
    }
}
 
Example #4
Source File: LimitStream.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public LimitStream(InputStream is, NBTSizeTracker limit) {
    super(is);
    this.limit = limit;
}