Search in sources :

Example 1 with ArrowEntity

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

the class EntityAIArcherTraining method shoot.

/**
 * The ranged attack modus
 *
 * @return the next state to go to.
 */
protected IAIState shoot() {
    if (currentShootingTarget == null || !isSetup()) {
        worker.getCitizenData().setVisibleStatus(VisibleCitizenStatus.WORKING);
        return START_WORKING;
    }
    if (worker.isUsingItem()) {
        WorkerUtil.faceBlock(currentShootingTarget, worker);
        worker.swing(Hand.MAIN_HAND);
        final ArrowEntity arrow = ModEntities.MC_NORMAL_ARROW.create(world);
        arrow.setBaseDamage(0);
        arrow.setOwner(worker);
        arrow.setPos(worker.getX(), worker.getY() + 1, worker.getZ());
        final double xVector = currentShootingTarget.getX() - worker.getX();
        final double yVector = currentShootingTarget.getY() - arrow.getY();
        final double zVector = currentShootingTarget.getZ() - worker.getZ();
        final double distance = (double) MathHelper.sqrt(xVector * xVector + zVector * zVector);
        final double chance = HIT_CHANCE_DIVIDER / (getPrimarySkillLevel() / 2.0 + 1);
        arrow.shoot(xVector, yVector + distance * RANGED_AIM_SLIGHTLY_HIGHER_MULTIPLIER, zVector, RANGED_VELOCITY, (float) chance);
        worker.playSound(SoundEvents.SKELETON_SHOOT, (float) BASIC_VOLUME, (float) SoundUtils.getRandomPitch(worker.getRandom()));
        worker.level.addFreshEntity(arrow);
        final double xDiff = currentShootingTarget.getX() - worker.getX();
        final double zDiff = currentShootingTarget.getZ() - worker.getZ();
        final double goToX = xDiff > 0 ? MOVE_MINIMAL : -MOVE_MINIMAL;
        final double goToZ = zDiff > 0 ? MOVE_MINIMAL : -MOVE_MINIMAL;
        worker.move(MoverType.SELF, new Vector3d(goToX, 0, goToZ));
        if (worker.getRandom().nextBoolean()) {
            worker.getCitizenItemHandler().damageItemInHand(Hand.MAIN_HAND, 1);
        }
        worker.stopUsingItem();
        this.incrementActionsDoneAndDecSaturation();
        arrowInProgress = arrow;
        currentAttackDelay = RANGED_ATTACK_DELAY_BASE;
    } else {
        reduceAttackDelay();
        if (currentAttackDelay <= 0) {
            worker.startUsingItem(Hand.MAIN_HAND);
        }
        return ARCHER_SHOOT;
    }
    return ARCHER_CHECK_SHOT;
}
Also used : Vector3d(net.minecraft.util.math.vector.Vector3d) ArrowEntity(net.minecraft.entity.projectile.ArrowEntity)

Example 2 with ArrowEntity

use of net.minecraft.entity.projectile.ArrowEntity in project BleachHack by BleachDrinker420.

the class ArrowJuke method onTick.

