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

The following examples show how to use net.minecraft.item.ItemStack#getTagCompound() . 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: ItemConverter.java    From NOVA-Core with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Item getNovaItem(ItemStack itemStack) {
	if (itemStack.getItemDamage() == net.minecraftforge.oredict.OreDictionary.WILDCARD_VALUE) {
		// TODO: Deal withPriority wildcard meta values - important for the ore dictionary
		return getNovaItem(new ItemStack(itemStack.getItem(), 1, 0));
	}

	if (itemStack.getTagCompound() != null && itemStack.getTagCompound() instanceof FWNBTTagCompound) {
		return ((FWNBTTagCompound) itemStack.getTagCompound()).getItem();
	} else {
		ItemFactory itemFactory = registerMinecraftMapping(itemStack.getItem(), itemStack.getItemDamage());

		Data data = itemStack.getTagCompound() != null ? DataConverter.instance().toNova(itemStack.getTagCompound()) : new Data();
		if (!itemStack.getHasSubtypes() && itemStack.getItemDamage() > 0) {
			data.put("damage", itemStack.getItemDamage());
		}

		return itemFactory.build(data);
	}
}
 
Example 2
Source File: ItemSatelliteIdentificationChip.java    From AdvancedRocketry with MIT License 6 votes vote down vote up
public SatelliteBase getSatellite(ItemStack stack) {
	if(stack.hasTagCompound()) {
		NBTTagCompound nbt = stack.getTagCompound();

		long satId = nbt.getLong("satelliteId");

		SatelliteBase satellite = zmaster587.advancedRocketry.dimension.DimensionManager.getInstance().getSatellite(satId);

		if(satellite != null) {

			if(!nbt.hasKey("dimId") || nbt.getInteger("dimId") == -1) {
				nbt.setInteger("dimId", satellite.getDimensionId());
			}

			if( zmaster587.advancedRocketry.dimension.DimensionManager.getInstance().getDimensionProperties(satellite.getDimensionId()) != null)
				nbt.setString(name, zmaster587.advancedRocketry.dimension.DimensionManager.getInstance().getDimensionProperties(satellite.getDimensionId()).getName());
		}


		return satellite;
	}
	return null;
}
 
Example 3
Source File: ItemChestPickup.java    From BetterChests with GNU Lesser General Public License v3.0 6 votes vote down vote up
private ItemStack getDrop(BlockPos pos, World world) {

		IBlockState state = world.getBlockState(pos);

		Block block = state.getBlock();
		ItemStack stack = block.getItem(world, pos, state);
		TileEntity te = world.getTileEntity(pos);
		if (te == null) {
			return stack;
		}

		if (!stack.hasTagCompound()) {
			stack.setTagCompound(new NBTTagCompound());
		}
		NBTTagCompound nbt = stack.getTagCompound();
		nbt.setTag("BlockEntityTag", te.writeToNBT(new NBTTagCompound()));
		return stack;
	}
 
Example 4
Source File: HandItem.java    From pycode-minecraft with MIT License 6 votes vote down vote up
@Override
public EnumActionResult onItemUse(ItemStack stackIn, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (world.isRemote) {
        return EnumActionResult.PASS;
    }
    if (stackIn.stackSize != 0) {
        float yaw = player.getHorizontalFacing().getHorizontalAngle();
        NBTTagCompound compound = stackIn.getTagCompound();
        HandEntity entity = new HandEntity(world, compound,
                pos.getX() + .5, pos.getY() + 1.0, pos.getZ() + .5, yaw);
        world.spawnEntityInWorld(entity);
        --stackIn.stackSize;
        return EnumActionResult.SUCCESS;
    } else {
        return EnumActionResult.FAIL;
    }
}
 
Example 5
Source File: Utils.java    From SkyblockAddons with MIT License 6 votes vote down vote up
public String getReforgeFromItem(ItemStack item) {
    if (item.hasTagCompound()) {
        NBTTagCompound extraAttributes = item.getTagCompound();
        if (extraAttributes.hasKey("ExtraAttributes")) {
            extraAttributes = extraAttributes.getCompoundTag("ExtraAttributes");
            if (extraAttributes.hasKey("modifier")) {
                String reforge = WordUtils.capitalizeFully(extraAttributes.getString("modifier"));

                reforge = reforge.replace("_sword", ""); //fixes reforges like "Odd_sword"
                reforge = reforge.replace("_bow", "");

                return reforge;
            }
        }
    }
    return null;
}
 
