net.minecraft.init.Enchantments Java Examples

The following examples show how to use net.minecraft.init.Enchantments. 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: ItemFukumame.java    From TofuCraftReload with MIT License 6 votes vote down vote up
public static void applyEffect(EntityFukumame fukumame, ItemStack stack) {
        int k = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack);

        if (k > 0) {
            fukumame.setDamage(fukumame.getDamage() + (double) k * 0.25D + 0.25D);
        }

//        int l = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, stack);
//
//        if (l > 0)
//        {
//            fukumame.setKnockbackStrength(l);
//        }

        if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0) {
            fukumame.setFire(100);
        }

    }
 
Example #2
Source File: OpenBlock.java    From OpenModsLib with MIT License 6 votes vote down vote up
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 #3
Source File: ItemUnicornDagger.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SubscribeEvent
public static void onAttackEntity(AttackEntityEvent event) {
	if (event.getTarget().canBeAttackedWithItem() && !event.getTarget().hitByEntity(event.getEntity()) && event.getTarget() instanceof EntityLivingBase && event.getTarget().hurtResistantTime <= 0) {
		EntityLivingBase attacker = event.getEntityLiving();
		EntityLivingBase target = (EntityLivingBase) event.getTarget();

		if (attacker.getHeldItemMainhand() == ItemStack.EMPTY)
			return;
		if (attacker.getHeldItemMainhand().getItem() != ModItems.UNICORN_DAGGER)
			return;

		float damage = 1 + EnchantmentHelper.getEnchantmentLevel(Enchantments.KNOCKBACK, attacker.getHeldItemMainhand());
		float attackCD = attacker instanceof EntityPlayer ? ((EntityPlayer) attacker).getCooledAttackStrength(0.5F) : 1;
		damage *= (0.2f + attackCD * attackCD * 0.8f);

		target.attackEntityFrom(DamageSource.causeIndirectMagicDamage(attacker, null), damage);
		target.hurtResistantTime = 0;
	}
}
 
Example #4
Source File: AutoArmorHack.java    From ForgeWurst with GNU General Public License v3.0 6 votes vote down vote up
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 #5
Source File: AutoFishHack.java    From ForgeWurst with GNU General Public License v3.0 6 votes vote down vote up
private int getRodValue(ItemStack stack)
{
	if(WItem.isNullOrEmpty(stack)
		|| !(stack.getItem() instanceof ItemFishingRod))
		return -1;
	
	int luckOTSLvl = EnchantmentHelper
		.getEnchantmentLevel(Enchantments.LUCK_OF_THE_SEA, stack);
	int lureLvl =
		EnchantmentHelper.getEnchantmentLevel(Enchantments.LURE, stack);
	int unbreakingLvl = EnchantmentHelper
		.getEnchantmentLevel(Enchantments.UNBREAKING, stack);
	int mendingBonus =
		EnchantmentHelper.getEnchantmentLevel(Enchantments.MENDING, stack);
	int noVanishBonus = WEnchantments.hasVanishingCurse(stack) ? 0 : 1;
	
	return luckOTSLvl * 9 + lureLvl * 9 + unbreakingLvl * 2 + mendingBonus
		+ noVanishBonus;
}
 
Example #6
Source File: CraftEventFactory.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
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 #7
Source File: AutoArmorModule.java    From seppuku with GNU General Public License v3.0 6 votes vote down vote up
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 #8
Source File: AutoToolModule.java    From seppuku with GNU General Public License v3.0 6 votes vote down vote up
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 #9
Source File: BlockYuba.java    From TofuCraftReload with MIT License 6 votes vote down vote up
@Override
public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, @Nullable ItemStack stack)
{
    player.addStat(StatList.getBlockStats(this), 1);
    player.addExhaustion(0.025F);

    if (this.canSilkHarvest(worldIn, pos, state, player) && EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, stack) > 0)
    {
        this.dropYuba(worldIn, pos, state);
    }
    else
    {
        if (stack != null && OreDictionary.containsMatch(false, OreDictionary.getOres("stickWood"), new ItemStack(Items.STICK)))
        {
            this.dropYuba(worldIn, pos, state);
        }
    }
}
 
