| 1 | package net.minecraft.world.entity.projectile.hurtingprojectile;
|
| 2 |
|
| 3 | import java.util.List;
|
| 4 | import net.minecraft.core.particles.ParticleOptions;
|
| 5 | import net.minecraft.core.particles.ParticleTypes;
|
| 6 | import net.minecraft.core.particles.PowerParticleOption;
|
| 7 | import net.minecraft.world.effect.MobEffectInstance;
|
| 8 | import net.minecraft.world.effect.MobEffects;
|
| 9 | import net.minecraft.world.entity.AreaEffectCloud;
|
| 10 | import net.minecraft.world.entity.EntityType;
|
| 11 | import net.minecraft.world.entity.EntityTypes;
|
| 12 | import net.minecraft.world.entity.LivingEntity;
|
| 13 | import net.minecraft.world.level.Level;
|
| 14 | import net.minecraft.world.phys.EntityHitResult;
|
| 15 | import net.minecraft.world.phys.HitResult;
|
| 16 | import net.minecraft.world.phys.Vec3;
|
| 17 |
|
| 18 | public class DragonFireball extends AbstractHurtingProjectile {
|
| 19 | public static final float SPLASH_RANGE = 4.0F;
|
| 20 |
|
| 21 | public DragonFireball(final EntityType<? extends DragonFireball> type, final Level level) {
|
| 22 | super(type, level);
|
| 23 | }
|
| 24 |
|
| 25 | public DragonFireball(final Level level, final LivingEntity mob, final Vec3 direction) {
|
| 26 | super(EntityTypes.DRAGON_FIREBALL, mob, direction, level);
|
| 27 | }
|
| 28 |
|
| 29 | @Override
|
| 30 | protected void onHit(final HitResult hitResult) {
|
| 31 | super.onHit(hitResult);
|
| 32 | if (hitResult.getType() != HitResult.Type.ENTITY || !this.ownedBy(((EntityHitResult)hitResult).getEntity())) {
|
| 33 | if (!this.level().isClientSide()) {
|
| 34 | List<LivingEntity> entitiesOfClass = this.level().getEntitiesOfClass(LivingEntity.class, this.getBoundingBox().inflate(4.0, 2.0, 4.0));
|
| 35 | AreaEffectCloud cloud = new AreaEffectCloud(this.level(), this.getX(), this.getY(), this.getZ());
|
| 36 | if (this.getOwner() instanceof LivingEntity livingEntity) {
|
| 37 | cloud.setOwner(livingEntity);
|
| 38 | }
|
| 39 |
|
| 40 | cloud.setCustomParticle(PowerParticleOption.create(ParticleTypes.DRAGON_BREATH, 1.0F));
|
| 41 | cloud.setRadius(3.0F);
|
| 42 | cloud.setDuration(600);
|
| 43 | cloud.setRadiusPerTick((7.0F - cloud.getRadius()) / cloud.getDuration());
|
| 44 | cloud.setPotionDurationScale(0.25F);
|
| 45 | cloud.addEffect(new MobEffectInstance(MobEffects.INSTANT_DAMAGE, 1, 1));
|
| 46 | if (!entitiesOfClass.isEmpty()) {
|
| 47 | for (LivingEntity entity : entitiesOfClass) {
|
| 48 | double dist = this.distanceToSqr(entity);
|
| 49 | if (dist < 16.0) {
|
| 50 | cloud.setPos(entity.getX(), entity.getY(), entity.getZ());
|
| 51 | break;
|
| 52 | }
|
| 53 | }
|
| 54 | }
|
| 55 |
|
| 56 | this.level().levelEvent(2006, this.blockPosition(), this.isSilent() ? -1 : 1);
|
| 57 | this.level().addFreshEntity(cloud);
|
| 58 | this.discard();
|
| 59 | }
|
| 60 | }
|
| 61 | }
|
| 62 |
|
| 63 | @Override
|
| 64 | protected ParticleOptions getTrailParticle() {
|
| 65 | return PowerParticleOption.create(ParticleTypes.DRAGON_BREATH, 1.0F);
|
| 66 | }
|
| 67 |
|
| 68 | @Override
|
| 69 | protected boolean shouldBurn() {
|
| 70 | return false;
|
| 71 | }
|
| 72 | }
|
| 73 |
|