Java Code Examples for net.minecraft.nbt.NBTBase

The following examples show how to use net.minecraft.nbt.NBTBase. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: wailanbt   Source File: NBTHelper.java    License: MIT License 6 votes vote down vote up
public static String NBTToString(NBTBase tag) {
    switch (tag.getId()) {
        case 0:
        case 3:
        case 7:
        case 9:
        case 10:
        case 11:
            return tag.toString();
        case 1:
        case 2:
        case 4:
        case 5:
        case 6:
            return StringUtils.substring(tag.toString(), 0, -1);
        case 8:
            return StringUtils.substring(tag.toString(), 1, -1);
        default:
            return "__ERROR__";

    }
}
 
Example 2
Source Project: NBTEdit   Source File: NBTTree.java    License: GNU General Public License v3.0 6 votes vote down vote up
public void addChildrenToTag (Node<NamedNBT> parent, NBTTagCompound tag){
	for (Node<NamedNBT> child : parent.getChildren()){
		NBTBase base = child.getObject().getNBT();
		String name = child.getObject().getName();
		if (base instanceof NBTTagCompound){
			NBTTagCompound newTag = new NBTTagCompound();
			addChildrenToTag(child, newTag);
			tag.setTag(name, newTag);
		}
		else if (base instanceof NBTTagList){
			NBTTagList list = new NBTTagList();
			addChildrenToList(child, list);
			tag.setTag(name, list);
		}
		else
			tag.setTag(name, base.copy());
	}
}
 
Example 3
Source Project: WearableBackpacks   Source File: BackpackCapability.java    License: MIT License 6 votes vote down vote up
@Override
public void readNBT(Capability<IBackpack> capability, IBackpack instance, EnumFacing side, NBTBase nbt) {
	BackpackCapability backpack = (BackpackCapability)instance;
	if (!(nbt instanceof NBTTagCompound)) return;
	NBTTagCompound compound = (NBTTagCompound)nbt;
	
	ItemStack stack = NbtUtils.readItem(compound.getCompoundTag(TAG_STACK));
	backpack.setStack(stack);
	
	IBackpackType type;
	if (stack.isEmpty()) {
		// Try to get the backpack type from the chestplate slot.
		stack = backpack.entity.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
		backpack.lastType = type = BackpackHelper.getBackpackType(stack);
		if (type == null) return; // No backpack equipped.
	} else type = BackpackHelper.getBackpackType(stack);
	
	IBackpackData data = type.createBackpackData(stack);
	NBTBase dataTag = compound.getTag(TAG_DATA);
	if (dataTag != null) data.deserializeNBT(dataTag);
	backpack.setData(data);
	
	backpack.mayDespawn = compound.getBoolean(TAG_MAY_DESPAWN);
}
 
Example 4
Source Project: ehacks-pro   Source File: NBTTree.java    License: GNU General Public License v3.0 6 votes vote down vote up
public void addChildrenToTag(Node<NamedNBT> parent, NBTTagCompound tag) {
    for (Node<NamedNBT> child : parent.getChildren()) {
        NBTBase base = child.getObject().getNBT();
        String name = child.getObject().getName();
        if (base instanceof NBTTagCompound) {
            NBTTagCompound newTag = new NBTTagCompound();
            this.addChildrenToTag(child, newTag);
            tag.setTag(name, newTag);
            continue;
        }
        if (base instanceof NBTTagList) {
            NBTTagList list = new NBTTagList();
            this.addChildrenToList(child, list);
            tag.setTag(name, list);
            continue;
        }
        tag.setTag(name, base.copy());
    }
}
 
Example 5
Source Project: NBTEdit   Source File: GuiNBTTree.java    License: GNU General Public License v3.0 6 votes vote down vote up
public void editSelected() {
	if (focused != null){
		NBTBase base = focused.getObject().getNBT();
		if (focused.hasChildren() &&  (base instanceof NBTTagCompound || base instanceof NBTTagList)){
			focused.setDrawChildren(!focused.shouldDrawChildren());
			int index = -1;
			
			if(focused.shouldDrawChildren() && (index = indexOf(focused)) != -1)
				offset =  (START_Y+1) - nodes.get(index).y + offset;
			
			initGUI();
		}
		else if (buttons[11].isEnabled()){
			edit();
		}
	}
	else if (focusedSlotIndex != -1){
		stopEditingSlot();
	}
}
 
