Search in sources :

Example 1 with SnowballEntity

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

the class ProjectileEffectHelper method fireSnowballAtNearbyEnemy.

public static void fireSnowballAtNearbyEnemy(LivingEntity attacker, int distance) {
    World world = attacker.getEntityWorld();
    List<LivingEntity> nearbyEntities = world.getEntitiesByClass(LivingEntity.class, new Box(attacker.getX() - distance, attacker.getY() - distance, attacker.getZ() - distance, attacker.getX() + distance, attacker.getY() + distance, attacker.getZ() + distance), (nearbyEntity) -> AbilityHelper.isAoeTarget(nearbyEntity, attacker, attacker));
    if (nearbyEntities.size() < 2)
        return;
    nearbyEntities.sort(Comparator.comparingDouble(livingEntity -> livingEntity.squaredDistanceTo(attacker)));
    LivingEntity target = nearbyEntities.get(0);
    if (target != null) {
        SnowballEntity snowballEntity = new SnowballEntity(world, attacker);
        // borrowed from AbstractSkeletonEntity
        double towardsX = target.getX() - attacker.getX();
        double towardsZ = target.getZ() - attacker.getZ();
        double euclideanDist = (double) MathHelper.sqrt(towardsX * towardsX + towardsZ * towardsZ);
        double towardsY = target.getBodyY(0.3333333333333333D) - snowballEntity.getY() + euclideanDist * (double) 0.2F;
        snowballEntity.setProperties(attacker, attacker.pitch, attacker.yaw, 0.0F, 1.5F, 1.0F);
        setProjectileTowards(snowballEntity, towardsX, towardsY, towardsZ, 0);
        // 
        attacker.world.spawnEntity(snowballEntity);
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) World(net.minecraft.world.World) Box(net.minecraft.util.math.Box) SnowballEntity(net.minecraft.entity.projectile.thrown.SnowballEntity) PersistentProjectileEntity(net.minecraft.entity.projectile.PersistentProjectileEntity) Set(java.util.Set) net.minecraft.item(net.minecraft.item) Random(java.util.Random) EnchantmentHelper(net.minecraft.enchantment.EnchantmentHelper) ProjectileEntity(net.minecraft.entity.projectile.ProjectileEntity) Quaternion(net.minecraft.util.math.Quaternion) List(java.util.List) SoundEvents(net.minecraft.sound.SoundEvents) Vec3d(net.minecraft.util.math.Vec3d) MathHelper(net.minecraft.util.math.MathHelper) Vector3f(net.minecraft.client.util.math.Vector3f) MeleeRangedEnchantmentList(chronosacaria.mcdw.enchants.lists.MeleeRangedEnchantmentList) Comparator(java.util.Comparator) Box(net.minecraft.util.math.Box) World(net.minecraft.world.World) SnowballEntity(net.minecraft.entity.projectile.thrown.SnowballEntity)

Example 2 with SnowballEntity

use of net.minecraft.entity.projectile.thrown.SnowballEntity in project MCDungeonsArmors by chronosacaria.

the class ProjectileEffectHelper method fireSnowballAtNearbyEnemy.

public static void fireSnowballAtNearbyEnemy(LivingEntity user, int distance) {
    World world = user.getEntityWorld();
    List<LivingEntity> nearbyEntities = world.getEntitiesByClass(LivingEntity.class, new Box(user.getX() - distance, user.getY() - distance, user.getZ() - distance, user.getX() + distance, user.getY() + distance, user.getZ() + distance), (nearbyEntity) -> nearbyEntity != user && AbilityHelper.canFireAtEnemy(user, nearbyEntity));
    if (nearbyEntities.size() < 2)
        return;
    Optional<LivingEntity> nearest = nearbyEntities.stream().min(Comparator.comparingDouble(e -> e.squaredDistanceTo(user)));
    LivingEntity target = nearest.get();
    SnowballEntity snowballEntity = new SnowballEntity(world, user);
    // borrowed from AbstractSkeletonEntity
    double d = target.getX() - snowballEntity.getX();
    double e = target.getBodyY(0.3333333333333333D) - snowballEntity.getY();
    double f = target.getZ() - snowballEntity.getZ();
    double g = Math.sqrt(d * d + f * f);
    snowballEntity.setVelocity(user, user.getPitch(), user.getYaw(), 0.0F, 1.5F, 1.0F);
    setProjectileTowards(snowballEntity, d, e, g, 0);
    // 
    user.world.spawnEntity(snowballEntity);
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) Entity(net.minecraft.entity.Entity) LivingEntity(net.minecraft.entity.LivingEntity) World(net.minecraft.world.World) Box(net.minecraft.util.math.Box) SnowballEntity(net.minecraft.entity.projectile.thrown.SnowballEntity) PersistentProjectileEntity(net.minecraft.entity.projectile.PersistentProjectileEntity) Items(net.minecraft.item.Items) ArmorSets(chronosacaria.mcda.items.ArmorSets) ProjectileEntity(net.minecraft.entity.projectile.ProjectileEntity) Direction(net.minecraft.util.math.Direction) ItemStack(net.minecraft.item.ItemStack) List(java.util.List) Vec3d(net.minecraft.util.math.Vec3d) CleanlinessHelper.hasArmorSet(chronosacaria.mcda.api.CleanlinessHelper.hasArmorSet) MathHelper(net.minecraft.util.math.MathHelper) ShulkerBulletEntity(net.minecraft.entity.projectile.ShulkerBulletEntity) Optional(java.util.Optional) Mcda.random(chronosacaria.mcda.Mcda.random) Comparator(java.util.Comparator) Box(net.minecraft.util.math.Box) World(net.minecraft.world.World) SnowballEntity(net.minecraft.entity.projectile.thrown.SnowballEntity)

Example 3 with SnowballEntity

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

the class ProjectileSimulator method summonProjectile.

public static Entity summonProjectile(PlayerEntity thrower, boolean allowThrowables, boolean allowXp, boolean allowPotions) {
    ItemStack hand = (isThrowable(thrower.getInventory().getMainHandStack().getItem(), allowThrowables, allowXp, allowPotions) ? thrower.getInventory().getMainHandStack() : isThrowable(thrower.getInventory().offHand.get(0).getItem(), allowThrowables, allowXp, allowPotions) ? thrower.getInventory().offHand.get(0) : null);
    if (hand == null) {
        return null;
    }
    if (hand.getItem() instanceof RangedWeaponItem) {
        float charged = hand.getItem() == Items.CROSSBOW && CrossbowItem.isCharged(hand) ? 1f : hand.getItem() == Items.CROSSBOW ? 0f : BowItem.getPullProgress(thrower.getItemUseTime());
        if (charged > 0f) {
            Entity e = new ArrowEntity(mc.world, mc.player);
            initProjectile(e, thrower, 0f, charged * 3);
            return e;
        }
    } else if (hand.getItem() instanceof SnowballItem || hand.getItem() instanceof EggItem || hand.getItem() instanceof EnderPearlItem) {
        Entity e = new SnowballEntity(mc.world, mc.player);
        initProjectile(e, thrower, 0f, 1.5f);
        return e;
    } else if (hand.getItem() instanceof ExperienceBottleItem) {
        Entity e = new ExperienceBottleEntity(mc.world, mc.player);
        initProjectile(e, thrower, -20f, 0.7f);
        return e;
    } else if (hand.getItem() instanceof ThrowablePotionItem) {
        Entity e = new PotionEntity(mc.world, mc.player);
        initProjectile(e, thrower, -20f, 0.5f);
        return e;
    } else if (hand.getItem() instanceof TridentItem) {
        Entity e = new TridentEntity(mc.world, mc.player, hand);
        initProjectile(e, thrower, 0f, 2.5f);
        return e;
    }
    return null;
}
Also used : Entity(net.minecraft.entity.Entity) PotionEntity(net.minecraft.entity.projectile.thrown.PotionEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) SnowballEntity(net.minecraft.entity.projectile.thrown.SnowballEntity) TridentEntity(net.minecraft.entity.projectile.TridentEntity) ThrownEntity(net.minecraft.entity.projectile.thrown.ThrownEntity) ArrowEntity(net.minecraft.entity.projectile.ArrowEntity) ExperienceBottleEntity(net.minecraft.entity.projectile.thrown.ExperienceBottleEntity) ArrowEntity(net.minecraft.entity.projectile.ArrowEntity) PotionEntity(net.minecraft.entity.projectile.thrown.PotionEntity) ExperienceBottleEntity(net.minecraft.entity.projectile.thrown.ExperienceBottleEntity) TridentEntity(net.minecraft.entity.projectile.TridentEntity) SnowballEntity(net.minecraft.entity.projectile.thrown.SnowballEntity)

Example 4 with SnowballEntity

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

the class Trajectories method onTick.

@BleachSubscribe
public void onTick(EventTick event) {
    poses.clear();
    Entity entity = ProjectileSimulator.summonProjectile(mc.player, getSetting(1).asToggle().getState(), getSetting(2).asToggle().getState(), getSetting(3).asToggle().getState());
    if (entity != null) {
        poses.add(ProjectileSimulator.simulate(entity));
    }
    if (getSetting(4).asToggle().getState()) {
        for (Entity e : mc.world.getEntities()) {
            if (e instanceof ThrownEntity || e instanceof PersistentProjectileEntity) {
                if (!getSetting(4).asToggle().getChild(0).asToggle().getState() && (e instanceof SnowballEntity || e instanceof EggEntity || e instanceof EnderPearlEntity)) {
                    continue;
                }
                if (!getSetting(4).asToggle().getChild(1).asToggle().getState() && e instanceof ExperienceBottleEntity) {
                    continue;
                }
                if (!mc.world.getBlockCollisions(e, e.getBoundingBox()).allMatch(VoxelShape::isEmpty))
                    continue;
                Triple<List<Vec3d>, Entity, BlockPos> p = ProjectileSimulator.simulate(e);
                if (p.getLeft().size() >= 2)
                    poses.add(p);
            }
        }
    }
    if (getSetting(5).asToggle().getState()) {
        for (PlayerEntity e : mc.world.getPlayers()) {
            if (e == mc.player)
                continue;
            Entity proj = ProjectileSimulator.summonProjectile(e, getSetting(1).asToggle().getState(), getSetting(2).asToggle().getState(), getSetting(3).asToggle().getState());
            if (proj != null) {
                poses.add(ProjectileSimulator.simulate(proj));
            }
        }
    }
}
Also used : EnderPearlEntity(net.minecraft.entity.projectile.thrown.EnderPearlEntity) PersistentProjectileEntity(net.minecraft.entity.projectile.PersistentProjectileEntity) ThrownEntity(net.minecraft.entity.projectile.thrown.ThrownEntity) ExperienceBottleEntity(net.minecraft.entity.projectile.thrown.ExperienceBottleEntity) EggEntity(net.minecraft.entity.projectile.thrown.EggEntity) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) SnowballEntity(net.minecraft.entity.projectile.thrown.SnowballEntity) EnderPearlEntity(net.minecraft.entity.projectile.thrown.EnderPearlEntity) ThrownEntity(net.minecraft.entity.projectile.thrown.ThrownEntity) PersistentProjectileEntity(net.minecraft.entity.projectile.PersistentProjectileEntity) EggEntity(net.minecraft.entity.projectile.thrown.EggEntity) ExperienceBottleEntity(net.minecraft.entity.projectile.thrown.ExperienceBottleEntity) ArrayList(java.util.ArrayList) List(java.util.List) BlockPos(net.minecraft.util.math.BlockPos) SnowballEntity(net.minecraft.entity.projectile.thrown.SnowballEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe)

