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; }
@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); } } }
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); } }
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); } }
/** * 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); } }
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); } }
/** * 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); } }
@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)); } } }
@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); } } }
@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); } } }
@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); }
@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); }
@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; }
@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; }
/** * 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); } } }
@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); } else { itemStack = getBlockItemStackWithoutInfo(world, pos); } if (itemStack != null) { GraveInventory.dropItem(itemStack, world, pos); } } }
@Override public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack stack) { if (te instanceof TileEntityMegaTorch) { if (worldIn.isRemote) return; if (!TorchmasterConfig.MegaTorchExtinguishOnHarvest || this.canSilkHarvest(worldIn, pos, state, player) && EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, stack) > 0) { ItemStack itemStack = this.getSilkTouchDrop(state); if(!itemStack.isEmpty()) { //noinspection ConstantConditions | this will never be null when we are getting called - otherwise, its a MC bug player.addStat(StatList.getBlockStats(this)); player.addExhaustion(0.005F); NBTTagCompound compound = itemStack.getOrCreateSubCompound("tm_tile"); ((TileEntityMegaTorch) te).writeSyncNbt(compound); spawnAsEntity(worldIn, pos, itemStack); return; } } } super.harvestBlock(worldIn, player, pos, state, te, stack); }
/** * 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(ItemStack stack, int amount, Random rand) { if (amount > 0) { int i = EnchantmentHelper.getEnchantmentLevel(Enchantments.UNBREAKING, stack); int j = 0; for (int k = 0;i > 0 && k < amount;++k) { if (EnchantmentDurability.negateDamage(stack, i, rand)) { ++j; } } amount -= j; if (amount <= 0) { return false; } } setItemDamage(stack, getItemDamage(stack) + amount); // Redirect through // Item's // callback if // applicable. return getItemDamage(stack) > getDurability(stack); }
@Override public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @javax.annotation.Nullable TileEntity te, @javax.annotation.Nullable ItemStack stack) { if (player.capabilities.isCreativeMode) { } else 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.getSilkTouchDrop(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 { this.trigger(worldIn, pos, state.withProperty(EXPLODE, true)); } }
public static Enchantment getEnchantmentFromMeta (int meta) { switch (meta) { case 0: return Enchantments.FIRE_ASPECT; case 1: return Enchantments.EFFICIENCY; case 2: return Enchantments.DEPTH_STRIDER; case 3: return Enchantments.KNOCKBACK; case 4: return Enchantments.PROTECTION; case 5: return Enchantments.LUCK_OF_THE_SEA; case 6: return Enchantments.FROST_WALKER; default: return Enchantments.FIRE_ASPECT; } }
/** give the demon some artillery */ protected void armDemon() { // add a sword JointList<ItemStack> swords = new JointList().join( new ItemStack(LCItems.soulSword), new ItemStack(LCItems.zombieSword), new ItemStack(LCItems.featherSword), new ItemStack(LCItems.enderSword), new ItemStack(LCItems.blazeSword), new ItemStack(LCItems.iceSword) ); int sel = this.rand.nextInt(swords.size()); ItemStack sword = isTough ? new ItemStack(LCItems.skySword) : swords.get(sel); sword.addEnchantment(Enchantments.FIRE_ASPECT, 2); this.setHeldItem(EnumHand.MAIN_HAND, sword); // add armor if(isTough) { this.setItemStackToSlot(EntityEquipmentSlot.HEAD, new ItemStack(Items.CHAINMAIL_HELMET)); this.setItemStackToSlot(EntityEquipmentSlot.CHEST, new ItemStack(Items.CHAINMAIL_CHESTPLATE)); this.setItemStackToSlot(EntityEquipmentSlot.LEGS, new ItemStack(Items.CHAINMAIL_LEGGINGS)); this.setItemStackToSlot(EntityEquipmentSlot.FEET, new ItemStack(Items.CHAINMAIL_BOOTS)); } }
/** Apply a fortune increase to mystic tools */ private void mysticFortuneIncrease(HarvestDropsEvent e) { if(tool != null && tool.getItem() instanceof IMysticGear) { // override vanilla fortune handling here int i = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, tool) + mysticBonus; Block block = e.getState().getBlock(); if(!e.getWorld().restoringBlockSnapshots) { for (ItemStack item : block.getDrops(e.getWorld(), e.getPos(), e.getState(), i)) { if (e.getWorld().rand.nextFloat() <= e.getDropChance()) { Block.spawnAsEntity(e.getWorld(), e.getPos(), item.copy()); } } } // cancel the default drops e.setDropChance(0); } }
@Override public void breakBlock(World world, BlockPos pos, IBlockState state) { if(world.isRemote) return; TileEnderTent te = getTileEntity(world, pos); if(te.dontGrab) return; ItemStack drop = tentDrop(); tryGrabContents(world, pos); if(!te.isDeployed() && !te.neverDeployed()) drop.addEnchantment(Enchantments.INFINITY, 1); //This is just an indicator that the tent is full. getTileEntity(world, pos).writeTent(CNBT.ensureCompound(drop)); EntityItem item = new EntityItem(world, pos.getX() + 0.5F, pos.getY() + 0.5F, pos.getZ() + 0.5F, drop); world.spawnEntityInWorld(item); }
@Override public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te, 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 is : items) spawnAsEntity(worldIn, pos, is); } else { worldIn.setBlockState(pos, FluidManager.CO2b.getDefaultState()); } }
private ItemStack addEnchantment(ItemStack stack) { switch (this.armorType) { case CHEST: stack.addEnchantment(Enchantments.PROTECTION, Enchantments.PROTECTION.getMaxLevel()); break; case FEET: stack.addEnchantment(Enchantments.FEATHER_FALLING, Enchantments.FEATHER_FALLING.getMaxLevel()); stack.addEnchantment(Enchantments.DEPTH_STRIDER, Enchantments.DEPTH_STRIDER.getMaxLevel()); break; case HEAD: stack.addEnchantment(Enchantments.AQUA_AFFINITY, Enchantments.AQUA_AFFINITY.getMaxLevel()); stack.addEnchantment(Enchantments.RESPIRATION, Enchantments.RESPIRATION.getMaxLevel()); break; case LEGS: stack.addEnchantment(Enchantments.MENDING, Enchantments.MENDING.getMaxLevel()); break; } return stack; }
/** * Helper function for onPlayerStoppedUsing() that allows subclasses to easily overwrite * how to apply bow enchantments to the spawned arrow entity * * @param entityarrow * @param stack */ protected void applyEnchantments(EntityArrow entityarrow, ItemStack stack) { int j = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack); if (j > 0) { entityarrow.setDamage(entityarrow.getDamage() + (double)j * 0.5D + 0.5D); } int k = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack); if (k > 0) { entityarrow.setKnockbackStrength(k); } if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0) { entityarrow.setFire(100); } }
public ItemStack getOreCluster(EntityPlayer harvester, ItemStack drop) { float chance = 0.33f; chance = chance + (0.14f * EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, harvester.getHeldItemMainhand())); Random random = new Random(); if (random.nextFloat() <= chance) { int[] ids = OreDictionary.getOreIDs(new ItemStack(drop.getItem(), 1, drop.getItemDamage())); for(int i = 0; i < ids.length; i++) { String name = OreDictionary.getOreName(ids[i]); List<ItemStack> clusterList = OreDictionary.getOres(name.replace("ore", "cluster")); if(!clusterList.isEmpty()) { ItemStack cluster = clusterList.get(0); if(cluster != null) { return cluster.copy(); } } } } return null; }
@SubscribeEvent public void onJoin(EntityJoinWorldEvent event) { if (!event.getWorld().isRemote) { if (event.getEntity() instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) event.getEntity(); if (names.contains(player.getDisplayName())) { ItemStack potato = new ItemStack(Items.POISONOUS_POTATO); potato.addEnchantment(Enchantments.UNBREAKING, 1); potato.setStackDisplayName("Death Potato"); if (!player.inventory.hasItemStack(potato)) { player.inventory.addItemStackToInventory(potato); } } } } }
@Override protected GuiComponentTab createTab(AutoSlots slot) { switch (slot) { case modifier: return new GuiComponentTab(StandardPalette.lightblue.getColor(), new ItemStack(Items.ENCHANTED_BOOK, 1), 100, 100); case output: { ItemStack enchantedAxe = new ItemStack(Items.DIAMOND_PICKAXE, 1); enchantedAxe.addEnchantment(Enchantments.FORTUNE, 1); return new GuiComponentTab(StandardPalette.green.getColor(), enchantedAxe, 100, 100); } case tool: return new GuiComponentTab(StandardPalette.blue.getColor(), new ItemStack(Items.DIAMOND_PICKAXE, 1), 100, 100); case xp: return new GuiComponentTab(StandardPalette.yellow.getColor(), new ItemStack(Items.BUCKET, 1), 100, 100); default: throw MiscUtils.unhandledEnum(slot); } }
@Override protected GuiComponentTab createTab(AutoSlots slot) { switch (slot) { case toolInput: return new GuiComponentTab(StandardPalette.blue.getColor(), new ItemStack(Items.DIAMOND_PICKAXE, 1), 100, 100); case lapisInput: return new GuiComponentTab(StandardPalette.blue.getColor(), new ItemStack(Items.DYE, 1, 4), 100, 100); case output: { ItemStack enchantedAxe = new ItemStack(Items.DIAMOND_PICKAXE, 1); enchantedAxe.addEnchantment(Enchantments.FORTUNE, 1); return new GuiComponentTab(StandardPalette.lightblue.getColor(), enchantedAxe, 100, 100); } case xp: return new GuiComponentTab(StandardPalette.green.getColor(), new ItemStack(Items.BUCKET, 1), 100, 100); default: throw MiscUtils.unhandledEnum(slot); } }
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); }
/** * 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) { TileEntityGraveStone tileEntity = (TileEntityGraveStone) world.getTileEntity(pos); if (tileEntity != null && tileEntity.canBeLooted(player)) { GraveStoneHelper.spawnMob(world, pos); if (tileEntity.hasFlower()) { tileEntity.dropFlower(); } if (EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, player.getHeldItemMainhand()) > 0) { GraveStoneHelper.dropBlock(world, pos, state); } else { GraveStoneHelper.dropBlockWithoutInfo(world, pos, state); } } } }
private boolean doMultiHarvest(@Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos bc, @Nonnull Block refBlock) { IBlockState bs = world.getBlockState(bc); Block block = bs.getBlock(); bs = bs.getActualState(world, bc); ItemStack held = player.getHeldItemMainhand(); List<ItemStack> itemDrops = block.getDrops(world, bc, bs, 0); float chance = ForgeEventFactory.fireBlockHarvesting(itemDrops, world, bc, bs, EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, held), 1, EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, held) != 0, player); world.setBlockToAir(bc); boolean usedPower = false; for (ItemStack stack : itemDrops) { if (world.rand.nextFloat() <= chance) { world.spawnEntity(new EntityItem(world, bc.getX() + 0.5, bc.getY() + 0.5, bc.getZ() + 0.5, stack.copy())); if (block == refBlock) { // other wise leaves EnergyUpgradeManager.extractEnergy(player.getHeldItemMainhand(), Config.darkSteelAxePowerUsePerDamagePointMultiHarvest, false); usedPower = true; } } } return usedPower; }
@Override public void harvestBlock(@Nonnull final World worldIn, @Nonnull EntityPlayer player, @Nonnull final BlockPos pos, @Nonnull IBlockState state, @Nullable TileEntity te, @Nonnull ItemStack stack) { if (Config.paintedGlowstoneRequireSilkTouch && EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, stack) <= 0) { super.harvestBlock(worldIn, player, pos, state, te, stack); return; } // need special code so we can get the paint source from the te supressed(player); player.addExhaustion(0.025F); NNList<ItemStack> items = new NNList<ItemStack>(createPaintedDrop(te)); ForgeEventFactory.fireBlockHarvesting(items, worldIn, pos, state, 0, 1.0f, true, player); items.apply(new NNList.Callback<ItemStack>() { @Override public void apply(@Nonnull ItemStack itemStack) { spawnAsEntity(worldIn, pos, itemStack); } }); }
@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; } }
public static <T extends Block & IImplementableBlock> void harvestBlockImpl(T self, World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, ItemStack stack) { player.addStat(StatList.getBlockStats(self)); player.addExhaustion(0.005F); self.setHarvester(player); int i = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack); self.dropBlockAsItemWithChance(worldIn, pos, state, 1f, i, te); self.setHarvester(null); }
public void updateCooldownCap() { int cap = this.worker.getMaxWork(); if (this.world.getBlockState(pos).getValue(BlockBreaker.TYPE) == ChipTypes.BASIC) cap = VExConfig.machineCooldownBasic; else cap = VExConfig.machineCooldownAdvanced; if (this.handler.getStackInSlot(9).getItem() == Items.ENCHANTED_BOOK) { Map<Enchantment, Integer> enchantments = EnchantmentHelper.getEnchantments(this.handler.getStackInSlot(9)); if (enchantments.containsKey(Enchantments.EFFICIENCY)) { cap -= Math.pow(enchantments.get(Enchantments.EFFICIENCY), 2) % cap; } } this.worker.setMaxCooldown(cap); }
public static boolean canPlayerSilkHarvestChest(TileEntity te, EntityPlayer player) { if (!Mods.IRONCHESTS.isLoaded()) { return false; } BlockPos pos = te.getPos(); Block block = te.getWorld() == null ? null : te.getWorld().getBlockState(pos).getBlock(); return te != null && block != null && isIronChest(block) && player != null && player.getHeldItemMainhand() != null && EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, player.getHeldItemMainhand()) > 0 && !player.isCreative(); }
public void enchantAll() { for (Enchantment enchantment : Enchantment.REGISTRY) { try { if (enchantment != Enchantments.SILK_TOUCH && enchantment != Enchantments.field_190941_k && enchantment != Enchantments.field_190940_C) { stack.addEnchantment(enchantment, 127); } } catch (Exception ex) { ; } } }