net.minecraft.util.datafix.FixTypes#net.minecraft.nbt.CompressedStreamTools源码实例Demo

下面列出了net.minecraft.util.datafix.FixTypes#net.minecraft.nbt.CompressedStreamTools 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: GregTech   文件: TemplateManager.java
public static Template getBuiltinTemplate(World world, ResourceLocation templateId) {
    if (templateMap.containsKey(templateId)) {
        return templateMap.get(templateId);
    }
    Template template = new Template();
    String resourcePath = "/assets/" + templateId.getResourceDomain() + "/structures/" + templateId.getResourcePath() + ".nbt";
    InputStream inputStream = TemplateManager.class.getResourceAsStream(resourcePath);
    if (inputStream != null) {
        try {
            NBTTagCompound nbttagcompound = CompressedStreamTools.readCompressed(inputStream);
            if (!nbttagcompound.hasKey("DataVersion", 99)) {
                nbttagcompound.setInteger("DataVersion", 500);
            }
            DataFixer dataFixer = world.getMinecraftServer().getDataFixer();
            template.read(dataFixer.process(FixTypes.STRUCTURE, nbttagcompound));
        } catch (IOException exception) {
            GTLog.logger.error("Failed to load builtin template {}", templateId, exception);
        } finally {
            IOUtils.closeQuietly(inputStream);
        }
    } else {
        GTLog.logger.warn("Failed to find builtin structure with path {}", resourcePath);
    }
    templateMap.put(templateId, template);
    return template;
}
 
源代码2 项目: Hyperium   文件: HyperiumServerList.java
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);
    }
}
 
源代码3 项目: Hyperium   文件: HyperiumServerList.java
public void saveServerList(List<ServerData> servers, Minecraft mc) {
    try {
        NBTTagList nbttaglist = new NBTTagList();

        for (ServerData server : servers) {
            NBTTagCompound nbtCompound = server.getNBTCompound();
            nbttaglist.appendTag(nbtCompound);
        }

        NBTTagCompound nbttagcompound = new NBTTagCompound();
        nbttagcompound.setTag("servers", nbttaglist);
        CompressedStreamTools.safeWrite(nbttagcompound, new File(mc.mcDataDir, "servers.dat"));
    } catch (Exception exception) {
        Hyperium.LOGGER.error("Save server list error", exception);
    }
}
 
