net.minecraft.enchantment.EnchantmentHelper Java Examples
The following examples show how to use
net.minecraft.enchantment.EnchantmentHelper.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EntityToroNpc.java From ToroQuest with GNU General Public License v3.0 | 7 votes |
protected void handleSuccessfulAttack(Entity entityIn, int knockback) { if (knockback > 0 && entityIn instanceof EntityLivingBase) { ((EntityLivingBase) entityIn).knockBack(this, (float) knockback * 0.5F, (double) MathHelper.sin(this.rotationYaw * 0.017453292F), (double) (-MathHelper.cos(this.rotationYaw * 0.017453292F))); this.motionX *= 0.6D; this.motionZ *= 0.6D; } int j = EnchantmentHelper.getFireAspectModifier(this); if (j > 0) { entityIn.setFire(j * 4); } if (entityIn instanceof EntityPlayer) { EntityPlayer entityplayer = (EntityPlayer) entityIn; ItemStack itemstack = this.getHeldItemMainhand(); ItemStack itemstack1 = entityplayer.isHandActive() ? entityplayer.getActiveItemStack() : null; if (itemstack != null && itemstack1 != null && itemstack.getItem() instanceof ItemAxe && itemstack1.getItem() == Items.SHIELD) { float f1 = 0.25F + (float) EnchantmentHelper.getEfficiencyModifier(this) * 0.05F; if (this.rand.nextFloat() < f1) { entityplayer.getCooldownTracker().setCooldown(Items.SHIELD, 100); this.world.setEntityState(entityplayer, (byte) 30); } } } this.applyEnchantments(this, entityIn); }
Example #2
Source File: BoingHandler.java From CommunityMod with GNU Lesser General Public License v2.1 | 6 votes |
@SubscribeEvent public static void onJump(InputEvent.KeyInputEvent event) { if(jump.isPressed()) { EntityPlayerSP player = Minecraft.getMinecraft().player; BlockPos pos = new BlockPos(player.posX, player.posY, player.posZ); int level = EnchantmentHelper.getMaxEnchantmentLevel(BiJump.BOINGBOING, player); if(player.world.getBlockState(pos).getBlock().equals(Blocks.AIR) && player.world.getBlockState(pos.add(0, -2, 0)).getBlock().equals(Blocks.AIR) && !jumpybois.contains(player) && level > 0) { player.sprintingTicksLeft += 40; player.addVelocity(0, 1.2 * Math.sqrt(level), 0); jumpybois.add(player); new Timer().schedule(new TimerTask(){ @Override public void run(){ jumpybois.remove(player);}}, 7000); } } }
Example #3
Source File: AutoArmorModule.java From seppuku with GNU General Public License v3.0 | 6 votes |
private int findArmorSlot(EntityEquipmentSlot type) { int slot = -1; float damage = 0; for (int i = 9; i < 45; i++) { final ItemStack s = Minecraft.getMinecraft().player.inventoryContainer.getSlot(i).getStack(); if (s != null && s.getItem() != Items.AIR) { if (s.getItem() instanceof ItemArmor) { final ItemArmor armor = (ItemArmor) s.getItem(); if (armor.armorType == type) { final float currentDamage = (armor.damageReduceAmount + EnchantmentHelper.getEnchantmentLevel(Enchantments.PROTECTION, s)); final boolean cursed = this.curse.getValue() ? (EnchantmentHelper.hasBindingCurse(s)) : false; if (currentDamage > damage && !cursed) { damage = currentDamage; slot = i; } } } } } return slot; }
Example #4
Source File: ModEnchantments.java From Et-Futurum with The Unlicense | 6 votes |
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); } } }
Example #5
Source File: CraftEventFactory.java From Thermos with GNU General Public License v3.0 | 6 votes |
public static BlockBreakEvent callBlockBreakEvent(net.minecraft.world.World world, int x, int y, int z, net.minecraft.block.Block block, int blockMetadata, net.minecraft.entity.player.EntityPlayerMP player) { org.bukkit.block.Block bukkitBlock = world.getWorld().getBlockAt(x, y, z); org.bukkit.event.block.BlockBreakEvent blockBreakEvent = new org.bukkit.event.block.BlockBreakEvent(bukkitBlock, ((EntityPlayerMP)player).getBukkitEntity()); EntityPlayerMP playermp = (EntityPlayerMP)player; if (!(playermp instanceof FakePlayer)) { if (!(playermp.theItemInWorldManager.getGameType().isAdventure() && !playermp.isCurrentToolAdventureModeExempt(x, y, z)) && !(playermp.theItemInWorldManager.getGameType().isCreative() && playermp.getHeldItem() != null && playermp.getHeldItem().getItem() instanceof ItemSword)) { int exp = 0; if (!(block == null || !player.canHarvestBlock(block) || // Handle empty block or player unable to break block scenario block.canSilkHarvest(world, player, x, y, z, blockMetadata) && EnchantmentHelper.getSilkTouchModifier(player))) // If the block is being silk harvested, the exp dropped is 0 { int meta = block.getDamageValue(world, x, y, z); int bonusLevel = EnchantmentHelper.getFortuneModifier(player); exp = block.getExpDrop(world, meta, bonusLevel); } blockBreakEvent.setExpToDrop(exp); } else blockBreakEvent.setCancelled(true); } world.getServer().getPluginManager().callEvent(blockBreakEvent); return blockBreakEvent; }
Example #6
Source File: OpenBlock.java From OpenModsLib with MIT License | 6 votes |
protected void handleNormalDrops(World world, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te, @Nonnull ItemStack stack) { harvesters.set(player); final int fortune = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack); boolean addNormalDrops = true; if (te instanceof ICustomHarvestDrops) { final ICustomHarvestDrops dropper = (ICustomHarvestDrops)te; final List<ItemStack> drops = Lists.newArrayList(); dropper.addHarvestDrops(player, drops, state, fortune, false); ForgeEventFactory.fireBlockHarvesting(drops, world, pos, state, fortune, 1.0f, false, player); for (ItemStack drop : drops) spawnAsEntity(world, pos, drop); addNormalDrops = !dropper.suppressBlockHarvestDrops(); } if (addNormalDrops) dropBlockAsItem(world, pos, state, fortune); harvesters.set(null); }
Example #7
Source File: AutoToolModule.java From seppuku with GNU General Public License v3.0 | 6 votes |
private int getToolHotbar(BlockPos pos) { int index = -1; float speed = 1.0f; for (int i = 0; i <= 9; i++) { final ItemStack stack = Minecraft.getMinecraft().player.inventory.getStackInSlot(i); if (stack != null && stack != ItemStack.EMPTY) { final float digSpeed = EnchantmentHelper.getEnchantmentLevel(Enchantments.EFFICIENCY, stack); final float destroySpeed = stack.getDestroySpeed(Minecraft.getMinecraft().world.getBlockState(pos)); if ((digSpeed + destroySpeed) > speed) { speed = (digSpeed + destroySpeed); index = i; } } } return index; }
Example #8
Source File: EntityArcher.java From Electro-Magic-Tools with GNU General Public License v3.0 | 6 votes |
@Override public void attackEntityWithRangedAttack(EntityLivingBase par1EntityLivingBase, float par2) { EntityArrow entityarrow = new EntityArrow(this.worldObj, this, par1EntityLivingBase, 1.6F, (float) (14 - this.worldObj.difficultySetting.getDifficultyId() * 4)); int i = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, this.getHeldItem()); int j = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, this.getHeldItem()); entityarrow.setDamage((double) (par2 * 2.0F) + this.rand.nextGaussian() * 0.25D + (double) ((float) this.worldObj.difficultySetting.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) { entityarrow.setFire(100); } this.playSound("random.bow", 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F)); this.worldObj.spawnEntityInWorld(entityarrow); }
Example #9
Source File: AutoToolModule.java From seppuku with GNU General Public License v3.0 | 6 votes |
private int getToolInventory(BlockPos pos) { int index = -1; float speed = 1.0f; for (int i = 9; i < 36; i++) { final ItemStack stack = Minecraft.getMinecraft().player.inventoryContainer.getSlot(i).getStack(); if (stack != null && stack != ItemStack.EMPTY) { final float digSpeed = EnchantmentHelper.getEnchantmentLevel(Enchantments.EFFICIENCY, stack); final float destroySpeed = stack.getDestroySpeed(Minecraft.getMinecraft().world.getBlockState(pos)); if ((digSpeed + destroySpeed) > speed) { speed = (digSpeed + destroySpeed); index = i; } } } return index; }
Example #10
Source File: EntityToroNpc.java From ToroQuest with GNU General Public License v3.0 | 6 votes |
public boolean attackEntityAsMob(Entity entityIn) { float f = (float) this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue(); int knockback = 0; if (entityIn instanceof EntityLivingBase) { f += EnchantmentHelper.getModifierForCreature(this.getHeldItemMainhand(), ((EntityLivingBase) entityIn).getCreatureAttribute()); knockback += EnchantmentHelper.getKnockbackModifier(this); } boolean successfulAttack = entityIn.attackEntityFrom(DamageSource.causeMobDamage(this), f); if (successfulAttack) { handleSuccessfulAttack(entityIn, knockback); } return successfulAttack; }
Example #11
Source File: CraftEventFactory.java From Kettle with GNU General Public License v3.0 | 6 votes |
public static BlockBreakEvent callBlockBreakEvent(net.minecraft.world.World world, BlockPos pos, IBlockState state, EntityPlayerMP player) { Block bBlock = world.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()); BlockBreakEvent bbe = new BlockBreakEvent(bBlock, player.getBukkitEntity()); EntityPlayerMP playermp = player; net.minecraft.block.Block block = state.getBlock(); if (!(playermp instanceof FakePlayer)) { boolean isSwordNoBreak = playermp.interactionManager.getGameType().isCreative() && !playermp.getHeldItemMainhand().isEmpty() && playermp.getHeldItemMainhand().getItem() instanceof ItemSword; if (!isSwordNoBreak) { int exp = 0; if (!(block == null || !player.canHarvestBlock(block.getDefaultState()) || block.canSilkHarvest(world, pos, block.getBlockState().getBaseState(), player) && EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, player.getHeldItemMainhand()) > 0)) { int bonusLevel = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, player.getHeldItemMainhand()); exp = block.getExpDrop(state, world, pos, bonusLevel); } bbe.setExpToDrop(exp); } else { bbe.setCancelled(true); } } world.getServer().getPluginManager().callEvent(bbe); return bbe; }
Example #12
Source File: IForgeBlock.java From patchwork-api with GNU Lesser General Public License v2.1 | 6 votes |
/** * Use this to change the fog color used when the entity is "inside" a material. * {@link Vec3d} is used here as "r/g/b" 0 - 1 values. * * @param state The state at the entity viewport. * @param world The world. * @param pos The position at the entity viewport. * @param entity the entity * @param originalColor The current fog color, You are not expected to use this, Return as the default if applicable. * @return The new fog color. */ @Environment(EnvType.CLIENT) default Vec3d getFogColor(BlockState state, CollisionView world, BlockPos pos, Entity entity, Vec3d originalColor, float partialTicks) { if (state.getMaterial() == Material.WATER) { float visibility = 0.0F; if (entity instanceof LivingEntity) { LivingEntity ent = (LivingEntity) entity; visibility = (float) EnchantmentHelper.getRespiration(ent) * 0.2F; if (ent.hasStatusEffect(StatusEffects.WATER_BREATHING)) { visibility = visibility * 0.3F + 0.6F; } } return new Vec3d(0.02F + visibility, 0.02F + visibility, 0.2F + visibility); } else if (state.getMaterial() == Material.LAVA) { return new Vec3d(0.6F, 0.1F, 0.0F); } return originalColor; }
Example #13
Source File: AutoArmorHack.java From ForgeWurst with GNU General Public License v3.0 | 6 votes |
private int getArmorValue(ItemArmor item, ItemStack stack) { int armorPoints = item.damageReduceAmount; int prtPoints = 0; int armorToughness = (int)item.toughness; int armorType = item.getArmorMaterial() .getDamageReductionAmount(EntityEquipmentSlot.LEGS); if(useEnchantments.isChecked()) { Enchantment protection = Enchantments.PROTECTION; int prtLvl = EnchantmentHelper.getEnchantmentLevel(protection, stack); EntityPlayerSP player = WMinecraft.getPlayer(); DamageSource dmgSource = DamageSource.causePlayerDamage(player); prtPoints = protection.calcModifierDamage(prtLvl, dmgSource); } return armorPoints * 5 + prtPoints * 3 + armorToughness + armorType; }
Example #14
Source File: ComponentExcavation.java From Artifacts with MIT License | 6 votes |
@Override public boolean onBlockDestroyed(ItemStack itemStack, World world, Block destroyedBlock, int x, int y, int z, EntityLivingBase player) { //System.out.println("Test (" + x + "," + y + "," + z + ")"); //player.getLookVec(); int numBlocks = 0; for(int i=-1;i<=1;i++) { for(int j=-1;j<=1;j++) { for(int k=-1;k<=1;k++) { Block block = world.getBlock(x+i, y+j, z+k); if(block != null) { System.out.println("block: " + block.getUnlocalizedName()); System.out.println("can: " + itemStack.getItem().canHarvestBlock(block, itemStack)); if(this.canHarvestBlock(block, itemStack)) { int fortuneLevel = EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, itemStack); block.dropBlockAsItem(world, x, y, z, world.getBlockMetadata(x+i, y+j, z+k), fortuneLevel); world.setBlockToAir(x+i, y+j, z+k); numBlocks++; } } } } } itemStack.damageItem(numBlocks/3, player); //Block block = Block.blocksList[l] return false; }
Example #15
Source File: VanillaEnchantLogic.java From OpenModsLib with MIT License | 5 votes |
private List<EnchantmentData> getEnchantmentList(@Nonnull ItemStack stack, Level level, int xpLevels) { rand.setSeed(seed + level.ordinal()); List<EnchantmentData> list = EnchantmentHelper.buildEnchantmentList(rand, stack, xpLevels, false); if (stack.getItem() == Items.BOOK && list.size() > 1) { list.remove(this.rand.nextInt(list.size())); } return list; }
Example #16
Source File: ContainerEnchantment.java From Et-Futurum with The Unlicense | 5 votes |
@SuppressWarnings("unchecked") private List<EnchantmentData> func_178148_a(ItemStack stack, int seed, int level) { rand.setSeed(enchantmentSeed + seed); List<EnchantmentData> list = EnchantmentHelper.buildEnchantmentList(rand, stack, level); if (stack.getItem() == Items.book && list != null && list.size() > 1) list.remove(rand.nextInt(list.size())); return list; }
Example #17
Source File: ModEnchantments.java From Et-Futurum with The Unlicense | 5 votes |
public static void onPlayerPickupXP(PlayerPickupXpEvent event) { EntityPlayer player = event.entityPlayer; EntityXPOrb orb = event.orb; if (player.worldObj.isRemote) return; if (!EtFuturum.enableMending) return; ItemStack[] stacks = new ItemStack[5]; stacks[0] = player.getCurrentEquippedItem(); // held stacks[1] = player.getEquipmentInSlot(1); // boots stacks[2] = player.getEquipmentInSlot(2); // leggings stacks[3] = player.getEquipmentInSlot(3); // chestplate stacks[4] = player.getEquipmentInSlot(4); // helmet for (ItemStack stack : stacks) if (stack != null && stack.getItemDamage() > 0 && EnchantmentHelper.getEnchantmentLevel(mending.effectId, stack) > 0) { int xp = orb.xpValue; while (xp > 0 && stack.getItemDamage() > 0) { stack.setItemDamage(stack.getItemDamage() - 2); xp--; } if (xp <= 0) { orb.setDead(); event.setCanceled(true); return; } } }
Example #18
Source File: MixinEnchantmentHelper.java From VanillaFix with MIT License | 5 votes |
/** @reason Fix memory leak. See mixin class comment. */ @Overwrite public static void applyArthropodEnchantments(EntityLivingBase user, Entity target) { EnchantmentHelper.DamageIterator enchantmentIteratorDamage = new EnchantmentHelper.DamageIterator(); enchantmentIteratorDamage.user = user; enchantmentIteratorDamage.target = target; if (user != null) { applyEnchantmentModifierArray(enchantmentIteratorDamage, user.getEquipmentAndArmor()); } if (user instanceof EntityPlayer) { applyEnchantmentModifier(enchantmentIteratorDamage, user.getHeldItemMainhand()); } }
Example #19
Source File: VanillaEnchantLogic.java From OpenModsLib with MIT License | 5 votes |
public boolean setup(@Nonnull ItemStack stack, Level level, int power) { if (stack.isEmpty() || !stack.isItemEnchantable()) return false; rand.setSeed(seed); this.toEnchant = stack.copy(); this.level = level; this.xpLevels = EnchantmentHelper.calcItemStackEnchantability(rand, level.ordinal(), power, toEnchant); if (this.xpLevels <= level.ordinal() + 1) this.xpLevels = 0; return true; }
Example #20
Source File: ItemHeartUpgrade.java From Cyberware with MIT License | 5 votes |
protected float applyPotionDamageCalculations(EntityLivingBase e, DamageSource source, float damage) { if (source.isDamageAbsolute()) { return damage; } else { if (e.isPotionActive(MobEffects.RESISTANCE) && source != DamageSource.outOfWorld) { int i = (e.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(e.getArmorInventoryList(), source); if (k > 0) { damage = CombatRules.getDamageAfterMagicAbsorb(damage, (float)k); } return damage; } } }
Example #21
Source File: InfusionEnchantmentRecipe.java From AdvancedMod with GNU General Public License v3.0 | 5 votes |
public float getEssentiaMod(ItemStack recipeInput) { float mod = EnchantmentHelper.getEnchantmentLevel(enchantment.effectId, recipeInput); Map map1 = EnchantmentHelper.getEnchantments(recipeInput); Iterator iterator = map1.keySet().iterator(); while (iterator.hasNext()) { int j1 = ((Integer)iterator.next()).intValue(); if (j1 != enchantment.effectId) mod += EnchantmentHelper.getEnchantmentLevel(j1, recipeInput) * .1f; } return mod; }
Example #22
Source File: MixinEnchantmentHelper.java From VanillaFix with MIT License | 5 votes |
/** @reason Fix memory leak. See mixin class comment. */ @Overwrite public static void applyThornEnchantments(EntityLivingBase user, Entity attacker) { EnchantmentHelper.HurtIterator enchantmentIteratorHurt = new EnchantmentHelper.HurtIterator(); enchantmentIteratorHurt.attacker = attacker; enchantmentIteratorHurt.user = user; if (user != null) { applyEnchantmentModifierArray(enchantmentIteratorHurt, user.getEquipmentAndArmor()); } if (attacker instanceof EntityPlayer) { applyEnchantmentModifier(enchantmentIteratorHurt, user.getHeldItemMainhand()); } }
Example #23
Source File: InfusionEnchantmentRecipe.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
public float getEssentiaMod(ItemStack recipeInput) { float mod = EnchantmentHelper.getEnchantmentLevel(enchantment.effectId, recipeInput); Map map1 = EnchantmentHelper.getEnchantments(recipeInput); Iterator iterator = map1.keySet().iterator(); while (iterator.hasNext()) { int j1 = ((Integer)iterator.next()).intValue(); if (j1 != enchantment.effectId) mod += EnchantmentHelper.getEnchantmentLevel(j1, recipeInput) * .1f; } return mod; }
Example #24
Source File: MixinEnchantmentHelper.java From VanillaFix with MIT License | 5 votes |
/** @reason Fix memory leak. See class comment. */ @Overwrite public static int getEnchantmentModifierDamage(Iterable<ItemStack> stacks, DamageSource source) { EnchantmentHelper.ModifierDamage enchantmentModifierDamage = new EnchantmentHelper.ModifierDamage(); enchantmentModifierDamage.damageModifier = 0; enchantmentModifierDamage.source = source; applyEnchantmentModifierArray(enchantmentModifierDamage, stacks); return enchantmentModifierDamage.damageModifier; }
Example #25
Source File: AutoToolHack.java From ForgeWurst with GNU General Public License v3.0 | 5 votes |
private float getDestroySpeed(ItemStack stack, IBlockState state) { float speed = WItem.getDestroySpeed(stack, state); if(speed > 1) { int efficiency = EnchantmentHelper .getEnchantmentLevel(Enchantments.EFFICIENCY, stack); if(efficiency > 0 && !WItem.isNullOrEmpty(stack)) speed += efficiency * efficiency + 1; } return speed; }
Example #26
Source File: CraftItemStack.java From Kettle with GNU General Public License v3.0 | 5 votes |
@Override public int getEnchantmentLevel(Enchantment ench) { Validate.notNull(ench, "Cannot find null enchantment"); if (handle == null) { return 0; } return EnchantmentHelper.getEnchantmentLevel(CraftEnchantment.getRaw(ench), handle); }
Example #27
Source File: GTHelperStack.java From GT-Classic with GNU Lesser General Public License v3.0 | 5 votes |
public static int getItemStackEnchantmentLevel(ItemStack stack) { if (!stack.isEmpty() && stack.isItemEnchanted() && !(stack.getItem() instanceof IElectricTool)) { int level = 0; for (Map.Entry<Enchantment, Integer> entry : EnchantmentHelper.getEnchantments(stack).entrySet()) { level = level + entry.getValue(); } return level; } return 0; }
Example #28
Source File: VanillaEnhancementsHud.java From Hyperium with GNU Lesser General Public License v3.0 | 5 votes |
private String getEnchantmentString(ItemStack heldItemStack) { String enchantBuilder; Map<Integer, Integer> en = EnchantmentHelper.getEnchantments(heldItemStack); enchantBuilder = en.entrySet().stream().map(entry -> ChatColor.BOLD.toString() + Maps.ENCHANTMENT_SHORT_NAME.get(entry.getKey()) + " " + entry.getValue() + " ").collect(Collectors.joining()); return enchantBuilder.trim(); }
Example #29
Source File: PressureChamberVacuumEnchantHandler.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
/** * This method will be called when the recipe should output its items. te stacks the recipe outputs, maybe dependent on the input stacks. * @param inputStacks. These stacks can be modified (like adding/removing NBT data eg.) * @return outputStacks. Stacks that will pop 'out of the chamber' */ @Override public ItemStack[] craftRecipe(ItemStack[] inputStacks, ItemStack[] removedStacks){ ItemStack enchantedStack = null; int enchantmentCount = 0; for(ItemStack stack : inputStacks) { if(stack.getItem() == Items.enchanted_book) continue; enchantmentCount = EnchantmentHelper.getEnchantments(stack).size(); if(enchantmentCount > 0) { enchantedStack = stack; break; } } if(enchantedStack == null) { System.err.println("[Pressure Chamber Vacuum Enchantment Handler] No enchanted stack found! Report to MineMaarten!"); return null; } // take a random enchantment of the enchanted stack. int enchIndex = new Random().nextInt(((NBTTagList)enchantedStack.getTagCompound().getTag("ench")).tagCount()); NBTTagCompound enchTag = ((NBTTagList)enchantedStack.getTagCompound().getTag("ench")).getCompoundTagAt(enchIndex); ((NBTTagList)enchantedStack.getTagCompound().getTag("ench")).removeTag(enchIndex); if(((NBTTagList)enchantedStack.getTagCompound().getTag("ench")).tagCount() == 0) { enchantedStack.getTagCompound().removeTag("ench"); if(enchantedStack.getTagCompound().hasNoTags()) { enchantedStack.setTagCompound(null); } } //and create an enchanted book. ItemStack enchantedBook = new ItemStack(Items.enchanted_book); NBTTagCompound baseTag = new NBTTagCompound(); NBTTagList enchList = new NBTTagList(); enchList.appendTag(enchTag); baseTag.setTag("StoredEnchantments", enchList); enchantedBook.setTagCompound(baseTag); return new ItemStack[]{enchantedBook}; }
Example #30
Source File: ToolMetaItemListener.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@SubscribeEvent public static void onXpOrbPickup(PlayerPickupXpEvent event) { EntityPlayer player = event.getEntityPlayer(); EntityXPOrb xpOrb = event.getOrb(); ItemStack itemStack = EnchantmentHelper.getEnchantedItem(Enchantments.MENDING, player); if (!itemStack.isEmpty() && itemStack.getItem() instanceof ToolMetaItem) { ToolMetaItem<?> toolMetaItem = (ToolMetaItem<?>) itemStack.getItem(); int maxDurabilityRegain = xpToDurability(xpOrb.xpValue); int durabilityRegained = toolMetaItem.regainItemDurability(itemStack, maxDurabilityRegain); xpOrb.xpValue -= durabilityToXp(durabilityRegained); } }