Example 5 with SnowballEntity

use of net.minecraft.entity.projectile.thrown.SnowballEntity in project LittleMaidReBirth-Fabric by SistrScarlet.

the class LittleMaidEntity method damage.

@Override
public boolean damage(DamageSource source, float amount) {
    if (!world.isClient) {
        // 味方のが当たってもちゃんと動くようにフレンド判定より前
        if (amount <= 0 && source.getSource() instanceof SnowballEntity) {
            play(LMSounds.HURT_SNOW);
            return false;
        }
    }
    Entity attacker = source.getAttacker();
    // Friendからの攻撃を除外
    if (attacker instanceof LivingEntity && isFriend((LivingEntity) attacker)) {
        return false;
    }
    boolean isHurtTime = 0 < this.hurtTime;
    boolean result = super.damage(source, amount);
    if (!world.isClient && !isHurtTime) {
        if (!result || amount <= 0F) {
            play(LMSounds.HURT_NO_DAMAGE);
        } else if (amount > 0F && ((LivingAccessor) this).blockedByShield_LM(source)) {
            play(LMSounds.HURT_GUARD);
        } else if (source == DamageSource.FALL) {
            play(LMSounds.HURT_FALL);
        } else if (source.isFire()) {
            play(LMSounds.HURT_FIRE);
        } else {
            play(LMSounds.HURT);
        }
    }
    return result;
}
Also used : CustomPacketEntity(net.sistr.lmml.network.util.CustomPacketEntity) PassiveEntity(net.minecraft.entity.passive.PassiveEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) TameableEntity(net.minecraft.entity.passive.TameableEntity) SnowballEntity(net.minecraft.entity.projectile.thrown.SnowballEntity) LivingAccessor(net.sistr.littlemaidrebirth.util.LivingAccessor) SnowballEntity(net.minecraft.entity.projectile.thrown.SnowballEntity)

