Java 类net.minecraft.enchantment.EnchantmentHelper 实例源码

项目:pnc-repressurized    文件:PressureChamberPressureEnchantHandler.java   
private ItemStack[] getRecipeIngredients(ItemStackHandler inputStacks) {
    List<ItemStack> enchantedBooks = new ItemStackHandlerIterable(inputStacks)
                                                .stream()
                                                .filter(book -> book.getItem() == Items.ENCHANTED_BOOK)
                                                .collect(Collectors.toList());

    if (enchantedBooks.isEmpty()) return null;

    for (ItemStack inputStack : new ItemStackHandlerIterable(inputStacks)) {
        if ((inputStack.isItemEnchantable() || inputStack.isItemEnchanted()) && inputStack.getItem() != Items.ENCHANTED_BOOK) {
            for (ItemStack enchantedBook : enchantedBooks) {
                Map<Enchantment, Integer> bookMap = EnchantmentHelper.getEnchantments(enchantedBook);
                for (Map.Entry<Enchantment, Integer> entry : bookMap.entrySet()) {
                    if (entry.getKey().canApply(inputStack)) {
                        return new ItemStack[]{ inputStack, enchantedBook};
                    }
                }
            }
        }
    }
    return null;
}
项目:Backmemed    文件:Block.java   
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack stack)
{
    player.addStat(StatList.getBlockStats(this));
    player.addExhaustion(0.005F);

    if (this.canSilkHarvest() && EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, stack) > 0)
    {
        ItemStack itemstack = this.getSilkTouchDrop(state);
        spawnAsEntity(worldIn, pos, itemstack);
    }
    else
    {
        int i = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack);
        this.dropBlockAsItem(worldIn, pos, state, i);
    }
}
项目:RunicArcana    文件:ScriptActivationEventHandler.java   
@SubscribeEvent
public void blockBreakEvent(BlockEvent.BreakEvent event)
{
    EntityPlayer player = event.getPlayer();
    ItemStack OmniItem = null;
    if(EnchantmentHelper.getEnchantmentLevel(ModEnchantment.runicenchantment, player.getHeldItem(EnumHand.MAIN_HAND) )>0)
        OmniItem = player.getHeldItem(EnumHand.MAIN_HAND);
    else if(EnchantmentHelper.getEnchantmentLevel(ModEnchantment.runicenchantment, player.getHeldItem(EnumHand.OFF_HAND) )>0)
        OmniItem = player.getHeldItem(EnumHand.OFF_HAND);
    else return;

    CompiledSymbol[] script = ModDust.getScriptFromItem(OmniItem);
    if(script==null)return;

    new ScriptExecutor(script, player, OmniItem, ScriptExecutor.StartPoint.BLOCK_BREAK, event.getPos());
}
项目:DecompiledMinecraft    文件:EntityLiving.java   
/**
 * Enchants Entity's current equipments based on given DifficultyInstance
 */
