当前位置: 首页>>代码示例>>Java>>正文


Java Enchantments类代码示例

本文整理汇总了Java中net.minecraft.init.Enchantments的典型用法代码示例。如果您正苦于以下问题:Java Enchantments类的具体用法?Java Enchantments怎么用?Java Enchantments使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Enchantments类属于net.minecraft.init包,在下文中一共展示了Enchantments类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getBookLootingLevel

import net.minecraft.init.Enchantments; //导入依赖的package包/类
static int getBookLootingLevel(ItemStack stack) {
   NBTTagList nbttaglist = Items.ENCHANTED_BOOK.getEnchantments(stack);

   if (nbttaglist != null) {
      for (int i = 0; i < nbttaglist.tagCount(); ++i)
      {
         Enchantment enchantment = Enchantment.getEnchantmentByID(
               nbttaglist.getCompoundTagAt(i).getShort("id"));
         int j = nbttaglist.getCompoundTagAt(i).getShort("lvl");
         if (Enchantments.LOOTING == enchantment)
            return j;
      }
   }

   return 0;
}
 
开发者ID:arucil,项目名称:mc-Slingshot,代码行数:17,代码来源:RecipeLooting.java

示例2: onSheared

import net.minecraft.init.Enchantments; //导入依赖的package包/类
@SubscribeEvent
public void onSheared(EntityInteractSpecific event) {
	
	ItemStack rainbow = BaublesApi.getBaublesHandler((EntityPlayer)event.getEntityPlayer()).getStackInSlot(6);
	if (rainbow == null || (rainbow != null && rainbow.getItem() != this)) return;
	
	if (!(event.getTarget() instanceof IShearable)) return;
	if (!(event.getTarget() instanceof EntitySheep) || (event.getTarget() instanceof EntitySheep && ((EntitySheep)event.getTarget()).getSheared())) return;
	if (event.getItemStack() == null || (event.getItemStack() != null && !(event.getItemStack().getItem() instanceof ItemShears))) return;
	
	int fortune = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, event.getItemStack());
	if (!event.getWorld().isRemote) {
		List<ItemStack> wools = ((IShearable)event.getTarget()).onSheared(event.getItemStack(), event.getWorld(), event.getPos(), fortune);
		for (ItemStack is : wools) {
			Random rand = new Random();
			is.setItemDamage(rand.nextInt(15));
			EntityItem wool = new EntityItem(event.getWorld(), event.getTarget().posX, event.getTarget().posY, event.getTarget().posZ, is);
			event.getWorld().spawnEntityInWorld(wool);
		}
	}
}
 
开发者ID:bafomdad,项目名称:uniquecrops,代码行数:22,代码来源:EmblemRainbow.java

示例3: func_190547_a

import net.minecraft.init.Enchantments; //导入依赖的package包/类
public void func_190547_a(EntityLivingBase p_190547_1_, float p_190547_2_)
{
    int i = EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.POWER, p_190547_1_);
    int j = EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.PUNCH, p_190547_1_);
    this.setDamage((double)(p_190547_2_ * 2.0F) + this.rand.nextGaussian() * 0.25D + (double)((float)this.world.getDifficulty().getDifficultyId() * 0.11F));

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

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

    if (EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.FLAME, p_190547_1_) > 0)
    {
        this.setFire(100);
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:22,代码来源:EntityArrow.java

示例4: harvestBlock

import net.minecraft.init.Enchantments; //导入依赖的package包/类
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);
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:17,代码来源:Block.java

示例5: onUserHurt

import net.minecraft.init.Enchantments; //导入依赖的package包/类
/**
 * Whenever an entity that has this enchantment on one of its associated items is damaged this method will be
 * called.
 */