Example #10
Source File: AutoToolModule.java    From seppuku with GNU General Public License v3.0 6 votes vote down vote up
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 #11
Source File: AutoTool.java    From ForgeHax with MIT License 5 votes vote down vote up
private InvItem getBestWeapon(Entity target) {
  InvItem current = LocalPlayerInventory.getSelected();
  return LocalPlayerInventory.getHotbarInventory()
      .stream()
      .filter(this::isDurabilityGood)
      .max(
          Comparator.<InvItem>comparingDouble(item -> calculateDPS(item, target))
              .thenComparing(item -> getEnchantmentLevel(Enchantments.FIRE_ASPECT, item))
              .thenComparing(item -> getEnchantmentLevel(Enchantments.SWEEPING, item))
              .thenComparing(this::isInvincible)
              .thenComparing(LocalPlayerInventory::getHotbarDistance))
      .orElse(current);
}
 
Example #12
Source File: ItemUnicornDagger.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Multimap<String, AttributeModifier> getAttributeModifiers(EntityEquipmentSlot slot, ItemStack stack) {
	Multimap<String, AttributeModifier> modifiers = super.getAttributeModifiers(slot, stack);

	if (slot == EntityEquipmentSlot.MAINHAND) {
		modifiers.removeAll(SharedMonsterAttributes.ATTACK_DAMAGE.getName());
		modifiers.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier", EnchantmentHelper.getEnchantmentLevel(Enchantments.KNOCKBACK, stack), 0));
	}

	return modifiers;
}
 
Example #13
Source File: ItemFukumame.java    From TofuCraftReload with MIT License 5 votes vote down vote up
@Override
public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) {
    if (enchantment.type == EnumEnchantmentType.BREAKABLE) {
        return true;
    }

    if (enchantment == Enchantments.POWER) {
        return true;
    }
    return super.canApplyAtEnchantingTable(stack, enchantment);
}
 
Example #14
Source File: AutoToolHack.java    From ForgeWurst with GNU General Public License v3.0 5 votes vote down vote up
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 #15
Source File: EntityMonolithEye.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
protected void attackWithArrow(EntityLivingBase target) {

		int charge = 2 + rand.nextInt(10);

		EntityArrow entityarrow = new EntityTippedArrow(this.world, this);
		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.shoot(d0, d1 + d3 * 0.20000000298023224D, d2, 1.6F,
				(float) (14 - this.world.getDifficulty().getDifficultyId() * 4));
		int i = EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.POWER, this);
		int j = EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.PUNCH, this);
		entityarrow.setDamage((double) (charge * 2.0F) + this.rand.nextGaussian() * 0.25D
				+ (double) ((float) this.world.getDifficulty().getDifficultyId() * 0.11F));

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

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

		if (rand.nextBoolean()) {
			entityarrow.setFire(100);
		}

		this.playSound(SoundEvents.ENTITY_SKELETON_SHOOT, 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
		this.world.spawnEntity(entityarrow);
	}
 
Example #16
Source File: EntityMage.java    From ToroQuest with GNU General Public License v3.0 5 votes vote down vote up
protected void attackWithArrow(EntityLivingBase target) {

		int charge = 2 + rand.nextInt(10);

		EntityArrow entityarrow = new EntityTippedArrow(this.world, this);
		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.shoot(d0, d1 + d3 * 0.20000000298023224D, d2, 1.6F,
				(float) (14 - this.world.getDifficulty().getDifficultyId() * 4));
		int i = EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.POWER, this);
		int j = EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.PUNCH, this);
		entityarrow.setDamage((double) (charge * 2.0F) + this.rand.nextGaussian() * 0.25D
				+ (double) ((float) this.world.getDifficulty().getDifficultyId() * 0.11F));

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

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

		if (rand.nextBoolean()) {
			entityarrow.setFire(100);
		}

		this.playSound(SoundEvents.ENTITY_SKELETON_SHOOT, 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
		this.world.spawnEntity(entityarrow);
	}
 
