Search in sources :

Example 1 with AbstractArrowEntity

use of net.minecraft.entity.projectile.AbstractArrowEntity in project minecolonies by Minecolonies.

the class ItemPharaoScepter method releaseUsing.

@Override
public void releaseUsing(@NotNull final ItemStack stack, @NotNull final World worldIn, LivingEntity entityLiving, int timeLeft) {
    if (entityLiving instanceof PlayerEntity) {
        PlayerEntity playerentity = (PlayerEntity) entityLiving;
        int useDuration = this.getUseDuration(stack) - timeLeft;
        useDuration = net.minecraftforge.event.ForgeEventFactory.onArrowLoose(stack, worldIn, playerentity, useDuration, true);
        if (useDuration < 0) {
            return;
        }
        float speed = getPowerForTime(useDuration);
        if (!((double) speed < 0.1D)) {
            if (!worldIn.isClientSide) {
                ArrowItem arrowitem = (ArrowItem) Items.ARROW;
                AbstractArrowEntity abstractarrowentity = arrowitem.createArrow(worldIn, new ItemStack(arrowitem, 1), playerentity);
                abstractarrowentity = customArrow(abstractarrowentity);
                abstractarrowentity.shootFromRotation(playerentity, playerentity.xRot, playerentity.yRot, 0.0F, speed * 3.0F, 1.0F);
                if (speed == 1.0F) {
                    abstractarrowentity.setCritArrow(true);
                }
                int j = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.POWER_ARROWS, stack);
                if (j > 0) {
                    abstractarrowentity.setBaseDamage(abstractarrowentity.getBaseDamage() + (double) j * 0.5D + 0.5D);
                }
                int k = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.PUNCH_ARROWS, stack);
                if (k > 0) {
                    abstractarrowentity.setKnockback(k);
                }
                if (EnchantmentHelper.getItemEnchantmentLevel(Enchantments.FLAMING_ARROWS, stack) > 0) {
                    abstractarrowentity.setSecondsOnFire(100);
                }
                stack.hurtAndBreak(1, playerentity, new Consumer<PlayerEntity>() {

                    @Override
                    public void accept(final PlayerEntity player) {
                        player.broadcastBreakEvent(playerentity.getUsedItemHand());
                    }
                });
                abstractarrowentity.pickup = AbstractArrowEntity.PickupStatus.CREATIVE_ONLY;
                worldIn.addFreshEntity(abstractarrowentity);
            }
            worldIn.playSound(null, playerentity.getX(), playerentity.getY(), playerentity.getZ(), SoundEvents.ARROW_SHOOT, SoundCategory.PLAYERS, 1.0F, 1.0F / (random.nextFloat() * 0.4F + 1.2F) + speed * 0.5F);
            playerentity.awardStat(Stats.ITEM_USED.get(this));
        }
    }
}
Also used : ArrowItem(net.minecraft.item.ArrowItem) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity)

Example 2 with AbstractArrowEntity

use of net.minecraft.entity.projectile.AbstractArrowEntity in project minecolonies by Minecolonies.

the class ItemPharaoScepter method customArrow.

@NotNull
@Override
public AbstractArrowEntity customArrow(@NotNull AbstractArrowEntity arrow) {
    AbstractArrowEntity entity = ((ArrowItem) ModItems.firearrow).createArrow(arrow.level, new ItemStack(ModItems.firearrow, 1), (LivingEntity) arrow.getOwner());
    entity.pickup = AbstractArrowEntity.PickupStatus.DISALLOWED;
    entity.setSecondsOnFire(3);
    return entity;
}
Also used : ArrowItem(net.minecraft.item.ArrowItem) ItemStack(net.minecraft.item.ItemStack) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with AbstractArrowEntity

use of net.minecraft.entity.projectile.AbstractArrowEntity in project minecolonies by Minecolonies.

the class RangerCombatAI method doAttack.

