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

The following examples show how to use net.minecraft.item.ItemStack#getItemDamage() . 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: IOHelper.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
public static void spawnItemInWorld(World world, ItemStack itemStack, double x, double y, double z){

        if(world.isRemote) return;
        float dX = world.rand.nextFloat() * 0.8F + 0.1F;
        float dY = world.rand.nextFloat() * 0.8F + 0.1F;
        float dZ = world.rand.nextFloat() * 0.8F + 0.1F;

        EntityItem entityItem = new EntityItem(world, x + dX, y + dY, z + dZ, new ItemStack(itemStack.getItem(), itemStack.stackSize, itemStack.getItemDamage()));

        if(itemStack.hasTagCompound()) {
            entityItem.getEntityItem().setTagCompound((NBTTagCompound)itemStack.getTagCompound().copy());
        }

        float factor = 0.05F;
        entityItem.motionX = world.rand.nextGaussian() * factor;
        entityItem.motionY = world.rand.nextGaussian() * factor + 0.2F;
        entityItem.motionZ = world.rand.nextGaussian() * factor;
        world.spawnEntityInWorld(entityItem);
        itemStack.stackSize = 0;
    }
 
Example 2
Source File: CyberwareAPI.java    From Cyberware with MIT License 6 votes vote down vote up
private static ICyberware getLinkedWare(ItemStack stack)
{
	if (stack == null) return null;
	
	ItemStack test = new ItemStack(stack.getItem(), 1, stack.getItemDamage());
	ICyberware result = getWareFromKey(test);
	if (result != null)
	{
		return result;
	}
	
	ItemStack testGeneric = new ItemStack(stack.getItem(), 1, OreDictionary.WILDCARD_VALUE);
	result = getWareFromKey(testGeneric);
	if (result != null)
	{
		return result;
	}
	
	return null;
}
 
Example 3
Source File: NEIClientUtils.java    From NotEnoughItems with MIT License 5 votes vote down vote up
public static void deleteItemsOfType(ItemStack type) {
    Container c = getGuiContainer().inventorySlots;
    for (int i = 0; i < c.inventorySlots.size(); i++) {
        Slot slot = c.getSlot(i);
        if (slot == null)
            continue;

        ItemStack stack = slot.getStack();
        if (stack != null && stack.getItem() == type.getItem() && stack.getItemDamage() == type.getItemDamage()) {
            setSlotContents(i, null, true);
            slot.putStack(null);
        }
    }
}
 
Example 4
Source File: ThaumcraftApiHelper.java    From GardenCollection with MIT License 5 votes vote down vote up
public static boolean itemMatches(ItemStack target, ItemStack input, boolean strict)
{
    if (input == null && target != null || input != null && target == null)
    {
        return false;
    }
    return (target.getItem() == input.getItem() && 
    		((target.getItemDamage() == OreDictionary.WILDCARD_VALUE && !strict) || target.getItemDamage() == input.getItemDamage()));
}
 
Example 5
Source File: UniqueMetaIdentifier.java    From GardenCollection with MIT License 5 votes vote down vote up
public static UniqueMetaIdentifier createFor (ItemStack itemStack) {
    if (itemStack.getItem() == null)
        return null;

    String name = GameData.getItemRegistry().getNameForObject(itemStack.getItem());
    return new UniqueMetaIdentifier(name, itemStack.getItemDamage());
}
 
Example 6
Source File: TileCraftingGrid.java    From Translocators with MIT License 5 votes vote down vote up
private void doCraft(ItemStack mresult, InventoryCrafting craftMatrix, EntityPlayer player) {
    giveOrDropItem(mresult, player);

    FMLCommonHandler.instance().firePlayerCraftingEvent(player, mresult, craftMatrix);
    mresult.onCrafting(worldObj, player, mresult.stackSize);

    for (int slot = 0; slot < 9; ++slot) {
        ItemStack stack = craftMatrix.getStackInSlot(slot);
        if (stack == null)
            continue;

        craftMatrix.decrStackSize(slot, 1);
        if (stack.getItem().hasContainerItem(stack)) {
            ItemStack container = stack.getItem().getContainerItem(stack);

            if (container != null) {
                if (container.isItemStackDamageable() && container.getItemDamage() > container.getMaxDamage())
                    container = null;

                craftMatrix.setInventorySlotContents(slot, container);
            }
        }
    }

    for (int i = 0; i < 9; i++)
        items[i] = craftMatrix.getStackInSlot(i);
}
 
Example 7
Source File: CyberwareUserDataImpl.java    From Cyberware with MIT License 5 votes vote down vote up
@SideOnly(Side.CLIENT)
public void setOutOfPower(ItemStack stack)
{
	EntityPlayer p = Minecraft.getMinecraft().thePlayer;
	if (p != null && stack != null)
	{
		int i = -1;
		int n = 0;
		for (ItemStack e : outOfPower)
		{
			if (e != null && e.getItem() == stack.getItem() && e.getItemDamage() == stack.getItemDamage())
			{
				i = n;
				break;
			}
			n++;
		}
		if (i != -1)
		{
			outOfPower.remove(i);
			outOfPowerTimes.remove(i);
		}
		outOfPower.add(stack);
		outOfPowerTimes.add(p.ticksExisted);
		if (outOfPower.size() >= 8)
		{
			outOfPower.remove(0);
			outOfPowerTimes.remove(0);
		}
	}
}
 
Example 8
Source File: ItemKnifeNoodle.java    From Sakura_mod with MIT License 5 votes vote down vote up
@Override
  public ItemStack getContainerItem(ItemStack itemStack) {
      int dmg = itemStack.getItemDamage();
      if (dmg < this.getMaxDamage(itemStack))
      {
          ItemStack stack = itemStack.copy();
          stack.setItemDamage(dmg +1);
          return stack;
      }
return super.getContainerItem(itemStack);
  }
 
Example 9
Source File: ItemFukumame.java    From TofuCraftReload with MIT License 5 votes vote down vote up
@Override
public ItemStack dispenseStack(IBlockSource source, ItemStack stack) {
    if (stack.getItemDamage() >= stack.getMaxDamage()) return stack;

    EnumFacing enumfacing = source.getBlockState().getValue(BlockDispenser.FACING); // getFacing
    World world = source.getWorld();
    double d0 = source.getX() + (double) ((float) enumfacing.getFrontOffsetX() * 1.125F);
    double d1 = source.getY() + (double) ((float) enumfacing.getFrontOffsetY() * 1.125F);
    double d2 = source.getZ() + (double) ((float) enumfacing.getFrontOffsetZ() * 1.125F);

    for (int i = 0; i < 8; i++) {
        EntityFukumame fukumame = new EntityFukumame(world, d0, d1, d2);
        fukumame.shoot(enumfacing.getFrontOffsetX(), (enumfacing.getFrontOffsetY()), enumfacing.getFrontOffsetZ(), this.getProjectileVelocity(), this.getProjectileInaccuracy());

        applyEffect(fukumame, stack);

        if (!world.isRemote) {
            world.spawnEntity(fukumame);
        }
    }

    if (stack.isItemStackDamageable()) {
        stack.getItem();
        stack.attemptDamageItem(1, Item.itemRand, null);
    }
    source.getWorld().playEvent(1000, source.getBlockPos(), 0);
    return stack;
}
 
Example 10
Source File: ItemBlockEMTSolars2.java    From Electro-Magic-Tools with GNU General Public License v3.0 5 votes vote down vote up
@Override
@SuppressWarnings({"unchecked", "rawtypes"})
public void addInformation(ItemStack itemstack, EntityPlayer player, List list, boolean par4) {
    switch (itemstack.getItemDamage()) {
        case 0: {
            list.add(TextHelper.BRIGHT_BLUE + localize("tooltip.EMT.normalConditions") + ": " + TextHelper.LIGHT_GRAY + ConfigHandler.doubleCompressedSolarOutput + " " + localize("tooltip.EMT.euPerTick"));
            list.add(TextHelper.BRIGHT_GREEN + localize("tooltip.EMT.specialEffect") + ": " + TextHelper.LIGHT_GRAY + localize("tooltip.EMT.output.double.half") + " " + localize("tooltip.EMT.output.double.half.height"));
            break;
        }
        case 1: {
            list.add(TextHelper.BRIGHT_BLUE + localize("tooltip.EMT.normalConditions") + ": " + TextHelper.LIGHT_GRAY + ConfigHandler.tripleCompressedSolarOutput + " " + localize("tooltip.EMT.euPerTick"));
            list.add(TextHelper.BRIGHT_GREEN + localize("tooltip.EMT.specialEffect") + ": " + TextHelper.LIGHT_GRAY + localize("tooltip.EMT.output.double.half") + " " + localize("tooltip.EMT.output.double.half.height"));
            break;
        }
        case 2: {
            list.add(TextHelper.BRIGHT_BLUE + localize("tooltip.EMT.normalConditions") + ": " + TextHelper.LIGHT_GRAY + ConfigHandler.compressedSolarOutput + " " + localize("tooltip.EMT.euPerTick"));
            list.add(TextHelper.BRIGHT_GREEN + localize("tooltip.EMT.specialEffect") + ": " + TextHelper.LIGHT_GRAY + localize("tooltip.EMT.output.double.half") + " " + localize("tooltip.EMT.output.double.half.low"));
            break;
        }
        case 3: {
            list.add(TextHelper.BRIGHT_BLUE + localize("tooltip.EMT.normalConditions") + ": " + TextHelper.LIGHT_GRAY + ConfigHandler.doubleCompressedSolarOutput + " " + localize("tooltip.EMT.euPerTick"));
            list.add(TextHelper.BRIGHT_GREEN + localize("tooltip.EMT.specialEffect") + ": " + TextHelper.LIGHT_GRAY + localize("tooltip.EMT.output.double.half") + " " + localize("tooltip.EMT.output.double.half.low"));
            break;
        }
        case 4: {
            list.add(TextHelper.BRIGHT_BLUE + localize("tooltip.EMT.normalConditions") + ": " + TextHelper.LIGHT_GRAY + ConfigHandler.tripleCompressedSolarOutput + " " + localize("tooltip.EMT.euPerTick"));
            list.add(TextHelper.BRIGHT_GREEN + localize("tooltip.EMT.specialEffect") + ": " + TextHelper.LIGHT_GRAY + localize("tooltip.EMT.output.double.half") + " " + localize("tooltip.EMT.output.double.half.low"));
            break;
        }
        default: {
            list.add(localize("tooltip.EMT.forget"));
            break;
        }
    }
}
 
Example 11
Source File: ItemFootUpgrade.java    From Cyberware with MIT License 4 votes vote down vote up
@Override
public int getPowerConsumption(ItemStack stack)
{
	return stack.getItemDamage() == 1 ? LibConstants.AQUA_CONSUMPTION :
			stack.getItemDamage() == 2 ? LibConstants.WHEEL_CONSUMPTION : 0;
}
 
Example 12
Source File: InfusionEnchantmentRecipe.java    From AdvancedMod with GNU General Public License v3.0 4 votes vote down vote up
/**
     * Used to check if a recipe matches current crafting inventory
     * @param player 
     */
	public boolean matches(ArrayList<ItemStack> input, ItemStack central, World world, EntityPlayer player) {
		if (research.length()>0 && !ThaumcraftApiHelper.isResearchComplete(player.getCommandSenderName(), research)) {
    		return false;
    	}
		
		if (!enchantment.canApply(central) || !central.getItem().isItemTool(central)) {
			return false;
		}
				
		Map map1 = EnchantmentHelper.getEnchantments(central);
		Iterator iterator = map1.keySet().iterator();
        while (iterator.hasNext())
        {
        	int j1 = ((Integer)iterator.next()).intValue();
            Enchantment ench = Enchantment.enchantmentsList[j1];
            if (j1 == enchantment.effectId &&
            		EnchantmentHelper.getEnchantmentLevel(j1, central)>=ench.getMaxLevel())
            	return false;
            if (enchantment.effectId != ench.effectId && 
            	(!enchantment.canApplyTogether(ench) ||
            	!ench.canApplyTogether(enchantment))) {
            	return false;
            }
        }
		
		ItemStack i2 = null;
		
		ArrayList<ItemStack> ii = new ArrayList<ItemStack>();
		for (ItemStack is:input) {
			ii.add(is.copy());
		}
		
		for (ItemStack comp:components) {
			boolean b=false;
			for (int a=0;a<ii.size();a++) {
				 i2 = ii.get(a).copy();
				if (comp.getItemDamage()==OreDictionary.WILDCARD_VALUE) {
					i2.setItemDamage(OreDictionary.WILDCARD_VALUE);
				}
				if (areItemStacksEqual(i2, comp,true)) {
					ii.remove(a);
					b=true;
					break;
				}
			}
			if (!b) return false;
		}
//		System.out.println(ii.size());
		return ii.size()==0?true:false;
    }
 
Example 13
Source File: AdapterArcaneBore.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.BOOLEAN, description = "Is the pick broken?")
public boolean isPickaxeBroken(Object target) {
	ItemStack pick = getPick(target);
	return pick != null && pick.getItemDamage() + 1 == pick.getMaxDamage();
}
 
Example 14
Source File: ItemHeartUpgrade.java    From Cyberware with MIT License 4 votes vote down vote up
@Override
public int getPowerProduction(ItemStack stack)
{
	return stack.getItemDamage() == 3 ? LibConstants.COUPLER_PRODUCTION + 1 : 0;
}
 
Example 15
Source File: ItemBlockEMTSolars.java    From Electro-Magic-Tools with GNU General Public License v3.0 4 votes vote down vote up
@Override
public String getUnlocalizedName(ItemStack itemstack) {
    String name = "";
    switch (itemstack.getItemDamage()) {
        case 0: {
            name = "compressed";
            break;
        }
        case 1: {
            name = "doublecompressed";
            break;
        }
        case 2: {
            name = "triplecompressed";
            break;
        }
        case 3: {
            name = "water";
            break;
        }
        case 4: {
            name = "doublewater";
            break;
        }
        case 5: {
            name = "triplewater";
            break;
        }
        case 6: {
            name = "dark";
            break;
        }
        case 7: {
            name = "doubledark";
            break;
        }
        case 8: {
            name = "tripledark";
            break;
        }
        case 9: {
            name = "order";
            break;
        }
        case 10: {
            name = "doubleorder";
            break;
        }
        case 11: {
            name = "tripleorder";
            break;
        }
        case 12: {
            name = "fire";
            break;
        }
        case 13: {
            name = "doublefire";
            break;
        }
        case 14: {
            name = "triplefire";
            break;
        }
        case 15: {
            name = "air";
            break;
        }
        default:
            name = "nothing";
            break;
    }
    return getUnlocalizedName() + "." + name;
}
 
Example 16
Source File: ItemBrainUpgrade.java    From Cyberware with MIT License 4 votes vote down vote up
@Override
public boolean isIncompatible(ItemStack stack, ItemStack other)
{
	return other.getItem() == this && stack.getItemDamage() == 0 && other.getItemDamage() == 2;
}
 
Example 17
Source File: MessageFertilizerApplied.java    From AgriCraft with MIT License 4 votes vote down vote up
public MessageFertilizerApplied(ItemStack fertilizer, BlockPos pos) {
    this();
    this.pos = pos;
    this.fertilizer = fertilizer.getItem();
    this.meta = fertilizer.getItemDamage();
}
 
Example 18
Source File: GT_TileEntity_BioVat.java    From bartworks with MIT License 4 votes vote down vote up
public void doAllVisualThings() {
    if (this.getBaseMetaTileEntity().isServerSide()) {
        if (this.mMachine) {
            ItemStack aStack = this.mInventory[1];
            BioCulture lCulture = null;
            int xDir = ForgeDirection.getOrientation(this.getBaseMetaTileEntity().getBackFacing()).offsetX * 2;
            int zDir = ForgeDirection.getOrientation(this.getBaseMetaTileEntity().getBackFacing()).offsetZ * 2;

            if (this.getBaseMetaTileEntity().getTimer() % 200 == 0) {
                this.check_Chunk();
            }

            if (this.needsVisualUpdate && this.getBaseMetaTileEntity().getTimer() % GT_TileEntity_BioVat.TIMERDIVIDER == 0) {
                for (int x = -1; x < 2; x++)
                    for (int y = 1; y < 3; y++)
                        for (int z = -1; z < 2; z++)
                            this.getBaseMetaTileEntity().getWorld().setBlockToAir(xDir + x + this.getBaseMetaTileEntity().getXCoord(), y + this.getBaseMetaTileEntity().getYCoord(), zDir + z + this.getBaseMetaTileEntity().getZCoord());
            }

            this.height = this.reCalculateHeight();
            if (this.mFluid != null && this.height > 1 && this.reCalculateFluidAmmount() > 0) {
                if ((!(BW_Util.areStacksEqualOrNull(aStack, this.mStack))) || (this.needsVisualUpdate && this.getBaseMetaTileEntity().getTimer() % GT_TileEntity_BioVat.TIMERDIVIDER == 1)) {
                    for (int x = -1; x < 2; x++) {
                        for (int y = 1; y < this.height; y++) {
                            for (int z = -1; z < 2; z++) {
                                if (aStack == null || aStack.getItem() instanceof LabParts && aStack.getItemDamage() == 0) {
                                    if (this.mCulture == null || aStack == null || aStack.getTagCompound() == null || this.mCulture.getID() != aStack.getTagCompound().getInteger("ID")) {
                                        lCulture = aStack == null || aStack.getTagCompound() == null ? null : BioCulture.getBioCulture(aStack.getTagCompound().getString("Name"));
                                        this.sendPackagesOrRenewRenderer(x, y, z, lCulture);
                                    }
                                }
                            }
                        }
                    }
                    this.mStack = aStack;
                    this.mCulture = lCulture;
                }
                if (this.needsVisualUpdate && this.getBaseMetaTileEntity().getTimer() % GT_TileEntity_BioVat.TIMERDIVIDER == 1) {
                    if (this.getBaseMetaTileEntity().isClientSide())
                        new Throwable().printStackTrace();
                    this.placeFluid();
                    this.needsVisualUpdate = false;
                }
            }
        } else {
            this.onRemoval();
        }
    }
}
 
Example 19
Source File: ItemSkinUpgrade.java    From Cyberware with MIT License 4 votes vote down vote up
@Override
public int getPowerProduction(ItemStack stack)
{
	return stack.getItemDamage() == 0 ? LibConstants.SOLAR_PRODUCTION : 0;
}
 
Example 20
Source File: ItemStorageComponent.java    From ExtraCells1 with MIT License 4 votes vote down vote up
@Override
public String getUnlocalizedName(ItemStack itemstack)
{
	int i = itemstack.getItemDamage();
	return "item.storagecomponent." + suffixes[i];
}