Search in sources :

Example 21 with Enchantment

use of net.minecraft.enchantment.Enchantment in project SilentGems by SilentChaos512.

the class ItemEnchantmentToken method getOutlineColor.

public int getOutlineColor(ItemStack stack) {
    Enchantment ench = getSingleEnchantment(stack);
    if (ench != null && colorMap.containsKey(ench)) {
        int k = colorMap.get(ench);
        int r = (k >> 16) & 255;
        int g = (k >> 8) & 255;
        int b = k & 255;
        int j = (int) (160 * MathHelper.sin(ClientTickHandler.ticksInGame * OUTLINE_PULSATE_SPEED));
        j = MathHelper.clamp(j, 0, 255);
        r = MathHelper.clamp(r + j, 0, 255);
        g = MathHelper.clamp(g + j, 0, 255);
        b = MathHelper.clamp(b + j, 0, 255);
        return (r << 16) | (g << 8) | b;
    }
    return 0xFFFFFF;
}
Also used : Enchantment(net.minecraft.enchantment.Enchantment)

Example 22 with Enchantment

use of net.minecraft.enchantment.Enchantment in project SilentGems by SilentChaos512.

the class ItemEnchantmentToken method applyTokenToTool.

// ========
// Crafting
// ========
public boolean applyTokenToTool(ItemStack token, ItemStack tool) {
    if (StackHelper.isEmpty(token) || StackHelper.isEmpty(tool)) {
        return false;
    }
    // Get enchantments on token.
    Map<Enchantment, Integer> enchantmentsOnToken = getEnchantments(token);
    if (enchantmentsOnToken.isEmpty())
        return false;
    // Get enchantments on tool.
    Map<Enchantment, Integer> enchantmentsOnTool = EnchantmentHelper.getEnchantments(tool);
    // Make sure all enchantments can apply to the tool.
    for (Entry<Enchantment, Integer> entry : enchantmentsOnToken.entrySet()) {
        Enchantment ench = entry.getKey();
        // Valid for tool?
        if (!ench.canApply(tool))
            return false;
        // Does new enchantment conflict with any existing ones?
        for (Enchantment enchTool : enchantmentsOnTool.keySet()) {
            if (!ench.equals(enchTool) && !EnchantmentUtils.canApplyTogether(ench, enchTool))
                return false;
        }
    }
    // Appy enchantments to new copy of tool.
    if (!mergeEnchantmentLists(enchantmentsOnToken, enchantmentsOnTool)) {
        return false;
    }
    EnchantmentHelper.setEnchantments(enchantmentsOnToken, tool);
    return true;
}
Also used : Enchantment(net.minecraft.enchantment.Enchantment)

Example 23 with Enchantment

use of net.minecraft.enchantment.Enchantment in project SilentGems by SilentChaos512.

the class ItemEnchantmentToken method getEnchantments.

public Map<Enchantment, Integer> getEnchantments(ItemStack token) {
    if (StackHelper.isEmpty(token) || !token.hasTagCompound())
        return new HashMap<>();
    NBTTagList tagList = token.getTagCompound().getTagList(NBT_ENCHANTMENTS, 10);
    Map<Enchantment, Integer> map = new HashMap<>();
    if (tagList != null) {
        for (int i = 0; i < tagList.tagCount(); ++i) {
            String name = tagList.getCompoundTagAt(i).getString("name");
            int level = tagList.getCompoundTagAt(i).getShort("lvl");
            Enchantment ench = Enchantment.REGISTRY.getObject(new ResourceLocation(name));
            if (ench != null)
                map.put(ench, level);
        }
    }
    return map;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) HashMap(java.util.HashMap) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) Enchantment(net.minecraft.enchantment.Enchantment)

Example 24 with Enchantment

use of net.minecraft.enchantment.Enchantment in project DefiledLands by Lykrast.

the class EntityBookWyrm method onLivingUpdate.

/**
 * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
 * use this to react to sunlight and start to burn.
 */
