use of net.minecraft.item.ItemEnchantedBook in project NetherEx by LogicTechCorp.
the class Trade method getRandomTrade.
public MerchantRecipe getRandomTrade(Random rand) {
ItemStack outputStack = getItemToSell().copy();
ItemStack inputA = getItemToBuy().copy();
ItemStack inputB = getSecondItemToBuy().copy();
outputStack.setCount(rand.nextInt((outputAmount.getMax() - outputAmount.getMin()) + 1) + outputAmount.getMin());
inputA.setCount(rand.nextInt((inputAAmount.getMax() - inputAAmount.getMin()) + 1) + inputAAmount.getMin());
inputB.setCount(rand.nextInt((inputBAmount.getMax() - inputBAmount.getMin()) + 1) + inputBAmount.getMin());
if (outputEnchantments.size() > 0) {
for (TradeOffer.Enchantment outputEnchantment : outputEnchantments) {
Enchantment enchantment = Enchantment.getEnchantmentByLocation(outputEnchantment.getName());
TradeOffer.Amount enchantmentAmount = outputEnchantment.getAmount();
if (enchantment != null) {
if (outputStack.getItem() instanceof ItemEnchantedBook) {
((ItemEnchantedBook) outputStack.getItem()).addEnchantment(outputStack, new EnchantmentData(enchantment, rand.nextInt((enchantmentAmount.getMax() - enchantmentAmount.getMin()) + 1) + enchantmentAmount.getMin()));
} else {
outputStack.addEnchantment(enchantment, rand.nextInt((enchantmentAmount.getMax() - enchantmentAmount.getMin()) + 1) + enchantmentAmount.getMin());
}
}
}
}
return new MerchantRecipe(inputA, inputB, outputStack, 0, rand.nextInt((offerAmount.getMax() - offerAmount.getMin()) + 1) + offerAmount.getMin());
}
use of net.minecraft.item.ItemEnchantedBook in project BetterStorage by copygirl.
the class CardboardEnchantmentRecipe method makeEnchantedBook.
private ItemStack makeEnchantedBook(Enchantment ench, int level) {
ItemStack book = new ItemStack(Items.enchanted_book);
((ItemEnchantedBook) book.getItem()).addEnchantment(book, new EnchantmentData(ench, level));
return book;
}
use of net.minecraft.item.ItemEnchantedBook in project BetterStorage by copygirl.
the class RecipeInputEnchantedBook method matches.
@Override
public boolean matches(ItemStack stack) {
if (validEnchantments == null) {
validEnchantments = new HashSet<Enchantment>();
ItemStack[] items = { new ItemStack(BetterStorageItems.cardboardHelmet), new ItemStack(BetterStorageItems.cardboardChestplate), new ItemStack(BetterStorageItems.cardboardLeggings), new ItemStack(BetterStorageItems.cardboardBoots), new ItemStack(BetterStorageItems.cardboardSword), new ItemStack(BetterStorageItems.cardboardPickaxe), new ItemStack(BetterStorageItems.cardboardShovel), new ItemStack(BetterStorageItems.cardboardAxe), new ItemStack(BetterStorageItems.cardboardHoe) };
for (Enchantment ench : Enchantment.enchantmentsList) {
if ((ench == null) || !ench.isAllowedOnBooks())
continue;
for (ItemStack item : items) if (item.getItem() != null && ench.canApply(item)) {
validEnchantments.add(ench);
break;
}
}
}
if (stack.getItem() instanceof ItemEnchantedBook) {
Map<Integer, Integer> enchants = EnchantmentHelper.getEnchantments(stack);
for (Enchantment ench : validEnchantments) if (enchants.containsKey(ench.effectId))
return true;
}
return false;
}
Aggregations