Example 6
Source Project: Wizardry   Source File: SpellUtils.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
public static List<List<ModuleInstance>> deserializeModuleList(@Nonnull NBTTagList list) {
	List<List<ModuleInstance>> modules = new ArrayList<>();
	List<ModuleInstance> moduleList = new ArrayList<>();
	for (int i = 0; i < list.tagCount(); i++) {
		NBTBase base = list.get(i);
		if (!(base instanceof NBTTagString)) continue;
		NBTTagString string = (NBTTagString) base;
		if (string.isEmpty()) {
			if (!moduleList.isEmpty())
				modules.add(moduleList);
			moduleList = new ArrayList<>();
		}
		ModuleInstance module = ModuleInstance.deserialize(string);
		if (module == null) continue;
		moduleList.add(module);
	}
	if (!moduleList.isEmpty())
		modules.add(moduleList);
	return modules;
}
 
Example 7
@SubscribeEvent(priority = EventPriority.NORMAL)
public void on(ItemTooltipEvent e) {
    if (e.toolTip.size() > 0 && e.itemStack.hasTagCompound()) {
        if (e.itemStack.stackTagCompound.getBoolean("isStickyJar")) {
            e.toolTip.add(1, "\u00a7a" + StatCollector.translateToLocal("gadomancy.lore.stickyjar"));
        }
    }

    if(e.toolTip.size() > 0 && NBTHelper.hasPersistentData(e.itemStack)) {
        NBTTagCompound compound = NBTHelper.getPersistentData(e.itemStack);
        if(compound.hasKey("disguise")) {
            NBTBase base = compound.getTag("disguise");
            String lore;
            if(base instanceof NBTTagCompound) {
                ItemStack stack = ItemStack.loadItemStackFromNBT((NBTTagCompound) base);
                lore = String.format(StatCollector.translateToLocal("gadomancy.lore.disguise.item"), EnumChatFormatting.getTextWithoutFormattingCodes(stack.getDisplayName()));
            } else {
                lore = StatCollector.translateToLocal("gadomancy.lore.disguise.none");
            }
            e.toolTip.add("\u00a7a" + lore);
        }
    }
}
 
Example 8
Source Project: NBTEdit   Source File: GuiEditNBT.java    License: GNU General Public License v3.0 6 votes vote down vote up
private static void setValidValue(Node<NamedNBT> node, String value){
	NamedNBT named = node.getObject();
	NBTBase base = named.getNBT();
	
	if (base instanceof NBTTagByte)
		named.setNBT(new NBTTagByte(ParseHelper.parseByte(value)));
	if (base instanceof NBTTagShort)
		named.setNBT(new NBTTagShort(ParseHelper.parseShort(value)));
	if (base instanceof NBTTagInt)
		named.setNBT(new NBTTagInt(ParseHelper.parseInt(value)));
	if (base instanceof NBTTagLong)
		named.setNBT(new NBTTagLong(ParseHelper.parseLong(value)));
	if(base instanceof NBTTagFloat)
		named.setNBT(new NBTTagFloat(ParseHelper.parseFloat(value)));
	if(base instanceof NBTTagDouble)
		named.setNBT(new NBTTagDouble(ParseHelper.parseDouble(value)));
	if(base instanceof NBTTagByteArray)
		named.setNBT(new NBTTagByteArray(ParseHelper.parseByteArray(value)));
	if(base instanceof NBTTagIntArray)
		named.setNBT(new NBTTagIntArray(ParseHelper.parseIntArray(value)));
	if (base instanceof NBTTagString)
		named.setNBT(new NBTTagString(value));
}
 
Example 9
Source Project: ToroQuest   Source File: PlayerCivilization.java    License: GNU General Public License v3.0 6 votes vote down vote up
private Set<QuestData> readQuests(NBTBase tag) {
	Set<QuestData> quests = new HashSet<QuestData>();
	if (tag == null || !(tag instanceof NBTTagList)) {
		return quests;
	}
	NBTTagList list = (NBTTagList) tag;
	for (int i = 0; i < list.tagCount(); i++) {
		QuestData d = new QuestData();
		d.readNBT(list.getCompoundTagAt(i), getPlayer());
		if (!d.isValid()) {
			continue;
		}
		quests.add(d);
	}
	return quests;
}
 
