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

The following examples show how to use net.minecraft.item.ItemStack#setItemDamage() . 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: ItemEnderPouch.java    From EnderStorage with MIT License 6 votes vote down vote up
@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
{
    if(world.isRemote)
        return false;
    
    TileEntity tile = world.getTileEntity(x, y, z);
    if(tile instanceof TileEnderChest && player.isSneaking())
    {
        TileEnderChest chest = (TileEnderChest)tile;
        stack.setItemDamage(chest.freq);
        if(!stack.hasTagCompound())
            stack.setTagCompound(new NBTTagCompound());

        if (!EnderStorage.anarchyMode || chest.owner.equals(player.getCommandSenderName()))
            stack.getTagCompound().setString("owner", chest.owner);
        else
            stack.getTagCompound().setString("owner", "global");

        return true;
    }
    return false;
}
 
Example 2
Source File: GTUtility.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void setItem(ItemStack itemStack, ItemStack newStack) {
    try {
        Field itemField = Arrays.stream(ItemStack.class.getDeclaredFields())
            .filter(field -> field.getType() == Item.class)
            .findFirst().orElseThrow(ReflectiveOperationException::new);
        itemField.setAccessible(true);
        //replace item field instance
        itemField.set(itemStack, newStack.getItem());
        //set damage then
        itemStack.setItemDamage(newStack.getItemDamage());
        itemStack.setTagCompound(newStack.getTagCompound());

        Method forgeInit = ItemStack.class.getDeclaredMethod("forgeInit");
        forgeInit.setAccessible(true);
        //reinitialize forge capabilities and delegate reference
        forgeInit.invoke(itemStack);
    } catch (ReflectiveOperationException exception) {
        //should be impossible, actually
        throw new RuntimeException(exception);
    }
}
 
Example 3
Source File: ChestGenHooks.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void addItem(ResourceLocation lootTable, ItemStack item, int minAmount, int additionalAmount, int weight) {
    LootEntryItem itemEntry = new LootEntryItem(item.getItem(), weight, 1, new LootFunction[]{
        new LootFunction(NO_CONDITIONS) {
            @Override
            public ItemStack apply(ItemStack stack, Random rand, LootContext context) {
                stack.setItemDamage(item.getItemDamage());
                stack.setTagCompound(item.getTagCompound());
                stack.setCount(minAmount + rand.nextInt(additionalAmount));
                return stack;
            }
        }
    }, NO_CONDITIONS, "#gregtech:loot_" + item.toString());
    if (lootEntryItems.containsKey(lootTable)) {
        lootEntryItems.get(lootTable).add(itemEntry);
    } else {
        lootEntryItems.put(lootTable, Lists.newArrayList(itemEntry));
    }
}
 
Example 4
Source File: RecipeJam.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
@Nonnull
public ItemStack getCraftingResult(@Nonnull InventoryCrafting inv) {
	ItemStack jar = ItemStack.EMPTY;

	for (int i = 0; i < inv.getSizeInventory(); i++) {
		ItemStack stack = inv.getStackInSlot(i);
		if (stack.getItem() == ModItems.JAR_ITEM) {
			if (stack.getItemDamage() == 2)
				jar = stack;
		}
	}

	if (jar.isEmpty()) return ItemStack.EMPTY;

	ItemStack jamJar = new ItemStack(ModItems.JAR_ITEM);
	NBTHelper.setInt(jamJar, NBTConstants.NBT.FAIRY_COLOR, NBTHelper.getInt(jar, NBTConstants.NBT.FAIRY_COLOR, 0xFFFFFF));
	jamJar.setItemDamage(1);

	return jamJar;
}
 
Example 5
Source File: ItemRolling.java    From TofuCraftReload 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;
        }else
	return super.getContainerItem(itemStack);
}
 
Example 6
Source File: ModEnchantments.java    From Et-Futurum with The Unlicense 5 votes vote down vote up
public static void onPlayerPickupXP(PlayerPickupXpEvent event) {
	EntityPlayer player = event.entityPlayer;
	EntityXPOrb orb = event.orb;
	if (player.worldObj.isRemote)
		return;
	if (!EtFuturum.enableMending)
		return;

	ItemStack[] stacks = new ItemStack[5];
	stacks[0] = player.getCurrentEquippedItem(); // held
	stacks[1] = player.getEquipmentInSlot(1); // boots
	stacks[2] = player.getEquipmentInSlot(2); // leggings
	stacks[3] = player.getEquipmentInSlot(3); // chestplate
	stacks[4] = player.getEquipmentInSlot(4); // helmet

	for (ItemStack stack : stacks)
		if (stack != null && stack.getItemDamage() > 0 && EnchantmentHelper.getEnchantmentLevel(mending.effectId, stack) > 0) {
			int xp = orb.xpValue;
			while (xp > 0 && stack.getItemDamage() > 0) {
				stack.setItemDamage(stack.getItemDamage() - 2);
				xp--;
			}
			if (xp <= 0) {
				orb.setDead();
				event.setCanceled(true);
				return;
			}
		}
}
 
Example 7
Source File: ItemLevitationOrb.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void getSubItems(@Nullable CreativeTabs tab, @Nonnull NonNullList<ItemStack> subItems) {
	if (isInCreativeTab(tab)) {

		for (int i = 1; i < 10; i++) {
			ItemStack stack = new ItemStack(this);
			stack.setItemDamage((int) (stack.getMaxDamage() * (i / 10.0)));
			subItems.add(stack);
		}
	}
}
 
Example 8
Source File: Familiar_Old_AugmentInfusion.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean matches(ArrayList<ItemStack> input, ItemStack central, World world, EntityPlayer player) {
    if(central == null || !(central.getItem() instanceof ItemFamiliar_Old)) return false; //We call it "FamiliarAugment" Recipe for a reason..
    if(getRecipeInput() == null || !(getRecipeInput().getItem() instanceof ItemFamiliar_Old)) return false; //A bit late but still working..

    if ((this.research.length() > 0) && (!ThaumcraftApiHelper.isResearchComplete(player.getCommandSenderName(), this.research))) {
        return false;
    }

    ItemStack centralCopy = central.copy();
    if(!((ItemFamiliar_Old) centralCopy.getItem()).hasUpgrade(centralCopy, getUpgradeToAdd().getNeededPreviousUpgrade())) return false;

    ArrayList<ItemStack> ii = new ArrayList<ItemStack>();
    for (ItemStack is : input) {
        ii.add(is.copy());
    }
    for (ItemStack comp : getComponents()) {
        boolean b = false;
        for (int a = 0; a < ii.size(); a++) {
            centralCopy = ii.get(a).copy();
            if (comp.getItemDamage() == 32767) {
                centralCopy.setItemDamage(32767);
            }
            if (areItemStacksEqual(centralCopy, comp, true)) {
                ii.remove(a);
                b = true;
                break;
            }
        }
        if (!b) {
            return false;
        }
    }
    return ii.size() == 0;
}
 
Example 9
Source File: RecipeGun.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ItemStack getCraftingResult(InventoryCrafting inventory){
    if(!matches(inventory, null)) return null;
    ItemStack output = getRecipeOutput();
    for(int i = 0; i < inventory.getSizeInventory(); i++) {
        if(inventory.getStackInSlot(i) != null && inventory.getStackInSlot(i).getItem() == Itemss.airCanister) {
            output.setItemDamage(inventory.getStackInSlot(i).getItemDamage());
        }
    }
    return output;
}
 
Example 10
Source File: NEIbartworksConfig.java    From bartworks with MIT License 5 votes vote down vote up
@Optional.Method(modid = "NotEnoughItems")
    @Override
    public void loadConfig() {
        API.hideItem(new ItemStack(ItemRegistry.TAB));
        API.hideItem(new ItemStack(FluidLoader.bioFluidBlock));
        API.hideItem(new ItemStack(ItemRegistry.bw_fake_glasses));
        ItemStack[] prefixesToHide = {
                WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.dustTiny, WerkstoffLoader.Bismutite).copy(),
                WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.dustSmall, WerkstoffLoader.Bismutite).copy(),
                WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.crushed, WerkstoffLoader.Bismutite).copy(),
                WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.crushedPurified, WerkstoffLoader.Bismutite).copy(),
                WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.crushedCentrifuged, WerkstoffLoader.Bismutite).copy(),
                WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.nugget, WerkstoffLoader.Bismutite).copy(),
                WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.gemChipped, WerkstoffLoader.Bismutite).copy(),
                WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.gemFlawed, WerkstoffLoader.Bismutite).copy(),
                WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.gemFlawless, WerkstoffLoader.Bismutite).copy(),
                WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.gemExquisite, WerkstoffLoader.Bismutite).copy(),
                WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.dustImpure, WerkstoffLoader.Bismutite).copy(),
                WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.dustPure, WerkstoffLoader.Bismutite).copy(),
        };
        for (ItemStack stack : prefixesToHide) {
            stack.setItemDamage(Short.MAX_VALUE);
            API.hideItem(stack);
        }
//        for (int i = 0; i < Short.MAX_VALUE; i++) {
//            API.addItemListEntry(new ItemStack(WerkstoffLoader.BWOres,1,i));
//        }
    }
 
Example 11
Source File: ItemOrb.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean isSelected) {
	if (ManaManager.isManaEmpty(stack) && stack.getItemDamage() == 1)
		stack.setItemDamage(0);
	else if (!ManaManager.isManaEmpty(stack) && stack.getItemDamage() == 0)
		stack.setItemDamage(1);
}
 
Example 12
Source File: BlockGardenProxy.java    From GardenCollection with MIT License 5 votes vote down vote up
private void setPlantData (TileEntityGarden tileEntity, int slot, int data) {
    ItemStack itemStack = tileEntity.getPlantInSlot(slot);
    if (itemStack != null) {
        itemStack.setItemDamage(data);
        tileEntity.setInventorySlotContents(slot, itemStack);
    }
}
 
Example 13
Source File: DamageableShapelessOreRecipe.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
@Nonnull
@Override
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
{
    NonNullList<ItemStack> items = NonNullList.withSize(inv.getSizeInventory(), ItemStack.EMPTY);

    matches(inv, null);

    for (int i = 0; i < invSlots.length; i++)
    {
        int amount = damageAmounts[i];
        int invIndex = invSlots[i];
        if (amount > 0)
        {
            ItemStack stack = inv.getStackInSlot(invIndex).copy();
            stack.setItemDamage(stack.getItemDamage() + amount);
            if (stack.getItemDamage() > stack.getMaxDamage())
            {
                stack = ForgeHooks.getContainerItem(stack);
            }
            items.set(invIndex, stack);
        } else
        {
            items.set(invIndex, ForgeHooks.getContainerItem(inv.getStackInSlot(invIndex)));
        }
    }

    return items;
}
 
Example 14
Source File: ItemMobSpawner.java    From NotEnoughItems with MIT License 4 votes vote down vote up
private static void setDefaultTag(ItemStack itemstack) {
    if (!IDtoNameMap.containsKey(itemstack.getItemDamage()))
        itemstack.setItemDamage(idPig);
}
 
Example 15
Source File: InfusionEnchantmentRecipe.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 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 16
Source File: ItemMetalHoe.java    From BaseMetals with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void onUpdate(final ItemStack item, final World world, final Entity player, final int inventoryIndex, final boolean isHeld) {
	if(regenerates && !world.isRemote && isHeld && item.getItemDamage() > 0 && world.getTotalWorldTime() % regenInterval == 0){
		item.setItemDamage(item.getItemDamage() - 1);
	}
}
 
Example 17
Source File: RecipeBrew.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 4 votes vote down vote up
public boolean matches(IInventory inv) {
	List<Object> inputsMissing = new ArrayList(inputs);

	for(int i = 0; i < inv.getSizeInventory(); i++) {
		ItemStack stack = inv.getStackInSlot(i);
		if(stack == null)
			break;

		if(stack.getItem() instanceof IBrewContainer)
			continue;

		int stackIndex = -1, oredictIndex = -1;

		for(int j = 0; j < inputsMissing.size(); j++) {
			Object input = inputsMissing.get(j);
			if(input instanceof String) {
				List<ItemStack> validStacks = OreDictionary.getOres((String) input);
				boolean found = false;
				for(ItemStack ostack : validStacks) {
					ItemStack cstack = ostack.copy();
					if(cstack.getItemDamage() == Short.MAX_VALUE)
						cstack.setItemDamage(stack.getItemDamage());

					if(stack.isItemEqual(cstack)) {
						oredictIndex = j;
						found = true;
						break;
					}
				}


				if(found)
					break;
			} else if(input instanceof ItemStack && simpleAreStacksEqual((ItemStack) input, stack)) {
				stackIndex = j;
				break;
			}
		}

		if(stackIndex != -1)
			inputsMissing.remove(stackIndex);
		else if(oredictIndex != -1)
			inputsMissing.remove(oredictIndex);
		else return false;
	}

	return inputsMissing.isEmpty();
}
 
Example 18
Source File: ItemWirelessFreq.java    From WirelessRedstone with MIT License 4 votes vote down vote up
public final void setFreq(EntityPlayer player, int slot, ItemStack stack, int freq) {
    if (player.worldObj.isRemote)
        WRCoreCPH.sendSetItemFreq(slot, freq);
    else
        stack.setItemDamage(freq);
}
 
Example 19
Source File: ItemMobSpawner.java    From NotEnoughItems with MIT License 4 votes vote down vote up
private static void setDefaultTag(ItemStack itemstack) {
    if (!IDtoNameMap.containsKey(itemstack.getItemDamage())) {
        itemstack.setItemDamage(idPig);
    }
}
 
Example 20
Source File: InfiniteToolHandler.java    From NotEnoughItems with MIT License 4 votes vote down vote up
@Override
public void onPlaceInfinite(ItemStack heldItem) {
    heldItem.setItemDamage(-32000);
}