本文整理汇总了Java中org.jnbt.NBTInputStream.readTag方法的典型用法代码示例。如果您正苦于以下问题:Java NBTInputStream.readTag方法的具体用法?Java NBTInputStream.readTag怎么用?Java NBTInputStream.readTag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jnbt.NBTInputStream
的用法示例。
在下文中一共展示了NBTInputStream.readTag方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTag
import org.jnbt.NBTInputStream; //导入方法依赖的package包/类
/**
* Reads a tag from the chunk data.
* @param chunkX: Relative chunk x-coordinate of the chunk.
* @param chunkZ: Relative chunk x-coordinate of the chunk.
* @param tagName
* @return: The tag of the chunk with the given name.
* @throws ChunkNotFoundException: If the chunk at the given coordinates was not found.
* @throws TagNotFoundException: If the tag with the given name was not found.
*/
private Tag getTag(int chunkX, int chunkZ, String tagName) throws ChunkNotFoundException, TagNotFoundException {
try {
DataInputStream chunkData = getChunkAsStream(chunkX, chunkZ);
NBTInputStream nbtIs = new NBTInputStream(chunkData);
CompoundTag rootTag = (CompoundTag) nbtIs.readTag();
Map<String, Tag> rootMap = rootTag.getValue();
CompoundTag levelTag = (CompoundTag) rootMap.get("Level");
Map<String, Tag> levelMap = levelTag.getValue();
Tag tag = levelMap.get(tagName);
if(tag == null) {
throw new TagNotFoundException();
}
return levelMap.get(tagName);
} catch(IOException e) {
e.printStackTrace();
} return null;
}
示例2: load
import org.jnbt.NBTInputStream; //导入方法依赖的package包/类
/**
* Load a custom object in schematic format from an input stream. The stream
* is closed before exiting the method.
*
* @param name The name of the object.
* @param stream The input stream from which to load the object.
* @return A new <code>Schematic</code> containing the contents of the
* specified stream.
* @throws IOException If an I/O error occurred while reading the stream.
*/
public static Schematic load(String name, InputStream stream) throws IOException {
InputStream in = new BufferedInputStream(stream);
//noinspection TryFinallyCanBeTryWithResources // Not possible due to assignment of 'in' inside block
try {
byte[] magicNumber = new byte[2];
in.mark(2);
in.read(magicNumber);
in.reset();
if ((magicNumber[0] == (byte) 0x1f) && (magicNumber[1] == (byte) 0x8b)) {
in = new GZIPInputStream(in);
}
NBTInputStream nbtIn = new NBTInputStream(in);
CompoundTag tag = (CompoundTag) nbtIn.readTag();
return new Schematic(name, tag, null);
} finally {
in.close();
}
}
示例3: loadSchematic
import org.jnbt.NBTInputStream; //导入方法依赖的package包/类
public static Schematic loadSchematic(File file) throws IOException {
FileInputStream stream = new FileInputStream(file);
NBTInputStream nbtStream = new NBTInputStream(stream);
CompoundTag schematicTag = (CompoundTag)nbtStream.readTag();
nbtStream.close();
if(!schematicTag.getName().equals("Schematic")) {
throw new IllegalArgumentException("Tag \"Schematic\" does not exist or is not first");
}
Map<String, Tag> schematic = schematicTag.getValue();
if(!schematic.containsKey("Blocks")) {
throw new IllegalArgumentException("Schematic file is missing a \"Blocks\" tag");
}
short width = getChildTag(schematic, "Width", ShortTag.class).getValue();
short length = getChildTag(schematic, "Length", ShortTag.class).getValue();
short height = getChildTag(schematic, "Height", ShortTag.class).getValue();
String materials = getChildTag(schematic, "Materials", StringTag.class).getValue();
if(!materials.equals("Alpha")) {
throw new IllegalArgumentException("Schematic file is not an Alpha schematic");
}
byte[] blocks = getChildTag(schematic, "Blocks", ByteArrayTag.class).getValue();
byte[] blockData = getChildTag(schematic, "Data", ByteArrayTag.class).getValue();
return new Schematic(blocks, blockData, width, length, height);
}
示例4: loadUUIDSFirstTime
import org.jnbt.NBTInputStream; //导入方法依赖的package包/类
private static void loadUUIDSFirstTime(LocalUUIDCache plugin, File uuidFile, final File[] files)
{
if(!plugin.getDataFolder().exists())
plugin.getDataFolder().mkdir();
else if(uuidFile.exists())
uuidFile.delete();
else
{
try
{
uuidFile.createNewFile();
}
catch (IOException e)
{
e.printStackTrace();
}
}
int size = 0;
for(File file : files)
{
if(isUUID(file.getName()))
{
try
{
FileInputStream fStream = new FileInputStream(file);
NBTInputStream stream = new NBTInputStream(fStream);
Tag playerData = stream.readTag();
stream.close();
fStream.close();
final CompoundTag playerDataCompound = (CompoundTag)playerData;
if(playerDataCompound.getValue().get("bukkit") != null)
{
final CompoundTag bukkit = (CompoundTag) playerDataCompound.getValue().get("bukkit");
if(bukkit.getValue().get("lastKnownName") != null)
{
final Tag name = bukkit.getValue().get("lastKnownName");
final String lastKnownName = (String) name.getValue();
final UUID uuid = UUID.fromString(file.getName().substring(0, file.getName().indexOf(".")));
if(uuid != null)
ids.put(uuid, lastKnownName);
size += 1;
if((size % 1000) == 0)
System.out.println(size + " uuids loaded in!");
}
}
}
catch(IOException ex)
{
ex.printStackTrace();
}
}
}
LocalUUIDCache.getInstance().logger.log(Level.INFO, ids.values().size() + " uuids loaded");
}
示例5: loadSchematic
import org.jnbt.NBTInputStream; //导入方法依赖的package包/类
@SuppressWarnings("resource")
public static Schematic loadSchematic(File file) throws IOException
{
FileInputStream stream = new FileInputStream(file);
NBTInputStream nbtStream = new NBTInputStream(stream);
CompoundTag schematicTag = (CompoundTag) nbtStream.readTag();
if (!schematicTag.getName().equals("Schematic")) {
throw new IllegalArgumentException("Tag \"Schematic\" does not exist or is not first");
}
Map<String, Tag> schematic = schematicTag.getValue();
if (!schematic.containsKey("Blocks")) {
throw new IllegalArgumentException("Schematic file is missing a \"Blocks\" tag");
}
short width = getChildTag(schematic, "Width", ShortTag.class).getValue();
short length = getChildTag(schematic, "Length", ShortTag.class).getValue();
short height = getChildTag(schematic, "Height", ShortTag.class).getValue();
// Get blocks
byte[] blockId = getChildTag(schematic, "Blocks", ByteArrayTag.class).getValue();
byte[] blockData = getChildTag(schematic, "Data", ByteArrayTag.class).getValue();
byte[] addId = new byte[0];
short[] blocks = new short[blockId.length]; // Have to later combine IDs
// We support 4096 block IDs using the same method as vanilla Minecraft, where
// the highest 4 bits are stored in a separate byte array.
if (schematic.containsKey("AddBlocks")) {
addId = getChildTag(schematic, "AddBlocks", ByteArrayTag.class).getValue();
}
// Combine the AddBlocks data with the first 8-bit block ID
for (int index = 0; index < blockId.length; index++) {
if ((index >> 1) >= addId.length) { // No corresponding AddBlocks index
blocks[index] = (short) (blockId[index] & 0xFF);
} else {
if ((index & 1) == 0) {
blocks[index] = (short) (((addId[index >> 1] & 0x0F) << 8) + (blockId[index] & 0xFF));
} else {
blocks[index] = (short) (((addId[index >> 1] & 0xF0) << 4) + (blockId[index] & 0xFF));
}
}
}
return new Schematic(file.getName().replace(".schematic", ""), blocks, blockData, width, length, height);
}
示例6: getLevelTag
import org.jnbt.NBTInputStream; //导入方法依赖的package包/类
private CompoundTag getLevelTag(NBTInputStream nis) throws IOException {
CompoundTag rootTag = (CompoundTag) nis.readTag();
return getCompoundTagFromTag(rootTag, LEVEL);
}
示例7: loadSchematic
import org.jnbt.NBTInputStream; //导入方法依赖的package包/类
public Schematic loadSchematic(File file){
try{
if(file.exists()){
NBTInputStream nbtStream = new NBTInputStream(new FileInputStream(file));
CompoundTag compound = (CompoundTag) nbtStream.readTag();
Map<String, Tag> tags = compound.getValue();
Short width = ((ShortTag) tags.get("Width")).getValue();
Short height = ((ShortTag) tags.get("Height")).getValue();
Short length = ((ShortTag) tags.get("Length")).getValue();
String materials = ((StringTag) tags.get("Materials")).getValue();
byte[] blocksId = ((ByteArrayTag) tags.get("Blocks")).getValue();
byte[] data = ((ByteArrayTag) tags.get("Data")).getValue();
//ive found this at the github of the makers of worldedit so credits to them, it looks I was doing it wrong by using byte[] at the first place
//and the datavalues are hex while a byte is not hex but a short can accept hex as 16, now the only thing to learn is the Tag AddBlocks and why it is used.
short[] blocks = new short[blocksId.length];
//need to look a bit over this.
byte[] addId = new byte[0];
if (tags.containsKey("AddBlocks")) {
addId = ((ByteArrayTag) tags.get("AddBlocks")).getValue();
}
// Combine the AddBlocks data with the first 8-bit block ID
for (int index = 0; index < blocksId.length; index++) {
if ((index >> 1) >= addId.length) { // No corresponding AddBlocks index
blocks[index] = (short) (blocksId[index] & 0xFF);
} else {
if ((index & 1) == 0) {
blocks[index] = (short) (((addId[index >> 1] & 0x0F) << 8) + (blocksId[index] & 0xFF));
} else {
blocks[index] = (short) (((addId[index >> 1] & 0xF0) << 4) + (blocksId[index] & 0xFF));
}
}
}
//end of worldedit snippet.
nbtStream.close();
Schematic schematic = new Schematic(file.getName().replace(".schematic", ""), width, height, length, materials, blocks, data);
return schematic;
}
} catch(Exception e){
ManCo.log(LogType.SEVERE, "could not load this file: " + file.getName());
e.printStackTrace();
}
return null;
}
示例8: loadSchematic
import org.jnbt.NBTInputStream; //导入方法依赖的package包/类
public Schematic loadSchematic(File file){
try{
if(file.exists()){
NBTInputStream nbtStream = new NBTInputStream(new FileInputStream(file));
CompoundTag compound = (CompoundTag) nbtStream.readTag();
Map<String, Tag> tags = compound.getValue();
short width = ((ShortTag) tags.get("Width")).getValue();
short height = ((ShortTag) tags.get("Height")).getValue();
short length = ((ShortTag) tags.get("Length")).getValue();
String materials = ((StringTag) tags.get("Materials")).getValue();
byte[] blocksId = ((ByteArrayTag) tags.get("Blocks")).getValue();
byte[] data = ((ByteArrayTag) tags.get("Data")).getValue();
//ive found this at the github of the makers of worldedit so credits to them, it looks I was doing it wrong by using byte[] at the first place
//and the datavalues are hex while a byte is not hex but a short can accept hex as 16, now the only thing to learn is the Tag AddBlocks and why it is used.
short[] blocks = new short[blocksId.length];
//need to look a bit over this.
byte[] addId = new byte[0];
if (tags.containsKey("AddBlocks")) {
addId = ((ByteArrayTag) tags.get("AddBlocks")).getValue();
}
// Combine the AddBlocks data with the first 8-bit block ID
for (int index = 0; index < blocksId.length; index++) {
if ((index >> 1) >= addId.length) { // No corresponding AddBlocks index
blocks[index] = (short) (blocksId[index] & 0xFF);
} else {
if ((index & 1) == 0) {
blocks[index] = (short) (((addId[index >> 1] & 0x0F) << 8) + (blocksId[index] & 0xFF));
} else {
blocks[index] = (short) (((addId[index >> 1] & 0xF0) << 4) + (blocksId[index] & 0xFF));
}
}
}
//end of worldedit snippet.
nbtStream.close();
Schematic schematic = new Schematic(file.getName().replace(".schematic", ""), width, height, length, materials, blocks, data);
return schematic;
}
} catch(Exception e){
ManCo.log(LogType.SEVERE, "could not load this file: " + file.getName());
e.printStackTrace();
}
return null;
}
示例9: LevelFile
import org.jnbt.NBTInputStream; //导入方法依赖的package包/类
/**
* Loads the level.dat and reads the stored values.
* @param path The path to the level.dat
*/
public LevelFile(File path) {
try {
this.file = new File(path.getAbsolutePath());
//Create a NBT input stream.
FileInputStream fis = new FileInputStream(file);
GZIPInputStream gzipIs = new GZIPInputStream(fis);
NBTInputStream nbtIs = new NBTInputStream(gzipIs);
//Find through the compound clutter.
CompoundTag rootTag = (CompoundTag) nbtIs.readTag();
Map<String, Tag> rootMap = rootTag.getValue();
CompoundTag dataTag = (CompoundTag) rootMap.get("Data");
Map<String, Tag> dataMap = dataTag.getValue();
//Load the values from level.dat. Sorted like in level.dat.
thundering = (Byte) dataMap.get("thundering").getValue();
lastPlayed = (Long) dataMap.get("LastPlayed").getValue();
randomSeed = (Long) dataMap.get("RandomSeed").getValue();
version = (Integer) dataMap.get("version").getValue();
time = (Long) dataMap.get("Time").getValue();
raining = (Byte) dataMap.get("raining").getValue();
spawnX = (Integer) dataMap.get("SpawnX").getValue();
thunderTime = (Integer) dataMap.get("thunderTime").getValue();
spawnY = (Integer) dataMap.get("SpawnY").getValue();
spawnZ = (Integer) dataMap.get("SpawnZ").getValue();
levelName = (String) dataMap.get("LevelName").getValue();
sizeOnDisk = (Long) dataMap.get("SizeOnDisk").getValue();
rainTime = (Integer) dataMap.get("rainTime").getValue();
//Close the input streams.
nbtIs.close();
fis.close();
} catch(IOException e) {
e.printStackTrace();
}
}