• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java NBTOutputStream类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.jnbt.NBTOutputStream的典型用法代码示例。如果您正苦于以下问题:Java NBTOutputStream类的具体用法?Java NBTOutputStream怎么用?Java NBTOutputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



NBTOutputStream类属于org.jnbt包,在下文中一共展示了NBTOutputStream类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: writeToFile

import org.jnbt.NBTOutputStream; //导入依赖的package包/类
/**
 * Writes this region to a file.
 * 
 * @param path The path to write the file
 * @throws IOException 
 */
public void writeToFile(File path) throws IOException {
	// Write region file
	RegionFile regionFile = new RegionFile(path);
	try {
		 for(int x = 0; x < CHUNKS_PER_REGION_SIDE; x++) {
			for(int z = 0; z < CHUNKS_PER_REGION_SIDE; z++) {
				Chunk chunk = chunks[x][z];
				if(chunk != null && chunk.hasBlocks()) {
					NBTOutputStream out = new NBTOutputStream(regionFile.getChunkDataOutputStream(x, z), false);
					try {
						out.writeTag(chunks[x][z].getTag());
					} finally {
						out.close();
					}
				}
			}
		}
	} finally {
		regionFile.close();
	}
}
 
开发者ID:r-ralph,项目名称:Transcendens,代码行数:28,代码来源:Region.java


示例2: saveChangesToFile

import org.jnbt.NBTOutputStream; //导入依赖的package包/类
/**
 * Writes the current root compound tag (and value tags) to the given file.
 *
 * <p>
 * If the file doesn't exist it will be created.
 * </p>
 *
 * @param path <b>String</b> path to file
 * @throws FileNotFoundException
 * @throws IOException
 */
public void saveChangesToFile(final String path) throws FileNotFoundException, IOException {
    if (path.equals("")) {
        throw new IllegalArgumentException("Path is empty");
    }

    final File f = new File(path);

    if (!f.exists()) {
        if (f.getParentFile() != null) {
            f.getParentFile().mkdirs();
        }

        f.createNewFile();
    }

    try (final NBTOutputStream out = new NBTOutputStream(new FileOutputStream(f))) {
        out.writeTag(this.root);
    }
}
 
开发者ID:ssauermann,项目名称:BlockAPI,代码行数:31,代码来源:SchematicWrapper.java


示例3: saveChunk

import org.jnbt.NBTOutputStream; //导入依赖的package包/类
public void saveChunk(EnderChunk chunk) {
    EnderLogger.debug("Save: " + chunk);
    int x = chunk.getX(), z = chunk.getZ();
    long key = ((long) calculateRegionPos(x) << 32) ^ calculateRegionPos(z);
    synchronized (regionFileCache) {
        RegionFile region = regionFileCache.get(Long.valueOf(key));
        if (region == null) {
            region = new RegionFile(new File(regionDirectory, "r." + calculateRegionPos(x) + "." + calculateRegionPos(z) + ".mca"));
            regionFileCache.put(key, region);
        }
        try (DataOutputStream out = region.getChunkDataOutputStream(calculateChunkPos(x), calculateChunkPos(z))) {
            try (NBTOutputStream out1 = new NBTOutputStream(out)) {
                out1.writeTag(chunk.saveToNBT());
            }
        } catch (IOException ex) {
            EnderLogger.warn("Error while saving chunk");
            EnderLogger.exception(ex);
        }
    }
    chunk.chunkState.set(EnderChunk.ChunkState.LOADED);
}
 
开发者ID:SanderGielisse,项目名称:Enderstone,代码行数:22,代码来源:ChunkManager.java


示例4: clone

import org.jnbt.NBTOutputStream; //导入依赖的package包/类
@Override
public ItemStack clone() {
	try {
		ItemStack s = (ItemStack) super.clone();
		if (compoundTag == null) return s;
		ByteArrayOutputStream bytes = new ByteArrayOutputStream();
		try (NBTOutputStream stream = new NBTOutputStream(bytes)) {
			stream.writeTag(compoundTag);
		}
		try (NBTInputStream stream = new NBTInputStream(new ByteArrayInputStream(bytes.toByteArray()))) {
			s.setCompoundTag((CompoundTag) stream.readTag());
		}
		return s;
	} catch (CloneNotSupportedException | IOException err) {
		throw new AssertionError(err);
	}
}
 
