Java Code Examples for net.minecraft.nbt.NBTTagList#getStringTagAt()

The following examples show how to use net.minecraft.nbt.NBTTagList#getStringTagAt() . 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: CraftMetaBookSigned.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
CraftMetaBookSigned(NBTTagCompound tag) {
    super(tag, false);

    boolean resolved = true;
    if (tag.hasKey(RESOLVED.NBT)) {
        resolved = tag.getBoolean(RESOLVED.NBT);
    }

    if (tag.hasKey(BOOK_PAGES.NBT)) {
        NBTTagList pages = tag.getTagList(BOOK_PAGES.NBT, CraftMagicNumbers.NBT.TAG_STRING);

        for (int i = 0; i < Math.min(pages.tagCount(), MAX_PAGES); i++) {
            String page = pages.getStringTagAt(i);
            if (resolved) {
                try {
                    this.pages.add(ITextComponent.Serializer.jsonToComponent(page));
                    continue;
                } catch (Exception e) {
                    // Ignore and treat as an old book
                }
            }
            addPage(page);
        }
    }
}
 
Example 2
Source File: PythonCode.java    From pycode-minecraft with MIT License 6 votes vote down vote up
public static final String bookAsString(ItemStack book) {
    NBTTagCompound bookData = book.getTagCompound();
    NBTTagList pages;
    try {
        // pages are all of type TAG_String == 8
        pages = bookData.getTagList("pages", 8);
    } catch (NullPointerException e) {
        // this should not happen!
        return null;
    }
    // collapse the pages into one string
    StringBuilder sbStr = new StringBuilder();
    for(int i = 0;i<pages.tagCount();i++) {
        String s = pages.getStringTagAt(i);
        if (i > 0) sbStr.append("\n");
        sbStr.append(s);
    }
    return sbStr.toString();
}
 
Example 3
Source File: ItemPartFrame.java    From Framez with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List tip, boolean shift) {

    NBTTagCompound tag = stack.getTagCompound();

    if (tag == null)
        return;
    if (!tag.hasKey("modifiers"))
        return;

    tip.add(I18n.format("tooltip." + ModInfo.MODID + ":modifiers") + ":");

    NBTTagList l = tag.getTagList("modifiers", new NBTTagString().getId());
    for (int i = 0; i < l.tagCount(); i++) {
        String type = l.getStringTagAt(i);
        IFrameModifier mod = FrameModifierRegistry.instance().findModifier(type);
        boolean found = mod != null;

        tip.add((!found ? EnumChatFormatting.RED : "")
                + " - "
                + I18n.format("tooltip." + ModInfo.MODID + ":modifier." + type + ".name")
                + (mod != null && mod instanceof IFrameModifierMaterial ? " ["
                        + I18n.format("tooltip." + ModInfo.MODID + ":modifier.material") + "]" : ""));
    }
}
 
Example 4
Source File: ItemPartFrame.java    From Framez with GNU General Public License v3.0 6 votes vote down vote up
@Override
public String getUnlocalizedName(ItemStack stack) {

    NBTTagCompound tag = stack.getTagCompound();

    if (tag == null)
        return super.getUnlocalizedName(stack);
    if (!tag.hasKey("modifiers"))
        return super.getUnlocalizedName(stack);

    NBTTagList l = tag.getTagList("modifiers", new NBTTagString().getId());
    for (int i = 0; i < l.tagCount(); i++) {
        String type = l.getStringTagAt(i);
        IFrameModifier mod = FrameModifierRegistry.instance().findModifier(type);
        if (mod != null && mod instanceof IFrameModifierMaterial)
            return super.getUnlocalizedName(stack) + "." + type;
    }

    return super.getUnlocalizedName(stack);
}
 
Example 5
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 6
Source File: CraftMetaKnowledgeBook.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
CraftMetaKnowledgeBook(NBTTagCompound tag) {
    super(tag);

    if (tag.hasKey(BOOK_RECIPES.NBT)) {
        NBTTagList pages = tag.getTagList(BOOK_RECIPES.NBT, 8);

        for (int i = 0; i < pages.tagCount(); i++) {
            String recipe = pages.getStringTagAt(i);

            addRecipe(CraftNamespacedKey.fromString(recipe));
        }
    }
}
 