public void onLivingUpdate() {
    super.onLivingUpdate();
    if (digesting > 0 && digestTimer > 0) {
        digestTimer--;
        if (world.isRemote) {
            double d0 = this.rand.nextGaussian() * 0.02D;
            double d1 = this.rand.nextGaussian() * 0.02D;
            double d2 = this.rand.nextGaussian() * 0.02D;
            world.spawnParticle(EnumParticleTypes.ENCHANTMENT_TABLE, posX + (double) (rand.nextFloat() * width * 2.0F) - (double) width, posY + 0.25D + (double) (rand.nextFloat() * height), posZ + (double) (rand.nextFloat() * width * 2.0F) - (double) width, d0, d1, d2);
        }
        if (digestTimer <= 0) {
            digested++;
            digesting--;
            playDigestEffect(false);
            if (digesting > 0)
                digestTimer = getDigestTime();
        }
    }
    if (digested >= getMaxLevel()) {
        // Spawn the books
        digested -= getMaxLevel();
        playSound(SoundEvents.ENTITY_CHICKEN_EGG, 1.0F, (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F);
        playSound(SoundEvents.ENTITY_PLAYER_LEVELUP, 1.0F, 1.0F);
        playDigestEffect(true);
        if (!world.isRemote) {
            List<EnchantmentData> list = EnchantmentHelper.buildEnchantmentList(rand, new ItemStack(Items.BOOK), getMaxLevel(), isGolden());
            if (!list.isEmpty()) {
                // Sort by descending digested value
                Collections.sort(list, Comparator.comparingInt((e) -> -e.enchantment.getMinEnchantability(e.enchantmentLevel)));
                // Make sure that whatever books it gives back, it'll never exceed the enchantment level
                // To prevent endless loops
                int remaining = (int) (getMaxLevel() / Config.conversionRate);
                for (EnchantmentData e : list) {
                    int value = (int) (e.enchantment.getMinEnchantability(e.enchantmentLevel) * Config.conversionRate);
                    if (remaining >= value) {
                        remaining -= value;
                        ItemStack book = new ItemStack(Items.ENCHANTED_BOOK);
                        ItemEnchantedBook.addEnchantment(book, e);
                        entityDropItem(book, 0.5F);
                        if (remaining <= 0)
                            break;
                    }
                }
            }
        }
    }
}
Also used : IEntityAdditionalSpawnData(net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData) EntityAIMate(net.minecraft.entity.ai.EntityAIMate) Item(net.minecraft.item.Item) EnumDifficulty(net.minecraft.world.EnumDifficulty) EnumHand(net.minecraft.util.EnumHand) ModItems(lykrast.defiledlands.common.init.ModItems) EntityAIWanderAvoidWater(net.minecraft.entity.ai.EntityAIWanderAvoidWater) Block(net.minecraft.block.Block) Map(java.util.Map) EnchantmentData(net.minecraft.enchantment.EnchantmentData) ModSounds(lykrast.defiledlands.common.init.ModSounds) DifficultyInstance(net.minecraft.world.DifficultyInstance) Config(lykrast.defiledlands.common.util.Config) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityAILeapAtTarget(net.minecraft.entity.ai.EntityAILeapAtTarget) EntityAIAttackMelee(net.minecraft.entity.ai.EntityAIAttackMelee) Set(java.util.Set) ItemEnchantedBook(net.minecraft.item.ItemEnchantedBook) DataParameter(net.minecraft.network.datasync.DataParameter) Sets(com.google.common.collect.Sets) EnchantmentHelper(net.minecraft.enchantment.EnchantmentHelper) List(java.util.List) EntityAIHurtByTarget(net.minecraft.entity.ai.EntityAIHurtByTarget) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Entry(java.util.Map.Entry) EnumParticleTypes(net.minecraft.util.EnumParticleTypes) EntityDataManager(net.minecraft.network.datasync.EntityDataManager) EntityAIFollowParent(net.minecraft.entity.ai.EntityAIFollowParent) EntityAILookIdle(net.minecraft.entity.ai.EntityAILookIdle) EntityAISwimming(net.minecraft.entity.ai.EntityAISwimming) Enchantment(net.minecraft.enchantment.Enchantment) EntityAIWatchClosest(net.minecraft.entity.ai.EntityAIWatchClosest) EntityAgeable(net.minecraft.entity.EntityAgeable) DefiledLands(lykrast.defiledlands.core.DefiledLands) ItemStack(net.minecraft.item.ItemStack) ByteBuf(io.netty.buffer.ByteBuf) IEntityLivingData(net.minecraft.entity.IEntityLivingData) Nullable(javax.annotation.Nullable) Entity(net.minecraft.entity.Entity) EntityAITempt(net.minecraft.entity.ai.EntityAITempt) SoundEvents(net.minecraft.init.SoundEvents) Items(net.minecraft.init.Items) World(net.minecraft.world.World) BlockPos(net.minecraft.util.math.BlockPos) DamageSource(net.minecraft.util.DamageSource) IEntityDefiled(lykrast.defiledlands.common.entity.IEntityDefiled) SharedMonsterAttributes(net.minecraft.entity.SharedMonsterAttributes) EntityAIPanic(net.minecraft.entity.ai.EntityAIPanic) EntityAnimal(net.minecraft.entity.passive.EntityAnimal) DataSerializers(net.minecraft.network.datasync.DataSerializers) EntityLivingBase(net.minecraft.entity.EntityLivingBase) ModBlocks(lykrast.defiledlands.common.init.ModBlocks) MathHelper(net.minecraft.util.math.MathHelper) ResourceLocation(net.minecraft.util.ResourceLocation) EntityCreature(net.minecraft.entity.EntityCreature) Comparator(java.util.Comparator) Collections(java.util.Collections) SoundEvent(net.minecraft.util.SoundEvent) EnchantmentData(net.minecraft.enchantment.EnchantmentData) ItemStack(net.minecraft.item.ItemStack)

Example 25 with Enchantment

use of net.minecraft.enchantment.Enchantment in project BloodMagic by WayofTime.

the class OmegaArmour method getSubstituteStack.

public ItemStack getSubstituteStack(ItemStack boundStack, int stability, int affinity, int enchantability, int enchantmentLevel, Random rand) {
    ItemStack omegaStack = new ItemStack(this);
    if (boundStack != null && boundStack.hasTagCompound()) {
        NBTTagCompound tag = (NBTTagCompound) boundStack.getTagCompound().copy();
        omegaStack.setTagCompound(tag);
    }
    this.setContainedArmourStack(omegaStack, boundStack);
    SoulNetworkHandler.checkAndSetItemOwner(omegaStack, SoulNetworkHandler.getOwnerName(boundStack));
    this.setItemEnchantability(omegaStack, Math.min(enchantability, 70));
    EnchantmentHelper.setEnchantments(new HashMap(), omegaStack);
    List enchantList = new ArrayList();
    int adjustedEnchantLevel = Math.min(enchantmentLevel, 30);
    int additionalPasses = enchantmentLevel - adjustedEnchantLevel;
    for (int i = 0; i < 1 + additionalPasses; i++) {
        List lst = EnchantmentHelper.buildEnchantmentList(rand, omegaStack, adjustedEnchantLevel);
        if (lst != null) {
            enchantList.addAll(lst);
        }
    }
    Map<Enchantment, Map<Integer, Integer>> map = new HashMap();
    for (Object obj : enchantList) {
        EnchantmentData enchantmentdata = (EnchantmentData) obj;
        if (!map.containsKey(enchantmentdata.enchantmentobj)) {
            map.put(enchantmentdata.enchantmentobj, new HashMap());
        }
        Map<Integer, Integer> numMap = map.get(enchantmentdata.enchantmentobj);
        if (numMap.containsKey(enchantmentdata.enchantmentLevel)) {
            numMap.put(enchantmentdata.enchantmentLevel, numMap.get(enchantmentdata.enchantmentLevel) + 1);
        } else {
            numMap.put(enchantmentdata.enchantmentLevel, 1);
        }
    }
    for (Enchantment ench : this.illegalEnchantmentList) {
        if (map.containsKey(ench)) {
            map.remove(ench);
        }
    }
    List newEnchantList = new ArrayList();
    for (Entry<Enchantment, Map<Integer, Integer>> entry : map.entrySet()) {
        Enchantment ench = entry.getKey();
        Map<Integer, Integer> numMap = entry.getValue();
        if (numMap.isEmpty()) {
            continue;
        }
        int[] enchantValues = new int[1];
        for (Entry<Integer, Integer> entry1 : numMap.entrySet()) {
            int enchantLevel = entry1.getKey();
            int number = entry1.getValue();
            if (enchantLevel >= enchantValues.length) {
                int[] newEnchantValues = new int[enchantLevel + 1];
                for (int i = 0; i < enchantValues.length; i++) {
                    newEnchantValues[i] = enchantValues[i];
                }
                enchantValues = newEnchantValues;
            }
            enchantValues[enchantLevel] += number;
        }
        int size = enchantValues.length;
        int i = 0;
        while (i < size) {
            int number = enchantValues[i];
            if (number >= 2 && i + 1 >= size) {
                int[] newEnchantValues = new int[i + 2];
                for (int z = 0; z < enchantValues.length; z++) {
                    newEnchantValues[z] = enchantValues[z];
                }
                enchantValues = newEnchantValues;
                enchantValues[i + 1] += number / 2;
                size = enchantValues.length;
            }
            i++;
        }
        newEnchantList.add(new EnchantmentData(ench, enchantValues.length - 1));
    }
    Iterator iterator = newEnchantList.iterator();
    while (iterator.hasNext()) {
        EnchantmentData enchantmentdata = (EnchantmentData) iterator.next();
        {
            omegaStack.addEnchantment(enchantmentdata.enchantmentobj, enchantmentdata.enchantmentLevel);
        }
    }
    for (int i = 0; i < 1; i++) {
    // omegaStack = EnchantmentHelper.addRandomEnchantment(new Random(), omegaStack, 30);
    }
    return omegaStack;
}
Also used : HashMap(java.util.HashMap) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ArrayList(java.util.ArrayList) EnchantmentData(net.minecraft.enchantment.EnchantmentData) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ItemStack(net.minecraft.item.ItemStack) Enchantment(net.minecraft.enchantment.Enchantment) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Enchantment (net.minecraft.enchantment.Enchantment)55 ItemStack (net.minecraft.item.ItemStack)32 ArrayList (java.util.ArrayList)10 Map (java.util.Map)9 Item (net.minecraft.item.Item)9 EnchantmentData (net.minecraft.enchantment.EnchantmentData)8 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)7 NBTTagList (net.minecraft.nbt.NBTTagList)7 HashMap (java.util.HashMap)6 Iterator (java.util.Iterator)6 List (java.util.List)4 EntityLivingBase (net.minecraft.entity.EntityLivingBase)4 ResourceLocation (net.minecraft.util.ResourceLocation)4 Block (net.minecraft.block.Block)3 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)3 EnchantmentHelper (net.minecraft.enchantment.EnchantmentHelper)3 Entity (net.minecraft.entity.Entity)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 ItemEnchantedBook (net.minecraft.item.ItemEnchantedBook)3 ImmutableList (com.google.common.collect.ImmutableList)2