@Override
protected void doAttack(final LivingEntity target) {
    if (user.distanceToSqr(target) < RANGED_FLEE_SQDIST) {
        if (user.getRandom().nextInt(FLEE_CHANCE) == 0 && !((AbstractBuildingGuards) user.getCitizenData().getWorkBuilding()).getTask().equals(GuardTaskSetting.GUARD)) {
            user.getNavigation().moveAwayFromLivingEntity(target, getAttackDistance() / 2.0, getCombatMovementSpeed());
        }
    } else {
        user.getNavigation().stop();
    }
    user.getCitizenData().setVisibleStatus(ARCHER_COMBAT);
    user.swing(Hand.MAIN_HAND);
    int amountOfArrows = 1;
    if (user.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(DOUBLE_ARROWS) > 0) {
        if (user.getRandom().nextDouble() < user.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(DOUBLE_ARROWS)) {
            amountOfArrows++;
        }
    }
    for (int i = 0; i < amountOfArrows; i++) {
        final AbstractArrowEntity arrow = CombatUtils.createArrowForShooter(user);
        if (user.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(ARROW_PIERCE) > 0) {
            arrow.setPierceLevel((byte) 2);
        }
        // Add bow enchant effects: Knocback and fire
        final ItemStack bow = user.getItemInHand(Hand.MAIN_HAND);
        if (EnchantmentHelper.getItemEnchantmentLevel(Enchantments.FLAMING_ARROWS, bow) > 0) {
            arrow.setSecondsOnFire(100);
        }
        final int k = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.PUNCH_ARROWS, bow);
        if (k > 0) {
            arrow.setKnockback(k);
        }
        double damage = calculateDamage(arrow);
        arrow.setBaseDamage(damage);
        final float chance = HIT_CHANCE_DIVIDER / (user.getCitizenData().getCitizenSkillHandler().getLevel(Skill.Adaptability) + 1);
        CombatUtils.shootArrow(arrow, target, chance);
        user.playSound(SoundEvents.SKELETON_SHOOT, (float) BASIC_VOLUME, (float) SoundUtils.getRandomPitch(user.getRandom()));
    }
    target.setLastHurtByMob(user);
    user.getCitizenItemHandler().damageItemInHand(Hand.MAIN_HAND, 1);
    user.stopUsingItem();
    user.decreaseSaturationForContinuousAction();
}
Also used : ItemStack(net.minecraft.item.ItemStack) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity)

Example 4 with AbstractArrowEntity

use of net.minecraft.entity.projectile.AbstractArrowEntity in project bioplethora by AquexTheSeal.

the class ServerWorldEvents method onProjectileHit.