源代码4 项目: EnderStorage   文件: EnderStorageManager.java
private void save(boolean force) {
    if (!dirtyStorage.isEmpty() || force) {
        for (AbstractEnderStorage inv : dirtyStorage) {
            saveTag.put(inv.freq + ",type=" + inv.type(), inv.saveToTag());
            inv.setClean();
        }

        dirtyStorage.clear();

        try {
            File saveFile = saveFiles[saveTo];
            if (!saveFile.exists()) {
                saveFile.createNewFile();
            }
            DataOutputStream dout = new DataOutputStream(new FileOutputStream(saveFile));
            CompressedStreamTools.writeCompressed(saveTag, dout);
            dout.close();
            FileOutputStream fout = new FileOutputStream(saveFiles[2]);
            fout.write(saveTo);
            fout.close();
            saveTo ^= 1;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
 
源代码5 项目: NotEnoughItems   文件: NEIServerUtils.java
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;
}
 
源代码6 项目: NOVA-Core   文件: MCRetentionManager.java
/**
 * Saves NBT data in the world folder.
 * @param file File to save data to
 * @param data Data to save
 * @return True on success.
 */
public boolean saveFile(File file, NBTTagCompound data) {
	try {
		File tempFile = new File(file.getParent(), file.getName().replaceFirst("\\.nbt$", ".tmp.nbt"));

		CompressedStreamTools.writeCompressed(data, new FileOutputStream(tempFile));

		if (file.exists()) {
			file.delete();
		}

		tempFile.renameTo(file);
		return true;
	} catch (Exception e) {
		Game.logger().error("Failed to queueSave {}!", file.getName());
		e.printStackTrace();
		return false;
	}
}
 
源代码7 项目: NOVA-Core   文件: MCRetentionManager.java
/**
 * Saves NBT data in the world folder.
 * @param file File to save data to
 * @param data Data to save
 * @return True on success.
 */
public boolean saveFile(File file, NBTTagCompound data) {
	try {
		File tempFile = new File(file.getParent(), file.getName().replaceFirst("\\.nbt$", ".tmp.nbt"));

		CompressedStreamTools.writeCompressed(data, new FileOutputStream(tempFile));

		if (file.exists()) {
			file.delete();
		}

		tempFile.renameTo(file);
		return true;
	} catch (Exception e) {
		Game.logger().error("Failed to queueSave {}!", file.getName(), e);
		e.printStackTrace();
		return false;
	}
}
 
源代码8 项目: NOVA-Core   文件: MCRetentionManager.java
/**
 * Saves NBT data in the world folder.
 * @param file File to save data to
 * @param data Data to save
 * @return True on success.
 */
public boolean saveFile(File file, NBTTagCompound data) {
	try {
		File tempFile = new File(file.getParent(), file.getName().replaceFirst("\\.nbt$", ".tmp.nbt"));

		CompressedStreamTools.writeCompressed(data, new FileOutputStream(tempFile));

		if (file.exists()) {
			file.delete();
		}

		tempFile.renameTo(file);
		return true;
	} catch (Exception e) {
		Game.logger().error("Failed to queueSave {}!", file.getName(), e);
		e.printStackTrace();
		return false;
	}
}
 
源代码9 项目: qcraft-mod   文件: QCraftProxyCommon.java
public static NBTTagCompound loadNBTFromPath( File file )
{
    try
    {
        if( file != null && file.exists() )
        {
            InputStream input = new BufferedInputStream( new FileInputStream( file ) );
            try
            {
                return CompressedStreamTools.readCompressed( input );
            }
            finally
            {
                input.close();
            }
        }
    }
    catch( IOException e )
    {
        QCraft.log( "Warning: failed to load QCraft entanglement info" );
    }
    return null;
}
 
源代码10 项目: qcraft-mod   文件: QCraftProxyCommon.java
public static void saveNBTToPath( File file, NBTTagCompound nbt )
{
    try
    {
        if( file != null )
        {
            file.getParentFile().mkdirs();
            OutputStream output = new BufferedOutputStream( new FileOutputStream( file ) );
            try
            {
                CompressedStreamTools.writeCompressed( nbt, output );
            }
            finally
            {
                output.close();
            }
        }
    }
    catch( IOException e )
    {
        QCraft.log( "Warning: failed to save QCraft entanglement info" );
    }
}
 
源代码11 项目: EnderStorage   文件: EnderStorageManager.java
private void save(boolean force) {
    if (!dirtyStorage.isEmpty() || force) {
        for (AbstractEnderStorage inv : dirtyStorage) {
            saveTag.setTag(inv.freq + "|" + inv.owner + "|" + inv.type(), inv.saveToTag());
            inv.setClean();
        }

        dirtyStorage.clear();

        try {
            File saveFile = saveFiles[saveTo];
            if (!saveFile.exists())
                saveFile.createNewFile();
            DataOutputStream dout = new DataOutputStream(new FileOutputStream(saveFile));
            CompressedStreamTools.writeCompressed(saveTag, dout);
            dout.close();
            FileOutputStream fout = new FileOutputStream(saveFiles[2]);
            fout.write(saveTo);
            fout.close();
            saveTo ^= 1;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
 
源代码12 项目: enderutilities   文件: ByteBufUtilsEU.java
public static void writeNBTTagCompoundToBuffer(ByteBuf buf, NBTTagCompound tag)
{
    if (tag == null)
    {
        buf.writeByte(0);
        return;
    }

    try
    {
        CompressedStreamTools.write(tag, new ByteBufOutputStream(buf));
    }
    catch (IOException ioexception)
    {
        EnderUtilities.logger.error("IOException while trying to write a NBTTagCompound to ByteBuf");
        throw new EncoderException(ioexception);
    }
}
 
源代码13 项目: YUNoMakeGoodMap   文件: StructureUtil.java
private static Template loadTemplate(InputStream is)
{
    if (is == null)
        return null;
    try
    {
        NBTTagCompound nbt = CompressedStreamTools.readCompressed(is);
        Template template = new Template();
        template.read(nbt);
        return template;
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
    finally
    {
        if (is != null)
            IOUtils.closeQuietly(is);
    }
    return null;
}
 
源代码14 项目: archimedes-ships   文件: MsgTileEntities.java
@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();
		}
	}
}
 
源代码15 项目: litematica   文件: MaterialCache.java
public boolean writeToFile()
{
    if (this.dirty == false)
    {
        return false;
    }

    File dir = this.getCacheDir();
    File file = this.getCacheFile();

    try
    {
        if (dir.exists() == false && dir.mkdirs() == false)
        {
            Litematica.logger.warn("Failed to write the material list cache to file '{}'", file.getAbsolutePath());
            return false;
        }

        FileOutputStream os = new FileOutputStream(file);
        CompressedStreamTools.writeCompressed(this.writeToNBT(), os);
        os.close();
        this.dirty = false;

        return true;
    }
    catch (Exception e)
    {
        Litematica.logger.warn("Failed to write the material list cache to file '{}'", file.getAbsolutePath(), e);
    }

    return false;
}
 
源代码16 项目: litematica   文件: MaterialCache.java
public void readFromFile()
{
    File file = this.getCacheFile();

    if (file.exists() == false || file.canRead() == false)
    {
        return;
    }

    try
    {
        FileInputStream is = new FileInputStream(file);
        NBTTagCompound nbt = CompressedStreamTools.readCompressed(is);
        is.close();

        if (nbt != null)
        {
            this.readFromNBT(nbt);
            this.hasReadFromFile = true;
            this.dirty = false;
        }
    }
    catch (Exception e)
    {
        Litematica.logger.warn("Failed to read the material list cache from file '{}'", file.getAbsolutePath(), e);
    }
}
 
源代码17 项目: CodeChickenLib   文件: MCDataInput.java
/**
 * 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);
        }
    }
}
 
源代码18 项目: CodeChickenLib   文件: MCDataOutput.java
/**
 * Writes a {@link CompoundNBT} to the stream.
 *
 * @param tag The {@link CompoundNBT}.
 * @return The same stream.
 */
default MCDataOutput writeCompoundNBT(CompoundNBT tag) {
    if (tag == null) {
        writeBoolean(false);
    } else {
        try {
            writeBoolean(true);
            CompressedStreamTools.write(tag, toDataOutput());
        } catch (IOException e) {
            throw new EncoderException("Failed to write CompoundNBT to stream.", e);
        }
    }
    return this;
}
 
源代码19 项目: NotEnoughItems   文件: ItemPanelDumper.java
public void dumpNBT(File file) throws IOException {
    NBTTagList list = new NBTTagList();
    for (ItemStack stack : ItemPanel.items) {
        list.appendTag(stack.writeToNBT(new NBTTagCompound()));
    }

    NBTTagCompound tag = new NBTTagCompound();
    tag.setTag("list", list);

    CompressedStreamTools.writeCompressed(tag, new FileOutputStream(file));
}
 
源代码20 项目: NOVA-Core   文件: MCRetentionManager.java
public NBTTagCompound loadFile(File file) {
	try {
		if (file.exists()) {
			return CompressedStreamTools.readCompressed(new FileInputStream(file));
		} else {
			return new NBTTagCompound();
		}
	} catch (Exception e) {
		Game.logger().error("Failed to load {}!", file.getName());
		e.printStackTrace();
		return null;
	}
}
 
源代码21 项目: NOVA-Core   文件: MCRetentionManager.java
public NBTTagCompound loadFile(File file) {
	try {
		if (file.exists()) {
			return CompressedStreamTools.readCompressed(new FileInputStream(file));
		} else {
			return new NBTTagCompound();
		}
	} catch (Exception e) {
		Game.logger().error("Failed to load {}!", file.getName(), e);
		e.printStackTrace();
		return null;
	}
}
 
源代码22 项目: NOVA-Core   文件: MCRetentionManager.java
public NBTTagCompound loadFile(File file) {
	try {
		if (file.exists()) {
			return CompressedStreamTools.readCompressed(new FileInputStream(file));
		} else {
			return new NBTTagCompound();
		}
	} catch (Exception e) {
		Game.logger().error("Failed to load {}!", file.getName(), e);
		e.printStackTrace();
		return null;
	}
}
 
源代码23 项目: Gadomancy   文件: PacketSyncData.java
@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);
    }
}
 