Example 6
Source File: ItemQBlock.java    From qcraft-mod with Apache License 2.0 6 votes vote down vote up
public static int[] getTypes( ItemStack stack )
{
    // Get the tags
    int[] types = new int[ 6 ];
    if( stack.hasTagCompound() )
    {
        NBTTagCompound nbt = stack.getTagCompound();
        for( int i = 0; i < types.length; ++i )
        {
            if( nbt.hasKey( "s" + i ) )
            {
                types[ i ] = nbt.getInteger( "s" + i );
            }
            else
            {
                types[ i ] = 0;
            }
        }
    }
    return types;
}
 
Example 7
Source File: BW_NEI_BioLabHandler.java    From bartworks with MIT License 6 votes vote down vote up
public void loadCraftingRecipes(ItemStack aResult) {
    if (aResult != null && aResult.getItem() instanceof LabParts && aResult.getItemDamage() < 3) {
        for (GT_Recipe recipe : this.getSortedRecipes()) {
            if (aResult.getTagCompound() != null && recipe != null)
                for (int i = 0; i < recipe.mOutputs.length; i++) {
                    if (recipe.mOutputs[i] != null)
                        if (aResult.getTagCompound().equals(recipe.mOutputs[i].getTagCompound())) {
                            this.arecipes.add(new CachedDefaultRecipe(recipe));
                            break;
                        }

                }
        }
    } else
        super.loadCraftingRecipes(aResult);
}
 
Example 8
Source File: ItemExpCapsule.java    From Cyberware with MIT License 6 votes vote down vote up
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World worldIn, EntityPlayer playerIn, EnumHand hand)
{
	if (!playerIn.capabilities.isCreativeMode)
	{
		--stack.stackSize;
	}
	
	int xp = 0;
	if (stack.hasTagCompound())
	{
		NBTTagCompound c = stack.getTagCompound();
		if (c.hasKey("xp"))
		{
			xp = c.getInteger("xp");
		}
	}
	
	playerIn.addExperience(xp);
	
	return new ActionResult(EnumActionResult.SUCCESS, stack);
}
 
Example 9
Source File: TileEntitySolderingStation.java    From ExtraCells1 with MIT License 5 votes vote down vote up
public void changeTypes(EntityPlayer player, int slotID, int typesDelta)
{
	ItemStack storage = player.inventory.getCurrentItem().copy();
	if (storage != null && storage.getItem() == ItemEnum.STORAGEPHYSICAL.getItemInstance() && storage.getItemDamage() == 5)
	{

		if (!storage.hasTagCompound())
		{
			storage.setTagCompound(new NBTTagCompound());
		}
		NBTTagCompound nbt = storage.getTagCompound();
		int oldTypes = nbt.getInteger("custom_types");
		if (oldTypes + typesDelta >= 27 && oldTypes + typesDelta <= 63 && typesDelta != 0)
		{
			if (typesDelta > 0)
			{
				if (decreaseItemStack(Materials.matConversionMatrix.copy(), player.inventory))
				{
					nbt.setInteger("custom_types", oldTypes + typesDelta);
					player.inventory.mainInventory[player.inventory.currentItem] = storage;
				}
			} else if (typesDelta < 0)
			{
				if (player.inventory.addItemStackToInventory(Materials.matConversionMatrix.copy()))
				{
					nbt.setInteger("custom_types", oldTypes + typesDelta);
					player.inventory.mainInventory[player.inventory.currentItem] = storage;
				}
			}
		}
	}
}
 
Example 10
Source File: ItemSatelliteIdentificationChip.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
public long getSatelliteId(ItemStack stack) {
	if(stack.hasTagCompound()) {
		NBTTagCompound nbt = stack.getTagCompound();

		return nbt.getLong("satelliteId");
	}
	return -1;
}
 
Example 11
Source File: DataManager.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void setHeldItemAsTool()
{
    EntityPlayer player = Minecraft.getMinecraft().player;

    if (player != null)
    {
        ItemStack stack = player.getHeldItemMainhand();
        toolItem = stack.isEmpty() ? ItemStack.EMPTY : stack.copy();
        String cfgStr = "";

        if (stack.isEmpty() == false)
        {
            cfgStr = Item.REGISTRY.getNameForObject(stack.getItem()).toString();
            NBTTagCompound nbt = stack.getTagCompound();

            if (stack.isItemStackDamageable() == false || nbt != null)
            {
                cfgStr += "@" + stack.getMetadata();

                if (nbt != null)
                {
                    cfgStr += nbt.toString();
                }
            }
        }

        Configs.Generic.TOOL_ITEM.setValueFromString(cfgStr);
        InfoUtils.printActionbarMessage("litematica.message.set_currently_held_item_as_tool");
    }
}
 
Example 12
Source File: ItemSatelliteIdentificationChip.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
public void setDim(ItemStack stack, int dimId) {
	NBTTagCompound nbt;
	if(stack.hasTagCompound())
		nbt = stack.getTagCompound();
	else 
		return;

	nbt.setInteger("dimId", dimId);
}
 
Example 13
Source File: ModeSwitchBehavior.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void setModeForItemStack(ItemStack itemStack, T newMode) {
    if (!itemStack.hasTagCompound()) {
        itemStack.setTagCompound(new NBTTagCompound());
    }
    NBTTagCompound tagCompound = itemStack.getTagCompound();
    tagCompound.setInteger("Mode", ArrayUtils.indexOf(enumConstants, newMode));
}
 
Example 14
Source File: ItemEnderBucket.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static BucketMode fromStack(ItemStack stack)
{
    NBTTagCompound tag = stack.getTagCompound();
    return tag == null ? NORMAL : values()[MathHelper.clamp(tag.getByte("Mode"), 0, values().length - 1)];
}
 
Example 15
Source File: ItemWirelessRemote.java    From WirelessRedstone with MIT License 4 votes vote down vote up
public static boolean getTransmitting(ItemStack stack) {
    NBTTagCompound tag = stack.getTagCompound();
    return tag != null && tag.hasKey("on", 1) && tag.getBoolean("on");
}
 
Example 16
Source File: ToggleEnergyConsumerBehavior.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
public boolean isItemActive(ItemStack itemStack) {
    NBTTagCompound tagCompound = itemStack.getTagCompound();
    return tagCompound != null && tagCompound.getBoolean("Active");
}
 
Example 17
Source File: ItemArtifactArmor.java    From Artifacts with MIT License 4 votes vote down vote up
@Override
public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack)
{
	NBTTagCompound data = itemStack.getTagCompound();
	int effectID = 0;
	if(data != null) {
		if(!world.isRemote) {
			IArtifactComponent c;
			effectID = data.getInteger("onArmorTickUpdate");
			if(effectID != 0) {
				c = ArtifactsAPI.artifacts.getComponent(effectID);
				if(c != null)
					c.onArmorTickUpdate(world, player, itemStack, true);
			}
			effectID = data.getInteger("onArmorTickUpdate2");
			if(effectID != 0) {
				c = ArtifactsAPI.artifacts.getComponent(effectID);
				if(c != null)
					c.onArmorTickUpdate(world, player, itemStack, true);
			}
			effectID = data.getInteger("onTakeDamage");
			if(effectID != 0) {
				c = ArtifactsAPI.artifacts.getComponent(effectID);
				if(c != null && !(c instanceof ComponentBreathing))
					c.onArmorTickUpdate(world, player, itemStack, true);
			}
			effectID = data.getInteger("onDeath");
			if(effectID != 0) {
				c = ArtifactsAPI.artifacts.getComponent(effectID);
				if(c != null)
					c.onArmorTickUpdate(world, player, itemStack, true);
			}
		}
		ArrayList<String> keys = ArtifactsAPI.artifacts.getNBTKeys();
		String kk = "";
		int n = 0;
		for(int k = keys.size() - 1; k >= 0; k--) {
			kk = keys.get(k)+"_armor";
			if(data.hasKey(kk)) {
				n = data.getInteger(kk);
				if(n > 0)
					n--;
				data.setInteger(kk,n);
			}
		}
	}
	else if(!world.isRemote) {
		ItemStack newStack = ArtifactsAPI.artifacts.applyRandomEffects(new ItemStack(this));
		
		for(int i = 0; i < player.inventory.armorInventory.length; i++) {
			if(player.inventory.armorInventory[i] == itemStack) {
				player.inventory.armorInventory[i] = newStack;
			}
		}
	}
}
 
Example 18
Source File: ItemArtifactArmor.java    From Artifacts with MIT License 4 votes vote down vote up
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean advTooltip) {
	NBTTagCompound data = par1ItemStack.getTagCompound();
	int effectID = 0;
	if(data != null) {
       	IArtifactComponent c;

		effectID = data.getInteger("onArmorTickUpdate");
		if(effectID != 0) {
			c = ArtifactsAPI.artifacts.getComponent(effectID);
			if(c != null)
				c.addInformation(par1ItemStack, par2EntityPlayer, par3List, "when equipped.", advTooltip);
		}
		effectID = data.getInteger("onArmorTickUpdate2");
		if(effectID != 0) {
			c = ArtifactsAPI.artifacts.getComponent(effectID);
			if(c != null)
				c.addInformation(par1ItemStack, par2EntityPlayer, par3List, "when equipped.", advTooltip);
		}
		effectID = data.getInteger("onUpdate");
		if(effectID != 0) {
			c = ArtifactsAPI.artifacts.getComponent(effectID);
			if(c != null)
				c.addInformation(par1ItemStack, par2EntityPlayer, par3List, "passively.", advTooltip);
		}
		effectID = data.getInteger("onTakeDamage");
		if(effectID != 0) {
			c = ArtifactsAPI.artifacts.getComponent(effectID);
			if(c != null)
				c.addInformation(par1ItemStack, par2EntityPlayer, par3List, "after taking damage.", advTooltip);
		}
		effectID = data.getInteger("onDeath");
		if(effectID != 0) {
			c = ArtifactsAPI.artifacts.getComponent(effectID);
			if(c != null)
				c.addInformation(par1ItemStack, par2EntityPlayer, par3List, "after taking lethal damage.", advTooltip);
		}
		effectID = data.getInteger("onHeld");
		if(effectID != 0) {
			c = ArtifactsAPI.artifacts.getComponent(effectID);
			if(c != null)
				c.addInformation(par1ItemStack, par2EntityPlayer, par3List, "when held.", advTooltip);
		}
		par3List.add(par1ItemStack.getItemDamage() + "/" + par1ItemStack.getMaxDamage());
	}
	else {
		par3List.add(StatCollector.translateToLocal("tool.Helms, boots, etc."));
	}
}
 
Example 19
Source File: NBTHelper.java    From Levels with GNU General Public License v2.0 4 votes vote down vote up
public static NBTTagCompound loadStackNBT(ItemStack stack)
{
	return stack.hasTagCompound() ? stack.getTagCompound() : new NBTTagCompound();
}
 
Example 20
Source File: MixinTileEntityItemStackRenderer.java    From LiquidBounce with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @author CCBlueX
 */
@Overwrite
public void renderByItem(ItemStack itemStackIn) {
    if(itemStackIn.getItem() == Items.banner) {
        this.banner.setItemValues(itemStackIn);
        TileEntityRendererDispatcher.instance.renderTileEntityAt(this.banner, 0.0D, 0.0D, 0.0D, 0.0F);
    }else if(itemStackIn.getItem() == Items.skull) {
        GameProfile gameprofile = null;

        if(itemStackIn.hasTagCompound()) {
            NBTTagCompound nbttagcompound = itemStackIn.getTagCompound();

            try {
                if(nbttagcompound.hasKey("SkullOwner", 10)) {
                    gameprofile = NBTUtil.readGameProfileFromNBT(nbttagcompound.getCompoundTag("SkullOwner"));
                }else if(nbttagcompound.hasKey("SkullOwner", 8) && nbttagcompound.getString("SkullOwner").length() > 0) {
                    GameProfile lvt_2_2_ = new GameProfile(null, nbttagcompound.getString("SkullOwner"));
                    gameprofile = TileEntitySkull.updateGameprofile(lvt_2_2_);
                    nbttagcompound.removeTag("SkullOwner");
                    nbttagcompound.setTag("SkullOwner", NBTUtil.writeGameProfile(new NBTTagCompound(), gameprofile));
                }
            }catch(Exception ignored) {
            }
        }

        if(TileEntitySkullRenderer.instance != null) {
            GlStateManager.pushMatrix();
            GlStateManager.translate(-0.5F, 0.0F, -0.5F);
            GlStateManager.scale(2.0F, 2.0F, 2.0F);
            GlStateManager.disableCull();
            TileEntitySkullRenderer.instance.renderSkull(0.0F, 0.0F, 0.0F, EnumFacing.UP, 0.0F, itemStackIn.getMetadata(), gameprofile, -1);
            GlStateManager.enableCull();
            GlStateManager.popMatrix();
        }
    }else{
        Block block = Block.getBlockFromItem(itemStackIn.getItem());

        if(block == Blocks.ender_chest) {
            TileEntityRendererDispatcher.instance.renderTileEntityAt(this.enderChest, 0.0D, 0.0D, 0.0D, 0.0F);
        }else if(block == Blocks.trapped_chest) {
            TileEntityRendererDispatcher.instance.renderTileEntityAt(this.field_147718_c, 0.0D, 0.0D, 0.0D, 0.0F);
        }else if(block != Blocks.chest)
            net.minecraftforge.client.ForgeHooksClient.renderTileItem(itemStackIn.getItem(), itemStackIn.getMetadata());
        else{
            TileEntityRendererDispatcher.instance.renderTileEntityAt(this.field_147717_b, 0.0D, 0.0D, 0.0D, 0.0F);
        }
    }
}