@SubscribeEvent
public static void onProjectileHit(ProjectileImpactEvent event) {
    AlphemKingSpawnHelper.onProjectileImpact(event);
    Entity projectile = event.getEntity();
    RayTraceResult result = event.getRayTraceResult();
    if (result instanceof EntityRayTraceResult) {
        // =================================================
        // Totem of Swerving Skill
        // =================================================
        boolean targetIsEntity = ((EntityRayTraceResult) result).getEntity() instanceof LivingEntity;
        if (projectile instanceof AbstractArrowEntity) {
            ((AbstractArrowEntity) projectile).setPierceLevel((byte) 0);
        }
        if (!projectile.level.isClientSide && targetIsEntity) {
            LivingEntity user = ((LivingEntity) ((EntityRayTraceResult) result).getEntity());
            int shouldDodge = user.getRandom().nextInt(3);
            if ((user.getOffhandItem().getItem() instanceof SwervingTotemItem) || (user.getMainHandItem().getItem() instanceof SwervingTotemItem)) {
                if (shouldDodge == 1) {
                    boolean isNegVal = user.getRandom().nextBoolean();
                    int tpLoc = 1 + user.getRandom().nextInt(2);
                    user.level.playSound(null, user.getX(), user.getY(), user.getZ(), SoundEvents.GHAST_SHOOT, SoundCategory.PLAYERS, 1, 1);
                    if (user.level instanceof ServerWorld) {
                        ((ServerWorld) user.level).sendParticles(ParticleTypes.POOF, user.getX(), user.getY(), user.getZ(), 50, 0.65, 0.65, 0.65, 0.01);
                    }
                    BlockPos blockpos = new BlockPos(user.getX() + (isNegVal ? tpLoc : -tpLoc), user.getY(), user.getZ() + (isNegVal ? tpLoc : -tpLoc));
                    if (!user.level.getBlockState(blockpos).getMaterial().blocksMotion()) {
                        user.teleportTo(blockpos.getX(), blockpos.getY(), blockpos.getZ());
                        event.setCanceled(true);
                    }
                }
            }
        }
        // =================================================
        // Mob Special Skills
        // =================================================
        boolean targetIsAltyrus = ((EntityRayTraceResult) result).getEntity() instanceof AltyrusEntity;
        if (projectile instanceof AbstractArrowEntity) {
            ((AbstractArrowEntity) projectile).setPierceLevel((byte) 0);
        }
        if (!projectile.level.isClientSide() && targetIsAltyrus) {
            AltyrusEntity altyrus = ((AltyrusEntity) ((EntityRayTraceResult) result).getEntity());
            int shouldDodge = altyrus.getRandom().nextInt(3);
            if ((shouldDodge == 1) || (shouldDodge == 2)) {
                Vector3d projectilePos = event.getEntity().position();
                Vector3d rVec = altyrus.getLookAngle().yRot(0.5F + (float) Math.PI).add(altyrus.position());
                Vector3d lVec = altyrus.getLookAngle().yRot(0.5F + (float) Math.PI).add(altyrus.position());
                BlockPos pos = new BlockPos((int) altyrus.getX(), (int) altyrus.getY(), (int) altyrus.getZ());
                boolean rDir;
                if (projectilePos.distanceTo(rVec) < projectilePos.distanceTo(lVec)) {
                    rDir = true;
                } else if (projectilePos.distanceTo(rVec) > projectilePos.distanceTo(lVec)) {
                    rDir = false;
                } else {
                    rDir = altyrus.getRandom().nextBoolean();
                }
                Vector3d vectorThingy = event.getEntity().getDeltaMovement().yRot((float) ((rDir ? 0.5F : -0.5F) * Math.PI)).normalize();
                altyrus.setDodging(true);
                altyrus.level.playSound(null, pos, altyrus.getDodgeSound(), SoundCategory.HOSTILE, (float) 1, (float) 1);
                altyrus.setDeltaMovement(altyrus.getDeltaMovement().add(vectorThingy.x() * 0.5F, 0, vectorThingy.z() * 0.5F));
                event.setCanceled(true);
            }
        }
        boolean targetIsHelioblade = ((EntityRayTraceResult) result).getEntity() instanceof HeliobladeEntity;
        if (!projectile.level.isClientSide && targetIsHelioblade) {
            HeliobladeEntity helioblade = ((HeliobladeEntity) ((EntityRayTraceResult) result).getEntity());
            int shouldDodge = helioblade.getRandom().nextInt(3);
            if (projectile instanceof AbstractArrowEntity) {
                ((AbstractArrowEntity) projectile).setPierceLevel((byte) 0);
            }
            if ((shouldDodge == 1) || (shouldDodge == 2)) {
                Vector3d projectilePos = event.getEntity().position();
                Vector3d rVec = helioblade.getLookAngle().yRot(0.5F + (float) Math.PI).add(helioblade.position());
                Vector3d lVec = helioblade.getLookAngle().yRot(0.5F + (float) Math.PI).add(helioblade.position());
                BlockPos pos = new BlockPos((int) helioblade.getX(), (int) helioblade.getY(), (int) helioblade.getZ());
                boolean rDir;
                if (projectilePos.distanceTo(rVec) < projectilePos.distanceTo(lVec)) {
                    rDir = true;
                } else if (projectilePos.distanceTo(rVec) > projectilePos.distanceTo(lVec)) {
                    rDir = false;
                } else {
                    rDir = helioblade.getRandom().nextBoolean();
                }
                Vector3d vectorThingy = event.getEntity().getDeltaMovement().yRot((float) ((rDir ? 0.5F : -0.5F) * Math.PI)).normalize();
                helioblade.setDeltaMovement(helioblade.getDeltaMovement().add(vectorThingy.x() * 1F, 0, vectorThingy.z() * 1F));
                event.setCanceled(true);
            }
        }
        boolean targetIsPrimordialRing = ((EntityRayTraceResult) result).getEntity() instanceof PrimordialRingEntity;
        if (!projectile.level.isClientSide && targetIsPrimordialRing) {
            PrimordialRingEntity primordialRing = ((PrimordialRingEntity) ((EntityRayTraceResult) result).getEntity());
            if (projectile instanceof AbstractArrowEntity) {
                ((AbstractArrowEntity) projectile).setPierceLevel((byte) 0);
            }
            Vector3d projectilePos = event.getEntity().position();
            Vector3d rVec = primordialRing.getLookAngle().yRot(0.5F + (float) Math.PI).add(primordialRing.position());
            Vector3d lVec = primordialRing.getLookAngle().yRot(0.5F + (float) Math.PI).add(primordialRing.position());
            boolean rDir;
            if (projectilePos.distanceTo(rVec) < projectilePos.distanceTo(lVec)) {
                rDir = true;
            } else if (projectilePos.distanceTo(rVec) > projectilePos.distanceTo(lVec)) {
                rDir = false;
            } else {
                rDir = primordialRing.getRandom().nextBoolean();
            }
            Vector3d vectorThingy = event.getEntity().getDeltaMovement().yRot((float) ((rDir ? 0.5F : -0.5F) * Math.PI)).normalize();
            primordialRing.setDeltaMovement(primordialRing.getDeltaMovement().add(vectorThingy.x() * 1F, 0, vectorThingy.z() * 1F));
            event.setCanceled(true);
        }
    }
}
Also used : HeliobladeEntity(io.github.bioplethora.entity.creatures.HeliobladeEntity) PrimordialRingEntity(io.github.bioplethora.entity.others.PrimordialRingEntity) GrylynenEntity(io.github.bioplethora.entity.creatures.GrylynenEntity) Entity(net.minecraft.entity.Entity) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) AlphemKingEntity(io.github.bioplethora.entity.creatures.AlphemKingEntity) LivingEntity(net.minecraft.entity.LivingEntity) AltyrusEntity(io.github.bioplethora.entity.creatures.AltyrusEntity) EntityRayTraceResult(net.minecraft.util.math.EntityRayTraceResult) AltyrusEntity(io.github.bioplethora.entity.creatures.AltyrusEntity) RayTraceResult(net.minecraft.util.math.RayTraceResult) EntityRayTraceResult(net.minecraft.util.math.EntityRayTraceResult) LivingEntity(net.minecraft.entity.LivingEntity) ServerWorld(net.minecraft.world.server.ServerWorld) Vector3d(net.minecraft.util.math.vector.Vector3d) PrimordialRingEntity(io.github.bioplethora.entity.others.PrimordialRingEntity) HeliobladeEntity(io.github.bioplethora.entity.creatures.HeliobladeEntity) SwervingTotemItem(io.github.bioplethora.item.functionals.SwervingTotemItem) BlockPos(net.minecraft.util.math.BlockPos) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 5 with AbstractArrowEntity

