Java Code Examples for net.minecraft.nbt.CompressedStreamTools#writeCompressed()
The following examples show how to use
net.minecraft.nbt.CompressedStreamTools#writeCompressed() .
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: EnderStorageManager.java From EnderStorage with MIT License | 6 votes |
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); } } }
Example 2
Source File: MCRetentionManager.java From NOVA-Core with GNU Lesser General Public License v3.0 | 6 votes |
/** * 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; } }
Example 3
Source File: MCRetentionManager.java From NOVA-Core with GNU Lesser General Public License v3.0 | 6 votes |
/** * 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; } }
Example 4
Source File: MCRetentionManager.java From NOVA-Core with GNU Lesser General Public License v3.0 | 6 votes |
/** * 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; } }
Example 5
Source File: QCraftProxyCommon.java From qcraft-mod with Apache License 2.0 | 6 votes |
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" ); } }
Example 6
Source File: EnderStorageManager.java From EnderStorage with MIT License | 6 votes |
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); } } }
Example 7
Source File: MaterialCache.java From litematica with GNU Lesser General Public License v3.0 | 5 votes |
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; }
Example 8
Source File: ItemPanelDumper.java From NotEnoughItems with MIT License | 5 votes |
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)); }
Example 9
Source File: ItemPanelDumper.java From NotEnoughItems with MIT License | 5 votes |
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)); }
Example 10
Source File: IoUtil.java From EnderZoo with Creative Commons Zero v1.0 Universal | 5 votes |
public static void writeNBTTagCompound(NBTTagCompound compound, ByteBuf dataout) { try { if (compound == null) { dataout.writeShort(-1); } else { ByteArrayOutputStream baos = new ByteArrayOutputStream(); CompressedStreamTools.writeCompressed(compound, baos); byte[] buf = baos.toByteArray(); dataout.writeShort((short) buf.length); dataout.writeBytes(buf); } } catch (IOException e) { FMLCommonHandler.instance().raiseException(e, "IoUtil.writeNBTTagCompound", true); } }
Example 11
Source File: ISchematic.java From litematica with GNU Lesser General Public License v3.0 | 4 votes |
default void writeToStream(NBTTagCompound tag, FileOutputStream outputStream) throws IOException { CompressedStreamTools.writeCompressed(tag, outputStream); }
Example 12
Source File: NEIServerUtils.java From NotEnoughItems with MIT License | 4 votes |
public static void writeNBT(NBTTagCompound tag, File file) throws IOException { FileOutputStream out = new FileOutputStream(file); CompressedStreamTools.writeCompressed(tag, out); out.close(); }
Example 13
Source File: NEIServerUtils.java From NotEnoughItems with MIT License | 4 votes |
public static void writeNBT(NBTTagCompound tag, File file) throws IOException { FileOutputStream out = new FileOutputStream(file); CompressedStreamTools.writeCompressed(tag, out); out.close(); }
Example 14
Source File: MoCTools.java From mocreaturesdev with GNU General Public License v3.0 | 4 votes |
/** * Reduces the counter on the offline player * * @param playername */ public static void reduceTamedByOfflinePlayer(String playername) { NBTTagCompound compound = ((SaveHandler) ((WorldServer) MinecraftServer.getServer().worldServerForDimension(0)).getSaveHandler()).getPlayerData(playername); if (compound != null && compound.hasKey("ForgeData")) { NBTTagCompound nbtt = compound.getCompoundTag("ForgeData"); int count = nbtt.getInteger("NumberTamed"); //System.out.println("tamed entities for player " + playername + " =" + count); count--; if (count < 0) { count = 0; } nbtt.setInteger("NumberTamed", count); compound.setCompoundTag("ForgeData", nbtt); try { SaveHandler saveHandler = ((SaveHandler) ((WorldServer) MinecraftServer.getServer().worldServerForDimension(0)).getSaveHandler()); // as long as we know the world folder name we can generate the path to players directory // still need to test how other worlds will work String playersDirectory = ".\\" + saveHandler.getWorldDirectoryName() + "\\players\\"; File playerFile = new File(playersDirectory + playername + ".dat"); File playerFileNew = new File(playersDirectory, playername + ".tmp"); //System.out.println("playerFile = " + playerFile + ", playerFileNew = " + playerFileNew + ", playerFile parent = " + playerFile.getParent()); CompressedStreamTools.writeCompressed(compound, new FileOutputStream(playerFileNew)); if (playerFile.exists()) { playerFile.delete(); } playerFileNew.renameTo(playerFile); // test to see if changes took effect compound = ((SaveHandler) ((WorldServer) MinecraftServer.getServer().worldServerForDimension(0)).getSaveHandler()).getPlayerData(playername); if (compound.hasKey("ForgeData")) { NBTTagCompound nbttest = compound.getCompoundTag("ForgeData"); //System.out.println("tamed entities for player " + playername + " is now " + nbttest.getInteger("NumberTamed")); } } catch (Exception e) { e.printStackTrace(); } } }
Example 15
Source File: SyncableInventory.java From OpenPeripheral-Addons with MIT License | 4 votes |
@Override public void writeToStream(DataOutputStream stream) throws IOException { NBTTagCompound tag = new NBTTagCompound(); writeToNBT(tag); CompressedStreamTools.writeCompressed(tag, stream); }