Java Code Examples for net.minecraft.nbt.CompressedStreamTools#read()

The following examples show how to use net.minecraft.nbt.CompressedStreamTools#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: HyperiumServerList.java    From Hyperium with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void loadServerList(List<ServerData> servers, Minecraft mc) {
    try {
        servers.clear();
        NBTTagCompound nbttagcompound = CompressedStreamTools
            .read(new File(mc.mcDataDir, "servers.dat"));

        if (nbttagcompound == null) return;

        NBTTagList nbttaglist = nbttagcompound.getTagList("servers", 10);

        int bound = nbttaglist.tagCount();
        for (int i = 0; i < bound; i++) {
            ServerData serverDataFromNBTCompound = ServerData.getServerDataFromNBTCompound(nbttaglist.getCompoundTagAt(i));
            servers.add(serverDataFromNBTCompound);
        }
    } catch (Exception exception) {
        Hyperium.LOGGER.error("Failed to load server list", exception);
    }
}
 
Example 2
Source File: NEIServerUtils.java    From NotEnoughItems with MIT License 6 votes vote down vote up
public static NBTTagCompound readNBT(File file) throws IOException {
    if (!file.exists()) {
        return null;
    }
    FileInputStream in = new FileInputStream(file);
    NBTTagCompound tag;
    try {
        tag = CompressedStreamTools.readCompressed(in);
    } catch (ZipException e) {
        if (e.getMessage().equals("Not in GZIP format")) {
            tag = CompressedStreamTools.read(file);
        } else {
            throw e;
        }
    }
    in.close();
    return tag;
}
 
Example 3
Source File: MsgTileEntities.java    From archimedes-ships with MIT License 6 votes vote down vote up
@Override
public void decodeInto(ChannelHandlerContext ctx, ByteBuf buf, EntityPlayer player) throws IOException
{
	super.decodeInto(ctx, buf, player);
	if (ship != null)
	{
		DataInputStream in = new DataInputStream(new ByteBufInputStream(buf));
		try
		{
			tagCompound = CompressedStreamTools.read(in);
		} catch (IOException e)
		{
			throw e;
		} finally
		{
			in.close();
		}
	}
}
 
Example 4
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 5
Source File: NEIServerUtils.java    From NotEnoughItems with MIT License 5 votes vote down vote up
public static NBTTagCompound readNBT(File file) throws IOException {
    if(!file.exists()) return null;
    FileInputStream in = new FileInputStream(file);
    NBTTagCompound tag;
    try {
        tag = CompressedStreamTools.readCompressed(in);
    } catch(ZipException e) {
        if(e.getMessage().equals("Not in GZIP format"))
            tag = CompressedStreamTools.read(file);
        else
            throw e;
    }
    in.close();
    return tag;
}
 
Example 6
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 7
Source File: SaveStates.java    From NBTEdit with GNU General Public License v3.0 5 votes vote down vote up
public void read() throws IOException{
	if (file.exists() && file.canRead()){
		NBTTagCompound root = CompressedStreamTools.read(file);
		for (int i =0; i < 7; ++i){
			String name = "slot" + (i+1);
			if (root.hasKey(name))
				tags[i].tag = root.getCompoundTag(name);
			if (root.hasKey(name+"Name"))
				tags[i].name = root.getString(name+"Name");
		}
	}
}
 
Example 8
Source File: NBTHelper.java    From ehacks-pro with GNU General Public License v3.0 4 votes vote down vote up
public static NBTTagCompound nbtRead(DataInputStream in) throws IOException {
    return CompressedStreamTools.read(in);
}
 
Example 9
Source File: NBTHelper.java    From NBTEdit with GNU General Public License v3.0 4 votes vote down vote up
public static NBTTagCompound nbtRead(DataInputStream in) throws IOException {
	return CompressedStreamTools.read(in);
}