use of net.minecraft.entity.projectile.AbstractArrowEntity in project endergetic by team-abnormals.

the class BoofBlockEntity method tick.

@Override
public void tick() {
    AxisAlignedBB bb = this.getBoundingBox().inflate(0, 0.25F, 0);
    List<Entity> entities = this.level.getEntitiesOfClass(Entity.class, bb, (entity -> !entity.isPassenger()));
    for (Entity entity : entities) {
        if (!EETags.EntityTypes.BOOF_BLOCK_RESISTANT.contains(entity.getType())) {
            if (entity instanceof AbstractArrowEntity) {
                this.setForProjectile(true);
                this.level.setBlockAndUpdate(getOrigin(), Blocks.AIR.defaultBlockState());
                entity.push(MathHelper.sin((float) (entity.yRot * Math.PI / 180.0F)) * 3 * 0.1F, 0.55D, -MathHelper.cos((float) (entity.yRot * Math.PI / 180.0F)) * 3 * 0.1F);
            } else {
                if (entity.getY() - 0.45F >= this.getY()) {
                    entity.push(0, this.random.nextFloat() * 0.05D + 0.35D, 0);
                } else if (entity.getY() < this.getY() - 1F) {
                    entity.push(0, this.random.nextFloat() * -0.05D - 0.35D, 0);
                } else {
                    float amount = 0.5F;
                    Vector3d result = entity.position().subtract(this.position());
                    entity.push(result.x * amount, this.random.nextFloat() * 0.45D + 0.25D, result.z * amount);
                }
            }
            if (!(entity instanceof PlayerEntity)) {
                entity.hurtMarked = true;
            }
        }
    }
    if (this.tickCount >= 10) {
        if (this.level.isAreaLoaded(this.getOrigin(), 1) && this.level.getBlockState(getOrigin()).getBlock() == EEBlocks.BOOF_BLOCK.get() && !this.isForProjectile()) {
            this.level.setBlockAndUpdate(this.getOrigin(), EEBlocks.BOOF_BLOCK.get().defaultBlockState());
        } else if (this.level.isAreaLoaded(this.getOrigin(), 1) && this.isForProjectile()) {
            this.level.setBlockAndUpdate(this.getOrigin(), EEBlocks.BOOF_BLOCK.get().defaultBlockState());
        }
        this.remove();
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EntityType(net.minecraft.entity.EntityType) EntityDataManager(net.minecraft.network.datasync.EntityDataManager) Entity(net.minecraft.entity.Entity) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) World(net.minecraft.world.World) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) CompoundNBT(net.minecraft.nbt.CompoundNBT) EEBlocks(com.minecraftabnormals.endergetic.core.registry.EEBlocks) BlockPos(net.minecraft.util.math.BlockPos) DataParameter(net.minecraft.network.datasync.DataParameter) DamageSource(net.minecraft.util.DamageSource) Blocks(net.minecraft.block.Blocks) Vector3d(net.minecraft.util.math.vector.Vector3d) List(java.util.List) DataSerializers(net.minecraft.network.datasync.DataSerializers) FMLPlayMessages(net.minecraftforge.fml.network.FMLPlayMessages) IPacket(net.minecraft.network.IPacket) MathHelper(net.minecraft.util.math.MathHelper) NetworkHooks(net.minecraftforge.fml.network.NetworkHooks) EEEntities(com.minecraftabnormals.endergetic.core.registry.EEEntities) EETags(com.minecraftabnormals.endergetic.core.registry.other.EETags) Entity(net.minecraft.entity.Entity) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Vector3d(net.minecraft.util.math.vector.Vector3d) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Aggregations

