Java Code Examples for net.minecraft.item.ItemStack#getSubCompound()

The following examples show how to use net.minecraft.item.ItemStack#getSubCompound() . 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: ItemUtils.java    From SkyblockAddons with MIT License 6 votes vote down vote up
/**
 * Returns the Skyblock Item ID of a given Skyblock item
 *
 * @param item the Skyblock item to check
 * @return the Skyblock Item ID of this item or {@code null} if this isn't a valid Skyblock item
 */
public static String getSkyBlockItemID(final ItemStack item) {
    if (item == null) {
        throw new NullPointerException("Item cannot be null.");
    }
    else if (!item.hasTagCompound()) {
        return null;
    }

    NBTTagCompound skyBlockData = item.getSubCompound("ExtraAttributes", false);

    if (skyBlockData != null) {
        String itemId = skyBlockData.getString("id");

        if (!itemId.equals("")) {
            return itemId;
        }
    }

    return null;
}
 
Example 2
Source File: ItemUtils.java    From SkyblockAddons with MIT License 5 votes vote down vote up
/**
 * Returns the rarity of a given Skyblock item
 *
 * @param item the Skyblock item to check
 * @return the rarity of the item if a valid rarity is found, {@code INVALID} if no rarity is found, {@code null} if item is {@code null}
 */
public static Rarity getRarity(ItemStack item) {
    if (item == null || !item.hasTagCompound())  {
        return null;
    }

    NBTTagCompound display = item.getSubCompound("display", false);

    if (display == null || !display.hasKey("Lore")) {
        return null;
    }

    NBTTagList lore = display.getTagList("Lore", Constants.NBT.TAG_STRING);

    // Determine the item's rarity
    for (int i = 0; i < lore.tagCount(); i++) {
        String currentLine = lore.getStringTagAt(i);

        for (Rarity rarity : EnumSet.allOf(Rarity.class)) {
            if (currentLine.startsWith(rarity.getTag())) {
                return rarity;
            }
        }
    }

    // If the item doesn't have a valid rarity, return null
    return null;
}
 
Example 3
Source File: ItemRailConfigurator.java    From Signals with GNU General Public License v3.0 5 votes vote down vote up
public MCPos getLinkedRail(ItemStack stack){
    NBTTagCompound tag = stack.getSubCompound("linkingRail");
    if(tag != null) {
        if(tag.hasKey("dim")) {
            //Legacy conversion FIXME remove in 1.13
            tag.setInteger("d", tag.getInteger("dim"));
            tag.removeTag("dim");
        }
        return new MCPos(tag);
    }
    return null;
}
 
Example 4
Source File: ItemTicket.java    From Signals with GNU General Public License v3.0 5 votes vote down vote up
public static List<String> getDestinations(ItemStack stack){
    NBTTagCompound tag = stack.getSubCompound("destinations");
    if(tag != null) {
        NBTTagList tagList = tag.getTagList("destinations", Constants.NBT.TAG_STRING);
        return StreamSupport.stream(tagList.spliterator(), false).map(nbt -> ((NBTTagString)nbt).getString()).collect(Collectors.toList());
    } else {
        return Collections.emptyList();
    }
}
 
Example 5
Source File: Shield.java    From minecraft-roguelike with GNU General Public License v3.0 5 votes vote down vote up
public static void applyBanner(ItemStack banner, ItemStack shield){
	
       NBTTagCompound bannerNBT = banner.getSubCompound("BlockEntityTag");
       NBTTagCompound shieldNBT = bannerNBT == null ? new NBTTagCompound() : bannerNBT.copy();
       shieldNBT.setInteger("Base", banner.getMetadata() & 15);
       shield.setTagInfo("BlockEntityTag", shieldNBT);

}
 
Example 6
Source File: ToolMetaItem.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
private static NBTTagCompound getToolStatsTag(ItemStack itemStack) {
    return itemStack.getSubCompound("GT.ToolStats");
}
 
Example 7
Source File: AbstractMaterialPartBehavior.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected NBTTagCompound getPartStatsTag(ItemStack itemStack) {
    return itemStack.getSubCompound("GT.PartStats");
}