本文整理汇总了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;
}
示例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);
}
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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));
}
}
}
示例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);
}
}
}
示例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);
}
}
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
}