net.minecraft.nbt.CompressedStreamTools Java Examples
The following examples show how to use
net.minecraft.nbt.CompressedStreamTools.
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: TemplateManager.java From GregTech with GNU Lesser General Public License v3.0 | 6 votes |
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; }
Example #2
Source File: MsgTileEntities.java From archimedes-ships with MIT License | 6 votes |
@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 #3
Source File: StructureUtil.java From YUNoMakeGoodMap with Apache License 2.0 | 6 votes |
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; }
Example #4
Source File: ByteBufUtilsEU.java From enderutilities with GNU Lesser General Public License v3.0 | 6 votes |
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); } }
Example #5
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 #6
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 #7
Source File: QCraftProxyCommon.java From qcraft-mod with Apache License 2.0 | 6 votes |
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; }
Example #8
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 #9
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 #10
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 #11
Source File: NEIServerUtils.java From NotEnoughItems with MIT License | 6 votes |
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 #12
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 #13
Source File: HyperiumServerList.java From Hyperium with GNU Lesser General Public License v3.0 | 6 votes |
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); } }
Example #14
Source File: HyperiumServerList.java From Hyperium with GNU Lesser General Public License v3.0 | 6 votes |
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 #15
Source File: SaveStates.java From NBTEdit with GNU General Public License v3.0 | 5 votes |
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 #16
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 #17
Source File: MCDataInput.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
/** * 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 #18
Source File: EnergyBridgeTracker.java From enderutilities with GNU Lesser General Public License v3.0 | 5 votes |
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); } }
Example #19
Source File: PlacementProperties.java From enderutilities with GNU Lesser General Public License v3.0 | 5 votes |
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"); } }
Example #20
Source File: TemplateManagerEU.java From enderutilities with GNU Lesser General Public License v3.0 | 5 votes |
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); }
Example #21
Source File: TemplateManagerEU.java From enderutilities with GNU Lesser General Public License v3.0 | 5 votes |
private void readTemplateMetadataFromStream(String id, InputStream stream) throws IOException { NBTTagCompound nbt = CompressedStreamTools.readCompressed(stream); TemplateMetadata templateMeta = new TemplateMetadata(); templateMeta.read(nbt); this.templateMetas.put(id, templateMeta); }
Example #22
Source File: ByteBufUtilsEU.java From enderutilities with GNU Lesser General Public License v3.0 | 5 votes |
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 #23
Source File: SaveStates.java From NBTEdit with GNU General Public License v3.0 | 5 votes |
public void write() throws IOException{ NBTTagCompound root = new NBTTagCompound(); for (int i = 0; i <7; ++i){ root.setTag("slot" + (i+1), tags[i].tag); root.setString("slot" + (i+1)+"Name", tags[i].name); } CompressedStreamTools.write(root, file); }
Example #24
Source File: MsgTileEntities.java From archimedes-ships with MIT License | 5 votes |
@Override public void encodeInto(ChannelHandlerContext ctx, ByteBuf buf) throws IOException { super.encodeInto(ctx, buf); tagCompound = new NBTTagCompound(); NBTTagList list = new NBTTagList(); for (TileEntity te : ship.getShipChunk().chunkTileEntityMap.values()) { NBTTagCompound nbt = new NBTTagCompound(); if (te instanceof TileEntityHelm) { ((TileEntityHelm) te).writeNBTforSending(nbt); } else { te.writeToNBT(nbt); } list.appendTag(nbt); } tagCompound.setTag("list", list); DataOutputStream out = new DataOutputStream(new ByteBufOutputStream(buf)); try { CompressedStreamTools.write(tagCompound, out); out.flush(); } catch (IOException e) { throw e; } finally { out.close(); } }
Example #25
Source File: IoUtil.java From EnderZoo with Creative Commons Zero v1.0 Universal | 5 votes |
public static NBTTagCompound readNBTTagCompound(ByteBuf dataIn) { try { short size = dataIn.readShort(); if (size < 0) { return null; } else { byte[] buffer = new byte[size]; dataIn.readBytes(buffer); return CompressedStreamTools.readCompressed(new ByteArrayInputStream(buffer)); } } catch (IOException e) { FMLCommonHandler.instance().raiseException(e, "Custom Packet", true); return null; } }
Example #26
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 #27
Source File: MCDataOutputWrapper.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
public MCDataOutputWrapper writeNBTTagCompound(NBTTagCompound nbt) { if (nbt == null) this.writeByte(0); else try { CompressedStreamTools.write(nbt, dataout); } catch (IOException ioexception) { throw new EncoderException(ioexception); } return this; }
Example #28
Source File: ItemUtils.java From OpenModsLib with MIT License | 5 votes |
/** * This function returns fingerprint of NBTTag. It can be used to compare two tags */ public static String getNBTHash(NBTTagCompound tag) { try { MessageDigest digest = MessageDigest.getInstance("MD5"); OutputStream dump = new NullOutputStream(); DigestOutputStream hasher = new DigestOutputStream(dump, digest); DataOutput output = new DataOutputStream(hasher); CompressedStreamTools.write(tag, output); byte[] hash = digest.digest(); return new String(Hex.encodeHex(hash)); } catch (IOException | NoSuchAlgorithmException e) { throw new RuntimeException(e); } }
Example #29
Source File: MCRetentionManager.java From NOVA-Core with GNU Lesser General Public License v3.0 | 5 votes |
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; } }
Example #30
Source File: MCDataOutput.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
/** * 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; }