use of net.minecraft.enchantment.EnchantmentData 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.enchantment.EnchantmentData in project MineFactoryReloaded by powercrystals.
the class AutoEnchantmentHelper method addRandomEnchantment.
@SuppressWarnings("unchecked")
public static ItemStack addRandomEnchantment(Random rand, ItemStack stack, int level) {
if (stack == null) {
return null;
}
ItemStack output = stack.splitStack(1);
List<EnchantmentData> enchantments = buildEnchantmentList(rand, output, level);
if (enchantments == null) {
return output;
}
Map<Integer, Integer> existingEnchants = getEnchantments(output);
boolean isBook = output.itemID == Item.book.itemID;
if (isBook) {
output.itemID = Item.enchantedBook.itemID;
}
Collections.shuffle(enchantments);
outerlist: for (EnchantmentData newEnchant : enchantments) {
if (isBook) {
Item.enchantedBook.func_92115_a(output, newEnchant);
return output;
} else {
for (Entry<Integer, Integer> oldEnchant : existingEnchants.entrySet()) {
if (oldEnchant.getKey() == newEnchant.enchantmentobj.effectId) {
if (oldEnchant.getValue() <= newEnchant.enchantmentLevel) {
updateEnchantment(output, oldEnchant.getKey(), (short) newEnchant.enchantmentLevel);
}
continue outerlist;
}
}
output.addEnchantment(newEnchant.enchantmentobj, newEnchant.enchantmentLevel);
}
}
return output;
}
use of net.minecraft.enchantment.EnchantmentData in project MineFactoryReloaded by powercrystals.
the class AutoEnchantmentHelper method mapEnchantmentData.
public static Map<Integer, EnchantmentData> mapEnchantmentData(int targetEnchantability, ItemStack stack) {
HashMap<Integer, EnchantmentData> enchantmentMap = null;
boolean isBook = stack.itemID == Item.book.itemID;
for (int var7 = 0; var7 < Enchantment.enchantmentsList.length; ++var7) {
Enchantment enchantment = Enchantment.enchantmentsList[var7];
if (enchantment != null && (isBook || enchantment.canApplyAtEnchantingTable(stack))) {
for (int enchLevel = enchantment.getMinLevel(); enchLevel <= enchantment.getMaxLevel(); ++enchLevel) {
if (targetEnchantability >= enchantment.getMinEnchantability(enchLevel) && targetEnchantability <= enchantment.getMaxEnchantability(enchLevel)) {
if (enchantmentMap == null) {
enchantmentMap = new HashMap<Integer, EnchantmentData>();
}
enchantmentMap.put(Integer.valueOf(enchantment.effectId), new EnchantmentData(enchantment, enchLevel));
}
}
}
}
return enchantmentMap;
}
use of net.minecraft.enchantment.EnchantmentData in project MineFactoryReloaded by powercrystals.
the class TileEntityAutoEnchanter method getEnchantmentMultiplier.
@SuppressWarnings("unchecked")
private double getEnchantmentMultiplier() {
ItemStack s = getStackInSlot(0);
if (s == null) {
return 1;
}
Map<Integer, EnchantmentData> enchantments = AutoEnchantmentHelper.getEnchantments(s);
if (enchantments == null || enchantments.size() == 0) {
return 1;
}
return Math.pow(enchantments.size() + 1.0, 2);
}
use of net.minecraft.enchantment.EnchantmentData 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());
}
Aggregations