public void onUserHurt(EntityLivingBase user, Entity attacker, int level)
{
    Random random = user.getRNG();
    ItemStack itemstack = EnchantmentHelper.getEnchantedItem(Enchantments.THORNS, user);

    if (shouldHit(level, random))
    {
        if (attacker != null)
        {
            attacker.attackEntityFrom(DamageSource.causeThornsDamage(user), (float)getDamage(level, random));
        }

        if (!itemstack.func_190926_b())
        {
            itemstack.damageItem(3, user);
        }
    }
    else if (!itemstack.func_190926_b())
    {
        itemstack.damageItem(1, user);
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:27,代码来源:EnchantmentThorns.java

示例6: BreakEvent

import net.minecraft.init.Enchantments; //导入依赖的package包/类
public BreakEvent(World world, BlockPos pos, IBlockState state, EntityPlayer player)
{
    super(world, pos, state);
    this.player = player;

    if (state == null || !ForgeHooks.canHarvestBlock(state.getBlock(), player, world, pos) || // Handle empty block or player unable to break block scenario
        (state.getBlock().canSilkHarvest(world, pos, world.getBlockState(pos), player) && EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, player.getHeldItemMainhand()) > 0)) // If the block is being silk harvested, the exp dropped is 0
    {
        this.exp = 0;
    }
    else
    {
        int bonusLevel = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, player.getHeldItemMainhand());
        this.exp = state.getBlock().getExpDrop(state, world, pos, bonusLevel);
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:17,代码来源:BlockEvent.java

示例7: onUserHurt

import net.minecraft.init.Enchantments; //导入依赖的package包/类
/**
 * Whenever an entity that has this enchantment on one of its associated items is damaged this method will be
 * called.
 */
public void onUserHurt(EntityLivingBase user, Entity attacker, int level)
{
    Random random = user.getRNG();
    ItemStack itemstack = EnchantmentHelper.getEnchantedItem(Enchantments.THORNS, user);

    if (shouldHit(level, random))
    {
        if (attacker != null)
        {
            attacker.attackEntityFrom(DamageSource.causeThornsDamage(user), (float)getDamage(level, random));
        }

        if (itemstack != null)
        {
            damageArmor(itemstack, 3, user);
        }
    }
    else if (itemstack != null)
    {
        damageArmor(itemstack, 1, user);
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:27,代码来源:EnchantmentThorns.java

示例8: onBlockBreak

import net.minecraft.init.Enchantments; //导入依赖的package包/类
@SubscribeEvent
public void onBlockBreak(BlockEvent.BreakEvent e)
{
    IBlockState state = e.getState();
    World world = e.getWorld();
    BlockPos pos = e.getPos();
    EntityPlayer player = e.getPlayer();
    ItemStack heldItem = player.getHeldItem(EnumHand.MAIN_HAND);
    if (state.getBlock() == Blocks.mob_spawner) {
        Map<Enchantment, Integer> enchants = EnchantmentHelper.getEnchantments(heldItem);
        if (enchants.containsKey(Enchantments.silkTouch)) {
            ItemStack stack = new ItemStack(Blocks.mob_spawner, 1, 0);
            NBTTagCompound nbttagcompound = new NBTTagCompound();
            world.getTileEntity(pos).writeToNBT(nbttagcompound);
            stack.setTagInfo("BlockEntityTag", nbttagcompound);

            e.setExpToDrop(0);
            e.getWorld().spawnEntityInWorld(new EntityItem(world, pos.getX(), pos.getY(), pos.getZ(), stack));
        }
    }
}
 
开发者ID:GamingsModding,项目名称:LittleThings-old,代码行数:22,代码来源:DropableSpawners.java

示例9: onRuneActivatedbyPlayer

import net.minecraft.init.Enchantments; //导入依赖的package包/类
@Override
public void onRuneActivatedbyPlayer(EntityPlayer player,ItemStack[] sacrifice, boolean negated) {
	World world = player.world;
	if(!world.isRemote){
		if(negated || Utils.takeXP(player, 5)){
			//find the bow stack
			ItemStack bow=ItemStack.EMPTY;
			if(sacrifice!=null){
				for(ItemStack i:sacrifice){
					if(i.getItem()==Items.BOW){
						bow=i;
					}
				}
			}
			if(bow.isEmpty() && negated)bow = new ItemStack(Items.BOW);
			bow.addEnchantment(Enchantments.FLAME, Enchantments.FLAME.getMaxLevel());
			bow.setItemDamage(0);
			Utils.spawnItemCentered(world, getPos(), bow);
			this.onPatternBroken();
		}else{
			this.onPatternBrokenByPlayer(player);
		}
	}
}
 
开发者ID:Xilef11,项目名称:runesofwizardry-classics,代码行数:25,代码来源:RuneEntityEnchantingFireBow.java

示例10: onRuneActivatedbyPlayer

import net.minecraft.init.Enchantments; //导入依赖的package包/类
@Override
public void onRuneActivatedbyPlayer(EntityPlayer player,
		ItemStack[] sacrifice, boolean negated) {
	World world = player.world;
	if(!world.isRemote){
		if(negated || Utils.takeXP(player, 10)){
			//find the bow stack
			ItemStack toEnchant=ItemStack.EMPTY;
			if(sacrifice!=null){
				for(ItemStack i:sacrifice){
					if(i.getItem()==Items.DIAMOND_PICKAXE || i.getItem()==Items.DIAMOND_SHOVEL){
						toEnchant=i;
					}
				}
			}
			if(toEnchant.isEmpty() && negated)toEnchant=new ItemStack(Items.DIAMOND_PICKAXE);
			toEnchant.addEnchantment(Enchantments.SILK_TOUCH, Enchantments.SILK_TOUCH.getMaxLevel());
			toEnchant.setItemDamage(0);
			Utils.spawnItemCentered(world, getPos(), toEnchant);
			this.onPatternBroken();
		}else{
			this.onPatternBrokenByPlayer(player);
		}
	}
}
 
开发者ID:Xilef11,项目名称:runesofwizardry-classics,代码行数:26,代码来源:RuneEntityEnchantingSilktouch.java

示例11: attackEntityWithRangedAttack

import net.minecraft.init.Enchantments; //导入依赖的package包/类
@Override
public void attackEntityWithRangedAttack(EntityLivingBase target, float distanceFactor) {
	ItemStack arrowItem = this.getHeldItemOffhand();
	if (arrowItem.isEmpty() || !(arrowItem.getItem() instanceof ItemArrow))
		return;

	EntityArrow entityarrow = getArrow(distanceFactor);
	double d0 = target.posX - this.posX;
	double d1 = target.getEntityBoundingBox().minY + (double) (target.height / 3.0F) - entityarrow.posY;
	double d2 = target.posZ - this.posZ;
	double d3 = (double) MathHelper.sqrt(d0 * d0 + d2 * d2);
	entityarrow.setThrowableHeading(d0, d1 + d3 * 0.20000000298023224D, d2, 1.6F, (float) (14 - this.world.getDifficulty().getDifficultyId() * 4));

	if (EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.INFINITY, this) <= 0) {
		if (arrowItem.getCount() > 1)
			arrowItem.shrink(1);
		else
			setHeldItem(EnumHand.OFF_HAND, ItemStack.EMPTY);
		entityarrow.pickupStatus = EntityArrow.PickupStatus.ALLOWED;
	}

	if (!getHeldItemMainhand().isEmpty())
		getHeldItemMainhand().damageItem(1, this);
	this.playSound(SoundEvents.ENTITY_SKELETON_SHOOT, 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
	this.world.spawnEntity(entityarrow);
}
 
开发者ID:The-Fireplace-Minecraft-Mods,项目名称:Overlord,代码行数:27,代码来源:EntityConvertedSkeleton.java

示例12: attackEntityWithRangedAttack

import net.minecraft.init.Enchantments; //导入依赖的package包/类
@Override
public void attackEntityWithRangedAttack(EntityLivingBase target, float distanceFactor) {
	ItemStack itemstack = this.getHeldItemOffhand();
	if (itemstack.isEmpty() || !(itemstack.getItem() instanceof ItemArrow))
		return;

	EntityArrow entityarrow = getArrow(distanceFactor);
	double d0 = target.posX - this.posX;
	double d1 = target.getEntityBoundingBox().minY + (double) (target.height / 3.0F) - entityarrow.posY;
	double d2 = target.posZ - this.posZ;
	double d3 = (double) MathHelper.sqrt(d0 * d0 + d2 * d2);
	entityarrow.setThrowableHeading(d0, d1 + d3 * 0.20000000298023224D, d2, 1.6F, (float) (14 - this.world.getDifficulty().getDifficultyId() * 4));

	if (EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.INFINITY, this) <= 0) {
		if (itemstack.getCount() > 1)
			itemstack.shrink(1);
		else
			setHeldItem(EnumHand.OFF_HAND, ItemStack.EMPTY);
		entityarrow.pickupStatus = EntityArrow.PickupStatus.ALLOWED;
	}

	if (!getHeldItemMainhand().isEmpty())
		getHeldItemMainhand().damageItem(1, this);
	this.playSound(SoundEvents.ENTITY_SKELETON_SHOOT, 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
	this.world.spawnEntity(entityarrow);
}
 
开发者ID:The-Fireplace-Minecraft-Mods,项目名称:Overlord,代码行数:27,代码来源:EntitySkeletonWarrior.java

示例13: onBlockActivated

import net.minecraft.init.Enchantments; //导入依赖的package包/类
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
{
	if((state.getValue(AGE)) < 3)return false;
	
	if(worldIn.isRemote){
		return true;
	}
	
	Random rand = worldIn instanceof World ? worldIn.rand : Util.rand;
	int fortune = EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.FORTUNE, playerIn);
	int count = 1 + rand.nextInt(2) + (fortune > 0 ? rand.nextInt(fortune + 1) : 0);
	ItemStack crop = getCrop(state.getValue(TYPE));
	worldIn.setBlockState(pos, state.withProperty(AGE, 0));
	if(ItemStackTools.isValid(crop)){
		for (int i = 0; i < count; i++)
		{
			ItemUtil.spawnItemInWorldWithoutMotion(worldIn, crop, pos);
		}
	}
	return true;
}
 
开发者ID:Alec-WAM,项目名称:CrystalMod,代码行数:23,代码来源:BlockCrystalPlant.java

示例14: onBlockActivated

import net.minecraft.init.Enchantments; //导入依赖的package包/类
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
{
	if((state.getValue(AGE)) < 3)return false;
	
	if(worldIn.isRemote){
		return true;
	}
	
	Random rand = worldIn instanceof World ? worldIn.rand : Util.rand;
	int fortune = EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.FORTUNE, playerIn);
	int count = 1 + rand.nextInt(2) + (fortune > 0 ? rand.nextInt(fortune + 1) : 0);
	ItemStack crop = new ItemStack(ModItems.crystalBerry, 1, state.getValue(TYPE).getMeta());
	worldIn.setBlockState(pos, state.withProperty(AGE, 0));
	double x = pos.getX() + 0.5 + (side.getFrontOffsetX() * 0.6);
	double y = pos.getY() + 0.25 + (side.getFrontOffsetY() * 0.6);
	double z = pos.getZ() + 0.5 + (side.getFrontOffsetZ() * 0.6);
	if(ItemStackTools.isValid(crop)){
		for (int i = 0; i < count; i++)
		{
			ItemUtil.spawnItemInWorldWithoutMotion(new EntityItem(worldIn, x, y, z, crop));
		}
	}
	return true;
}
 
开发者ID:Alec-WAM,项目名称:CrystalMod,代码行数:26,代码来源:BlockCrystalBerryBush.java

示例15: onBlockHarvested

import net.minecraft.init.Enchantments; //导入依赖的package包/类
/**
 * Called when the block is attempted to be harvested
 */
@Override
public void onBlockHarvested(World world, BlockPos pos, IBlockState state, EntityPlayer player) {
    player.addExhaustion(0.025F);
    if (!world.isRemote && !world.restoringBlockSnapshots) {
        ItemStack itemStack;
        if (EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, player.getHeldItemMainhand()) > 0) {
            itemStack = getBlockItemStack(world, pos, state);
        } else {
            itemStack = new ItemStack(Blocks.CHEST, 1, 0);
        }

        if (itemStack != null) {
            GraveInventory.dropItem(itemStack, world, pos);
        }
    }
}
 
开发者ID:NightKosh,项目名称:Gravestone-mod-Extended,代码行数:20,代码来源:BlockHauntedChest.java


注:本文中的net.minecraft.init.Enchantments类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。