开发者ID:SanderGielisse,项目名称:Enderstone,代码行数:18,代码来源:ItemStack.java


示例5: writeItemStack

import org.jnbt.NBTOutputStream; //导入依赖的package包/类
public void writeItemStack(ItemStack stack) {
	if (stack == null) {
		this.writeShort(-1);
		return;
	}
	this.writeShort(stack.getBlockId());
	this.writeByte(stack.getAmount());
	this.writeShort(stack.getDamage());

	if (stack.getCompoundTag() == null) {
		this.writeByte(0);
		return;
	}
	try (NBTOutputStream outStream = new NBTOutputStream(new DataOutputStream(new ByteBufOutputStream(this.buffer)))) {
		outStream.writeTag(stack.getCompoundTag());
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:SanderGielisse,项目名称:Enderstone,代码行数:20,代码来源:PacketDataWrapper.java


示例6: save

import org.jnbt.NBTOutputStream; //导入依赖的package包/类
/**
 * Saves the level.dat to the disk.
 * @throws IOException
 */
public void save() throws IOException {
	
	//Create a NBT output stream.
	FileOutputStream fos = new FileOutputStream(file);
	GZIPOutputStream gzipOs = new GZIPOutputStream(fos);
	NBTOutputStream nbtOs = new NBTOutputStream(gzipOs);
	
	//Create new tags. Sorted like in level.dat.
	ByteTag 	tagThundering 	= new ByteTag("thundering", thundering);
	LongTag 	tagLastPlayed 	= new LongTag("LastPlayed", lastPlayed);
	LongTag 	tagRandomSeed 	= new LongTag("RandomSeed", randomSeed);
	IntTag 		tagVersion 		= new IntTag("version", version);
	LongTag 	tagTime 		= new LongTag("Time", time);
	ByteTag 	tagRaining 		= new ByteTag("raining", raining);
	IntTag 		tagSpawnX 		= new IntTag("SpawnX", spawnX);
	IntTag 		tagThunderTime 	= new IntTag("thunderTime", thunderTime);
	IntTag 		tagSpawnY 		= new IntTag("SpawnY", spawnY);
	IntTag 		tagSpawnZ 		= new IntTag("SpawnZ", spawnZ);
	StringTag 	tagLevelName 	= new StringTag("LevelName", levelName);
	LongTag 	tagSizeOnDisk 	= new LongTag("SizeOnDisk", sizeOnDisk);
	IntTag 		tagRainTime 	= new IntTag("rainTime", rainTime);
	
	Map<String, Tag> dataMap = new HashMap<String, Tag>();
	dataMap.put("thundering", tagThundering);
	dataMap.put("LastPlayed", tagLastPlayed);
	dataMap.put("RandomSeed", tagRandomSeed);
	dataMap.put("version", tagVersion);
	dataMap.put("Time", tagTime);
	dataMap.put("raining", tagRaining);
	dataMap.put("SpawnX", tagSpawnX);
	dataMap.put("thunderTime", tagThunderTime);
	dataMap.put("SpawnY", tagSpawnY);
	dataMap.put("SpawnZ", tagSpawnZ);
	dataMap.put("LevelName", tagLevelName);
	dataMap.put("SizeOnDisk", tagSizeOnDisk);
	dataMap.put("rainTime", tagRainTime);
	
	//Find through the compound clutter.
	CompoundTag dataTag = new CompoundTag("Data", dataMap);
	Map<String, Tag> rootMap = new HashMap<String, Tag>();
	rootMap.put("Data", dataTag);
	CompoundTag rootTag = new CompoundTag("", rootMap);
	
	nbtOs.writeTag(rootTag);
	
	//Flush and close the output streams.
	nbtOs.close();
	fos.close();
	
}
 
开发者ID:sd5,项目名称:mcBetaTerrainGenerator,代码行数:55,代码来源:LevelFile.java



注:本文中的org.jnbt.NBTOutputStream类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java StackPopLevel类代码示例发布时间:2022-05-22
下一篇:
Java ClusterInfo类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap