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

The following examples show how to use net.minecraft.item.ItemStack#isItemEnchantable() . 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: PressureChamberPressureEnchantHandler.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ItemStack[] isValidRecipe(ItemStack[] inputStacks){
    List<ItemStack> enchantedBooks = new ArrayList<ItemStack>();
    for(ItemStack book : inputStacks) {
        if(book.getItem() == Items.enchanted_book) enchantedBooks.add(book);
    }
    if(enchantedBooks.size() == 0) return null;
    for(ItemStack inputStack : inputStacks) {
        if((inputStack.isItemEnchantable() || inputStack.isItemEnchanted()) && inputStack.getItem() != Items.enchanted_book) {
            //Map map = EnchantmentHelper.getEnchantments(inputStack);
            // Iterator toolEnchantIterator = map.keySet().iterator();
            // while(toolEnchantIterator.hasNext()){
            //    Enchantment toolEnchant = Enchantment.enchantmentsList[((Integer)toolEnchantIterator.next()).intValue()];
            for(ItemStack enchantedBook : enchantedBooks) {
                Map bookMap = EnchantmentHelper.getEnchantments(enchantedBook);
                Iterator bookEnchantIterator = bookMap.keySet().iterator();
                while(bookEnchantIterator.hasNext()) {
                    Enchantment bookEnchant = Enchantment.enchantmentsList[((Integer)bookEnchantIterator.next()).intValue()];
                    if(bookEnchant.canApply(inputStack)) {
                        return new ItemStack[]{inputStack, enchantedBook};
                    }
                }
            }
            //  }
        }
    }
    return null;
}
 
Example 2
Source File: VanillaEnchantLogic.java    From OpenModsLib with MIT License 5 votes vote down vote up
public boolean setup(@Nonnull ItemStack stack, Level level, int power) {
	if (stack.isEmpty() || !stack.isItemEnchantable()) return false;

	rand.setSeed(seed);
	this.toEnchant = stack.copy();
	this.level = level;
	this.xpLevels = EnchantmentHelper.calcItemStackEnchantability(rand, level.ordinal(), power, toEnchant);

	if (this.xpLevels <= level.ordinal() + 1) this.xpLevels = 0;
	return true;
}
 
Example 3
Source File: ContainerEnchantment.java    From Et-Futurum with The Unlicense 4 votes vote down vote up
/**
 * Callback for when the crafting matrix is changed.
 */
@Override
public void onCraftMatrixChanged(IInventory p_75130_1_) {
	if (p_75130_1_ == tableInventory) {
		ItemStack var2 = p_75130_1_.getStackInSlot(0);
		int power;

		if (var2 != null && var2.isItemEnchantable()) {
			if (!world.isRemote) {
				power = 0;
				int j;

				for (j = -1; j <= 1; ++j)
					for (int k = -1; k <= 1; ++k)
						if ((j != 0 || k != 0) && world.isAirBlock(posX + k, posY, posZ + j) && world.isAirBlock(posX + k, posY + 1, posZ + j)) {
							power += ForgeHooks.getEnchantPower(world, posX + k * 2, posY, posZ + j * 2);
							power += ForgeHooks.getEnchantPower(world, posX + k * 2, posY + 1, posZ + j * 2);

							if (k != 0 && j != 0) {
								power += ForgeHooks.getEnchantPower(world, posX + k * 2, posY, posZ + j);
								power += ForgeHooks.getEnchantPower(world, posX + k * 2, posY + 1, posZ + j);
								power += ForgeHooks.getEnchantPower(world, posX + k, posY, posZ + j * 2);
								power += ForgeHooks.getEnchantPower(world, posX + k, posY + 1, posZ + j * 2);
							}
						}

				rand.setSeed(enchantmentSeed);

				for (j = 0; j < 3; ++j) {
					enchantLevels[j] = EnchantmentHelper.calcItemStackEnchantability(rand, j, power, var2);
					field_178151_h[j] = -1;

					if (enchantLevels[j] < j + 1)
						enchantLevels[j] = 0;
				}

				for (j = 0; j < 3; ++j)
					if (enchantLevels[j] > 0) {
						List<EnchantmentData> var7 = func_178148_a(var2, j, enchantLevels[j]);

						if (var7 != null && !var7.isEmpty()) {
							EnchantmentData var6 = var7.get(rand.nextInt(var7.size()));
							field_178151_h[j] = var6.enchantmentobj.effectId | var6.enchantmentLevel << 8;
						}
					}

				detectAndSendChanges();
			}
		} else
			for (power = 0; power < 3; ++power) {
				enchantLevels[power] = 0;
				field_178151_h[power] = -1;
			}
	}
}