net.minecraft.nbt.NBTBase Java Examples

The following examples show how to use net.minecraft.nbt.NBTBase. 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 check out the related API usage on the sidebar.
Example #1
Source File: NBTTree.java    From NBTEdit with 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 #2
Source File: EventHandlerWorld.java    From Gadomancy with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 #3
Source File: SpellUtils.java    From Wizardry with 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 #4
Source File: GuiNBTTree.java    From NBTEdit with 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 #5
Source File: GuiEditNBT.java    From NBTEdit with 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 #6
Source File: PlayerCivilization.java    From ToroQuest with 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 #7
Source File: NBTTree.java    From ehacks-pro with 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 #8
Source File: RailCraftTrainHandler.java    From Signals with GNU General Public License v3.0 6 votes vote down vote up
@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 #9
Source File: BackpackCapability.java    From WearableBackpacks with 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 #10
Source File: NBTHelper.java    From wailanbt with 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 #11
Source File: LPRoutedItem.java    From Logistics-Pipes-2 with 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 File: SellSign.java    From MyTown2 with 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
Source File: NBTUtils.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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 File: ItemBackpack.java    From WearableBackpacks with 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 #15
Source File: GuiNBTTree.java    From ehacks-pro with 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 #16
Source File: GuiEditSingleNBT.java    From ehacks-pro with 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 #17
Source File: GuiEditNBT.java    From NBTEdit with 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 #18
Source File: SpellRing.java    From Wizardry with 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 #19
Source File: ProcessData.java    From Wizardry with 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 #20
Source File: ProcessData.java    From Wizardry with 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 #21
Source File: DataConverter.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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 #22
Source File: WizardryWorldStorage.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 #23
Source File: MiscCapabilityStorage.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example #24
Source File: MiscCapabilityStorage.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void readNBT(Capability<IMiscCapability> capability, IMiscCapability instance, EnumFacing side, NBTBase nbt) {
	NBTTagCompound tag = (NBTTagCompound) nbt;

	if (tag.hasUniqueId("fairy_selected")) {
		instance.setSelectedFairy(NBTHelper.getUniqueId(tag, "fairy_selected"));
	} else instance.setSelectedFairy(null);
}
 
Example #25
Source File: GuiNBTTree.java    From NBTEdit with GNU General Public License v3.0 5 votes vote down vote up
private void buttonClicked(GuiNBTButton button){
	if (button.getId() == 16)
		paste();
	else if (button.getId() == 15)
		cut();
	else if (button.getId() == 14)
		copy();
	else if (button.getId() == 13)
		deleteSelected();
	else if (button.getId() == 12)
		edit();
	else if (focused != null){
		focused.setDrawChildren(true);
		List<Node<NamedNBT>> children = focused.getChildren();
		String type = NBTStringHelper.getButtonName(button.getId());

		if (focused.getObject().getNBT() instanceof NBTTagList){
			NBTBase nbt = NBTStringHelper.newTag(button.getId());
			if (nbt != null){
				Node<NamedNBT> newNode = new Node<NamedNBT>(focused, new NamedNBT("",nbt));
				children.add(newNode);
				setFocused(newNode);
			}
		}
		else if (children.size() == 0){
			setFocused(insert(type + "1", button.getId()));
		}
		else{
			for (int i =1; i <= children.size()+1; ++i){
				String name = type + i;
				if (validName(name,children)){
					setFocused(insert(name,button.getId()));
					break;
				}
			}
		}
		initGUI(true);
	}
}
 
Example #26
Source File: PlayerCivilization.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
private Map<CivilizationType, Integer> readNBTReputationList(NBTBase tag) {
	Map<CivilizationType, Integer> reputations = defaultRepMap();
	if (tag == null || !(tag instanceof NBTTagList)) {
		return reputations;
	}
	NBTTagList list = (NBTTagList) tag;
	for (int i = 0; i < list.tagCount(); i++) {
		NBTTagCompound c = list.getCompoundTagAt(i);
		reputations.put(e(c.getString("civ")), c.getInteger("amount"));
	}
	return reputations;
}
 
Example #27
Source File: CyberwareUserDataImpl.java    From Cyberware with MIT License 5 votes vote down vote up
@Override
public void readNBT(Capability<ICyberwareUserData> capability, ICyberwareUserData instance, EnumFacing side, NBTBase nbt)
{
	if (nbt instanceof NBTTagCompound)
	{
		instance.deserializeNBT((NBTTagCompound) nbt);
	}
	else
	{
		throw new IllegalStateException("Cyberware NBT should be a NBTTagCompound!");
	}
}
 
Example #28
Source File: StorageLastRelay.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@Override
public NBTBase writeNBT(Capability<ICapabilityLastRelay> capability,
    ICapabilityLastRelay instance, EnumFacing side) {
    int x = 0, y = 0, z = 0;

    if (instance.hasLastRelay()) {
        x = instance.getLastRelay().getX();
        y = instance.getLastRelay().getY();
        z = instance.getLastRelay().getZ();
    }

    return new NBTTagIntArray(new int[]{x, y, z});
}
 
Example #29
Source File: BackpackCapability.java    From WearableBackpacks with MIT License 5 votes vote down vote up
@Override
public void deserializeNBT(NBTTagCompound compound) {
	backpack.stack = NbtUtils.readItem(compound.getCompoundTag(TAG_STACK));
	
	IBackpackType type;
	if (backpack.stack.isEmpty()) {
		if (!compound.hasKey(TAG_TYPE, NbtType.STRING)) return;
		// If the backpack has its type saved, restore it.
		// This is the case when the backpack stack is equipped in
		// the chest armor slot, which has not yet been loaded. :'(
		String id = compound.getString(TAG_TYPE);
		backpack.lastType = type = BackpackHelper.getBackpackType(MiscUtils.getItemFromName(id));
		if (type == null) return;
	} else type = BackpackHelper.getBackpackType(backpack.stack);
	
	if (type == null) {
		WearableBackpacks.LOG.error("Backpack type was null when deserializing backpack capability");
		return;
	}
	
	backpack.data = type.createBackpackData(backpack.getStack());
	NBTBase dataTag = compound.getTag(TAG_DATA);
	if ((backpack.data != null) && (dataTag != null))
		backpack.data.deserializeNBT(dataTag);
	
	backpack.mayDespawn = compound.getBoolean(TAG_MAY_DESPAWN);
}
 
Example #30
Source File: ReflectionUtil.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static List<NBTBase> getTagList(NBTTagList list) {
	if (NBTTAGLIST_TAGLIST == null) {
		return null;
	}
	try {
		return (List) NBTTAGLIST_TAGLIST.get(list);
	} catch (IllegalArgumentException | IllegalAccessException ex) {
		return null;
	}
}