当前位置: 首页>>代码示例>>Java>>正文


Java Tag类代码示例

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


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

示例1: addTag

import org.jnbt.Tag; //导入依赖的package包/类
/**
 * Copy the values of a compound tag to a new map and add a new tag. An
 * existing tag with the same name is replaced.
 *
 * @param t <b>Tag</b> new tag
 * @param parentTag <b>CompoundTag</b> parent tag
 * @return <b>Map&lt;String, Tag&gt;</b> map with the old values and the new
 *         one
 */
// Can't be null (checked by Guava)
@SuppressWarnings("null")
private static Map<String, Tag> addTag(final Tag t, final CompoundTag parentTag) {
    final Map<String, Tag> map = new HashMap<>();

    // Copy old Map
    for (final Tag old : parentTag.getValue().values()) {
        map.put(checkNotNull(old.getName()), old);
    }

    // Add t to map (replace possibly existing old value)
    map.put(checkNotNull(t.getName()), t);

    return map;
}
 
开发者ID:ssauermann,项目名称:BlockAPI,代码行数:25,代码来源:SchematicWrapper.java

示例2: getTag

import org.jnbt.Tag; //导入依赖的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;
}
 
开发者ID:sd5,项目名称:AncientTerrain,代码行数:33,代码来源:Region.java

示例3: toNBT

import org.jnbt.Tag; //导入依赖的package包/类
@Override
public Tag toNBT() {
    setByteArray(TAG_BLOCKS, blocks);
    setByteArray(TAG_DATA, data);
    setByteArray(TAG_SKY_LIGHT, skyLight);
    setByteArray(TAG_BLOCK_LIGHT, blockLight);
    setByteArray(TAG_HEIGHT_MAP, heightMap);
    List<Tag> entityTags = new ArrayList<>(entities.size());
    entityTags.addAll(entities.stream().map(Entity::toNBT).collect(toList()));
    setList(TAG_ENTITIES, CompoundTag.class, entityTags);
    List<Tag> tileEntityTags = new ArrayList<>(entities.size());
    tileEntityTags.addAll(tileEntities.stream().map(TileEntity::toNBT).collect(toList()));
    setList(TAG_TILE_ENTITIES, CompoundTag.class, tileEntityTags);
    setLong(TAG_LAST_UPDATE, System.currentTimeMillis());
    setInt(TAG_X_POS, xPos);
    setInt(TAG_Z_POS, zPos);
    setBoolean(TAG_TERRAIN_POPULATED, terrainPopulated);

    return new CompoundTag("", Collections.singletonMap("", super.toNBT()));
}
 
开发者ID:Captain-Chaos,项目名称:WorldPainter,代码行数:21,代码来源:ChunkImpl.java

示例4: toNBT

import org.jnbt.Tag; //导入依赖的package包/类
@Override
public Tag toNBT() {
    setByte(TAG_Y2, level);
    setByteArray(TAG_BLOCKS, blocks);
    if (add != null) {
        for (byte b: add) {
            if (b != 0) {
                setByteArray(TAG_ADD, add);
                break;
            }
        }
    }
    setByteArray(TAG_DATA, data);
    setByteArray(TAG_SKY_LIGHT, skyLight);
    setByteArray(TAG_BLOCK_LIGHT, blockLight);
    return super.toNBT();
}
 
开发者ID:Captain-Chaos,项目名称:WorldPainter,代码行数:18,代码来源:ChunkImpl2.java

示例5: loadChildren

import org.jnbt.Tag; //导入依赖的package包/类
@Override
protected Node[] loadChildren() {
    try (InputStream in = new BufferedInputStream(new FileInputStream(file))) {
        in.mark(2);
        Tag tag;
        if ((in.read() == 0x1f) && (in.read() == 0x8b)) {
            // Gzip signature
            in.reset();
            tag = new NBTInputStream(new GZIPInputStream(in)).readTag();
        } else {
            tag = new NBTInputStream(in).readTag();
        }
        return new Node[] {new TagNode(tag)};
    } catch (IOException e) {
        throw new RuntimeException("I/O error while reading level.dat file", e);
    }
}
 
开发者ID:Captain-Chaos,项目名称:WorldPainter,代码行数:18,代码来源:NBTFileNode.java

示例6: getChildTag

