Search in sources :

Example 16 with PersistentProjectileEntity

use of net.minecraft.entity.projectile.PersistentProjectileEntity in project MCDungeonsWeapons by chronosacaria.

the class PoisonCloudShotEnchantmentMixin method onPoisonCloudShotEnchantmentEntityHit.

@Inject(method = "onEntityHit", at = @At("TAIL"))
private void onPoisonCloudShotEnchantmentEntityHit(EntityHitResult entityHitResult, CallbackInfo ci) {
    if (!(entityHitResult.getEntity() instanceof LivingEntity)) {
        return;
    }
    PersistentProjectileEntity persistentProjectileEntity = (PersistentProjectileEntity) (Object) this;
    Entity target = entityHitResult.getEntity();
    LivingEntity shooter = (LivingEntity) persistentProjectileEntity.getOwner();
    ItemStack mainHandStack = null;
    if (shooter != null) {
        mainHandStack = shooter.getMainHandStack();
    }
    if (mainHandStack != null && (EnchantmentHelper.getLevel(EnchantsRegistry.POISON_CLOUD, mainHandStack) >= 1)) {
        int level = EnchantmentHelper.getLevel(EnchantsRegistry.POISON_CLOUD, mainHandStack);
        float poisonCloudShotRand = shooter.getRandom().nextFloat();
        if (poisonCloudShotRand <= 0.2F) {
            if (target instanceof LivingEntity) {
                AOECloudHelper.spawnPoisonCloud(shooter, (LivingEntity) target, level - 1);
            }
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) Entity(net.minecraft.entity.Entity) LivingEntity(net.minecraft.entity.LivingEntity) PersistentProjectileEntity(net.minecraft.entity.projectile.PersistentProjectileEntity) PersistentProjectileEntity(net.minecraft.entity.projectile.PersistentProjectileEntity) ItemStack(net.minecraft.item.ItemStack) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 17 with PersistentProjectileEntity

use of net.minecraft.entity.projectile.PersistentProjectileEntity in project MCDungeonsWeapons by chronosacaria.

the class McdwLongBow method onStoppedUsing.

@Override
public void onStoppedUsing(ItemStack stack, World world, LivingEntity user, int remainingUseTicks) {
    super.onStoppedUsing(stack, world, user, remainingUseTicks);
    if (user instanceof PlayerEntity) {
        PlayerEntity playerEntity = (PlayerEntity) user;
        boolean bl = playerEntity.abilities.creativeMode || EnchantmentHelper.getLevel(Enchantments.INFINITY, stack) > 0;
        ItemStack itemStack = playerEntity.getArrowType(stack);
        if (!itemStack.isEmpty() || bl) {
            if (itemStack.isEmpty()) {
                itemStack = new ItemStack(Items.ARROW);
            }
            int i = this.getMaxUseTime(stack) - remainingUseTicks;
            float f = getPullProgress(i);
            if ((double) f >= 0.1D) {
                boolean bl2 = bl && itemStack.getItem() == Items.ARROW;
                if (!world.isClient) {
                    ArrowItem arrowItem = ((ArrowItem) (itemStack.getItem() instanceof ArrowItem ? itemStack.getItem() : Items.ARROW));
                    PersistentProjectileEntity persistentProjectileEntity = arrowItem.createArrow(world, itemStack, playerEntity);
                    persistentProjectileEntity.setProperties(playerEntity, playerEntity.pitch, playerEntity.yaw, 0.0F, f * maxBowRange, 1.0F);
                    if (f == 1.0F) {
                        persistentProjectileEntity.setCritical(true);
                    }
                    // POWER ENCHANTMENT
                    int j = EnchantmentHelper.getLevel(Enchantments.POWER, stack);
                    if (j > 0) {
                        persistentProjectileEntity.setDamage(persistentProjectileEntity.getDamage() + (double) j * 0.5D + 0.5D);
                    }
                    // PUNCH ENCHANTMENT
                    int k = EnchantmentHelper.getLevel(Enchantments.PUNCH, stack);
                    if (k > 0) {
                        persistentProjectileEntity.setPunch(k);
                    }
                    // FLAME ENCHANTMENT
                    if (EnchantmentHelper.getLevel(Enchantments.FLAME, stack) > 0) {
                        persistentProjectileEntity.setOnFireFor(100);
                    }
                }
            }
        }
    }
}
Also used : PersistentProjectileEntity(net.minecraft.entity.projectile.PersistentProjectileEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 18 with PersistentProjectileEntity

use of net.minecraft.entity.projectile.PersistentProjectileEntity in project MCDungeonsWeapons by chronosacaria.

the class McdwShortBow method onStoppedUsing.

@Override
public void onStoppedUsing(ItemStack stack, World world, LivingEntity user, int remainingUseTicks) {
    super.onStoppedUsing(stack, world, user, remainingUseTicks);
    if (user instanceof PlayerEntity) {
        PlayerEntity playerEntity = (PlayerEntity) user;
        boolean bl = playerEntity.abilities.creativeMode || EnchantmentHelper.getLevel(Enchantments.INFINITY, stack) > 0;
        ItemStack itemStack = playerEntity.getArrowType(stack);
        if (!itemStack.isEmpty() || bl) {
            if (itemStack.isEmpty()) {
                itemStack = new ItemStack(Items.ARROW);
            }
            int i = this.getMaxUseTime(stack) - remainingUseTicks;
            float f = getPullProgress(i);
            if ((double) f >= 0.1D) {
                boolean bl2 = bl && itemStack.getItem() == Items.ARROW;
                if (!world.isClient) {
                    ArrowItem arrowItem = ((ArrowItem) (itemStack.getItem() instanceof ArrowItem ? itemStack.getItem() : Items.ARROW));
                    PersistentProjectileEntity persistentProjectileEntity = arrowItem.createArrow(world, itemStack, playerEntity);
                    persistentProjectileEntity.setProperties(playerEntity, playerEntity.pitch, playerEntity.yaw, 0.0F, f * maxBowRange, 1.0F);
                    if (f >= 0.4F) {
                        persistentProjectileEntity.setCritical(true);
                    }
                    // POWER ENCHANTMENT
                    int j = EnchantmentHelper.getLevel(Enchantments.POWER, stack);
                    if (j > 0) {
                        persistentProjectileEntity.setDamage(persistentProjectileEntity.getDamage() + (double) j * 0.5D + 0.5D);
                    }
                    // PUNCH ENCHANTMENT
                    int k = EnchantmentHelper.getLevel(Enchantments.PUNCH, stack);
                    if (k > 0) {
                        persistentProjectileEntity.setPunch(k);
                    }
                    // FLAME ENCHANTMENT
                    if (EnchantmentHelper.getLevel(Enchantments.FLAME, stack) > 0) {
                        persistentProjectileEntity.setOnFireFor(100);
                    }
                }
            }
        }
    }
}
Also used : PersistentProjectileEntity(net.minecraft.entity.projectile.PersistentProjectileEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 19 with PersistentProjectileEntity

use of net.minecraft.entity.projectile.PersistentProjectileEntity in project MCDungeonsWeapons by chronosacaria.

the class GrowingEnchantmentMixin method onGrowingEnchantmentEntityHit.

@Inject(method = "onEntityHit", at = @At("TAIL"))
private void onGrowingEnchantmentEntityHit(EntityHitResult entityHitResult, CallbackInfo ci) {
    if (!(entityHitResult.getEntity() instanceof LivingEntity)) {
        return;
    }
    PersistentProjectileEntity persistentProjectileEntity = (PersistentProjectileEntity) (Object) this;
    Entity target = entityHitResult.getEntity();
    LivingEntity shooter = (LivingEntity) persistentProjectileEntity.getOwner();
    ItemStack mainHandStack = null;
    if (shooter != null) {
        mainHandStack = shooter.getMainHandStack();
    }
    if (McdwEnchantsConfig.getValue("growing")) {
        if (mainHandStack != null && (EnchantmentHelper.getLevel(EnchantsRegistry.GROWING, mainHandStack) >= 1)) {
            int level = EnchantmentHelper.getLevel(EnchantsRegistry.GROWING, mainHandStack);
            double originalDamage = persistentProjectileEntity.getDamage();
            double damageModifier = 0;
            if (level == 1)
                damageModifier = 1.25D;
            if (level == 2)
                damageModifier = 1.5D;
            if (level == 3)
                damageModifier = 1.75D;
            double squareDistanceTo = shooter.distanceTo(target);
            double distance = Math.sqrt(squareDistanceTo);
            double distanceTraveledModifier = distance * 0.1;
            persistentProjectileEntity.setDamage(originalDamage * Math.min(distanceTraveledModifier, damageModifier));
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) Entity(net.minecraft.entity.Entity) LivingEntity(net.minecraft.entity.LivingEntity) PersistentProjectileEntity(net.minecraft.entity.projectile.PersistentProjectileEntity) ArrowEntity(net.minecraft.entity.projectile.ArrowEntity) PersistentProjectileEntity(net.minecraft.entity.projectile.PersistentProjectileEntity) ItemStack(net.minecraft.item.ItemStack) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 20 with PersistentProjectileEntity

use of net.minecraft.entity.projectile.PersistentProjectileEntity in project MCDungeonsWeapons by chronosacaria.

the class RadianceShotEnchantmentMixin method onRadianceShotEnchantmentEntityHit.

@Inject(method = "onEntityHit", at = @At("TAIL"))
private void onRadianceShotEnchantmentEntityHit(EntityHitResult entityHitResult, CallbackInfo ci) {
    if (!(entityHitResult.getEntity() instanceof LivingEntity)) {
        return;
    }
    PersistentProjectileEntity persistentProjectileEntity = (PersistentProjectileEntity) (Object) this;
    Entity target = entityHitResult.getEntity();
    LivingEntity shooter = (LivingEntity) persistentProjectileEntity.getOwner();
    ItemStack mainHandStack = null;
    if (shooter != null) {
        mainHandStack = shooter.getMainHandStack();
    }
    if (McdwEnchantsConfig.getValue("radiance_shot")) {
        if (mainHandStack != null && (EnchantmentHelper.getLevel(EnchantsRegistry.RADIANCE_SHOT, mainHandStack) >= 1)) {
            int level = EnchantmentHelper.getLevel(EnchantsRegistry.RADIANCE_SHOT, mainHandStack);
            float radianceShotRand = shooter.getRandom().nextFloat();
            if (radianceShotRand <= 0.2F) {
                if (target instanceof LivingEntity) {
                    AOECloudHelper.spawnRegenCloudAtPos(shooter, true, target.getBlockPos(), level - 1);
                }
            }
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) Entity(net.minecraft.entity.Entity) LivingEntity(net.minecraft.entity.LivingEntity) PersistentProjectileEntity(net.minecraft.entity.projectile.PersistentProjectileEntity) ArrowEntity(net.minecraft.entity.projectile.ArrowEntity) PersistentProjectileEntity(net.minecraft.entity.projectile.PersistentProjectileEntity) ItemStack(net.minecraft.item.ItemStack) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

PersistentProjectileEntity (net.minecraft.entity.projectile.PersistentProjectileEntity)24 ItemStack (net.minecraft.item.ItemStack)11 LivingEntity (net.minecraft.entity.LivingEntity)10 Inject (org.spongepowered.asm.mixin.injection.Inject)10 PlayerEntity (net.minecraft.entity.player.PlayerEntity)8 Entity (net.minecraft.entity.Entity)7 Quaternion (net.minecraft.util.math.Quaternion)5 Vec3d (net.minecraft.util.math.Vec3d)5 List (java.util.List)3 Vector3f (net.minecraft.client.util.math.Vector3f)3 ProjectileEntity (net.minecraft.entity.projectile.ProjectileEntity)3 SnowballEntity (net.minecraft.entity.projectile.thrown.SnowballEntity)3 MeleeRangedEnchantmentList (chronosacaria.mcdw.enchants.lists.MeleeRangedEnchantmentList)2 Comparator (java.util.Comparator)2 Random (java.util.Random)2 Set (java.util.Set)2 EnchantmentHelper (net.minecraft.enchantment.EnchantmentHelper)2 ArrowEntity (net.minecraft.entity.projectile.ArrowEntity)2 net.minecraft.item (net.minecraft.item)2 CrossbowItem (net.minecraft.item.CrossbowItem)2