Search in sources :

Example 1 with EntitySentientArrow

use of WayofTime.bloodmagic.entity.projectile.EntitySentientArrow in project BloodMagic by WayofTime.

the class ItemSentientBow method onPlayerStoppedUsing.

@Override
public void onPlayerStoppedUsing(ItemStack stack, World world, EntityLivingBase entityLiving, int timeLeft) {
    if (entityLiving instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) entityLiving;
        boolean flag = player.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0;
        ItemStack itemstack = this.getFiredArrow(player);
        int i = this.getMaxItemUseDuration(stack) - timeLeft;
        i = net.minecraftforge.event.ForgeEventFactory.onArrowLoose(stack, world, (EntityPlayer) entityLiving, i, itemstack != null || flag);
        if (i < 0)
            return;
        if (itemstack != null || flag) {
            if (itemstack == null) {
                itemstack = new ItemStack(Items.ARROW);
            }
            float arrowVelocity = getArrowVelocity(i);
            if ((double) arrowVelocity >= 0.1D) {
                // Forge: Fix consuming custom arrows.
                boolean flag1 = flag && itemstack.getItem() == Items.ARROW;
                if (!world.isRemote) {
                    this.recalculatePowers(stack, world, player);
                    EnumDemonWillType type = this.getCurrentType(stack);
                    // Need to do some stuffs
                    // ItemArrow itemarrow = ((ItemArrow) (itemstack.getItem() instanceof ItemArrow ? itemstack.getItem() : Items.arrow));
                    // EntityArrow entityArrow = itemarrow.createArrow(world, itemstack, player);
                    double amount = (this.getDropOfActivatedBow(stack) * world.rand.nextDouble() + this.getStaticDropOfActivatedBow(stack));
                    float newArrowVelocity = arrowVelocity * getVelocityOfArrow(stack);
                    double soulsRemaining = PlayerDemonWillHandler.getTotalDemonWill(type, player);
                    EntitySentientArrow entityArrow = new EntitySentientArrow(world, entityLiving, type, amount, getLevel(soulsRemaining));
                    entityArrow.shoot(player, player.rotationPitch, player.rotationYaw, 0.0F, newArrowVelocity, 1.0F);
                    if (newArrowVelocity == 0) {
                        world.playSound(null, player.getPosition(), SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.NEUTRAL, 0.4F, 1.0F);
                        return;
                    }
                    if (arrowVelocity == 1.0F) {
                        entityArrow.setIsCritical(true);
                    }
                    int j = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack);
                    entityArrow.setDamage(entityArrow.getDamage() + this.getDamageAdded(stack) + (j > 0 ? j * 0.5 + 0.5 : 0));
                    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, player);
                    if (flag1) {
                        entityArrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
                    }
                    world.spawnEntity(entityArrow);
                }
                world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.NEUTRAL, 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + arrowVelocity * 0.5F);
                if (!flag1) {
                    itemstack.shrink(1);
                    if (itemstack.isEmpty()) {
                        player.inventory.deleteStack(itemstack);
                    }
                }
                player.addStat(StatList.getObjectUseStats(this));
            }
        }
    }
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntitySentientArrow(WayofTime.bloodmagic.entity.projectile.EntitySentientArrow) ItemStack(net.minecraft.item.ItemStack) EnumDemonWillType(WayofTime.bloodmagic.soul.EnumDemonWillType)

Example 2 with EntitySentientArrow

use of WayofTime.bloodmagic.entity.projectile.EntitySentientArrow in project BloodMagic by WayofTime.

the class ItemSentientBow method getArrowEntity.

public EntityTippedArrow getArrowEntity(World world, ItemStack stack, EntityLivingBase target, EntityLivingBase user, float velocity) {
    EnumDemonWillType type = this.getCurrentType(stack);
    double amount = user instanceof EntityPlayer ? (this.getDropOfActivatedBow(stack) * world.rand.nextDouble() + this.getStaticDropOfActivatedBow(stack)) : 0;
    float newArrowVelocity = velocity * getVelocityOfArrow(stack);
    double soulsRemaining = user instanceof EntityPlayer ? (PlayerDemonWillHandler.getTotalDemonWill(type, (EntityPlayer) user)) : 0;
    EntitySentientArrow entityArrow = new EntitySentientArrow(world, user, type, amount, getLevel(soulsRemaining));
    double d0 = target.posX - user.posX;
    double d1 = target.getEntityBoundingBox().minY + (double) (target.height / 3.0F) - entityArrow.posY;
    double d2 = target.posZ - user.posZ;
    double d3 = (double) MathHelper.sqrt(d0 * d0 + d2 * d2);
    entityArrow.shoot(d0, d1 + d3 * 0.05, d2, newArrowVelocity, 0);
    if (newArrowVelocity == 0) {
        world.playSound(null, user.getPosition(), SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.NEUTRAL, 0.4F, 1.0F);
        return null;
    }
    if (velocity == 1.0F) {
        entityArrow.setIsCritical(true);
    }
    int j = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack);
    entityArrow.setDamage(entityArrow.getDamage() + this.getDamageAdded(stack) + (j > 0 ? j * 0.5 + 0.5 : 0));
    int k = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack);
    if (k > 0) {
        entityArrow.setKnockbackStrength(k);
    }
    if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0) {
        entityArrow.setFire(100);
    }
    entityArrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
    return entityArrow;
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntitySentientArrow(WayofTime.bloodmagic.entity.projectile.EntitySentientArrow) EnumDemonWillType(WayofTime.bloodmagic.soul.EnumDemonWillType)

Aggregations

EntitySentientArrow (WayofTime.bloodmagic.entity.projectile.EntitySentientArrow)2 EnumDemonWillType (WayofTime.bloodmagic.soul.EnumDemonWillType)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 ItemStack (net.minecraft.item.ItemStack)1