Example 10
@Override
public Set<EntityMinecart> getLinkedCarts(EntityMinecart cart){
    //Debug code:
    //return cart.world.loadedEntityList.stream().filter(x -> x instanceof EntityMinecart && x.getTags().contains("link")).map(x -> (EntityMinecart)x).collect(Collectors.toSet());

    //NBT methods based on https://github.com/brotazoa/Signals/commit/52e1466d78626e39df9db79ff48cf663ad8aa76e
    if(cart.getEntityData().hasKey("rcTrain")) // cart is part of an RC train
    {
        NBTBase tag = cart.getEntityData().getTag("rcTrain");

        Stream<EntityMinecart> allCarts = cart.world.loadedEntityList.stream().filter(entity -> entity instanceof EntityMinecart).map(entity -> (EntityMinecart)entity);
        return allCarts.filter(c -> c.getEntityData().hasKey("rcTrain") && c.getEntityData().getTag("rcTrain").equals(tag)).collect(Collectors.toSet());
    } else {
        return Collections.emptySet();
    }
}
 
Example 11
Source Project: Logistics-Pipes-2   Source File: LPRoutedItem.java    License: MIT License 6 votes vote down vote up
public static LPRoutedItem readFromNBT(NBTTagCompound compound, TileGenericPipe holder) {
	double x = compound.getDouble("posX");
	double y = compound.getDouble("posY");
	double z = compound.getDouble("posZ");
	UUID id = compound.getUniqueId("UID");
	ItemStack content = new ItemStack(compound.getCompoundTag("inventory"));
	int ticks = compound.getInteger("ticks");
	Deque<EnumFacing> routingInfo = new ArrayDeque<>();
	NBTTagList routeList = (NBTTagList) compound.getTag("route");
	for(Iterator<NBTBase> i = routeList.iterator(); i.hasNext();) {
		NBTTagCompound node = (NBTTagCompound) i.next();
		EnumFacing nodeTuple = EnumFacing.values()[node.getInteger("heading")];
		routingInfo.add(nodeTuple);
	}
	LPRoutedItem item = new LPRoutedItem(x, y, z, content, ticks, id);
	item.setHeading(EnumFacing.VALUES[compound.getInteger("heading")]);
	item.setHolding(holder);
	item.route = routingInfo;
	return item;
}
 
Example 12
Source Project: MyTown2   Source File: SellSign.java    License: The Unlicense 6 votes vote down vote up
@Override
public boolean isTileValid(TileEntitySign te) {
    if (!te.signText[0].startsWith(Sign.IDENTIFIER)) {
        return false;
    }

    try {
        NBTTagCompound rootTag = SignClassTransformer.getMyEssentialsDataValue(te);
        if (rootTag == null)
            return false;

        if (!rootTag.getString("Type").equals(SellSignType.instance.getTypeID()))
            return false;

        NBTBase data = rootTag.getTag("Value");
        if (!(data instanceof NBTTagCompound))
            return false;

        NBTTagCompound signData = (NBTTagCompound) data;

        MyTownUniverse.instance.getOrMakeResident(UUID.fromString(signData.getString("Owner")));
        return true;
    } catch (Exception ex) {
        return false;
    }
}
 
Example 13
/**
 * Inserts a new tag into the given NBTTagList at position <b>index</b>.
 * To do this the list will be re-created and the new list is returned.
 */
@Nonnull
public static NBTTagList insertToTagList(@Nonnull NBTTagList tagList, @Nonnull NBTBase tag, int index)
{
    int count = tagList.tagCount();
    if (index >= count)
    {
        index = count > 0 ? count - 1 : 0;
    }

    NBTTagList newList = new NBTTagList();
    for (int i = 0; i < index; i++)
    {
        newList.appendTag(tagList.removeTag(0));
    }

    newList.appendTag(tag);

    count = tagList.tagCount();
    for (int i = 0; i < count; i++)
    {
        newList.appendTag(tagList.removeTag(0));
    }

    return newList;
}
 
Example 14
Source Project: Kettle   Source File: CraftMetaSkull.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
void serializeInternal(final Map<String, NBTBase> internalTags) {
    if (profile != null) {
        NBTTagCompound nbtData = new NBTTagCompound();
        NBTUtil.writeGameProfile(nbtData, profile);
        internalTags.put(SKULL_PROFILE.NBT, nbtData);
    }
}
 