Aggregations

SnowballEntity (net.minecraft.entity.projectile.thrown.SnowballEntity)5 PlayerEntity (net.minecraft.entity.player.PlayerEntity)4 List (java.util.List)3 Entity (net.minecraft.entity.Entity)3 LivingEntity (net.minecraft.entity.LivingEntity)3 PersistentProjectileEntity (net.minecraft.entity.projectile.PersistentProjectileEntity)3 Comparator (java.util.Comparator)2 ProjectileEntity (net.minecraft.entity.projectile.ProjectileEntity)2 ExperienceBottleEntity (net.minecraft.entity.projectile.thrown.ExperienceBottleEntity)2 ThrownEntity (net.minecraft.entity.projectile.thrown.ThrownEntity)2 Box (net.minecraft.util.math.Box)2 MathHelper (net.minecraft.util.math.MathHelper)2 Vec3d (net.minecraft.util.math.Vec3d)2 World (net.minecraft.world.World)2 Mcda.random (chronosacaria.mcda.Mcda.random)1 CleanlinessHelper.hasArmorSet (chronosacaria.mcda.api.CleanlinessHelper.hasArmorSet)1 ArmorSets (chronosacaria.mcda.items.ArmorSets)1 MeleeRangedEnchantmentList (chronosacaria.mcdw.enchants.lists.MeleeRangedEnchantmentList)1 ArrayList (java.util.ArrayList)1 Optional (java.util.Optional)1