protected void setEnchantmentBasedOnDifficulty(DifficultyInstance difficulty)
{
    float f = difficulty.getClampedAdditionalDifficulty();

    if (this.getHeldItem() != null && this.rand.nextFloat() < 0.25F * f)
    {
        EnchantmentHelper.addRandomEnchantment(this.rand, this.getHeldItem(), (int)(5.0F + f * (float)this.rand.nextInt(18)));
    }

    for (int i = 0; i < 4; ++i)
    {
        ItemStack itemstack = this.getCurrentArmor(i);

        if (itemstack != null && this.rand.nextFloat() < 0.5F * f)
        {
            EnchantmentHelper.addRandomEnchantment(this.rand, itemstack, (int)(5.0F + f * (float)this.rand.nextInt(18)));
        }
    }
}
项目:SerenityCE    文件:AutoTool.java   
private int getBestSlotMining(Block block) {
    int bestSlot = -1;
    float bestHardness = 1F;

    for (int index = 36; index < 45; index++) {
        ItemStack stack = mc.thePlayer.inventoryContainer.getSlot(index).getStack();
        if (stack != null) {
            float str = stack.getStrVsBlock(block);
            if (str > 1F) {
                int efficiencyLevel = EnchantmentHelper.getEnchantmentLevel(Enchantment.efficiency.effectId, stack);
                str += (efficiencyLevel * efficiencyLevel + 1);
            }

            if (str > bestHardness) {
                bestHardness = str;
                bestSlot = index;
            }
        }
    }

    return bestSlot;
}
项目:CustomWorldGen    文件:EntityAISkeletonRiders.java   
private EntitySkeleton createSkeleton(DifficultyInstance p_188514_1_, EntityHorse p_188514_2_)
{
    EntitySkeleton entityskeleton = new EntitySkeleton(p_188514_2_.worldObj);
    entityskeleton.onInitialSpawn(p_188514_1_, (IEntityLivingData)null);
    entityskeleton.setPosition(p_188514_2_.posX, p_188514_2_.posY, p_188514_2_.posZ);
    entityskeleton.hurtResistantTime = 60;
    entityskeleton.enablePersistence();

    if (entityskeleton.getItemStackFromSlot(EntityEquipmentSlot.HEAD) == null)
    {
        entityskeleton.setItemStackToSlot(EntityEquipmentSlot.HEAD, new ItemStack(Items.IRON_HELMET));
    }

    EnchantmentHelper.addRandomEnchantment(entityskeleton.getRNG(), entityskeleton.getHeldItemMainhand(), (int)(5.0F + p_188514_1_.getClampedAdditionalDifficulty() * (float)entityskeleton.getRNG().nextInt(18)), false);
    EnchantmentHelper.addRandomEnchantment(entityskeleton.getRNG(), entityskeleton.getItemStackFromSlot(EntityEquipmentSlot.HEAD), (int)(5.0F + p_188514_1_.getClampedAdditionalDifficulty() * (float)entityskeleton.getRNG().nextInt(18)), false);
    entityskeleton.worldObj.spawnEntityInWorld(entityskeleton);
    return entityskeleton;
}
项目:AdvancedCombat    文件:RecipeFlexibleUpgrade.java   
/** Gets an upgradeable stack */
@Override
public @Nonnull ItemStack getUpgradableStack(List<ItemStack> s) {
    if(ACUtils.doesItemStackListContain(s, upgrade, true)) {
        ItemStack toUpgrade = s.get(0);
        if(enchant.canApply(toUpgrade)) { // no sword needed now!
            Map<Enchantment, Integer> activeEnchs = EnchantmentHelper.getEnchantments(toUpgrade);
            for(Enchantment i : activeEnchs.keySet()) {
                if(i == enchant) {
                    int level = activeEnchs.get(i);
                    if(level >= maxLevel) {
                        return ItemStack.EMPTY;
                    }
                }
            }
            return toUpgrade.copy();
        }
    }
    return ItemStack.EMPTY;
}
项目:DecompiledMinecraft    文件:Block.java   
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te)
{
    player.triggerAchievement(StatList.mineBlockStatArray[getIdFromBlock(this)]);
    player.addExhaustion(0.025F);

    if (this.canSilkHarvest() && EnchantmentHelper.getSilkTouchModifier(player))
    {
        ItemStack itemstack = this.createStackedBlock(state);

        if (itemstack != null)
        {
            spawnAsEntity(worldIn, pos, itemstack);
        }
    }
    else
    {
        int i = EnchantmentHelper.getFortuneModifier(player);
        this.dropBlockAsItem(worldIn, pos, state, i);
    }
}
项目:DecompiledMinecraft    文件:EntityLiving.java   
/**
 * Enchants Entity's current equipments based on given DifficultyInstance
 */