Example 15
Source Project: WearableBackpacks   Source File: BackpackDataItems.java    License: MIT License 5 votes vote down vote up
@Override
public NBTBase serializeNBT() {
	return NbtUtils.createCompound(
		TAG_SIZE, _size.serializeNBT(),
		TAG_ITEMS, ((_items != null) ? _items.serializeNBT() : null),
		TAG_LOOT_TABLE, ((_lootTable != null) ? _lootTable.toString() : null),
		TAG_LOOT_TABLE_SEED, ((_lootTable != null) ? _lootTableSeed : null));
}
 
Example 16
Source Project: ehacks-pro   Source File: Debug.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static NBTTagCompound jsonToNBT(String json) {
    NBTBase nbtTag = null;
    try {
        nbtTag = JsonToNBT.func_150315_a(json.replaceAll("'", "\""));
    } catch (Exception err) {
        return null;
    }
    return (NBTTagCompound) nbtTag;
}
 
Example 17
Source Project: ehacks-pro   Source File: NBTStringHelper.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static NBTBase newTag(byte type) {
    switch (type) {
        case 1: {
            return new NBTTagCompound();
        }
        case 2: {
            return new NBTTagByte((byte) 0);
        }
        case 3: {
            return new NBTTagShort();
        }
        case 4: {
            return new NBTTagInt(0);
        }
        case 5: {
            return new NBTTagLong(0L);
        }
        case 6: {
            return new NBTTagFloat(0.0f);
        }
        case 7: {
            return new NBTTagDouble(0.0);
        }
        case 8: {
            return new NBTTagString("");
        }
        case 9: {
            return new NBTTagList();
        }
        case 10: {
            return new NBTTagByteArray(new byte[0]);
        }
        case 11: {
            return new NBTTagIntArray(new int[0]);
        }
    }
    return null;
}
 
Example 18
Source Project: ehacks-pro   Source File: NBTStringHelper.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static String toString(NBTBase base) {
    switch (GuiNBTNode.NBT_ICON_MAPPING[base.getId() - 1]) {
        case 0: {
            return "(TagCompound)";
        }
        case 1: {
            return "" + ((NBTTagByte) base).func_150290_f();
        }
        case 2: {
            return "" + ((NBTTagShort) base).func_150289_e();
        }
        case 3: {
            return "" + ((NBTTagInt) base).func_150287_d();
        }
        case 4: {
            return "" + ((NBTTagLong) base).func_150291_c();
        }
        case 5: {
            return "" + ((NBTTagFloat) base).func_150288_h();
        }
        case 6: {
            return "" + ((NBTTagDouble) base).func_150286_g();
        }
        case 7: {
            return ((NBTTagString) base).func_150285_a_();
        }
        case 8: {
            return "(TagList)";
        }
        case 9: {
            return base.toString();
        }
        case 10: {
            return base.toString();
        }
    }
    return "?";
}
 
Example 19
Source Project: ehacks-pro   Source File: GuiEditSingleNBT.java    License: GNU General Public License v3.0 5 votes vote down vote up
private boolean validName() {
    for (Node<NamedNBT> node : this.node.getParent().getChildren()) {
        NBTBase base = node.getObject().getNBT();
        if (base == this.nbt || !node.getObject().getName().equals(this.key.getText())) {
            continue;
        }
        return false;
    }
    return true;
}
 
Example 20
Source Project: ehacks-pro   Source File: GuiNBTTree.java    License: GNU General Public License v3.0 5 votes vote down vote up
private Node<NamedNBT> insert(String name, byte type) {
    NBTBase nbt = NBTStringHelper.newTag(type);
    if (nbt != null) {
        return this.insert(new NamedNBT(name, nbt));
    }
    return null;
}
 
Example 21
Source Project: ehacks-pro   Source File: GuiNBTTree.java    License: GNU General Public License v3.0 5 votes vote down vote up
private boolean canAddToParent(NBTBase parent, NBTBase child) {
    if (parent instanceof NBTTagCompound) {
        return true;
    }
    if (parent instanceof NBTTagList) {
        NBTTagList list = (NBTTagList) parent;
        return list.tagCount() == 0 || list.func_150303_d() == child.getId();
    }
    return false;
}
 
