use of net.minecraft.enchantment.Enchantment 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.enchantment.Enchantment in project RFToolsDimensions by McJty.
the class ModCrafting method createEnchantedItem.
public static ItemStack createEnchantedItem(Item item, Enchantment enchantment, int amount) {
ItemStack stack = new ItemStack(item);
Map<Enchantment, Integer> enchant = new HashMap<>();
enchant.put(enchantment, amount);
EnchantmentHelper.setEnchantments(enchant, stack);
return stack;
}
use of net.minecraft.enchantment.Enchantment in project SpongeCommon by SpongePowered.
the class DamageEventHandler method createAttackEnchantmentFunction.
public static List<DamageFunction> createAttackEnchantmentFunction(net.minecraft.item.ItemStack heldItem, EnumCreatureAttribute creatureAttribute, float attackStrength) {
final Multimap<Enchantment, Integer> enchantments = LinkedHashMultimap.create();
final List<DamageFunction> damageModifierFunctions = new ArrayList<>();
if (!heldItem.isEmpty()) {
NBTTagList nbttaglist = heldItem.getEnchantmentTagList();
if (nbttaglist.hasNoTags()) {
return ImmutableList.of();
}
for (int i = 0; i < nbttaglist.tagCount(); ++i) {
int j = nbttaglist.getCompoundTagAt(i).getShort("id");
int enchantmentLevel = nbttaglist.getCompoundTagAt(i).getShort("lvl");
final Enchantment enchantment = Enchantment.getEnchantmentByID(j);
if (enchantment != null) {
enchantments.put(enchantment, enchantmentLevel);
}
}
if (enchantments.isEmpty()) {
return ImmutableList.of();
}
ItemStackSnapshot snapshot = ItemStackUtil.snapshotOf(heldItem);
for (Map.Entry<Enchantment, Collection<Integer>> enchantment : enchantments.asMap().entrySet()) {
final DamageModifier enchantmentModifier = DamageModifier.builder().type(DamageModifierTypes.WEAPON_ENCHANTMENT).cause(Cause.of(EventContext.empty(), snapshot, enchantment)).build();
DoubleUnaryOperator enchantmentFunction = (damage) -> {
double totalDamage = 0;
for (int level : enchantment.getValue()) {
totalDamage += (double) enchantment.getKey().calcDamageByCreature(level, creatureAttribute) * attackStrength;
}
return totalDamage;
};
damageModifierFunctions.add(new DamageFunction(enchantmentModifier, enchantmentFunction));
}
}
return damageModifierFunctions;
}
use of net.minecraft.enchantment.Enchantment in project SpongeCommon by SpongePowered.
the class MixinEntityVillagerListEnchantedBookForEmeralds method apply.
@Override
public TradeOffer apply(Random random) {
checkNotNull(random, "Random cannot be null!");
Enchantment enchantment = Enchantment.REGISTRY.getRandomObject(random);
int enchantmentLevel = MathHelper.getInt(random, enchantment.getMinLevel(), enchantment.getMaxLevel());
ItemStack itemstack = ItemEnchantedBook.getEnchantedItemStack(new EnchantmentData(enchantment, enchantmentLevel));
int emeraldCount = 2 + random.nextInt(5 + enchantmentLevel * 10) + 3 * enchantmentLevel;
if (enchantment.isTreasureEnchantment()) {
emeraldCount *= 2;
}
if (emeraldCount > 64) {
emeraldCount = 64;
}
return (TradeOffer) new MerchantRecipe(new ItemStack(Items.BOOK), new ItemStack(Items.EMERALD, emeraldCount), itemstack);
}
use of net.minecraft.enchantment.Enchantment in project Wurst-MC-1.12 by Wurst-Imperium.
the class EnchantCmd method call.
@Override
public void call(String[] args) throws CmdException {
if (!WMinecraft.getPlayer().capabilities.isCreativeMode)
throw new CmdError("Creative mode only.");
if (args.length == 0) {
ItemStack currentItem = WMinecraft.getPlayer().inventory.getCurrentItem();
if (currentItem == null)
throw new CmdError("There is no item in your hand.");
for (Enchantment enchantment : Enchantment.REGISTRY) try {
if (enchantment == WEnchantments.SILK_TOUCH)
continue;
currentItem.addEnchantment(enchantment, 127);
} catch (Exception e) {
}
} else if (args[0].equals("all")) {
int items = 0;
for (int i = 0; i < 40; i++) {
ItemStack currentItem = WMinecraft.getPlayer().inventory.getStackInSlot(i);
if (currentItem == null)
continue;
items++;
for (Enchantment enchantment : Enchantment.REGISTRY) try {
if (enchantment == WEnchantments.SILK_TOUCH)
continue;
currentItem.addEnchantment(enchantment, 127);
} catch (Exception e) {
}
}
if (items == 1)
ChatUtils.message("Enchanted 1 item.");
else
ChatUtils.message("Enchanted " + items + " items.");
} else
throw new CmdSyntaxError();
}
Aggregations