Example #17
Source File: GTItemRockCutter.java    From GT-Classic with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items) {
	if (!isInCreativeTab(tab)) {
		return;
	}
	ItemStack empty = new ItemStack(this, 1, 0);
	ItemStack full = new ItemStack(this, 1, 0);
	ElectricItem.manager.discharge(empty, 2.147483647E9D, Integer.MAX_VALUE, true, false, false);
	ElectricItem.manager.charge(full, 2.147483647E9D, Integer.MAX_VALUE, true, false);
	empty.addEnchantment(Enchantments.SILK_TOUCH, 1);
	full.addEnchantment(Enchantments.SILK_TOUCH, 1);
	items.add(empty);
	items.add(full);
}
 
Example #18
Source File: ToolUtility.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static boolean applyShearBehavior(ItemStack itemStack, BlockPos pos, EntityPlayer player) {
    Block block = player.world.getBlockState(pos).getBlock();
    if (block instanceof IShearable) {
        IShearable target = (IShearable) block;
        if (target.isShearable(itemStack, player.world, pos)) {
            int fortuneLevel = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, itemStack);
            List<ItemStack> drops = target.onSheared(itemStack, player.world, pos, fortuneLevel);
            dropListOfItems(player.world, pos, drops);
                     player.world.setBlockState(pos, Blocks.AIR.getDefaultState(), 11);
            return true;
        }
    }
    return false;
}
 
Example #19
Source File: OpenBlock.java    From OpenModsLib with MIT License 5 votes vote down vote up
@Override
public void harvestBlock(World world, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te, @Nonnull ItemStack stack) {
	player.addStat(StatList.getBlockStats(this));
	player.addExhaustion(0.025F);

	if (canSilkHarvest(world, pos, state, player) && EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, stack) > 0) {
		handleSilkTouchDrops(world, player, pos, state, te);
	} else {
		handleNormalDrops(world, player, pos, state, te, stack);
	}
}
 
Example #20
Source File: ToolMetaItem.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static int calculateToolDamage(ItemStack itemStack, Random random, int amount) {
    int level = EnchantmentHelper.getEnchantmentLevel(Enchantments.UNBREAKING, itemStack);
    int damageNegated = 0;
    for (int k = 0; level > 0 && k < amount; ++k) {
        if (EnchantmentDurability.negateDamage(itemStack, level, random)) {
            ++damageNegated;
        }
    }
    return Math.max(0, amount - damageNegated);
}
 
Example #21
Source File: ToolMetaItemListener.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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);
    }
}
 
Example #22
Source File: BlockLogNatural2.java    From TFC2 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest)
{
	if(world.isRemote)
		return true;

	//get our item parameters
	ItemStack stack = player.getHeldItemMainhand();
	int fortune = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack);
	int maxCut = 0;
	if(stack.getItem() instanceof ItemAxe)
	{
		maxCut = ((ItemAxe)stack.getItem()).maxTreeSize;
	}
	else return false;

	//create the map of our tree
	BlockPosList tree = BlockLogNatural.getTreeForCut(world, pos);
	int count = tree.size();

	//if the tree has too many blocks then prevent chopping
	if(count > maxCut)
	{
		player.sendMessage(new TextComponentTranslation(Core.translate("gui.axe.treetoobig")));
		return false;
	}
	else if(count > stack.getMaxDamage() - stack.getItemDamage())
	{
		player.sendMessage(new TextComponentTranslation(Core.translate("gui.axe.needsrepair")));
		return false;
	}
	else
	{
		for(BlockPos p : tree)
		{
			IBlockState s = world.getBlockState(p);
			this.onBlockHarvested(world, pos, s, player);
			world.setBlockToAir(p);
			s.getBlock().dropBlockAsItem(world, p, s, fortune);
		}
	}
	stack.damageItem(count-1, player);

	return true;
}
 
Example #23
Source File: ModifierSmashing.java    From ExNihiloAdscensio with MIT License 4 votes vote down vote up
@Override
public boolean canApplyTogether(Enchantment enchantment)
{
    return enchantment != Enchantments.SILK_TOUCH;
}
 