Example 22
Source Project: NBTEdit   Source File: NBTStringHelper.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static String getNBTNameSpecial(NamedNBT namedNBT){
	String name = namedNBT.getName();
	NBTBase obj = namedNBT.getNBT();

	String s = toString(obj);
	return Strings.isNullOrEmpty(name) ? "" + s : name + ": " + s + SECTION_SIGN + 'r';
}
 
Example 23
Source Project: WearableBackpacks   Source File: ItemBackpack.java    License: MIT License 5 votes vote down vote up
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
	
	IBackpack backpack = BackpackHelper.getBackpack(Minecraft.getMinecraft().player);
	boolean isEquipped = ((backpack != null) && (backpack.getStack() == stack));
	
	// If the shift key is held down, display equip / unequip hints,
	// otherwise just display "Hold SHIFT for more info" message.
	if (LangUtils.tooltipIsShiftKeyDown(tooltip)) {
		boolean equipAsChestArmor = WearableBackpacks.CONFIG.equipAsChestArmor.get();
		boolean enableSelfInteraction = WearableBackpacks.CONFIG.enableSelfInteraction.get();
		
		// If own backpacks can be interacted with while equipped and one is either
		// currently equipped or won't be equipped as chest armor, display open hint.
		// Does not display anything if key is unbound.
		if (enableSelfInteraction && (isEquipped || !equipAsChestArmor))
			LangUtils.formatTooltipKey(tooltip, "openHint", KeyBindingHandler.openBackpack);
		
		// If the backpack is the player's currently equipped backpack, display unequip hint.
		if (isEquipped) LangUtils.formatTooltip(tooltip, "unequipHint");
		// If not equipped, display the equip hint. If equipAsChestArmor is off,
		// use extended tooltip, which also explains how to unequip the backpack.
		else LangUtils.formatTooltip(tooltip, "equipHint" + (!equipAsChestArmor ? ".extended" : ""));
	}
	
	// If someone's using the player's backpack right now, display it in the tooltip.
	if (isEquipped && (backpack.getPlayersUsing() > 0))
		LangUtils.formatTooltipPrepend(tooltip, "\u00A8o", "used");
	
	
	// Only display the following information if advanced tooltips are enabled.
	if (!flagIn.isAdvanced()) return;
	
	NBTBase customSize = NbtUtils.get(stack, TAG_CUSTOM_SIZE);
	if (customSize != null)
		try { tooltip.add("Custom Size: " + BackpackSize.parse(customSize)); }
		catch (Exception ex) {  } // Ignore NBT parse exceptions - they're already logged in createBackpackData.
	
}
 
Example 24
Source Project: NBTEdit   Source File: GuiEditNBT.java    License: GNU General Public License v3.0 5 votes vote down vote up
private boolean validName(){
	for (Node<NamedNBT> node : this.node.getParent().getChildren()){
		NBTBase base = node.getObject().getNBT();
		if (base != nbt && node.getObject().getName().equals(key.getText()))
			return false;
	}
	return true;
}
 
Example 25
Source Project: Wizardry   Source File: SpellRing.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void deserializeNBT(NBTTagCompound nbt) {
	// NOTE: Don't store nbt argument to serializedNBT. This one must be generated only by serializeNBT()

	if (nbt.hasKey("module")) this.module = ModuleInstance.deserialize(nbt.getString("module"));
	if (nbt.hasKey("extra")) informationTag = sortInformationTag(nbt.getCompoundTag("extra"));
	if (nbt.hasKey("primary_color")) primaryColor = Color.decode(nbt.getString("primary_color"));
	if (nbt.hasKey("secondary_color")) secondaryColor = Color.decode(nbt.getString("secondary_color"));

	if (nbt.hasKey("modifiers")) {
		compileTimeModifiers.clear();
		for (NBTBase base : nbt.getTagList("modifiers", Constants.NBT.TAG_COMPOUND)) {
			if (base instanceof NBTTagCompound) {
				NBTTagCompound modifierCompound = (NBTTagCompound) base;
				if (modifierCompound.hasKey("operation") && modifierCompound.hasKey("attribute") && modifierCompound.hasKey("modifier")) {
					Operation operation = Operation.values()[modifierCompound.getInteger("operation") % Operation.values().length];
					Attribute attribute = AttributeRegistry.getAttributeFromName(modifierCompound.getString("attribute"));

					float modifierFixed = FixedPointUtils.getFixedFromNBT(modifierCompound, "modifier");
					compileTimeModifiers.put(operation, new AttributeModifierSpellRing(attribute, modifierFixed, operation));
				}
			}
		}
	}

	if (nbt.hasKey("child_ring")) {
		SpellRing childRing = deserializeRing(nbt.getCompoundTag("child_ring"));
		childRing.setParentRing(this);
		setChildRing(childRing);
	}

	if (nbt.hasKey("uuid")) uniqueID = UUID.fromString(nbt.getString("uuid"));

}
 
