Java Code Examples for net.minecraft.item.ItemStack.hasTagCompound()

The following are Jave code examples for showing how to use hasTagCompound() of the net.minecraft.item.ItemStack class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: minecraft-territorialdealings   File: ClaimTerritoryOrder.java   View Source Code Vote up 6 votes
private String getNameOfFaction(ItemStack stack)
{
	// We're storing the faction ID in the item after it has been signed by a leader
	if (stack.hasTagCompound())
	{
		String id = stack.getTagCompound().getString("factionID");
		
		if (id == null || id.isEmpty())
		{
			// ...eh?
			return null;
		}
		else
		{
			// What're you called...
			return TerritoryHandler.getNameOfFaction(UUID.fromString(id));
		}
	}
	else
	{
		// Has no faction ID tag, so cannot be signed
		return null;
	}
}
 
Example 2
Project: DecompiledMinecraft   File: RecipesBanners.java   View Source Code Vote up 6 votes
public ItemStack[] getRemainingItems(InventoryCrafting inv)
{
    ItemStack[] aitemstack = new ItemStack[inv.getSizeInventory()];

    for (int i = 0; i < aitemstack.length; ++i)
    {
        ItemStack itemstack = inv.getStackInSlot(i);

        if (itemstack != null)
        {
            if (itemstack.getItem().hasContainerItem())
            {
                aitemstack[i] = new ItemStack(itemstack.getItem().getContainerItem());
            }
            else if (itemstack.hasTagCompound() && TileEntityBanner.getPatterns(itemstack) > 0)
            {
                aitemstack[i] = itemstack.copy();
                aitemstack[i].stackSize = 1;
            }
        }
    }

    return aitemstack;
}
 
Example 3
Project: Thermionics   File: ItemChunkUnloader.java   View Source Code Vote up 6 votes
public Optional<Boolean> isChunkLoaded(ItemStack stack) {
	if (!stack.hasTagCompound()) return UNATTUNED;
	
	NBTTagCompound tag = stack.getTagCompound();
	if (tag.hasKey("world")) {
		int worldId = tag.getInteger("world");
		if (!DimensionManager.isDimensionRegistered(worldId)) return UNATTUNED;
		
		//We're reasonably certain at this point the unloader is attuned to a valid world.
		
		WorldServer world = DimensionManager.getWorld(worldId);
		if (world==null) return UNLOADED;
		
		//boolean playerLoad = world.getPlayerChunkMap().contains(tag.getInteger("x"), tag.getInteger("z"));
		//System.out.println("chunk["+tag.getInteger("x")+","+tag.getInteger("z")+"] isPlayerLoaded:"+playerLoad);
		
		Chunk chunk = world.getChunkProvider().getLoadedChunk(tag.getInteger("x"), tag.getInteger("z"));
		return (chunk!=null) ? LOADED : UNLOADED;
		//Chunk chunk = world.getChunkFromChunkCoords(tag.getInteger("x"),tag.getInteger("z"));
		//return (chunk.isLoaded()) ? LOADED : UNLOADED;
	}
	
	return UNATTUNED;
}
 
Example 4
Project: minecraft-territorialdealings   File: ClaimTerritoryOrder.java   View Source Code Vote up 5 votes
private void setFactionID(ItemStack stack, UUID id)
{
	if (stack == null) { return; }
	if (id == null) { return; }
	
	if (!stack.hasTagCompound())
	{
		stack.setTagCompound(new NBTTagCompound());	// Init
	}
	
	stack.getTagCompound().setString("factionID", id.toString());	// Done
}
 
Example 5
Project: DecompiledMinecraft   File: EnchantmentHelper.java   View Source Code Vote up 5 votes
/**
 * Set the enchantments for the specified stack.
 */
