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


Java ByteArrayTag类代码示例

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


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

示例1: getAnvil4Bit

import org.jnbt.ByteArrayTag; //导入依赖的package包/类
private static byte getAnvil4Bit(ByteArrayTag tag, final int x, final int y, final int z)
{
	final int index = calcAnvil4BitIndex(x, y, z);
	if (index == 2048)
		System.out.println();;
	
	final int doublet = tag.getValue()[index];
	
	// Upper or lower half?
	final boolean isUpper = (x % 2 == 1);
	
	byte half;
	if (isUpper)
	{
		half = (byte)((doublet >> 4) & 0xF);
	}
	else
	{
		half = (byte)(doublet & 0xF);
	}
	
	return half;
}
 
开发者ID:tectonicus,项目名称:tectonicus,代码行数:24,代码来源:RawChunk.java

示例2: get4Bit

import org.jnbt.ByteArrayTag; //导入依赖的package包/类
private static byte get4Bit(ByteArrayTag tag, final int x, final int y, final int z)
{
	final int index = calc4BitIndex(x, y, z);
	final int doublet = tag.getValue()[index];
	
	// Upper or lower half?
	final boolean isUpper = (y % 2 == 1);
	
	byte half;
	if (isUpper)
	{
		half = (byte)((doublet >> 4) & 0xF);
	}
	else
	{
		half = (byte)(doublet & 0xF);
	}
	
	return half;
}
 
开发者ID:tectonicus,项目名称:tectonicus,代码行数:21,代码来源:RawChunk.java

示例3: getTag

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

示例4: loadSchematic

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

示例5: ChunkSection

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

示例6: getData

import org.jnbt.ByteArrayTag; //导入依赖的package包/类
/**
 * Returns the data values of the blocks in this chunk.
 * @param chunkX: Relative chunk x-coordinate of the chunk.
 * @param chunkZ: Relative chunk x-coordinate of the chunk.
 * @return An array of bytes containing the data values of each block.
 * @throws ChunkNotFoundException
 */
public byte[] getData(int chunkX, int chunkZ) throws ChunkNotFoundException {
	
	//1 byte for 1 nibble.
	byte[] data = new byte[32768]; //16 * 16 * 128 = 32768
	
	//1 byte for 2 nibble.
	byte[] compressedData = new byte[16384]; //16 * 16 * 128 / 2 = 16384
	try {
		compressedData = ((ByteArrayTag) getTag(chunkX, chunkZ, "Data")).getValue();
	} catch (TagNotFoundException e) {
		e.printStackTrace();
	}
	
	for(int x = 0; x < 16; x++) {
		for(int z = 0; z < 16; z++) {
			for(int y = 0; y < 128; y++) {
				int offset = (y + z * 128 + x * 128 * 16) / 2; //Get the offset of the byte where the nibble is in.
				
				int part = y % 2; //Check whether we need the first or the second part of the byte.
				
				byte nibble;
				if(part == 1) {
					nibble = (byte) (compressedData[offset] >> 4 & 0xF); //Get the first part of the byte ---> first nibble.
				} else {
					nibble = (byte) (compressedData[offset] & 0xF); //Get the second part of the byte ---> second nibble.
				}
				
				data[(y + (z * 128) + (x * 128 * 16))] = nibble;
			}
		}
	}
	
	return data;
	
}
 
开发者ID:sd5,项目名称:AncientTerrain,代码行数:43,代码来源:Region.java

示例7: loadSchematic

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

示例8: loadSchematic

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

示例9: loadSchematic

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

示例10: getByteArray

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

示例11: setByteArray

import org.jnbt.ByteArrayTag; //导入依赖的package包/类
protected final void setByteArray(String name, byte[] bytes) {
    tag.setTag(name, new ByteArrayTag(name, bytes));
}
 
开发者ID:Captain-Chaos,项目名称:WorldPainter,代码行数:4,代码来源:AbstractNBTItem.java

示例12: readBlocks

import org.jnbt.ByteArrayTag; //导入依赖的package包/类
/**
 * Returns a byte array containing all block ids of the schematic.
 * <p>
 * Each block id uses 8 bits.
 * </p>
 *
 * @return <b>byte[]</b> blocks
 */
// Can't be null (checked by Guava)
@SuppressWarnings("null")
public byte[] readBlocks() {
    return checkNotNull(((ByteArrayTag) this.read(ESchematicFields.BLOCKS)).getValue());
}
 
开发者ID:ssauermann,项目名称:BlockAPI,代码行数:14,代码来源:SchematicWrapper.java

示例13: readData

import org.jnbt.ByteArrayTag; //导入依赖的package包/类
/**
 * Returns a byte array containing all data values for the blocks of the
 * schematic.
 * <p>
 * Each data value uses the lower 4 bits of a byte.
 * </p>
 *
 * @return <b>byte[]</b> blocks
 */
// Can't be null (checked by Guava)
@SuppressWarnings("null")
public byte[] readData() {
    return checkNotNull(((ByteArrayTag) this.read(ESchematicFields.DATA)).getValue());
}
 
开发者ID:ssauermann,项目名称:BlockAPI,代码行数:15,代码来源:SchematicWrapper.java

示例14: writeBlocks

import org.jnbt.ByteArrayTag; //导入依赖的package包/类
/**
 * Adds a tag for the blocks of the schematic to the root compound tag.
 *
 * @param value <b>byte[]</b> blocks
 */
public void writeBlocks(final byte[] value) {
    final ByteArrayTag t = new ByteArrayTag(ESchematicFields.BLOCKS.getKey(), value);
    this.addTagToRoot(t);
}
 
开发者ID:ssauermann,项目名称:BlockAPI,代码行数:10,代码来源:SchematicWrapper.java

示例15: writeData

import org.jnbt.ByteArrayTag; //导入依赖的package包/类
/**
 * Adds a tag for the data values (for blocks) of the schematic to the root
 * compound tag.
 *
 * @param value <b>byte[]</b> data values
 */
public void writeData(final byte[] value) {
    final ByteArrayTag t = new ByteArrayTag(ESchematicFields.DATA.getKey(), value);
    this.addTagToRoot(t);
}
 
开发者ID:ssauermann,项目名称:BlockAPI,代码行数:11,代码来源:SchematicWrapper.java


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