Example #24
Source File: BlockLogNaturalPalm.java    From TFC2 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest)
{
	if(world.isRemote)
		return true;

	//get our item parameters
	ItemStack stack = player.getHeldItemMainhand();
	int fortune = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack);
	int maxCut = 0;
	if(stack.getItem() instanceof ItemAxe)
	{
		maxCut = ((ItemAxe)stack.getItem()).maxTreeSize;
	}
	else return false;

	//create the map of our tree
	BlockPosList tree = BlockLogNatural.getTreeForCut(world, pos);
	int count = tree.size();

	//if the tree has too many blocks then prevent chopping
	if(count > maxCut)
	{
		player.sendMessage(new TextComponentTranslation(Core.translate("gui.axe.treetoobig")));
		return false;
	}
	else if(count > stack.getMaxDamage() - stack.getItemDamage())
	{
		player.sendMessage(new TextComponentTranslation(Core.translate("gui.axe.needsrepair")));
		return false;
	}
	else
	{
		for(BlockPos p : tree)
		{
			IBlockState s = world.getBlockState(p);
			this.onBlockHarvested(world, pos, s, player);
			world.setBlockToAir(p);
			s.getBlock().dropBlockAsItem(world, p, s, fortune);
		}
	}
	stack.damageItem(count-1, player);

	return true;
}
 
Example #25
Source File: BlockLogNatural.java    From TFC2 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest)
{
	if(world.isRemote)
		return true;

	//get our item parameters
	ItemStack stack = player.getHeldItemMainhand();
	int fortune = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack);
	int maxCut = 0;
	if(stack.getItem() instanceof ItemAxe)
	{
		maxCut = ((ItemAxe)stack.getItem()).maxTreeSize;
	}
	else return false;

	//create the map of our tree
	BlockPosList tree = BlockLogNatural.getTreeForCut(world, pos);
	int count = tree.size();

	//if the tree has too many blocks then prevent chopping
	if(count > maxCut)
	{
		player.sendMessage(new TextComponentTranslation(Core.translate("gui.axe.treetoobig")));
		return false;
	}
	else if(count > stack.getMaxDamage() - stack.getItemDamage())
	{
		player.sendMessage(new TextComponentTranslation(Core.translate("gui.axe.needsrepair")));
		return false;
	}
	else
	{
		for(BlockPos p : tree)
		{
			IBlockState s = world.getBlockState(p);
			this.onBlockHarvested(world, pos, s, player);
			world.setBlockToAir(p);
			s.getBlock().dropBlockAsItem(world, p, s, fortune);
		}
	}
	stack.damageItem(count-1, player);

	return true;
}
 
Example #26
Source File: ItemZundaBow.java    From TofuCraftReload with MIT License 4 votes vote down vote up
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft)
{
    if (entityLiving instanceof EntityPlayer)
    {
        EntityPlayer entityplayer = (EntityPlayer)entityLiving;
        boolean flag = entityplayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0;
        ItemStack itemstack = this.findAmmo(entityplayer);

        int i = this.getMaxItemUseDuration(stack) - timeLeft;
        i = net.minecraftforge.event.ForgeEventFactory.onArrowLoose(stack, worldIn, entityplayer, i, !itemstack.isEmpty() || flag);
        if (i < 0) return;

        if (!itemstack.isEmpty() || flag)
        {
            if (itemstack.isEmpty())
            {
                itemstack = new ItemStack(Items.ARROW);
            }

            float f = getArrowVelocity(i);

            if ((double)f >= 0.1D)
            {
                boolean flag1 = entityplayer.capabilities.isCreativeMode || (itemstack.getItem() instanceof ItemArrow && ((ItemArrow) itemstack.getItem()).isInfinite(itemstack, stack, entityplayer));

                if (!worldIn.isRemote)
                {
                    ItemArrow itemarrow = (ItemArrow)(itemstack.getItem() instanceof ItemArrow ? itemstack.getItem() : Items.ARROW);
                    EntityArrow entityarrow = itemarrow.createArrow(worldIn, itemstack, entityplayer);
                    entityarrow.shoot(entityplayer, entityplayer.rotationPitch, entityplayer.rotationYaw, 0.0F, f * 3.05F, 1.0F);

                    if (f == 1.0F)
                    {
                        entityarrow.setIsCritical(true);
                    }

                    int j = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack);

                    if(entityarrow instanceof EntityZundaArrow){
                        entityarrow.setDamage(entityarrow.getDamage() + 2.0D);
                    }

                    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);
                    }

                    stack.damageItem(1, entityplayer);

                    if (flag1 || entityplayer.capabilities.isCreativeMode && (itemstack.getItem() == Items.SPECTRAL_ARROW || itemstack.getItem() == Items.TIPPED_ARROW))
                    {
                        entityarrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
                    }

                    worldIn.spawnEntity(entityarrow);
                }

                worldIn.playSound((EntityPlayer)null, entityplayer.posX, entityplayer.posY, entityplayer.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);

                if (!flag1 && !entityplayer.capabilities.isCreativeMode)
                {
                    itemstack.shrink(1);

                    if (itemstack.isEmpty())
                    {
                        entityplayer.inventory.deleteStack(itemstack);
                    }
                }

                entityplayer.addStat(StatList.getObjectUseStats(this));
            }
        }
    }
}
 