Example 26
Source Project: Wizardry   Source File: ProcessData.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
public <T extends NBTBase, E> void registerDataType(@Nonnull Class<E> type, @Nonnull Class<T> storageType, @Nonnull Process<T, E> process) throws DataInitException {
	String dataTypeName = type.getName();
	if( datatypeRegistry.containsKey(dataTypeName) )
		throw new DataInitException("Datatype '" + dataTypeName + "' is already registered.");
	
	DatatypeEntry<T,E> entry = new DatatypeEntry<>(dataTypeName, type, storageType, process);
	datatypeRegistry.put(dataTypeName, entry);
}
 
Example 27
Source Project: Wizardry   Source File: ProcessData.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
@Nonnull
public NBTBase serialize(@Nullable Object object) {
	if( object != null ) {
		if( !dataTypeClazz.isAssignableFrom(object.getClass()) )
			throw new DataSerializationException("Object to serialize must be at least of class '" + dataTypeClazz + "'");
	}
	return ioProcess.serialize((E)object);
}
 
Example 28
/**
 * Reads an unknown object withPriority a known name from NBT
 * @param tag - tag to read the value from
 * @param key - name of the value
 * @return object or suggestionValue if nothing is found
 */
public Object load(NBTTagCompound tag, String key) {
	if (tag != null && key != null) {
		NBTBase saveTag = tag.getTag(key);

		if (saveTag instanceof NBTTagFloat) {
			return tag.getFloat(key);
		} else if (saveTag instanceof NBTTagDouble) {
			return tag.getDouble(key);
		} else if (saveTag instanceof NBTTagInt) {
			return tag.getInteger(key);
		} else if (saveTag instanceof NBTTagString) {
			if (tag.getBoolean(key + "::nova.isBigInteger")) {
				return new BigInteger(tag.getString(key));
			} else if (tag.getBoolean(key + "::nova.isBigDecimal")) {
				return new BigDecimal(tag.getString(key));
			} else {
				return tag.getString(key);
			}
		} else if (saveTag instanceof NBTTagShort) {
			return tag.getShort(key);
		} else if (saveTag instanceof NBTTagByte) {
			if (tag.getBoolean(key + "::nova.isBoolean")) {
				return tag.getBoolean(key);
			} else {
				return tag.getByte(key);
			}
		} else if (saveTag instanceof NBTTagLong) {
			return tag.getLong(key);
		} else if (saveTag instanceof NBTTagByteArray) {
			return tag.getByteArray(key);
		} else if (saveTag instanceof NBTTagIntArray) {
			return tag.getIntArray(key);
		} else if (saveTag instanceof NBTTagCompound) {
			NBTTagCompound innerTag = tag.getCompoundTag(key);
			return toNova(innerTag);
		}
	}
	return null;
}
 
Example 29
@Override
public void readNBT(Capability<WizardryWorld> capability, WizardryWorld instance, EnumFacing side, NBTBase nbt) {
	HashMap<UUID, Integer> map = new HashMap<>();
	NBTTagCompound tag = (NBTTagCompound) nbt;
	NBTTagCompound playerBackup = tag.getCompoundTag(BACKUP_NBT_TAG);

	for(String playerId : playerBackup.getKeySet()) {
		map.put(UUID.fromString(playerId), playerBackup.getInteger(playerId));
	}

	instance.setBackupMap(map);
}
 
Example 30
@Override
public NBTBase writeNBT(Capability<IMiscCapability> capability, IMiscCapability instance, EnumFacing side) {
	NBTTagCompound nbt = new NBTTagCompound();

	if (instance.getSelectedFairyUUID() != null)
		NBTHelper.setUniqueId(nbt, "fairy_selected", instance.getSelectedFairyUUID());

	return nbt;
}