protected void setEnchantmentBasedOnDifficulty(DifficultyInstance difficulty)
{
    float f = difficulty.getClampedAdditionalDifficulty();

    if (this.getHeldItem() != null && this.rand.nextFloat() < 0.25F * f)
    {
        EnchantmentHelper.addRandomEnchantment(this.rand, this.getHeldItem(), (int)(5.0F + f * (float)this.rand.nextInt(18)));
    }

    for (int i = 0; i < 4; ++i)
    {
        ItemStack itemstack = this.getCurrentArmor(i);

        if (itemstack != null && this.rand.nextFloat() < 0.5F * f)
        {
            EnchantmentHelper.addRandomEnchantment(this.rand, itemstack, (int)(5.0F + f * (float)this.rand.nextInt(18)));
        }
    }
}
项目:AdvancedCombat    文件:RecipeEnchantmentUpgrade.java   
/** Gets an upgradeable stack */
public @Nonnull ItemStack getUpgradableStack(@Nonnull List<ItemStack> s) {
    if(ACUtils.doesItemStackListContain(s, upgrade, true)) {
        ItemStack toUpgrade = s.get(0);
        if(enchant.canApply(toUpgrade) && toUpgrade.getItem() instanceof ItemSword) {
            Map<Enchantment, Integer> activeEnchs = EnchantmentHelper.getEnchantments(toUpgrade);
            for(Enchantment i : activeEnchs.keySet()) {
                if(i == enchant) {
                    int level = activeEnchs.get(i);
                    if(level >= maxLevel) {
                        return ItemStack.EMPTY;
                    }
                }
            }
            return toUpgrade.copy();
        }
    }
    return ItemStack.EMPTY;
}
项目:DecompiledMinecraft    文件:Block.java   
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te)
{
    player.triggerAchievement(StatList.mineBlockStatArray[getIdFromBlock(this)]);
    player.addExhaustion(0.025F);

    if (this.canSilkHarvest() && EnchantmentHelper.getSilkTouchModifier(player))
    {
        ItemStack itemstack = this.createStackedBlock(state);

        if (itemstack != null)
        {
            spawnAsEntity(worldIn, pos, itemstack);
        }
    }
    else
    {
        int i = EnchantmentHelper.getFortuneModifier(player);
        this.dropBlockAsItem(worldIn, pos, state, i);
    }
}
项目:Mods    文件:TNTCannon.java   
public boolean allowBlock(ItemStack stack, IBlockState block, World world) {
    float speed = BlockLauncher.getHardness(block, world);
    float mult = 1 + EnchantmentHelper.getEnchantmentLevel(BlockLauncher.enchHeavy, stack) * 0.6F;
    if (this.getType(stack) == 0)
        return speed <= 2.2f * mult;
    else if (this.getType(stack) == 2)
        return speed <= 2.0f * mult;
    else if (this.getType(stack) == 1)
        return speed >= 2.2f / mult;
    else if (this.getType(stack) == 4)
        return speed <= 2.2f * mult;
    else if (this.getType(stack) == 5)
        return speed >= 2.2f * mult;
    else if (this.getType(stack) == 3)
        return block.getMaterial().getCanBurn() && block.getBlock() != Blocks.TNT;
    else if (this.getType(stack) > 15)
        return block.getBlock() == Blocks.TNT;
    return true;
}
项目:BaseClient    文件:Aura.java   
private void attack(final EntityLivingBase ent, final boolean crit) {
    this.swingItem();
    if (crit) {
        this.crit();
    }
    else {
        this.mc.thePlayer.sendQueue.addToSendQueue(new C03PacketPlayer());
    }
    final float sharpLevel = EnchantmentHelper.func_152377_a(this.mc.thePlayer.getHeldItem(), ent.getCreatureAttribute());
    final boolean vanillaCrit = this.mc.thePlayer.fallDistance > 0.0f && !this.mc.thePlayer.onGround && !this.mc.thePlayer.isOnLadder() && !this.mc.thePlayer.isInWater() && !this.mc.thePlayer.isPotionActive(Potion.blindness) && this.mc.thePlayer.ridingEntity == null;
    this.mc.thePlayer.sendQueue.addToSendQueue(new C02PacketUseEntity(ent, C02PacketUseEntity.Action.ATTACK));
    if (crit || vanillaCrit) {
        this.mc.thePlayer.onCriticalHit(ent);
    }
    if (sharpLevel > 0.0f) {
        this.mc.thePlayer.onEnchantmentCritical(ent);
    }
}
项目:BaseClient    文件:EntityLiving.java   
/**
 * Enchants Entity's current equipments based on given DifficultyInstance
 */
protected void setEnchantmentBasedOnDifficulty(DifficultyInstance difficulty)
{
    float f = difficulty.getClampedAdditionalDifficulty();

    if (this.getHeldItem() != null && this.rand.nextFloat() < 0.25F * f)
    {
        EnchantmentHelper.addRandomEnchantment(this.rand, this.getHeldItem(), (int)(5.0F + f * (float)this.rand.nextInt(18)));
    }

    for (int i = 0; i < 4; ++i)
    {
        ItemStack itemstack = this.getCurrentArmor(i);

        if (itemstack != null && this.rand.nextFloat() < 0.5F * f)
        {
            EnchantmentHelper.addRandomEnchantment(this.rand, itemstack, (int)(5.0F + f * (float)this.rand.nextInt(18)));
        }
    }
}
项目:Zombe-Modpack    文件:EntityPlayer.java   
public void func_190777_m(boolean p_190777_1_)
{
    float f = 0.25F + (float)EnchantmentHelper.getEfficiencyModifier(this) * 0.05F;

    if (p_190777_1_)
    {
        f += 0.75F;
    }

    if (this.rand.nextFloat() < f)
    {
        this.getCooldownTracker().setCooldown(Items.SHIELD, 100);
        this.resetActiveHand();
        this.world.setEntityState(this, (byte)30);
    }
}
项目:BaseClient    文件:EntitySkeleton.java   
/**
 * Attack the specified entity using a ranged attack.
 */
