LightningBoltEntity lightning = new LightningBoltEntity(EntityType.LIGHTNING_BOLT, this.getWorld());
lightning.setLocationAndAngles(this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), rng.nextFloat() * 360, 0);
if (this.getWorld().isThundering()) {
if (this.getWorld().getGameTime() % (350 - rng.nextInt(200)) == 0) {
this.getWorld().addEntity(lightning);
}
}
you first create a new LightningBoltEntity and after that you check if you need to, dont do that