net.minecraft.enchantment.EnchantmentData Java Examples

The following examples show how to use net.minecraft.enchantment.EnchantmentData. 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: ContainerEnchantment.java    From Et-Futurum with The Unlicense 5 votes vote down vote up
@SuppressWarnings("unchecked")
private List<EnchantmentData> func_178148_a(ItemStack stack, int seed, int level) {
	rand.setSeed(enchantmentSeed + seed);
	List<EnchantmentData> list = EnchantmentHelper.buildEnchantmentList(rand, stack, level);

	if (stack.getItem() == Items.book && list != null && list.size() > 1)
		list.remove(rand.nextInt(list.size()));

	return list;
}
 
Example #2
Source File: VanillaEnchantLogic.java    From OpenModsLib with MIT License 5 votes vote down vote up
private List<EnchantmentData> getEnchantmentList(@Nonnull ItemStack stack, Level level, int xpLevels) {
	rand.setSeed(seed + level.ordinal());
	List<EnchantmentData> list = EnchantmentHelper.buildEnchantmentList(rand, stack, xpLevels, false);

	if (stack.getItem() == Items.BOOK && list.size() > 1) {
		list.remove(this.rand.nextInt(list.size()));
	}

	return list;
}
 
Example #3
Source File: ShopkeeperTradesForEarth.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
private static ItemStack silkTouch() {
	ItemStack stack = new ItemStack(Items.ENCHANTED_BOOK);
	ItemEnchantedBook.addEnchantment(stack, new EnchantmentData(Enchantment.REGISTRY.getObjectById(33), 1));
	return stack;
}
 
Example #4
Source File: ShopkeeperTradesForFire.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
private static ItemStack level1FireProtection() {
	ItemStack stack = new ItemStack(Items.ENCHANTED_BOOK);
	stack.setStackDisplayName("Fire Protection I");
	ItemEnchantedBook.addEnchantment(stack, new EnchantmentData(Enchantment.REGISTRY.getObjectById(1), 1));
	return stack;
}
 
Example #5
Source File: ShopkeeperTradesForFire.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
private static ItemStack level2FireProtection() {
	ItemStack stack = new ItemStack(Items.ENCHANTED_BOOK);
	stack.setStackDisplayName("Fire Protection II");
	ItemEnchantedBook.addEnchantment(stack, new EnchantmentData(Enchantment.REGISTRY.getObjectById(1), 2));
	return stack;
}
 
Example #6
Source File: ShopkeeperTradesForFire.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
private static ItemStack level3FireProtection() {
	ItemStack stack = new ItemStack(Items.ENCHANTED_BOOK);
	stack.setStackDisplayName("Fire Protection III");
	ItemEnchantedBook.addEnchantment(stack, new EnchantmentData(Enchantment.REGISTRY.getObjectById(1), 3));
	return stack;
}
 
Example #7
Source File: ShopkeeperTradesForFire.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
private static ItemStack level4FireProtection() {
	ItemStack stack = new ItemStack(Items.ENCHANTED_BOOK);
	stack.setStackDisplayName("Fire Protection IV");
	ItemEnchantedBook.addEnchantment(stack, new EnchantmentData(Enchantment.REGISTRY.getObjectById(1), 4));
	return stack;
}
 
Example #8
Source File: ShopkeeperTradesForFire.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
private static ItemStack level5FireProtection() {
	ItemStack stack = new ItemStack(Items.ENCHANTED_BOOK);
	stack.setStackDisplayName("Fire Protection V");
	ItemEnchantedBook.addEnchantment(stack, new EnchantmentData(Enchantment.REGISTRY.getObjectById(1), 5));
	return stack;
}
 
Example #9
Source File: ShopkeeperTradesForSun.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
private static ItemStack level1BlastProtection() {
	ItemStack stack = new ItemStack(Items.ENCHANTED_BOOK);
	ItemEnchantedBook.addEnchantment(stack, new EnchantmentData(Enchantment.REGISTRY.getObjectById(3), 1));
	return stack;
}
 
Example #10
Source File: ShopkeeperTradesForSun.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
private static ItemStack level2BlastProtection() {
	ItemStack stack = new ItemStack(Items.ENCHANTED_BOOK);
	ItemEnchantedBook.addEnchantment(stack, new EnchantmentData(Enchantment.REGISTRY.getObjectById(3), 2));
	return stack;
}
 
Example #11
Source File: ShopkeeperTradesForSun.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
private static ItemStack level3BlastProtection() {
	ItemStack stack = new ItemStack(Items.ENCHANTED_BOOK);
	ItemEnchantedBook.addEnchantment(stack, new EnchantmentData(Enchantment.REGISTRY.getObjectById(3), 3));
	return stack;
}
 
Example #12
Source File: ShopkeeperTradesForSun.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
private static ItemStack level4BlastProtection() {
	ItemStack stack = new ItemStack(Items.ENCHANTED_BOOK);
	ItemEnchantedBook.addEnchantment(stack, new EnchantmentData(Enchantment.REGISTRY.getObjectById(3), 4));
	return stack;
}
 
Example #13
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;
			}
	}
}
 
Example #14
Source File: ContainerEnchantment.java    From Et-Futurum with The Unlicense 4 votes vote down vote up
/**
 * enchants the item on the table using the specified slot; also deducts XP from player
 */
@Override
public boolean enchantItem(EntityPlayer player, int id) {
	ItemStack var3 = tableInventory.getStackInSlot(0);
	ItemStack var4 = tableInventory.getStackInSlot(1);
	int var5 = id + 1;

	if ((var4 == null || var4.stackSize < var5) && !player.capabilities.isCreativeMode)
		return false;
	else if (enchantLevels[id] > 0 && var3 != null && (player.experienceLevel >= var5 && player.experienceLevel >= enchantLevels[id] || player.capabilities.isCreativeMode)) {
		if (!world.isRemote) {
			List<EnchantmentData> var6 = func_178148_a(var3, id, enchantLevels[id]);
			boolean var7 = var3.getItem() == Items.book;

			if (var6 != null) {
				chargeForEnchant(player, rand, var5);

				if (var7)
					var3.func_150996_a(Items.enchanted_book);

				for (int var8 = 0; var8 < var6.size(); ++var8) {
					EnchantmentData var9 = var6.get(var8);

					if (var7)
						Items.enchanted_book.addEnchantment(var3, var9);
					else
						var3.addEnchantment(var9.enchantmentobj, var9.enchantmentLevel);
				}

				if (!player.capabilities.isCreativeMode) {
					var4.stackSize -= var5;

					if (var4.stackSize <= 0)
						tableInventory.setInventorySlotContents(1, (ItemStack) null);
				}

				tableInventory.markDirty();
				enchantmentSeed = rand.nextInt();
				onCraftMatrixChanged(tableInventory);
			}
		}

		return true;
	} else
		return false;
}
 
Example #15
Source File: EnchantmentUtils.java    From OpenModsLib with MIT License 4 votes vote down vote up
public static void addAllBooks(Enchantment enchantment, List<ItemStack> items) {
	for (int i = enchantment.getMinLevel(); i <= enchantment.getMaxLevel(); i++)
		items.add(ItemEnchantedBook.getEnchantedItemStack(new EnchantmentData(enchantment, i)));
}
 
Example #16
Source File: EnchantingRecipe.java    From OpenModsLib with MIT License 4 votes vote down vote up
public EnchantingRecipe(IRecipe source, List<EnchantmentData> enchantments) {
	this.source = source;
	this.enchantments = ImmutableList.copyOf(enchantments);
}