源代码24 项目: Gadomancy   文件: PacketSyncData.java
@Override
public void toBytes(ByteBuf buf) {
    buf.writeInt(data.size());

    for(String key : data.keySet()) {
        AbstractData dat = data.get(key);
        NBTTagCompound cmp = new NBTTagCompound();
        if(shouldSyncAll) {
            dat.writeAllDataToPacket(cmp);
        } else {
            dat.writeToPacket(cmp);
        }

        StringHelper.writeToBuffer(buf, key);

        byte providerId = dat.getProviderID();
        buf.writeByte(providerId);

        byte[] abyte;
        try {
            abyte = CompressedStreamTools.compress(cmp);
        } catch (IOException e) {
            Gadomancy.log.warn("Compressing the NBTTagCompound of " + providerId + " threw an IOException! Skipping...");
            Gadomancy.log.warn("Exception message: " + e.getMessage());
            continue;
        }
        buf.writeShort((short) abyte.length);
        buf.writeBytes(abyte);
    }
}
 
源代码25 项目: NotEnoughItems   文件: NEIServerUtils.java
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;
}
 
源代码26 项目: NotEnoughItems   文件: ItemPanelDumper.java
public void dumpNBT(File file) throws IOException {
    NBTTagList list = new NBTTagList();
    for (ItemStack stack : ItemPanel.items)
        list.appendTag(stack.writeToNBT(new NBTTagCompound()));

    NBTTagCompound tag = new NBTTagCompound();
    tag.setTag("list", list);

    CompressedStreamTools.writeCompressed(tag, new FileOutputStream(file));
}
 