Example #27
Source File: AutoMend.java    From ForgeHax with MIT License 4 votes vote down vote up
private boolean isMendable(InvItem item) {
  return item.isItemDamageable()
      && EnchantmentHelper.getEnchantmentLevel(Enchantments.MENDING, item.getItemStack()) > 0;
}
 
Example #28
Source File: AutoTool.java    From ForgeHax with MIT License 4 votes vote down vote up
private boolean isSilkTouchable(InvItem item, IBlockState state, BlockPos pos) {
  return LocalPlayerInventory.getSelected().getIndex() == item.getIndex()
      && getEnchantmentLevel(Enchantments.SILK_TOUCH, item) > 0
      && state.getBlock().canSilkHarvest(getWorld(), pos, state, getLocalPlayer());
}
 
Example #29
Source File: ItemKotachi.java    From Sakura_mod with MIT License 4 votes vote down vote up
@Override
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) {
    int k = EnchantmentHelper.getEnchantmentLevel(Enchantments.SWEEPING, stack);

    if (k > 0) {
        //big sweep!!!
        entityLiving.swingArm(entityLiving.getActiveHand());

        float f = (float) entityLiving.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue();
        f += EnchantmentHelper.getModifierForCreature(stack, entityLiving.getCreatureAttribute()) / 1.5F;

        float f3 = EnchantmentHelper.getSweepingDamageRatio(entityLiving) * f;

        float sweepingRatio = EnchantmentHelper.getSweepingDamageRatio(entityLiving);

        for (Entity entitylivingbase : worldIn.getEntitiesWithinAABB(Entity.class, entityLiving.getEntityBoundingBox().grow(1.4D + sweepingRatio * 1.2D, 0.3D + sweepingRatio * 0.15D, 1.4D + sweepingRatio * 1.2D))) {
            if (entitylivingbase != entityLiving && !entityLiving.isOnSameTeam(entitylivingbase)) {
                if (entitylivingbase instanceof EntityLivingBase) {
                    if (entitylivingbase instanceof EntityPlayer && ((EntityPlayer) entitylivingbase).isActiveItemStackBlocking()) {
                        //disable shield
                        ((EntityPlayer) entitylivingbase).disableShield(false);
                    }
                    ((EntityLivingBase) entitylivingbase).knockBack(entityLiving, 0.4F + 0.1F * EnchantmentHelper.getSweepingDamageRatio(entityLiving), MathHelper.sin(entityLiving.rotationYaw * 0.017453292F), (-MathHelper.cos(entityLiving.rotationYaw * 0.017453292F)));
                    entitylivingbase.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) entityLiving), f3);
                }

                if (entitylivingbase instanceof MultiPartEntityPart) {
                    entitylivingbase.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) entityLiving), f3);
                }
            }
        }

        worldIn.playSound(null, entityLiving.posX, entityLiving.posY, entityLiving.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_SWEEP, entityLiving.getSoundCategory(), 1.0F, 1.0F);

        if (worldIn instanceof WorldServer) {
            double d0 = (-MathHelper.sin(entityLiving.rotationYaw * 0.017453292F));
            double d1 = MathHelper.cos(entityLiving.rotationYaw * 0.017453292F);
            ((WorldServer) worldIn).spawnParticle(EnumParticleTypes.SWEEP_ATTACK, entityLiving.posX + d0, entityLiving.posY + entityLiving.height * 0.5D, entityLiving.posZ + d1, 0, d0, 0.0D, d1, 0.0D);
        }

        stack.damageItem(2, entityLiving);

        ((EntityPlayer) entityLiving).getCooldownTracker().setCooldown(this, 16);
    }

}
 