AbstractArrowEntity (net.minecraft.entity.projectile.AbstractArrowEntity)32 ItemStack (net.minecraft.item.ItemStack)18 PlayerEntity (net.minecraft.entity.player.PlayerEntity)14 ArrowItem (net.minecraft.item.ArrowItem)7 LivingEntity (net.minecraft.entity.LivingEntity)6 Entity (net.minecraft.entity.Entity)5 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)4 Item (net.minecraft.item.Item)4 Vector3d (net.minecraft.util.math.vector.Vector3d)4 NotNull (org.jetbrains.annotations.NotNull)4 Overwrite (org.spongepowered.asm.mixin.Overwrite)4 ServerPlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge)3 CreeperEntity (net.minecraft.entity.monster.CreeperEntity)3 GhastEntity (net.minecraft.entity.monster.GhastEntity)3 AnimalEntity (net.minecraft.entity.passive.AnimalEntity)3 TameableEntity (net.minecraft.entity.passive.TameableEntity)3 AbstractHorseEntity (net.minecraft.entity.passive.horse.AbstractHorseEntity)3 DamagingProjectileEntity (net.minecraft.entity.projectile.DamagingProjectileEntity)3 BowItem (net.minecraft.item.BowItem)3 ICustomAttackSound (com.minecolonies.api.entity.ICustomAttackSound)2