源代码27 项目: enderutilities   文件: ByteBufUtilsEU.java
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));
    }
}
 
源代码28 项目: enderutilities   文件: EnergyBridgeTracker.java
public static void readFromDisk()
{
    // Clear the data structures when reading the data for a world/save, so that valid Energy Bridges
    // from another world won't carry over to a world/save that doesn't have the file yet.
    BRIDGE_LOCATIONS.clear();
    BRIDGE_COUNTS.clear();
    bridgeCountInEndDimensions = 0;

    try
    {
        File saveDir = DimensionManager.getCurrentSaveRootDirectory();

        if (saveDir == null)
        {
            return;
        }

        File file = new File(new File(saveDir, Reference.MOD_ID), "energybridges.dat");

        if (file.exists() && file.isFile())
        {
            FileInputStream is = new FileInputStream(file);
            readFromNBT(CompressedStreamTools.readCompressed(is));
            is.close();
        }
    }
    catch (Exception e)
    {
        EnderUtilities.logger.warn("Failed to read Energy Bridge data from file!", e);
    }
}
 
源代码29 项目: enderutilities   文件: PlacementProperties.java
public void readFromDisk()
{
    // Clear the data structures when reading the data for a world/save, so that data
    // from another world won't carry over to a world/save that doesn't have the file yet.
    this.properties.clear();
    this.indices.clear();

    try
    {
        File saveDir = DimensionManager.getCurrentSaveRootDirectory();

        if (saveDir == null)
        {
            return;
        }

        File file = new File(new File(saveDir, Reference.MOD_ID), FILE_NAME_BASE + ".dat");

        if (file.exists() && file.isFile())
        {
            this.readFromNBT(CompressedStreamTools.readCompressed(new FileInputStream(file)));
        }
    }
    catch (Exception e)
    {
        EnderUtilities.logger.warn("Failed to read Placement Properties data from file");
    }
}
 
源代码30 项目: enderutilities   文件: TemplateManagerEU.java
private void readTemplateFromStream(String id, InputStream stream) throws IOException
{
    NBTTagCompound nbt = CompressedStreamTools.readCompressed(stream);

    if (nbt.hasKey("DataVersion", Constants.NBT.TAG_ANY_NUMERIC) == false)
    {
        nbt.setInteger("DataVersion", 500);
    }

    TemplateEnderUtilities template = new TemplateEnderUtilities();
    template.read(this.fixer.process(FixTypes.STRUCTURE, nbt));
    this.templates.put(id, template);
}