Example #30
Source File: CraftServer.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public CraftServer(MinecraftServer console, PlayerList playerList) {
    this.console = console;
    this.playerList = (DedicatedPlayerList) playerList;
    this.playerView = Collections.unmodifiableList(Lists.transform(playerList.getPlayers(), EntityPlayerMP::getBukkitEntity));
    this.serverVersion = CraftServer.class.getPackage().getImplementationVersion();
    online.value = console.getPropertyManager().getBooleanProperty("online-mode", true);

    Bukkit.setServer(this);

    // Register all the Enchantments and PotionTypes now so we can stop new registration immediately after
    Enchantments.SHARPNESS.getClass();

    Potion.setPotionBrewer(new CraftPotionBrewer());
    MobEffects.BLINDNESS.getClass();
    // Ugly hack :(

    if (!Main.useConsole) {
        getLogger().info("Console input is disabled due to --noconsole command argument");
    }

    configuration = YamlConfiguration.loadConfiguration(getConfigFile());
    configuration.options().copyDefaults(true);
    configuration.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(
            getClass().getClassLoader().getResourceAsStream("configurations/bukkit.yml"), Charsets.UTF_8)));
    ConfigurationSection legacyAlias = null;
    if (!configuration.isString("aliases")) {
        legacyAlias = configuration.getConfigurationSection("aliases");
        configuration.set("aliases", "now-in-commands.yml");
    }
    saveConfig();
    if (getCommandsConfigFile().isFile()) {
        legacyAlias = null;
    }
    commandsConfiguration = YamlConfiguration.loadConfiguration(getCommandsConfigFile());
    commandsConfiguration.options().copyDefaults(true);
    commandsConfiguration.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(
            getClass().getClassLoader().getResourceAsStream("configurations/commands.yml"), Charsets.UTF_8)));
    saveCommandsConfig();

    // Migrate aliases from old file and add previously implicit $1- to pass all arguments
    if (legacyAlias != null) {
        ConfigurationSection aliases = commandsConfiguration.createSection("aliases");
        for (String key : legacyAlias.getKeys(false)) {
            ArrayList<String> commands = new ArrayList<String>();

            if (legacyAlias.isList(key)) {
                for (String command : legacyAlias.getStringList(key)) {
                    commands.add(command + " $1-");
                }
            } else {
                commands.add(legacyAlias.getString(key) + " $1-");
            }

            aliases.set(key, commands);
        }
    }

    saveCommandsConfig();
    overrideAllCommandBlockCommands = commandsConfiguration.getStringList("command-block-overrides").contains("*");
    unrestrictedAdvancements = commandsConfiguration.getBoolean("unrestricted-advancements");
    pluginManager.useTimings(configuration.getBoolean("settings.plugin-profiling"));
    monsterSpawn = configuration.getInt("spawn-limits.monsters");
    animalSpawn = configuration.getInt("spawn-limits.animals");
    waterAnimalSpawn = configuration.getInt("spawn-limits.water-animals");
    ambientSpawn = configuration.getInt("spawn-limits.ambient");
    console.autosavePeriod = configuration.getInt("ticks-per.autosave");
    warningState = WarningState.value(configuration.getString("settings.deprecated-verbose"));
    loadIcon(); // Fixed server ping stalling.
    chunkGCPeriod = configuration.getInt("chunk-gc.period-in-ticks");
    chunkGCLoadThresh = configuration.getInt("chunk-gc.load-threshold");
    loadIcon();
}