public static void setEnchantments(Map<Integer, Integer> enchMap, ItemStack stack)
{
    NBTTagList nbttaglist = new NBTTagList();
    Iterator iterator = enchMap.keySet().iterator();

    while (iterator.hasNext())
    {
        int i = ((Integer)iterator.next()).intValue();
        Enchantment enchantment = Enchantment.getEnchantmentById(i);

        if (enchantment != null)
        {
            NBTTagCompound nbttagcompound = new NBTTagCompound();
            nbttagcompound.setShort("id", (short)i);
            nbttagcompound.setShort("lvl", (short)((Integer)enchMap.get(Integer.valueOf(i))).intValue());
            nbttaglist.appendTag(nbttagcompound);

            if (stack.getItem() == Items.enchanted_book)
            {
                Items.enchanted_book.addEnchantment(stack, new EnchantmentData(enchantment, ((Integer)enchMap.get(Integer.valueOf(i))).intValue()));
            }
        }
    }

    if (nbttaglist.tagCount() > 0)
    {
        if (stack.getItem() != Items.enchanted_book)
        {
            stack.setTagInfo("ench", nbttaglist);
        }
    }
    else if (stack.hasTagCompound())
    {
        stack.getTagCompound().removeTag("ench");
    }
}
 
Example 6
Project: Mods   File: RIGEvents.java   View Source Code Vote up 5 votes
@SubscribeEvent
public void livingUpdate(LivingUpdateEvent event) {
	EntityLivingBase living = event.getEntityLiving();
	if(living.hasCapability(RIG.RIG_ITEM, null)) {
		ItemStack rig = living.getCapability(RIG.RIG_ITEM, null).getStackInSlot(0);
		if(rig.hasTagCompound() && living.isInWater()) {
			int extraair = 100 + RIGUpgrade.upgradesMap.get("Air").getAttributeValue(rig) * 100;
			if (living.getRNG().nextInt(300+extraair)>=300) {
				living.setAir(living.getAir()+1);
			}
		}
	}
}
 
Example 7
Project: Mods   File: EntitySaxtonHale.java   View Source Code Vote up 5 votes
@Override
public void verifySellingItem(ItemStack stack) {
	// TODO Auto-generated method stub
	if(!stack.isEmpty() && stack.hasTagCompound())
		stack.getTagCompound().setBoolean("Bought", true);
	/*if (this.trader != null && !stack.isEmpty() &&stack.getItem() instanceof ItemWeapon)
		this.trader.addStat(TF2Achievements.MANN_CO_MADE);*/

}
 
Example 8
Project: minecraft-quiverbow   File: EnderBow.java   View Source Code Vote up 5 votes
boolean isCurrentlyZoomed(ItemStack stack)
{
	if (stack == null) { return false; }	// Not a  valid item
	if (!stack.hasTagCompound()) { return false; } // No tag
	
	return stack.stackTagCompound.getBoolean("isZoomed");
}
 
Example 9
Project: Whoosh   File: ItemTransporter.java   View Source Code Vote up 5 votes
public static long getLastUsed(ItemStack stack) {

        if(!stack.hasTagCompound())
            return 0;

        NBTTagCompound tag = stack.getTagCompound();
        if(!tag.hasKey("LastUsed"))
            return 0;
        return tag.getLong("LastUsed");
    }
 
Example 10
Project: Mods   File: ItemStatue.java   View Source Code Vote up 5 votes
public String getItemStackDisplayName(ItemStack stack)
  {
if(!stack.hasTagCompound())
	return super.getItemStackDisplayName(stack);
if(!stack.getTagCompound().getCompoundTag("Statue").getBoolean("Player"))
	return I18n.translateToLocal("entity." + EntityList.getTranslationName
			(new ResourceLocation(stack.getTagCompound().getCompoundTag("Statue").getCompoundTag("Entity").getString("id")))+".name")+" "+
			I18n.translateToLocal(this.getUnlocalizedName() + ".name");
else
	return I18n.translateToLocal(this.getUnlocalizedName() + ".player.name");
  }
 
