Search in sources :

Example 1 with EnchantmentData

use of gregtech.api.enchants.EnchantmentData in project GregTech by GregTechCE.

the class ToolMetaItem method onCreated.

@Override
public void onCreated(ItemStack stack, World world, EntityPlayer player) {
    T metaToolValueItem = getItem(stack);
    if (metaToolValueItem != null) {
        IToolStats toolStats = metaToolValueItem.getToolStats();
        toolStats.onToolCrafted(stack, player);
        ArrayList<EnchantmentData> enchantments = new ArrayList<>(toolStats.getEnchantments(stack));
        SolidMaterial material = getPrimaryMaterial(stack);
        if (material == null) {
            return;
        }
        for (EnchantmentData enchantmentData : material.toolEnchantments) {
            Optional<EnchantmentData> sameEnchantment = enchantments.stream().filter(it -> it.enchantment == enchantmentData.enchantment).findAny();
            if (sameEnchantment.isPresent()) {
                enchantments.remove(sameEnchantment.get());
                int level = Math.min(enchantmentData.level + sameEnchantment.get().level, enchantmentData.enchantment.getMaxLevel());
                enchantments.add(new EnchantmentData(enchantmentData.enchantment, level));
            } else {
                enchantments.add(enchantmentData);
            }
        }
        for (EnchantmentData enchantmentData : enchantments) {
            stack.addEnchantment(enchantmentData.enchantment, enchantmentData.level);
        }
    }
}
Also used : ToolDictNames(gregtech.api.items.ToolDictNames) SolidMaterial(gregtech.api.unification.material.type.SolidMaterial) SimpleItemStack(gregtech.api.unification.stack.SimpleItemStack) Constants(net.minecraftforge.common.util.Constants) Materials(gregtech.api.unification.material.Materials) EntityEquipmentSlot(net.minecraft.inventory.EntityEquipmentSlot) Multimap(com.google.common.collect.Multimap) IDamagableItem(gregtech.api.items.IDamagableItem) EnchantmentData(gregtech.api.enchants.EnchantmentData) Material(gregtech.api.unification.material.type.Material) ModelBakery(net.minecraft.client.renderer.block.model.ModelBakery) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) HashMultimap(com.google.common.collect.HashMultimap) GregTechAPI(gregtech.api.GregTechAPI) Side(net.minecraftforge.fml.relauncher.Side) OreDictionary(net.minecraftforge.oredict.OreDictionary) MetaItem(gregtech.api.items.metaitem.MetaItem) CreativeTabs(net.minecraft.creativetab.CreativeTabs) ModelLoader(net.minecraftforge.client.model.ModelLoader) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) SoundCategory(net.minecraft.util.SoundCategory) Nullable(javax.annotation.Nullable) IMetaItemStats(gregtech.api.items.metaitem.stats.IMetaItemStats) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Entity(net.minecraft.entity.Entity) AttributeModifier(net.minecraft.entity.ai.attributes.AttributeModifier) World(net.minecraft.world.World) Collection(java.util.Collection) BlockPos(net.minecraft.util.math.BlockPos) SharedMonsterAttributes(net.minecraft.entity.SharedMonsterAttributes) IElectricItem(gregtech.api.capability.IElectricItem) IBlockState(net.minecraft.block.state.IBlockState) GTValues(gregtech.api.GTValues) Validate(org.apache.commons.lang3.Validate) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityDamageSource(net.minecraft.util.EntityDamageSource) ResourceLocation(net.minecraft.util.ResourceLocation) Optional(java.util.Optional) GTUtility(gregtech.api.util.GTUtility) SoundEvent(net.minecraft.util.SoundEvent) SolidMaterial(gregtech.api.unification.material.type.SolidMaterial) ArrayList(java.util.ArrayList) EnchantmentData(gregtech.api.enchants.EnchantmentData)

Aggregations

HashMultimap (com.google.common.collect.HashMultimap)1 Multimap (com.google.common.collect.Multimap)1 GTValues (gregtech.api.GTValues)1 GregTechAPI (gregtech.api.GregTechAPI)1 IElectricItem (gregtech.api.capability.IElectricItem)1 EnchantmentData (gregtech.api.enchants.EnchantmentData)1 IDamagableItem (gregtech.api.items.IDamagableItem)1 ToolDictNames (gregtech.api.items.ToolDictNames)1 MetaItem (gregtech.api.items.metaitem.MetaItem)1 IMetaItemStats (gregtech.api.items.metaitem.stats.IMetaItemStats)1 Materials (gregtech.api.unification.material.Materials)1 Material (gregtech.api.unification.material.type.Material)1 SolidMaterial (gregtech.api.unification.material.type.SolidMaterial)1 SimpleItemStack (gregtech.api.unification.stack.SimpleItemStack)1 GTUtility (gregtech.api.util.GTUtility)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Optional (java.util.Optional)1 Nullable (javax.annotation.Nullable)1 IBlockState (net.minecraft.block.state.IBlockState)1