public void attackEntityWithRangedAttack(EntityLivingBase p_82196_1_, float p_82196_2_)
{
    EntityArrow entityarrow = new EntityArrow(this.worldObj, this, p_82196_1_, 1.6F, (float)(14 - this.worldObj.getDifficulty().getDifficultyId() * 4));
    int i = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, this.getHeldItem());
    int j = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, this.getHeldItem());
    entityarrow.setDamage((double)(p_82196_2_ * 2.0F) + this.rand.nextGaussian() * 0.25D + (double)((float)this.worldObj.getDifficulty().getDifficultyId() * 0.11F));

    if (i > 0)
    {
        entityarrow.setDamage(entityarrow.getDamage() + (double)i * 0.5D + 0.5D);
    }

    if (j > 0)
    {
        entityarrow.setKnockbackStrength(j);
    }

    if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, this.getHeldItem()) > 0 || this.getSkeletonType() == 1)
    {
        entityarrow.setFire(100);
    }

    this.playSound("random.bow", 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
    this.worldObj.spawnEntityInWorld(entityarrow);
}
项目:Backmemed    文件:LootingEnchantBonus.java   
public ItemStack apply(ItemStack stack, Random rand, LootContext context)
{
    Entity entity = context.getKiller();

    if (entity instanceof EntityLivingBase)
    {
        int i = EnchantmentHelper.getLootingModifier((EntityLivingBase)entity);

        if (i == 0)
        {
            return stack;
        }

        float f = (float)i * this.count.generateFloat(rand);
        stack.func_190917_f(Math.round(f));

        if (this.limit != 0 && stack.func_190916_E() > this.limit)
        {
            stack.func_190920_e(this.limit);
        }
    }

    return stack;
}
项目:BaseClient    文件:Block.java   
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te)
{
    player.triggerAchievement(StatList.mineBlockStatArray[getIdFromBlock(this)]);
    player.addExhaustion(0.025F);

    if (this.canSilkHarvest() && EnchantmentHelper.getSilkTouchModifier(player))
    {
        ItemStack itemstack = this.createStackedBlock(state);

        if (itemstack != null)
        {
            spawnAsEntity(worldIn, pos, itemstack);
        }
    }
    else
    {
        int i = EnchantmentHelper.getFortuneModifier(player);
        this.dropBlockAsItem(worldIn, pos, state, i);
    }
}
项目:connor41-etfuturum2    文件:ModEnchantments.java   
public static void onLivingUpdate(EntityLivingBase entity) {
    if (entity.worldObj.isRemote)
        return;
    if (!EtFuturum.enableFrostWalker)
        return;

    ItemStack boots = entity.getEquipmentInSlot(1);
    int level = 0;
    if ((level = EnchantmentHelper.getEnchantmentLevel(frostWalker.effectId, boots)) > 0)
        if (entity.onGround) {
            int x = (int) entity.posX;
            int y = (int) entity.posY;
            int z = (int) entity.posZ;

            int radius = 1 + level;

            for (int i = -radius; i <= radius; i++)
                for (int j = -radius; j <= radius; j++) {
                    Block block = entity.worldObj.getBlock(x + i, y - 1, z + j);
                    if (block == Blocks.water || block == Blocks.flowing_water)
                        entity.worldObj.setBlock(x + i, y - 1, z + j, ModBlocks.frosted_ice);
                }
        }
}
项目:BetterBeginningsReborn    文件:ItemWickerShield.java   
private void doAxeStuff(EntityLivingBase attacked, EntityLivingBase attacker)
{
    //Copied from EntityMob#attackEntityAsMob() L134-150 START
    if (attacked instanceof EntityPlayer)
    {
        EntityPlayer entityplayer = (EntityPlayer)attacked;
        ItemStack itemstack = attacker.getHeldItemMainhand();
        ItemStack itemstack1 = entityplayer.isHandActive() ? entityplayer.getActiveItemStack() : ItemStack.EMPTY;

        if (!itemstack.isEmpty() && !itemstack1.isEmpty() && itemstack.getItem() instanceof ItemAxe && itemstack1.getItem() == RegisterItems.wickerShield)
        {
            float f1 = 0.25F + (float)EnchantmentHelper.getEfficiencyModifier(attacker) * 0.05F;

            if (attacker.world.rand.nextFloat() < f1)
            {
            entityplayer.getCooldownTracker().setCooldown(RegisterItems.wickerShield, 100);
            attacker.world.setEntityState(entityplayer, (byte) 30);
            }
        }
    }
    //Copied from EntityMob#attackEntityAsMob() L134-150 END
}
项目:pnc-repressurized    文件:PressureChamberVacuumEnchantHandler.java   
public ItemStack getDisenchantableItem(ItemStackHandler inputStacks){
    return new ItemStackHandlerIterable(inputStacks)
                    .stream()
                    .filter(stack -> stack.getItem() != Items.ENCHANTED_BOOK && EnchantmentHelper.getEnchantments(stack).size() > 0)
                    .findFirst()
                    .orElse(ItemStack.EMPTY);
}
项目:Industrial-Foregoing    文件:EnchantmentAplicatorTile.java   
public double getLevels() {
    NBTTagList list = ((ItemEnchantedBook) inEnchantedBook.getStackInSlot(0).getItem()).getEnchantments(inEnchantedBook.getStackInSlot(0));
    double amount = 0;
    for (int i = 0; i < list.tagCount(); ++i) {
        NBTTagCompound compound = ((NBTTagCompound) list.get(i));
        amount += EnchantmentHelper.calcItemStackEnchantability(this.world.rand, compound.getInteger("id"), compound.getShort("lvl"), inItem.getStackInSlot(0));

    }
    return amount;
}
项目:Industrial-Foregoing    文件:EnchantmentAplicatorTile.java   
@Override
protected float performWork() {
    if (WorkUtils.isDisabled(this.getBlockType())) return 0;
    if (!canWork()) return 0;
    int xp = (int) (getLevels() * 100);
    if (experienceTank.getFluidAmount() >= xp && ItemHandlerHelper.insertItem(outEnchantedItem, inItem.getStackInSlot(0), true).isEmpty()) {
        Map<Enchantment, Integer> mapFirst = EnchantmentHelper.getEnchantments(inEnchantedBook.getStackInSlot(0));
        Map<Enchantment, Integer> mapSecond = EnchantmentHelper.getEnchantments(inItem.getStackInSlot(0));
        for (Enchantment enchantmentFirst : mapFirst.keySet()) {
            if (enchantmentFirst != null) {
                if (mapSecond.containsKey(enchantmentFirst) && mapFirst.get(enchantmentFirst) == mapSecond.get(enchantmentFirst) && mapFirst.get(enchantmentFirst) >= enchantmentFirst.getMaxLevel())
                    return 0;
                int value = mapSecond.containsKey(enchantmentFirst) && mapFirst.get(enchantmentFirst) == mapSecond.get(enchantmentFirst) ? Math.min(mapFirst.get(enchantmentFirst) + 1, enchantmentFirst.getMaxLevel()) : mapFirst.get(enchantmentFirst);
                if (mapSecond.replace(enchantmentFirst, value) == null) {
                    mapSecond.put(enchantmentFirst, value);
                }
            }
        }
        ItemStack stack = inItem.getStackInSlot(0).copy();
        EnchantmentHelper.setEnchantments(mapSecond, stack);
        ItemHandlerHelper.insertItem(outEnchantedItem, stack, false);
        inItem.getStackInSlot(0).setCount(0);
        inEnchantedBook.getStackInSlot(0).setCount(0);
        experienceTank.drain(xp, true);
        return 500;
    }
    return 0;
}
项目:Backmemed    文件:EntityPlayer.java   
protected void func_190776_cN()
{
    for (int i = 0; i < this.inventory.getSizeInventory(); ++i)
    {
        ItemStack itemstack = this.inventory.getStackInSlot(i);

        if (!itemstack.func_190926_b() && EnchantmentHelper.func_190939_c(itemstack))
        {
            this.inventory.removeStackFromSlot(i);
        }
    }
}
项目:Backmemed    文件:ItemFishingRod.java   
public ActionResult<ItemStack> onItemRightClick(World itemStackIn, EntityPlayer worldIn, EnumHand playerIn)
{
    ItemStack itemstack = worldIn.getHeldItem(playerIn);

    if (worldIn.fishEntity != null)
    {
        int i = worldIn.fishEntity.handleHookRetraction();
        itemstack.damageItem(i, worldIn);
        worldIn.swingArm(playerIn);
    }
    else
    {
        itemStackIn.playSound((EntityPlayer)null, worldIn.posX, worldIn.posY, worldIn.posZ, SoundEvents.ENTITY_BOBBER_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));

        if (!itemStackIn.isRemote)
        {
            EntityFishHook entityfishhook = new EntityFishHook(itemStackIn, worldIn);
            int j = EnchantmentHelper.func_191528_c(itemstack);

            if (j > 0)
            {
                entityfishhook.func_191516_a(j);
            }

            int k = EnchantmentHelper.func_191529_b(itemstack);

            if (k > 0)
            {
                entityfishhook.func_191517_b(k);
            }

            itemStackIn.spawnEntityInWorld(entityfishhook);
        }

        worldIn.swingArm(playerIn);
        worldIn.addStat(StatList.getObjectUseStats(this));
    }

    return new ActionResult(EnumActionResult.SUCCESS, itemstack);
}
项目:harshencastle    文件:HandlerHarshenInventory.java   
@SubscribeEvent
public void onPlayerInteractXP(PlayerPickupXpEvent event)
{
        if (!EnchantmentHelper.getEnchantedItem(Enchantments.MENDING, event.getEntityPlayer()).isEmpty())
         return;
        HarshenItemStackHandler handler = HarshenUtils.getHandler(event.getEntityPlayer());
        for(int o = 0; o < handler.getSlots(); o++)
            if(handler.getStackInSlot(o).isItemDamaged() && EnchantmentHelper.getEnchantmentLevel(Enchantments.MENDING, handler.getStackInSlot(o)) > 0)
            {
                int i = Math.min(event.getOrb().xpValue * 2, (handler.getStackInSlot(o).getItemDamage()));
               event.getOrb().xpValue -= i / 2;
               HarshenUtils.damageFirstOccuringItem(event.getEntityPlayer(), handler.getStackInSlot(o).getItem(), - i);
                break;
            }
}
项目:uniquecrops    文件:BlockCropsBase.java   
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, @Nullable ItemStack stack, EnumFacing side, float hitX, float hitY, float hitZ) {

    if (clickHarvest && !world.isRemote) {
        if (player.getHeldItemMainhand() != null) return false;
        if (getAge(state) >= getMaxAge()) {
            world.setBlockState(pos, this.withAge(0), 3);
            int fortune = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, player.getHeldItemMainhand());
            this.dropBlockAsItem(world, pos, state, fortune);
            return true;
        }
    }
    return false;
}
项目:Randores2    文件:EmpoweredEnchantment.java   
public static boolean appliedTo(ItemStack stack) {
    for (Enchantment en : EnchantmentHelper.getEnchantments(stack).keySet()) {
        if (en instanceof EmpoweredEnchantment) {
            return true;
        }
    }

    return false;
}
项目:DecompiledMinecraft    文件:Entity.java   
protected void applyEnchantments(EntityLivingBase entityLivingBaseIn, Entity entityIn)
{
    if (entityIn instanceof EntityLivingBase)
    {
        EnchantmentHelper.applyThornEnchantments((EntityLivingBase)entityIn, entityLivingBaseIn);
    }

    EnchantmentHelper.applyArthropodEnchantments(entityLivingBaseIn, entityIn);
}
项目:DecompiledMinecraft    文件:EntityFishHook.java   
private ItemStack getFishingResult()
{
    float f = this.worldObj.rand.nextFloat();
    int i = EnchantmentHelper.getLuckOfSeaModifier(this.angler);
    int j = EnchantmentHelper.getLureModifier(this.angler);
    float f1 = 0.1F - (float)i * 0.025F - (float)j * 0.01F;
    float f2 = 0.05F + (float)i * 0.01F - (float)j * 0.01F;
    f1 = MathHelper.clamp_float(f1, 0.0F, 1.0F);
    f2 = MathHelper.clamp_float(f2, 0.0F, 1.0F);

    if (f < f1)
    {
        this.angler.triggerAchievement(StatList.junkFishedStat);
        return ((WeightedRandomFishable)WeightedRandom.getRandomItem(this.rand, JUNK)).getItemStack(this.rand);
    }
    else
    {
        f = f - f1;

        if (f < f2)
        {
            this.angler.triggerAchievement(StatList.treasureFishedStat);
            return ((WeightedRandomFishable)WeightedRandom.getRandomItem(this.rand, TREASURE)).getItemStack(this.rand);
        }
        else
        {
            float f3 = f - f2;
            this.angler.triggerAchievement(StatList.fishCaughtStat);
            return ((WeightedRandomFishable)WeightedRandom.getRandomItem(this.rand, FISH)).getItemStack(this.rand);
        }
    }
}
项目:CustomWorldGen    文件:EntityLivingBase.java   
/**
 * Reduces damage, depending on potions
 */