Example 7
Source File: CraftMetaBook.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
CraftMetaBook(NBTTagCompound tag, boolean handlePages) {
    super(tag);

    if (tag.hasKey(BOOK_TITLE.NBT)) {
        this.title = tag.getString(BOOK_TITLE.NBT);
    }

    if (tag.hasKey(BOOK_AUTHOR.NBT)) {
        this.author = tag.getString(BOOK_AUTHOR.NBT);
    }

    boolean resolved = false;
    if (tag.hasKey(RESOLVED.NBT)) {
        resolved = tag.getBoolean(RESOLVED.NBT);
    }

    if (tag.hasKey(GENERATION.NBT)) {
        generation = tag.getInteger(GENERATION.NBT);
    }

    if (tag.hasKey(BOOK_PAGES.NBT) && handlePages) {
        NBTTagList pages = tag.getTagList(BOOK_PAGES.NBT, CraftMagicNumbers.NBT.TAG_STRING);

        for (int i = 0; i < Math.min(pages.tagCount(), MAX_PAGES); i++) {
            String page = pages.getStringTagAt(i);
            if (resolved) {
                try {
                    this.pages.add(ITextComponent.Serializer.jsonToComponent(page));
                    continue;
                } catch (Exception e) {
                    // Ignore and treat as an old book
                }
            }
            addPage(page);
        }
    }
}
 
Example 8
Source File: RecipeCrudeHaloInfusion.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean matches(@Nonnull InventoryCrafting inv, @Nonnull World worldIn) {
	ItemStack foundHalo = ItemStack.EMPTY;
	boolean foundGlueStick = false;

	int availableItems = 0;
	for (int i = 0; i < inv.getSizeInventory(); i++) {
		ItemStack stack = inv.getStackInSlot(i);
		if (stack.getItem() == Items.SLIME_BALL) {
			if (foundGlueStick) return false;
			foundGlueStick = true;
		} else if (stack.getItem() == ModItems.FAKE_HALO) {
			if (!foundHalo.isEmpty()) return false;
			foundHalo = stack;
		} else if (HaloInfusionItemRegistry.isHaloInfusionItem(stack))
			availableItems++;
		else if (!stack.isEmpty()) {
			return false;
		}
	}

	if (!foundGlueStick || foundHalo.isEmpty() || availableItems <= 0) return false;

	NBTTagList slots = NBTHelper.getList(foundHalo, "slots", NBTTagString.class);
	if (slots == null) return availableItems <= 7;

	int freeSlots = 0;
	for (int j = 0; j < slots.tagCount(); j++) {
		if (freeSlots >= 7) break;
		String string = slots.getStringTagAt(j);
		HaloInfusionItem infusionItem = HaloInfusionItemRegistry.getItemFromName(string);
		if (infusionItem == HaloInfusionItemRegistry.EMPTY) freeSlots++;
	}

	return freeSlots >= availableItems;
}
 
Example 9
Source File: TileEntityQuantumComputer.java    From qcraft-mod with Apache License 2.0 5 votes vote down vote up
public static AreaData decode( NBTTagCompound nbttagcompound )
{
    AreaData storedData = new AreaData();
    storedData.m_shape = new AreaShape();
    storedData.m_shape.m_xMin = nbttagcompound.getInteger( "xmin" );
    storedData.m_shape.m_xMax = nbttagcompound.getInteger( "xmax" );
    storedData.m_shape.m_yMin = nbttagcompound.getInteger( "ymin" );
    storedData.m_shape.m_yMax = nbttagcompound.getInteger( "ymax" );
    storedData.m_shape.m_zMin = nbttagcompound.getInteger( "zmin" );
    storedData.m_shape.m_zMax = nbttagcompound.getInteger( "zmax" );

    int size =
        ( storedData.m_shape.m_xMax - storedData.m_shape.m_xMin + 1 ) *
        ( storedData.m_shape.m_yMax - storedData.m_shape.m_yMin + 1 ) *
        ( storedData.m_shape.m_zMax - storedData.m_shape.m_zMin + 1 );
    storedData.m_blocks = new Block[ size ];
    if( nbttagcompound.hasKey( "blockData" ) )
    {
        int[] blockIDs = nbttagcompound.getIntArray( "blockData" );
        for( int i=0; i<size; ++i )
        {
            storedData.m_blocks[i] = Block.getBlockById( blockIDs[i] );
        }
    }
    else
    {
        NBTTagList blockNames = nbttagcompound.getTagList( "blockNames", Constants.NBT.TAG_STRING );
        for( int i=0; i<size; ++i )
        {
            String name = blockNames.getStringTagAt( i );
            if( name.length() > 0 && !name.equals( "null" ) )
            {
                storedData.m_blocks[i] = Block.getBlockFromName( name );
            }
        }
    }
    storedData.m_metaData = nbttagcompound.getIntArray( "metaData" );
    return storedData;
}