import org.jnbt.Tag; //导入依赖的package包/类
/**
* Get child tag of a NBT structure.
*
* @param items The parent tag map
* @param key The name of the tag to get
* @param expected The expected type of the tag
* @return child tag casted to the expected type
* @throws DataException if the tag does not exist or the tag is not of the
* expected type
*/
private static <T extends Tag> T getChildTag(Map<String, Tag> items, String key, Class<T> expected) throws IllegalArgumentException
{
    if (!items.containsKey(key)) {
        throw new IllegalArgumentException("Schematic file is missing a \"" + key + "\" tag");
    }
    Tag tag = items.get(key);
    if (!expected.isInstance(tag)) {
        throw new IllegalArgumentException(key + " tag is not of tag type " + expected.getName());
    }
    return expected.cast(tag);
}
 
开发者ID:TheBusyBiscuit,项目名称:ExoticGarden,代码行数:22,代码来源:Schematic.java

示例7: getTag

import org.jnbt.Tag; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public Tag getTag() {
	// Create tag
	CompoundTagFactory factory = new CompoundTagFactory("");
	factory.set(new ByteArrayTag("Blocks", blockIds));
	factory.set(new ByteArrayTag("Data", blockData.getBytes()));
	factory.set(new ByteArrayTag("BlockLight", new NibbleArray(BLOCKS_PER_SECTION).getBytes()));
	factory.set(new ByteArrayTag("SkyLight", skyLight.getBytes()));
	factory.set(new ByteTag("Y", (byte)y));
	return factory.getTag();
}
 
开发者ID:r-ralph,项目名称:Transcendens,代码行数:15,代码来源:Section.java

示例8: getTag

import org.jnbt.Tag; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public Tag getTag() {
	// Get section tags
	ListTagFactory factory = new ListTagFactory("Sections", CompoundTag.class);
	for(Section section : sections) {
		if(section != null && section.getBlockCount() > 0) {
			factory.add(section.getTag());
		}
	}
	
	// Make level tags
	CompoundTagFactory factory2 = new CompoundTagFactory("Level");
	factory2.set(factory.getTag());
	factory2.set(new IntTag("xPos", xPos));
	factory2.set(new IntTag("zPos", zPos));
	factory2.set(new LongTag("LastUpdate", System.currentTimeMillis()));
	factory2.set(new ByteTag("V", (byte)1));
	factory2.set(new ByteTag("LightPopulated", (byte)1));
	factory2.set(new ByteTag("TerrainPopulated", (byte)1));
	
	// Make height map
	int[] heightMapAry = new int[BLOCKS_PER_CHUNK_SIDE * BLOCKS_PER_CHUNK_SIDE];
	int i = 0;
	for(int z = 0; z < BLOCKS_PER_CHUNK_SIDE; z++) {
		for(int x = 0; x < BLOCKS_PER_CHUNK_SIDE; x++) {
			heightMapAry[i] = heightMap[x][z];
			i++;
		}
	}
	factory2.set(new IntArrayTag("HeightMap", heightMapAry));
	
	// Make chunk tag
	CompoundTagFactory factory3 = new CompoundTagFactory("");
	factory3.set(factory2.getTag());
	return factory3.getTag();
}
 
开发者ID:r-ralph,项目名称:Transcendens,代码行数:40,代码来源:Chunk.java

示例9: getTag

import org.jnbt.Tag; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public Tag getTag() {
	// Set level tags
	CompoundTagFactory factory = new CompoundTagFactory("Data");
	factory.set(new ByteTag("allowCommands", allowCommands ? (byte)1 : (byte)0));
	factory.set(new IntTag("GameType", gameType.getValue()));
	factory.set(new StringTag("generatorName", generator.getGeneratorName()));
	factory.set(new LongTag("LastPlayed", System.currentTimeMillis()));
	factory.set(new StringTag("LevelName", levelName));
	factory.set(new ByteTag("MapFeatures", mapFeatures ? (byte)1 : (byte)0));
	factory.set(new LongTag("RandomSeed", randomSeed));
	factory.set(new IntTag("SpawnX", spawnX));
	factory.set(new IntTag("SpawnY", spawnY));
	factory.set(new IntTag("SpawnZ", spawnZ));
	factory.set(new IntTag("version", 19133));
	
	// Generator options
	String options = generator.getGeneratorOptions();
	if(options != null) {
		factory.set(new StringTag("generatorOptions", options));
	}
	
	// Make root tag
	CompoundTagFactory factory2 = new CompoundTagFactory("");
	factory2.set(factory.getTag());
	return factory2.getTag();
}
 
