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


Java StringTag类代码示例

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


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

示例1: getTag

import org.jnbt.StringTag; //导入依赖的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

示例2: loadSchematic

import org.jnbt.StringTag; //导入依赖的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

示例3: createBuilder

import org.jnbt.StringTag; //导入依赖的package包/类
private static Builder createBuilder(final FormatText[] text) {
    if (text.length > 4) {
        throw new IllegalArgumentException("Sign can't have more than 4 lines of text! Given: " + text.length);
    }
    final TileEntity.Builder b = new TileEntity.Builder("Sign");
    for (int i = 0; i < 4; i++) {
        final String s = (i < text.length) ? text[i].getStringWithCodes() : "";
        b.add(new StringTag("Text" + (i + 1), s));
    }
    return b;
}
 
开发者ID:ssauermann,项目名称:BlockAPI,代码行数:12,代码来源:SignEntity.java

示例4: getString

import org.jnbt.StringTag; //导入依赖的package包/类
public static String getString(CompoundTag parent, String name, final String defaultValue)
{
	StringTag tag = getChild(parent, name, StringTag.class);
	if (tag != null)
		return tag.getValue();
	else
		return defaultValue;
}
 
开发者ID:tectonicus,项目名称:tectonicus,代码行数:9,代码来源:NbtUtil.java

示例5: convertNBT

import org.jnbt.StringTag; //导入依赖的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

示例6: fromNBT

import org.jnbt.StringTag; //导入依赖的package包/类
public static TileEntity fromNBT(CompoundTag tileEntityTag) {
    String id = ((StringTag) tileEntityTag.getTag(TAG_ID)).getValue();
    switch (id) {
        case ID_CHEST:
            return new Chest(tileEntityTag);
        case ID_SIGN:
            return new WallSign(tileEntityTag);
        default:
            return new TileEntity(tileEntityTag);
    }
}
 
开发者ID:Captain-Chaos,项目名称:WorldPainter,代码行数:12,代码来源:TileEntity.java

示例7: fromNBT

import org.jnbt.StringTag; //导入依赖的package包/类
public static Entity fromNBT(CompoundTag entityTag) {
    String id = ((StringTag) entityTag.getTag(TAG_ID)).getValue();
    switch (id) {
        case ID_PLAYER:
            return new Player(entityTag);
        case ID_VILLAGER:
            return new Villager(entityTag);
        case ID_PAINTING:
            return new Painting(entityTag);
        default:
            return new Entity(entityTag);
    }
}
 
开发者ID:Captain-Chaos,项目名称:WorldPainter,代码行数:14,代码来源:Entity.java

示例8: setString

import org.jnbt.StringTag; //导入依赖的package包/类
protected final void setString(String name, String value) {
    if (value != null) {
        tag.setTag(name, new StringTag(name, value));
    } else {
        tag.setTag(name, null);
    }
}
 
开发者ID:Captain-Chaos,项目名称:WorldPainter,代码行数:8,代码来源:AbstractNBTItem.java

示例9: loadSchematic

import org.jnbt.StringTag; //导入依赖的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;
}
 
开发者ID:xize,项目名称:manco2,代码行数:58,代码来源:SchematicUtils.java

示例10: loadSchematic

import org.jnbt.StringTag; //导入依赖的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;
}
 
开发者ID:xize,项目名称:ManCo,代码行数:58,代码来源:SchematicUtils.java

示例11: save

import org.jnbt.StringTag; //导入依赖的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

示例12: getString

import org.jnbt.StringTag; //导入依赖的package包/类
protected final String getString(String name, String defaultValue) {
    StringTag stringTag = (StringTag) tag.getTag(name);
    return (stringTag != null) ? stringTag.getValue() : defaultValue;
}
 
开发者ID:Captain-Chaos,项目名称:WorldPainter,代码行数:5,代码来源:AbstractNBTItem.java

示例13: Builder

import org.jnbt.StringTag; //导入依赖的package包/类
/**
 * Creates a new TileEntity builder with the necessary tags. This does
 * not include the coordinates.
 *
 * @param id Entity id
 */
public Builder(final String id) {
    this.tags.put("id", new StringTag("id", id));
}
 
开发者ID:ssauermann,项目名称:BlockAPI,代码行数:10,代码来源:TileEntity.java


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