本文整理汇总了Java中net.minecraftforge.common.util.Constants.NBT.TAG_COMPOUND属性的典型用法代码示例。如果您正苦于以下问题:Java NBT.TAG_COMPOUND属性的具体用法?Java NBT.TAG_COMPOUND怎么用?Java NBT.TAG_COMPOUND使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类net.minecraftforge.common.util.Constants.NBT
的用法示例。
在下文中一共展示了NBT.TAG_COMPOUND属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: iterate
private static final void iterate(NBTTagCompound parent, NBTTreeConsumer consumer, int depth) {
if(parent == null) return;
consumer.consume(depth+1, "<compound>", parent, null);
for(Object keyObject : parent.getKeySet()) {
String key = (String)keyObject;
NBTBase value = parent.getTag(key);
consumer.consume(depth+1, key, value, parent);
if(value instanceof NBTTagCompound) {
iterate((NBTTagCompound)value, consumer, depth+1);
}
if(value instanceof NBTTagList) {
NBTTagList list = (NBTTagList) value;
if(list.getTagType() == NBT.TAG_COMPOUND) {
for(int i = 0; i < list.tagCount(); i++) {
NBTTagCompound compound = list.getCompoundTagAt(i);
iterate(compound, consumer, depth+1);
}
}
}
}
consumer.consume(depth+1, "", null, parent);
}
示例2: asJson
private static void asJson(NBTBase tag, StringBuilder builder) {
switch(tag.getId()) {
case NBT.TAG_BYTE: builder.append(((NBTTagByte)tag).getByte()).append('b'); break;
case NBT.TAG_SHORT: builder.append(((NBTTagShort)tag).getByte()).append('b'); break;
case NBT.TAG_INT: builder.append(((NBTTagInt)tag).getInt()); break;
case NBT.TAG_LONG: builder.append(((NBTTagLong)tag).getByte()).append('l'); break;
case NBT.TAG_FLOAT: builder.append(((NBTTagFloat)tag).getFloat()).append('f'); break;
case NBT.TAG_DOUBLE: builder.append(((NBTTagDouble)tag).getDouble()).append('d'); break;
case NBT.TAG_STRING: builder.append('"').append(((NBTTagString)tag).getString()).append('"'); break;
case NBT.TAG_BYTE_ARRAY: builder.append(Arrays.toString(((NBTTagByteArray)tag).getByteArray())); break;
case NBT.TAG_INT_ARRAY: builder.append(Arrays.toString(((NBTTagIntArray)tag).getIntArray())); break;
case NBT.TAG_COMPOUND: asJson((NBTTagCompound) tag, builder); break;
case NBT.TAG_LIST: asJson((NBTTagList) tag, builder); break;
}
}
示例3: addNBTToTooltip
public static void addNBTToTooltip(NBTTagCompound nbt, List<String> tooltip, int depth) {
if (nbt == null)
return;
String blank = Tool.makeString(' ', (depth - 1) * 3);
for (String key : nbt.getKeySet()) {
NBTBase base = nbt.getTag(key);
if (base.getId() == NBT.TAG_COMPOUND) {
tooltip.add(blank + "|-> " + key + " : (" + base.getClass().getSimpleName().replace("NBTTag", "") + ")");
addNBTToTooltip((NBTTagCompound) base, tooltip, depth + 1);
} else
tooltip.add(blank + "|-> " + key + " = (" + base.getClass().getSimpleName().replace("NBTTag", "") + ") " + base.toString());
}
}
示例4: nbtMerge
/**
* Merges two nbt tag compounds
*
* @param tag the tag to merge the "other" tag into
* @param other the tag which shall be merged into "tag"
* @param mergeLists whether lists shall be replaced or merged
*/
public static void nbtMerge(NBTTagCompound tag, NBTTagCompound other, boolean mergeLists) {
if (tag == null || other == null) return;
Iterator iterator = other.getKeySet().iterator();
while (iterator.hasNext())
{
String s = (String)iterator.next();
NBTBase nbtbase = other.getTag(s);
if (nbtbase.getId() == NBT.TAG_COMPOUND && tag.hasKey(s, NBT.TAG_COMPOUND))
{
nbtMerge(tag.getCompoundTag(s), (NBTTagCompound) nbtbase, mergeLists);
}
else if (nbtbase.getId() == NBT.TAG_LIST && tag.hasKey(s, NBT.TAG_LIST) && mergeLists) {
if (((NBTTagList) nbtbase).getTagType() == ((NBTTagList) tag.getTag(s)).getTagType()) {
NBTTagList l1 = (NBTTagList) nbtbase, l2 = (NBTTagList) tag.getTag(s);
for (int i = 0; i < l1.tagCount(); i++)
l2.appendTag(l1.get(i).copy());
}
else tag.setTag(s, nbtbase.copy());
}
else
{
tag.setTag(s, nbtbase.copy());
}
}
}