Example 11
Project: DecompiledMinecraft   File: InventoryHelper.java   View Source Code Vote up 5 votes
private static void spawnItemStack(World worldIn, double x, double y, double z, ItemStack stack)
{
    float f = RANDOM.nextFloat() * 0.8F + 0.1F;
    float f1 = RANDOM.nextFloat() * 0.8F + 0.1F;
    float f2 = RANDOM.nextFloat() * 0.8F + 0.1F;

    while (stack.stackSize > 0)
    {
        int i = RANDOM.nextInt(21) + 10;

        if (i > stack.stackSize)
        {
            i = stack.stackSize;
        }

        stack.stackSize -= i;
        EntityItem entityitem = new EntityItem(worldIn, x + (double)f, y + (double)f1, z + (double)f2, new ItemStack(stack.getItem(), i, stack.getMetadata()));

        if (stack.hasTagCompound())
        {
            entityitem.getEntityItem().setTagCompound((NBTTagCompound)stack.getTagCompound().copy());
        }

        float f3 = 0.05F;
        entityitem.motionX = RANDOM.nextGaussian() * (double)f3;
        entityitem.motionY = RANDOM.nextGaussian() * (double)f3 + 0.20000000298023224D;
        entityitem.motionZ = RANDOM.nextGaussian() * (double)f3;
        worldIn.spawnEntityInWorld(entityitem);
    }
}
 
Example 12
Project: CursedLasso   File: ItemCursedLasso.java   View Source Code Vote up 5 votes
@Override
public boolean itemInteractionForEntity(ItemStack item, EntityPlayer player, EntityLivingBase entity) {
    if (entity.worldObj.isRemote) {
        return false;
    }
    if (entity instanceof IMob) {
        if (item.hasTagCompound())
            return false;
        item.setTagCompound(new NBTTagCompound());
        NBTTagCompound mainTag = new NBTTagCompound();
        NBTTagCompound entityTag = new NBTTagCompound();
        entity.writeToNBT(entityTag);
        mainTag.setFloat("health",entity.getHealth());
        mainTag.setTag("data", entityTag);
        mainTag.setString("id", EntityList.getEntityString(entity));
        if (entity instanceof EntitySlime) {
            mainTag.setInteger("slimesize", ((EntitySlime) entity).getSlimeSize());
        }
        if(entity instanceof EntityZombie){
            mainTag.setBoolean("isBabyZombie",entity.isChild());
        }
        item.getTagCompound().setTag("entity",mainTag);
        player.setCurrentItemOrArmor(0, item);
        entity.setDead();
        return true;
    }
    return super.itemInteractionForEntity(item, player, entity);
}
 
Example 13
Project: minecraft-quiverbow   File: ERA.java   View Source Code Vote up 5 votes
@Override
public EnumRarity getRarity(ItemStack stack)
   {
	if (stack.hasTagCompound() && stack.getTagCompound().getBoolean("hasEmeraldMuzzle")) { return EnumRarity.rare; }
       
       return EnumRarity.common;	// Default
   }
 
Example 14
Project: minecraft-quiverbow   File: EnderBow.java   View Source Code Vote up 5 votes
void setCurrentZoom(ItemStack stack, boolean zoom)
{
	if (stack == null) { return; }	// Not a  valid item
	if (!stack.hasTagCompound()) { return; } // No tag
	
	stack.stackTagCompound.setBoolean("isZoomed", zoom);
}
 
Example 15
Project: minecraft-territorialdealings   File: ClaimTerritoryOrder.java   View Source Code Vote up 5 votes
@Override
public double getDurabilityForDisplay(ItemStack stack)
{
	if (stack.hasTagCompound()) 
	{ 
		return stack.getTagCompound().getFloat("displayDurability"); 
	}
	// else, no info yet about any territories

	return 1.0f;	// Displaying 1.0 as "full damage", meaning an empty bar.
}
 
Example 16
Project: CursedLasso   File: ItemCursedLasso.java   View Source Code Vote up 4 votes
@Override
@SideOnly(Side.CLIENT)
public boolean hasEffect(ItemStack item, int pass) {
    return item.hasTagCompound();
}
 
Example 17
Project: BaseClient   File: InventoryPlayer.java   View Source Code Vote up 4 votes
/**
 * This function stores as many items of an ItemStack as possible in a matching slot and returns the quantity of
 * left over items.
 */
