Search in sources :

Example 1 with LightningEntity

use of net.minecraft.entity.LightningEntity in project Therrassium by codeman1o1.

the class Smited method onTargetDamaged.

@Override
public void onTargetDamaged(LivingEntity user, Entity target, int level) {
    if (!user.world.isClient) {
        if (target instanceof LivingEntity) {
            LightningEntity lightningEntity = (LightningEntity) EntityType.LIGHTNING_BOLT.create(target.world);
            lightningEntity.refreshPositionAfterTeleport(Vec3d.ofBottomCenter(target.getBlockPos()));
            target.world.spawnEntity(lightningEntity);
        }
    }
    super.onTargetDamaged(user, target, level);
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) LightningEntity(net.minecraft.entity.LightningEntity)

Example 2 with LightningEntity

use of net.minecraft.entity.LightningEntity in project bewitchment by MoriyaShiine.

the class SpawnLightningRitualFunction method summonLightning.

private void summonLightning(World world, BlockPos pos) {
    LightningEntity entity = EntityType.LIGHTNING_BOLT.create(world);
    if (entity != null) {
        entity.updatePositionAndAngles(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, world.random.nextFloat() * 360, 0);
        world.spawnEntity(entity);
    }
}
Also used : LightningEntity(net.minecraft.entity.LightningEntity)

Example 3 with LightningEntity

use of net.minecraft.entity.LightningEntity in project Biome-Makeover by Lemonszz.

the class LightningBottleEntity method onCollision.

protected void onCollision(HitResult hitResult) {
    super.onCollision(hitResult);
    NetworkUtil.doLightningSplash(world, true, getBlockPos());
    if (!this.world.isClient) {
        world.playSound(null, getBlockPos(), BMEffects.BOTTLE_THUNDER, SoundCategory.NEUTRAL, 50F, 0.8F + this.random.nextFloat() * 0.2F);
        Box box = this.getBoundingBox().expand(4.0D, 2.0D, 4.0D);
        List<LivingEntity> entities = this.world.getEntitiesByClass(LivingEntity.class, box, EntityPredicates.VALID_LIVING_ENTITY);
        if (!entities.isEmpty()) {
            Iterator<LivingEntity> iterator = entities.iterator();
            while (iterator.hasNext()) {
                LivingEntity e = iterator.next();
                double distance = this.squaredDistanceTo(e);
                if (distance < 16.0D) {
                    int fireTicks = e.getFireTicks();
                    boolean isInvul = e.isInvulnerable();
                    LightningEntity dummyLightning = new LightningEntity(EntityType.LIGHTNING_BOLT, world);
                    dummyLightning.setPos(e.getX(), e.getY(), e.getZ());
                    e.setInvulnerable(true);
                    e.onStruckByLightning((ServerWorld) world, dummyLightning);
                    e.setFireTicks(fireTicks);
                    e.setInvulnerable(isInvul);
                    dummyLightning.remove();
                }
            }
        }
        // Loop through again to grab transformed entities for damage & effect
        entities = this.world.getEntitiesByClass(LivingEntity.class, box, EntityPredicates.VALID_LIVING_ENTITY);
        if (!entities.isEmpty()) {
            Iterator<LivingEntity> iterator = entities.iterator();
            while (iterator.hasNext()) {
                LivingEntity e = iterator.next();
                double distance = this.squaredDistanceTo(e);
                if (distance < 16.0D) {
                    NetworkUtil.doLightningEntity(world, e, 100);
                    if (!e.hasStatusEffect(BMPotions.SHOCKED)) {
                        e.addStatusEffect(new StatusEffectInstance(BMPotions.SHOCKED, 1000, 0));
                    } else {
                        e.addStatusEffect(new StatusEffectInstance(BMPotions.SHOCKED, 1000, Math.min(3, e.getStatusEffect(BMPotions.SHOCKED).getAmplifier() + 1)));
                    }
                    e.damage(DamageSource.magic(this, this.getOwner()), 0);
                    if (getOwner() instanceof LivingEntity) {
                        e.setAttacker((LivingEntity) getOwner());
                    }
                    if (e.getHealth() > e.getMaxHealth())
                        e.setHealth(e.getMaxHealth());
                }
            }
        }
        this.remove();
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) StatusEffectInstance(net.minecraft.entity.effect.StatusEffectInstance) LightningEntity(net.minecraft.entity.LightningEntity) Box(net.minecraft.util.math.Box)

Example 4 with LightningEntity

use of net.minecraft.entity.LightningEntity in project Biome-Makeover by Lemonszz.

the class ConductivityCurseEnchantment method onTick.

@Override
public void onTick(LivingEntity entity, ItemStack stack, int level) {
    ServerWorld world = (ServerWorld) entity.world;
    Random random = world.random;
    if (random.nextInt(11000 - (level * 1000)) == 0 && world.isThundering()) {
        BlockPos pos = entity.getBlockPos();
        if (world.hasRain(pos)) {
            LightningEntity lightningEntity = EntityType.LIGHTNING_BOLT.create(world);
            lightningEntity.refreshPositionAfterTeleport(Vec3d.ofBottomCenter(pos));
            world.spawnEntity(lightningEntity);
        }
    }
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) Random(java.util.Random) LightningEntity(net.minecraft.entity.LightningEntity) BlockPos(net.minecraft.util.math.BlockPos)

Example 5 with LightningEntity

use of net.minecraft.entity.LightningEntity in project Neutrino by FrostWizard4.

the class LightningRodArtifact method summonLightning.

public void summonLightning(PlayerEntity playerEntity, World world) {
    for (Entity e : world.getOtherEntities(playerEntity, Box.of(playerEntity.getPos(), 10, 10, 10))) {
        if (e instanceof MobEntity && (playerEntity.distanceTo(e) < 10)) {
            LightningEntity lightningEntity = new LightningEntity(EntityType.LIGHTNING_BOLT, world);
            lightningEntity.setPos(e.getX(), e.getY(), e.getZ());
            world.spawnEntity(lightningEntity);
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) MobEntity(net.minecraft.entity.mob.MobEntity) LightningEntity(net.minecraft.entity.LightningEntity) LightningEntity(net.minecraft.entity.LightningEntity) MobEntity(net.minecraft.entity.mob.MobEntity)

Aggregations

LightningEntity (net.minecraft.entity.LightningEntity)7 LivingEntity (net.minecraft.entity.LivingEntity)2 Random (java.util.Random)1 Entity (net.minecraft.entity.Entity)1 StatusEffectInstance (net.minecraft.entity.effect.StatusEffectInstance)1 MobEntity (net.minecraft.entity.mob.MobEntity)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)1 ServerWorld (net.minecraft.server.world.ServerWorld)1 BlockPos (net.minecraft.util.math.BlockPos)1 Box (net.minecraft.util.math.Box)1