本文整理汇总了Java中net.minecraft.enchantment.EnchantmentHelper类的典型用法代码示例。如果您正苦于以下问题:Java EnchantmentHelper类的具体用法?Java EnchantmentHelper怎么用?Java EnchantmentHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EnchantmentHelper类属于net.minecraft.enchantment包,在下文中一共展示了EnchantmentHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: harvestBlock
import net.minecraft.enchantment.EnchantmentHelper; //导入依赖的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);
}
}
示例2: getRecipeIngredients
import net.minecraft.enchantment.EnchantmentHelper; //导入依赖的package包/类
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;
}
示例3: blockBreakEvent
import net.minecraft.enchantment.EnchantmentHelper; //导入依赖的package包/类
@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());
}
示例4: setEnchantmentBasedOnDifficulty
import net.minecraft.enchantment.EnchantmentHelper; //导入依赖的package包/类
/**
* 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)));
}
}
}
示例5: getBestSlotMining
import net.minecraft.enchantment.EnchantmentHelper; //导入依赖的package包/类
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;
}
示例6: createSkeleton
import net.minecraft.enchantment.EnchantmentHelper; //导入依赖的package包/类
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;
}
示例7: getUpgradableStack
import net.minecraft.enchantment.EnchantmentHelper; //导入依赖的package包/类
/** 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;
}
示例8: harvestBlock
import net.minecraft.enchantment.EnchantmentHelper; //导入依赖的package包/类
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);
}
}
示例9: getUpgradableStack
import net.minecraft.enchantment.EnchantmentHelper; //导入依赖的package包/类
/** 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;
}
示例10: allowBlock
import net.minecraft.enchantment.EnchantmentHelper; //导入依赖的package包/类
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;
}
示例11: attack
import net.minecraft.enchantment.EnchantmentHelper; //导入依赖的package包/类
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);
}
}
示例12: func_190777_m
import net.minecraft.enchantment.EnchantmentHelper; //导入依赖的package包/类
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);
}
}
示例13: attackEntityWithRangedAttack
import net.minecraft.enchantment.EnchantmentHelper; //导入依赖的package包/类
/**
* 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);
}
示例14: apply
import net.minecraft.enchantment.EnchantmentHelper; //导入依赖的package包/类
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;
}
示例15: onLivingUpdate
import net.minecraft.enchantment.EnchantmentHelper; //导入依赖的package包/类
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);
}
}
}