private int storePartialItemStack(ItemStack itemStackIn)
{
    Item item = itemStackIn.getItem();
    int i = itemStackIn.stackSize;
    int j = this.storeItemStack(itemStackIn);

    if (j < 0)
    {
        j = this.getFirstEmptyStack();
    }

    if (j < 0)
    {
        return i;
    }
    else
    {
        if (this.mainInventory[j] == null)
        {
            this.mainInventory[j] = new ItemStack(item, 0, itemStackIn.getMetadata());

            if (itemStackIn.hasTagCompound())
            {
                this.mainInventory[j].setTagCompound((NBTTagCompound)itemStackIn.getTagCompound().copy());
            }
        }

        int k = i;

        if (i > this.mainInventory[j].getMaxStackSize() - this.mainInventory[j].stackSize)
        {
            k = this.mainInventory[j].getMaxStackSize() - this.mainInventory[j].stackSize;
        }

        if (k > this.getInventoryStackLimit() - this.mainInventory[j].stackSize)
        {
            k = this.getInventoryStackLimit() - this.mainInventory[j].stackSize;
        }

        if (k == 0)
        {
            return i;
        }
        else
        {
            i = i - k;
            this.mainInventory[j].stackSize += k;
            this.mainInventory[j].animationsToGo = 5;
            return i;
        }
    }
}
 
Example 18
Project: NemesisSystem   File: DiscoveryUtil.java   View Source Code Vote up 4 votes
private static boolean hasDiscoveryTag(ItemStack item) {
	if (!item.hasTagCompound()) {
		return false;
	}
	return item.getTagCompound().hasKey(NBT_DISCOVERY) || item.getTagCompound().hasKey(NBT_UNREAD_DISCOVERY);
}
 
Example 19
Project: BaseClient   File: EntityItem.java   View Source Code Vote up 4 votes
/**
 * Tries to merge this item with the item passed as the parameter. Returns true if successful. Either this item or
 * the other item will  be removed from the world.
 */
private boolean combineItems(EntityItem other)
{
    if (other == this)
    {
        return false;
    }
    else if (other.isEntityAlive() && this.isEntityAlive())
    {
        ItemStack itemstack = this.getEntityItem();
        ItemStack itemstack1 = other.getEntityItem();

        if (this.delayBeforeCanPickup != 32767 && other.delayBeforeCanPickup != 32767)
        {
            if (this.age != -32768 && other.age != -32768)
            {
                if (itemstack1.getItem() != itemstack.getItem())
                {
                    return false;
                }
                else if (itemstack1.hasTagCompound() ^ itemstack.hasTagCompound())
                {
                    return false;
                }
                else if (itemstack1.hasTagCompound() && !itemstack1.getTagCompound().equals(itemstack.getTagCompound()))
                {
                    return false;
                }
                else if (itemstack1.getItem() == null)
                {
                    return false;
                }
                else if (itemstack1.getItem().getHasSubtypes() && itemstack1.getMetadata() != itemstack.getMetadata())
                {
                    return false;
                }
                else if (itemstack1.stackSize < itemstack.stackSize)
                {
                    return other.combineItems(this);
                }
                else if (itemstack1.stackSize + itemstack.stackSize > itemstack1.getMaxStackSize())
                {
                    return false;
                }
                else
                {
                    itemstack1.stackSize += itemstack.stackSize;
                    other.delayBeforeCanPickup = Math.max(other.delayBeforeCanPickup, this.delayBeforeCanPickup);
                    other.age = Math.min(other.age, this.age);
                    other.setEntityItemStack(itemstack1);
                    this.setDead();
                    return true;
                }
            }
            else
            {
                return false;
            }
        }
        else
        {
            return false;
        }
    }
    else
    {
        return false;
    }
}
 
Example 20
Project: Melodium   File: ItemUtil.java   View Source Code Vote up 4 votes
public static NBTTagCompound getOrCreateTag(ItemStack item) {
	if (!item.hasTagCompound()) {
		item.setTagCompound(new NBTTagCompound());
	}
	return item.getTagCompound();
}