protected float applyPotionDamageCalculations(DamageSource source, float damage)
{
    if (source.isDamageAbsolute())
    {
        return damage;
    }
    else
    {
        if (this.isPotionActive(MobEffects.RESISTANCE) && source != DamageSource.outOfWorld)
        {
            int i = (this.getActivePotionEffect(MobEffects.RESISTANCE).getAmplifier() + 1) * 5;
            int j = 25 - i;
            float f = damage * (float)j;
            damage = f / 25.0F;
        }

        if (damage <= 0.0F)
        {
            return 0.0F;
        }
        else
        {
            int k = EnchantmentHelper.getEnchantmentModifierDamage(this.getArmorInventoryList(), source);

            if (k > 0)
            {
                damage = CombatRules.getDamageAfterMagicAbsorb(damage, (float)k);
            }

            return damage;
        }
    }
}
项目:DecompiledMinecraft    文件:EntityMob.java   
public boolean attackEntityAsMob(Entity entityIn)
{
    float f = (float)this.getEntityAttribute(SharedMonsterAttributes.attackDamage).getAttributeValue();
    int i = 0;

    if (entityIn instanceof EntityLivingBase)
    {
        f += EnchantmentHelper.func_152377_a(this.getHeldItem(), ((EntityLivingBase)entityIn).getCreatureAttribute());
        i += EnchantmentHelper.getKnockbackModifier(this);
    }

    boolean flag = entityIn.attackEntityFrom(DamageSource.causeMobDamage(this), f);

    if (flag)
    {
        if (i > 0)
        {
            entityIn.addVelocity((double)(-MathHelper.sin(this.rotationYaw * (float)Math.PI / 180.0F) * (float)i * 0.5F), 0.1D, (double)(MathHelper.cos(this.rotationYaw * (float)Math.PI / 180.0F) * (float)i * 0.5F));
            this.motionX *= 0.6D;
            this.motionZ *= 0.6D;
        }

        int j = EnchantmentHelper.getFireAspectModifier(this);

        if (j > 0)
        {
            entityIn.setFire(j * 4);
        }

        this.applyEnchantments(this, entityIn);
    }

    return flag;
}
项目:CustomWorldGen    文件:Entity.java   
protected void applyEnchantments(EntityLivingBase entityLivingBaseIn, Entity entityIn)
{
    if (entityIn instanceof EntityLivingBase)
    {
        EnchantmentHelper.applyThornEnchantments((EntityLivingBase)entityIn, entityLivingBaseIn);
    }

    EnchantmentHelper.applyArthropodEnchantments(entityLivingBaseIn, entityIn);
}
项目:DecompiledMinecraft    文件:Entity.java   
protected void applyEnchantments(EntityLivingBase entityLivingBaseIn, Entity entityIn)
{
    if (entityIn instanceof EntityLivingBase)
    {
        EnchantmentHelper.applyThornEnchantments((EntityLivingBase)entityIn, entityLivingBaseIn);
    }

    EnchantmentHelper.applyArthropodEnchantments(entityLivingBaseIn, entityIn);
}
项目:Backmemed    文件:EntityVillager.java   
public void func_190888_a(IMerchant p_190888_1_, MerchantRecipeList p_190888_2_, Random p_190888_3_)
{
    int i = 1;

    if (this.priceInfo != null)
    {
        i = this.priceInfo.getPrice(p_190888_3_);
    }

    ItemStack itemstack = new ItemStack(Items.EMERALD, i, 0);
    ItemStack itemstack1 = EnchantmentHelper.addRandomEnchantment(p_190888_3_, new ItemStack(this.enchantedItemStack.getItem(), 1, this.enchantedItemStack.getMetadata()), 5 + p_190888_3_.nextInt(15), false);
    p_190888_2_.add(new MerchantRecipe(itemstack, itemstack1));
}
项目:DecompiledMinecraft    文件:EntityFishHook.java   
private ItemStack getFishingResult()
{
    float f = this.worldObj.rand.nextFloat();
    int i = EnchantmentHelper.getLuckOfSeaModifier(this.angler);
    int j = EnchantmentHelper.getLureModifier(this.angler);
    float f1 = 0.1F - (float)i * 0.025F - (float)j * 0.01F;
    float f2 = 0.05F + (float)i * 0.01F - (float)j * 0.01F;
    f1 = MathHelper.clamp_float(f1, 0.0F, 1.0F);
    f2 = MathHelper.clamp_float(f2, 0.0F, 1.0F);

    if (f < f1)
    {
        this.angler.triggerAchievement(StatList.junkFishedStat);
        return ((WeightedRandomFishable)WeightedRandom.getRandomItem(this.rand, JUNK)).getItemStack(this.rand);
    }
    else
    {
        f = f - f1;

        if (f < f2)
        {
            this.angler.triggerAchievement(StatList.treasureFishedStat);
            return ((WeightedRandomFishable)WeightedRandom.getRandomItem(this.rand, TREASURE)).getItemStack(this.rand);
        }
        else
        {
            float f3 = f - f2;
            this.angler.triggerAchievement(StatList.fishCaughtStat);
            return ((WeightedRandomFishable)WeightedRandom.getRandomItem(this.rand, FISH)).getItemStack(this.rand);
        }
    }
}
项目:DecompiledMinecraft    文件:EntityVillager.java   
public void modifyMerchantRecipeList(MerchantRecipeList recipeList, Random random)
{
    int i = 1;

    if (this.field_179406_b != null)
    {
        i = this.field_179406_b.getPrice(random);
    }

    ItemStack itemstack = new ItemStack(Items.emerald, i, 0);
    ItemStack itemstack1 = new ItemStack(this.field_179407_a.getItem(), 1, this.field_179407_a.getMetadata());
    itemstack1 = EnchantmentHelper.addRandomEnchantment(random, itemstack1, 5 + random.nextInt(15));
    recipeList.add(new MerchantRecipe(itemstack, itemstack1));
}
项目:CustomWorldGen    文件:Block.java   
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, @Nullable ItemStack stack)
{
    player.addStat(StatList.getBlockStats(this));
    player.addExhaustion(0.025F);

    if (this.canSilkHarvest(worldIn, pos, state, player) && EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, stack) > 0)
    {
        java.util.List<ItemStack> items = new java.util.ArrayList<ItemStack>();
        ItemStack itemstack = this.createStackedBlock(state);

        if (itemstack != null)
        {
            items.add(itemstack);
        }

        net.minecraftforge.event.ForgeEventFactory.fireBlockHarvesting(items, worldIn, pos, state, 0, 1.0f, true, player);
        for (ItemStack item : items)
        {
            spawnAsEntity(worldIn, pos, item);
        }
    }
    else
    {
        harvesters.set(player);
        int i = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack);
        this.dropBlockAsItem(worldIn, pos, state, i);
        harvesters.set(null);
    }
}
项目:mc-Slingshot    文件:EntityBall.java   
@Override
protected void onImpact(RayTraceResult result) {
    if (result.typeOfHit == RayTraceResult.Type.ENTITY) {
        EntityLivingBase thrower = getThrower();
        // prevent damaging thrower
        if (result.entityHit == thrower)
            return;

        Entity entity = result.entityHit;
        DamageSource ds = createDamageSource(null == thrower ? this : thrower);

        if (isBurning() && !(entity instanceof EntityEnderman))
            entity.setFire(5);
        if (entity.attackEntityFrom(ds, getDamage())) {
            if (entity instanceof EntityLivingBase) {
                EntityLivingBase base = (EntityLivingBase) entity;

                if (knockbackStrength > 0) {
                    float f1 = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ);
                    if (f1 > 0f) {
                        base.addVelocity(motionX * knockbackStrength * 0.6000000238418579D / f1,
                            0.1D, motionZ * knockbackStrength * 0.6000000238418579D / f1);
                    }
                }

                if (null != thrower) {
                    EnchantmentHelper.applyThornEnchantments(base, thrower);
                    EnchantmentHelper.applyArthropodEnchantments(thrower, base);
                    if (base != thrower && base instanceof EntityPlayer && thrower instanceof EntityPlayerMP)
                    {
                        ((EntityPlayerMP)thrower).connection.sendPacket(new SPacketChangeGameState(6, 0.0F));
                    }
                }
            }
        }
    }
    if (!worldObj.isRemote)
        setDead();
}
项目:DecompiledMinecraft    文件:ItemStack.java   
/**
 * Attempts to damage the ItemStack with par1 amount of damage, If the ItemStack has the Unbreaking enchantment
 * there is a chance for each point of damage to be negated. Returns true if it takes more damage than
 * getMaxDamage(). Returns false otherwise or if the ItemStack can't be damaged or if all points of damage are
 * negated.
 */
public boolean attemptDamageItem(int amount, Random rand)
{
    if (!this.isItemStackDamageable())
    {
        return false;
    }
    else
    {
        if (amount > 0)
        {
            int i = EnchantmentHelper.getEnchantmentLevel(Enchantment.unbreaking.effectId, this);
            int j = 0;

            for (int k = 0; i > 0 && k < amount; ++k)
            {
                if (EnchantmentDurability.negateDamage(this, i, rand))
                {
                    ++j;
                }
            }

            amount -= j;

            if (amount <= 0)
            {
                return false;
            }
        }

        this.itemDamage += amount;
        return this.itemDamage > this.getMaxDamage();
    }
}