开发者ID:r-ralph,项目名称:Transcendens,代码行数:31,代码来源:Level.java

示例10: loadSchematic

import org.jnbt.Tag; //导入依赖的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);
}
 
开发者ID:Skyost,项目名称:OwnGarden,代码行数:29,代码来源:Schematic.java

示例11: getChildTag

import org.jnbt.Tag; //导入依赖的package包/类
/**
* Get child tag of a NBT structure.
*
* @param items The parent tag map
* @param key The name of the tag to get
* @param expected The expected type of the tag
* @return child tag casted to the expected type
* @throws DataException if the tag does not exist or the tag is not of the
* expected type
*/

private static <T extends Tag> T getChildTag(Map<String, Tag> items, String key, Class<T> expected) throws IllegalArgumentException {
	if(!items.containsKey(key)) {
		throw new IllegalArgumentException("Schematic file is missing a \"" + key + "\" tag");
	}
	Tag tag = items.get(key);
	if(!expected.isInstance(tag)) {
		throw new IllegalArgumentException(key + " tag is not of tag type " + expected.getName());
	}
	return expected.cast(tag);
}
 
开发者ID:Skyost,项目名称:OwnGarden,代码行数:22,代码来源:Schematic.java

示例12: loadChunkData

import org.jnbt.Tag; //导入依赖的package包/类
private void loadChunkData(CompoundTag levelTag) {
    // first, grab the biome data for the chunk...
    ChunkBiomeData biomeData = loadBiomeData(levelTag);

    // then grab all the defined sections...
    for (Tag t : getSectionTags(levelTag)) {
        CompoundTag sectionTag = (CompoundTag) t;
        int sIdx = getSectionIndex(sectionTag);
        sections[sIdx] = new ChunkSection(sectionTag, biomeData);
    }

    // remember the highest "used" section
    highestSection = highestUsedSection();
}
 
开发者ID:sdhunt,项目名称:McQuad,代码行数:15,代码来源:Chunk.java

示例13: ChunkSection

import org.jnbt.Tag; //导入依赖的package包/类
/**
 * Creates the chunk section from the specified (NBT compound) section tag.
 *
 * @param sectionTag the section tag
 * @param biomeData  the biome data associated with this chunk
 */
ChunkSection(CompoundTag sectionTag, ChunkBiomeData biomeData) {
    byte[] idsLow = getByteArrayFromTag(sectionTag, BLOCKS);
    Tag addTag = sectionTag.getValue().get(ADD);
    byte[] add = addTag == null ? null : ((ByteArrayTag) addTag).getValue();
    byte[] data = getByteArrayFromTag(sectionTag, DATA);

    if (add != null) {
        process(idsLow, add, data, biomeData);
    } else {
        process(idsLow, data, biomeData);
    }
}
 
开发者ID:sdhunt,项目名称:McQuad,代码行数:19,代码来源:ChunkSection.java

示例14: getChild

import org.jnbt.Tag; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static <T extends Tag> T getChild(CompoundTag parent, String name, Class<T> clazz)
{
	Tag child = parent.getValue().get(name);
	if (clazz.isInstance(child))
	{
		return (T)child;
	}
	else
	{
		return null;
	}
}
 
开发者ID:tectonicus,项目名称:tectonicus,代码行数:14,代码来源:NbtUtil.java

示例15: convertNBT

import org.jnbt.Tag; //导入依赖的package包/类
private Object convertNBT(Tag tag) throws InstantiationException, IllegalAccessException, InvocationTargetException {
    if (tag instanceof CompoundTag) {
        return convertNBT((CompoundTag) tag);
    } else if (tag instanceof ListTag) {
        return convertNBT(((ListTag) tag));
    } else if (tag instanceof StringTag) {
        return convertNBT((StringTag) tag);
    } else {
        throw new UnsupportedOperationException("Unsupported tag type " + tag.getClass().getSimpleName() + " encountered");
    }
}
 
开发者ID:Captain-Chaos,项目名称:WorldPainter,代码行数:12,代码来源:MC10InterfaceHelper.java


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