Search in sources :

Example 1 with NBTSizeTracker

use of net.minecraft.nbt.NBTSizeTracker in project RecurrentComplex by Ivorforce.

the class RCPacketBuffer method readBigTag.

@Nullable
public NBTTagCompound readBigTag() throws IOException {
    int i = this.readerIndex();
    byte b0 = this.readByte();
    if (b0 == 0) {
        return null;
    } else {
        this.readerIndex(i);
        try {
            return CompressedStreamTools.read(new ByteBufInputStream(this), new NBTSizeTracker(2097152L * 4));
        } catch (IOException ioexception) {
            throw new EncoderException(ioexception);
        }
    }
}
Also used : NBTSizeTracker(net.minecraft.nbt.NBTSizeTracker) EncoderException(io.netty.handler.codec.EncoderException) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) IOException(java.io.IOException) Nullable(javax.annotation.Nullable)

Example 2 with NBTSizeTracker

use of net.minecraft.nbt.NBTSizeTracker in project Railcraft by Railcraft.

the class RailcraftInputStream method readNBT.

@Nullable
public NBTTagCompound readNBT() throws IOException {
    mark(1);
    byte b = readByte();
    NBTTagCompound nbt = null;
    if (b != 0) {
        reset();
        try (DataInputStream nbtStream = new DataInputStream(new BufferedInputStream(new GZIPInputStream(this)))) {
            nbt = CompressedStreamTools.read(nbtStream, new NBTSizeTracker(2097152L));
        }
    }
    return nbt;
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) NBTSizeTracker(net.minecraft.nbt.NBTSizeTracker) BufferedInputStream(java.io.BufferedInputStream) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) DataInputStream(java.io.DataInputStream) Nullable(javax.annotation.Nullable)

Example 3 with NBTSizeTracker

use of net.minecraft.nbt.NBTSizeTracker in project BluePower by Qmunity.

the class ItemStackDatabase method loadItemStacks.

public List<ItemStack> loadItemStacks() {
    if (cache == null) {
        File targetLocation = new File(saveLocation);
        List<ItemStack> stacks = new ArrayList<ItemStack>();
        if (targetLocation.exists()) {
            File[] files = targetLocation.listFiles();
            for (File file : files) {
                try {
                    FileInputStream fos = new FileInputStream(file);
                    DataInputStream dos = new DataInputStream(fos);
                    short short1 = dos.readShort();
                    byte[] abyte = new byte[short1];
                    dos.read(abyte);
                    NBTTagCompound tag = CompressedStreamTools.func_152457_a(abyte, new NBTSizeTracker(2097152L));
                    ItemStack stack = new ItemStack(Items.stick);
                    stack.readFromNBT(tag);
                    if (stack.getItem() != null) {
                        stacks.add(stack);
                    } else {
                        BluePower.log.error("Couldn't retrieve an itemstack with item id: " + tag.getShort("id"));
                        Item item = GameRegistry.findItem(tag.getString("owner"), tag.getString("name"));
                        if (item != null) {
                            ItemStack backupStack = new ItemStack(item, stack.stackSize, tag.getShort("Damage"));
                            if (stack.hasTagCompound()) {
                                backupStack.setTagCompound(stack.getTagCompound());
                            }
                            stacks.add(backupStack);
                            BluePower.log.info("Successfully retrieved stack via its name: " + tag.getString("owner") + ":" + tag.getString("name"));
                        } else {
                            BluePower.log.error("Couldn't retrieve the item via its name: " + tag.getString("owner") + ":" + tag.getString("name"));
                        }
                    }
                    dos.close();
                } catch (IOException e) {
                    BluePower.log.error("Exception : " + e);
                }
            }
        }
        cache = stacks;
    }
    return cache;
}
Also used : NBTSizeTracker(net.minecraft.nbt.NBTSizeTracker) ArrayList(java.util.ArrayList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) Item(net.minecraft.item.Item) ItemStack(net.minecraft.item.ItemStack) File(java.io.File)

Aggregations

NBTSizeTracker (net.minecraft.nbt.NBTSizeTracker)3 DataInputStream (java.io.DataInputStream)2 IOException (java.io.IOException)2 Nullable (javax.annotation.Nullable)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 ByteBufInputStream (io.netty.buffer.ByteBufInputStream)1 EncoderException (io.netty.handler.codec.EncoderException)1 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 ArrayList (java.util.ArrayList)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 Item (net.minecraft.item.Item)1 ItemStack (net.minecraft.item.ItemStack)1