@BleachSubscribe
public void onTick(EventTick envent) {
    for (Entity e : mc.world.getEntities()) {
        if (e.age > 75 || !(e instanceof ArrowEntity) || ((ArrowEntity) e).getOwner() == mc.player)
            continue;
        int mode = getSetting(0).asMode().getMode();
        int steps = getSetting(2).asSlider().getValueInt();
        Box playerBox = mc.player.getBoundingBox().expand(0.3);
        List<Box> futureBoxes = new ArrayList<>(steps);
        Box currentBox = e.getBoundingBox();
        Vec3d currentVel = e.getVelocity();
        for (int i = 0; i < steps; i++) {
            currentBox = currentBox.offset(currentVel);
            currentVel = currentVel.multiply(0.99, 0.94, 0.99);
            futureBoxes.add(currentBox);
            if (!mc.world.getOtherEntities(null, currentBox).isEmpty() || WorldUtils.doesBoxCollide(currentBox)) {
                break;
            }
        }
        for (Box box : futureBoxes) {
            if (playerBox.intersects(box)) {
                for (Vec3d vel : getMoveVecs(e.getVelocity())) {
                    Box newBox = mc.player.getBoundingBox().offset(vel);
                    if (!WorldUtils.doesBoxCollide(newBox) && futureBoxes.stream().noneMatch(playerBox.offset(vel)::intersects)) {
                        if (mode == 0 && vel.y == 0) {
                            mc.player.setVelocity(vel);
                        } else {
                            mc.player.updatePosition(mc.player.getX() + vel.x, mc.player.getY() + vel.y, mc.player.getZ() + vel.z);
                            mc.player.networkHandler.sendPacket(new PlayerMoveC2SPacket.PositionAndOnGround(mc.player.getX(), mc.player.getY(), mc.player.getZ(), false));
                        }
                        return;
                    }
                }
            }
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) ArrowEntity(net.minecraft.entity.projectile.ArrowEntity) ArrowEntity(net.minecraft.entity.projectile.ArrowEntity) ArrayList(java.util.ArrayList) PlayerMoveC2SPacket(net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket) Box(net.minecraft.util.math.Box) Vec3d(net.minecraft.util.math.Vec3d) BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe)

Example 3 with ArrowEntity

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

the class PoiseClusterBlock method onProjectileHit.

@Override
public void onProjectileHit(World world, BlockState state, BlockRayTraceResult hit, ProjectileEntity projectile) {
    BlockPos pos = hit.getBlockPos();
    if (world.isEmptyBlock(pos.above()) && world.getEntitiesOfClass(PoiseClusterEntity.class, new AxisAlignedBB(pos.above())).isEmpty()) {
        if (!world.isClientSide) {
            PoiseClusterEntity cluster = new PoiseClusterEntity(world, pos, pos.getX(), pos.getY(), pos.getZ());
            cluster.setBlocksToMoveUp(10);
            world.addFreshEntity(cluster);
            if (projectile instanceof ArrowEntity) {
                projectile.remove();
            }
            world.setBlock(pos, Blocks.AIR.defaultBlockState(), 2);
            world.playSound(null, pos, EESounds.CLUSTER_BREAK.get(), SoundCategory.BLOCKS, 0.90F, 0.75F);
            Random rand = new Random();
            for (int i = 0; i < 8; i++) {
                double offsetX = MathUtil.makeNegativeRandomly(rand.nextFloat() * 0.25F, rand);
                double offsetZ = MathUtil.makeNegativeRandomly(rand.nextFloat() * 0.25F, rand);
                double x = pos.getX() + 0.5D + offsetX;
                double y = pos.getY() + 0.5D + (rand.nextFloat() * 0.05F);
                double z = pos.getZ() + 0.5D + offsetZ;
                NetworkUtil.spawnParticle("endergetic:short_poise_bubble", x, y, z, MathUtil.makeNegativeRandomly((rand.nextFloat() * 0.1F), rand) + 0.025F, (rand.nextFloat() * 0.15F) + 0.1F, MathUtil.makeNegativeRandomly((rand.nextFloat() * 0.1F), rand) + 0.025F);
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) PoiseClusterEntity(com.minecraftabnormals.endergetic.common.entities.PoiseClusterEntity) Random(java.util.Random) ArrowEntity(net.minecraft.entity.projectile.ArrowEntity) BlockPos(net.minecraft.util.math.BlockPos)

Example 4 with ArrowEntity

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

the class ChainsEnchantmentMixin method applyChainsEnchantment.

@Inject(method = "applyDamage(Lnet/minecraft/entity/damage/DamageSource;F)V", at = @At("HEAD"))
public void applyChainsEnchantment(DamageSource source, float amount, CallbackInfo info) {
    if (source.getSource() instanceof ArrowEntity) {
        return;
    }
    if (!(source.getAttacker() instanceof PlayerEntity))
        return;
    LivingEntity user = (LivingEntity) source.getAttacker();
    LivingEntity target = (LivingEntity) (Object) this;
    if (source.getSource() instanceof LivingEntity && !source.isProjectile()) {
        if (amount != 0.0F) {
            ItemStack mainHandStack = null;
            if (user != null) {
                mainHandStack = user.getMainHandStack();
            }
            boolean uniqueWeaponFlag = false;
            if (McdwEnchantsConfig.getValue("chains")) {
                if (mainHandStack != null && (EnchantmentHelper.getLevel(EnchantsRegistry.CHAINS, mainHandStack) >= 1)) {
                    int level = EnchantmentHelper.getLevel(EnchantsRegistry.CHAINS, mainHandStack);
                    float chance = user.getRandom().nextFloat();
                    if (chance <= 0.2f) {
                        AOEHelper.chainNearbyEntities(user, target, 1.5F * level, level);
                    }
                }
            }
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) ArrowEntity(net.minecraft.entity.projectile.ArrowEntity) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 5 with ArrowEntity

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

the class CommittedEnchantmentsMixin method applyCommittedEnchantmentDamage.

@Inject(method = "applyDamage(Lnet/minecraft/entity/damage/DamageSource;F)V", at = @At("HEAD"))
public void applyCommittedEnchantmentDamage(DamageSource source, float amount, CallbackInfo info) {
    if (!(source.getAttacker() instanceof PlayerEntity))
        return;
    LivingEntity user = (LivingEntity) source.getAttacker();
    LivingEntity target = (LivingEntity) (Object) this;
    if (source.isProjectile())
        return;
    if (source.getSource() instanceof ArrowEntity)
        return;
    if (source.getSource() instanceof PlayerEntity) {
        if (amount != 0.0F) {
            ItemStack mainHandStack = null;
            if (user != null) {
                mainHandStack = user.getMainHandStack();
            }
            if (mainHandStack != null && (EnchantmentHelper.getLevel(EnchantsRegistry.COMMITTED, mainHandStack) >= 1)) {
                int level = EnchantmentHelper.getLevel(EnchantsRegistry.COMMITTED, mainHandStack);
                float getTargetHealth = target.getHealth();
                float getTargetMaxHealth = target.getMaxHealth();
                float getTargetRemainingHealth = getTargetHealth / getTargetMaxHealth;
                float getOriginalDamage = (float) user.getAttributeValue(EntityAttributes.GENERIC_ATTACK_DAMAGE);
                float extraDamageMultiplier = 0.1F + level * 0.1F;
                float getExtraDamage = (getOriginalDamage * (1 - getTargetRemainingHealth) * extraDamageMultiplier);
                float chance = user.getRandom().nextFloat();
                if (chance <= 0.2) {
                    if ((Math.abs(getTargetHealth)) < (Math.abs(getTargetMaxHealth))) {
                        target.setHealth(getTargetHealth - (amount * getExtraDamage));
                        target.world.playSound(null, target.getX(), target.getY(), target.getZ(), SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.PLAYERS, 0.5F, 1.0F);
                    }
                }
            }
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) ArrowEntity(net.minecraft.entity.projectile.ArrowEntity) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

ArrowEntity (net.minecraft.entity.projectile.ArrowEntity)8 LivingEntity (net.minecraft.entity.LivingEntity)4 Entity (net.minecraft.entity.Entity)3 PlayerEntity (net.minecraft.entity.player.PlayerEntity)3 Vector3d (net.minecraft.util.math.vector.Vector3d)3 ItemStack (net.minecraft.item.ItemStack)2 Inject (org.spongepowered.asm.mixin.injection.Inject)2 BreakerData (com.fredtargaryen.fragileglass.config.behaviour.data.BreakerData)1 IBreakCapability (com.fredtargaryen.fragileglass.entity.capability.IBreakCapability)1 PoiseClusterEntity (com.minecraftabnormals.endergetic.common.entities.PoiseClusterEntity)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 BoatEntity (net.minecraft.entity.item.BoatEntity)1 FallingBlockEntity (net.minecraft.entity.item.FallingBlockEntity)1 TNTEntity (net.minecraft.entity.item.TNTEntity)1 MinecartEntity (net.minecraft.entity.item.minecart.MinecartEntity)1 FireballEntity (net.minecraft.entity.projectile.FireballEntity)1 FireworkRocketEntity (net.minecraft.entity.projectile.FireworkRocketEntity)1