-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
217 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/main/java/io/redspace/ironsspellbooks/effect/ThunderstormEffect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package io.redspace.ironsspellbooks.effect; | ||
|
||
import io.redspace.ironsspellbooks.api.registry.SpellRegistry; | ||
import io.redspace.ironsspellbooks.api.util.Utils; | ||
import io.redspace.ironsspellbooks.capabilities.magic.MagicManager; | ||
import io.redspace.ironsspellbooks.damage.DamageSources; | ||
import io.redspace.ironsspellbooks.damage.ISpellDamageSource; | ||
import io.redspace.ironsspellbooks.entity.spells.EchoingStrikeEntity; | ||
import io.redspace.ironsspellbooks.entity.spells.LightningStrike; | ||
import io.redspace.ironsspellbooks.registries.MobEffectRegistry; | ||
import io.redspace.ironsspellbooks.util.ParticleHelper; | ||
import net.minecraft.world.effect.MobEffectCategory; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.phys.Vec3; | ||
import net.minecraftforge.event.entity.living.LivingHurtEvent; | ||
import net.minecraftforge.eventbus.api.SubscribeEvent; | ||
import net.minecraftforge.fml.common.Mod; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
@Mod.EventBusSubscriber | ||
public class ThunderstormEffect extends MagicMobEffect { | ||
public ThunderstormEffect(MobEffectCategory pCategory, int pColor) { | ||
super(pCategory, pColor); | ||
} | ||
|
||
@Override | ||
public boolean isDurationEffectTick(int pDuration, int pAmplifier) { | ||
return pDuration % 40 == 0; | ||
} | ||
|
||
@Override | ||
public void applyEffectTick(LivingEntity entity, int pAmplifier) { | ||
var radiusSqr = 400; //20 | ||
entity.level.getEntitiesOfClass(LivingEntity.class, entity.getBoundingBox().inflate(20, 12, 20), | ||
livingEntity -> livingEntity != entity && | ||
horizontalDistanceSqr(livingEntity, entity) < radiusSqr && | ||
livingEntity.isPickable() && | ||
!livingEntity.isSpectator() && | ||
!DamageSources.isFriendlyFireBetween(livingEntity, entity) && | ||
Utils.hasLineOfSight(entity.level, entity, livingEntity, false) | ||
) | ||
.forEach(targetEntity -> { | ||
LightningStrike lightningStrike = new LightningStrike(entity.level); | ||
lightningStrike.setOwner(entity); | ||
lightningStrike.setDamage(getDamageFromAmplifier(pAmplifier, entity)); | ||
lightningStrike.setPos(targetEntity.position()); | ||
entity.level.addFreshEntity(lightningStrike); | ||
}); | ||
} | ||
|
||
private float horizontalDistanceSqr(LivingEntity livingEntity, LivingEntity entity2) { | ||
var dx = livingEntity.getX() - entity2.getX(); | ||
var dz = livingEntity.getZ() - entity2.getZ(); | ||
return (float) (dx * dx + dz * dz); | ||
} | ||
|
||
public static float getDamageFromAmplifier(int effectAmplifier, @Nullable LivingEntity caster) { | ||
var power = caster == null ? 1 : SpellRegistry.THUNDERSTORM_SPELL.get().getEntityPowerMultiplier(caster); | ||
return (((effectAmplifier - 7) * power) + 7); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/main/java/io/redspace/ironsspellbooks/spells/lightning/ThunderstormSpell.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package io.redspace.ironsspellbooks.spells.lightning; | ||
|
||
import com.mojang.math.Vector3f; | ||
import io.redspace.ironsspellbooks.IronsSpellbooks; | ||
import io.redspace.ironsspellbooks.api.config.DefaultConfig; | ||
import io.redspace.ironsspellbooks.api.magic.MagicData; | ||
import io.redspace.ironsspellbooks.api.registry.SchoolRegistry; | ||
import io.redspace.ironsspellbooks.api.spells.*; | ||
import io.redspace.ironsspellbooks.api.util.AnimationHolder; | ||
import io.redspace.ironsspellbooks.api.util.CameraShakeData; | ||
import io.redspace.ironsspellbooks.api.util.CameraShakeManager; | ||
import io.redspace.ironsspellbooks.api.util.Utils; | ||
import io.redspace.ironsspellbooks.capabilities.magic.MagicManager; | ||
import io.redspace.ironsspellbooks.damage.DamageSources; | ||
import io.redspace.ironsspellbooks.effect.ThunderstormEffect; | ||
import io.redspace.ironsspellbooks.particle.BlastwaveParticleOptions; | ||
import io.redspace.ironsspellbooks.particle.ZapParticleOption; | ||
import io.redspace.ironsspellbooks.registries.MobEffectRegistry; | ||
import io.redspace.ironsspellbooks.registries.SoundRegistry; | ||
import io.redspace.ironsspellbooks.util.ParticleHelper; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.network.chat.MutableComponent; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.sounds.SoundEvent; | ||
import net.minecraft.world.effect.MobEffectInstance; | ||
import net.minecraft.world.entity.Entity; | ||
import net.minecraft.world.entity.EntityType; | ||
import net.minecraft.world.entity.LightningBolt; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.entity.monster.Creeper; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.phys.Vec3; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@AutoSpellConfig | ||
public class ThunderstormSpell extends AbstractSpell { | ||
private final ResourceLocation spellId = new ResourceLocation(IronsSpellbooks.MODID, "thunderstorm"); | ||
|
||
@Override | ||
public List<MutableComponent> getUniqueInfo(int spellLevel, LivingEntity caster) { | ||
return List.of( | ||
Component.translatable("ui.irons_spellbooks.damage", Utils.stringTruncation(ThunderstormEffect.getDamageFromAmplifier(getAmplifierForLevel(spellLevel, caster), caster), 2)), | ||
Component.translatable("ui.irons_spellbooks.radius", 20), | ||
Component.translatable("ui.irons_spellbooks.effect_length", Utils.timeFromTicks(getDurationTicks(spellLevel, caster), 1)) | ||
); | ||
} | ||
|
||
private final DefaultConfig defaultConfig = new DefaultConfig() | ||
.setMinRarity(SpellRarity.RARE) | ||
.setSchoolResource(SchoolRegistry.LIGHTNING_RESOURCE) | ||
.setMaxLevel(8) | ||
.setCooldownSeconds(120) | ||
.build(); | ||
|
||
public ThunderstormSpell() { | ||
this.manaCostPerLevel = 10; | ||
this.baseSpellPower = 8; | ||
this.spellPowerPerLevel = 1; | ||
this.castTime = 40; | ||
this.baseManaCost = 70; | ||
} | ||
|
||
@Override | ||
public CastType getCastType() { | ||
return CastType.LONG; | ||
} | ||
|
||
@Override | ||
public DefaultConfig getDefaultConfig() { | ||
return defaultConfig; | ||
} | ||
|
||
@Override | ||
public ResourceLocation getSpellResource() { | ||
return spellId; | ||
} | ||
|
||
@Override | ||
public Optional<SoundEvent> getCastStartSound() { | ||
return Optional.of(SoundRegistry.THUNDERSTORM_PREPARE.get()); | ||
} | ||
|
||
@Override | ||
public void onCast(Level level, int spellLevel, LivingEntity entity, CastSource castSource, MagicData playerMagicData) { | ||
entity.addEffect(new MobEffectInstance(MobEffectRegistry.THUNDERSTORM.get(), getDurationTicks(spellLevel, entity), getAmplifierForLevel(spellLevel, entity), false, false, true)); | ||
super.onCast(level, spellLevel, entity, castSource, playerMagicData); | ||
} | ||
|
||
private int getAmplifierForLevel(int spellLevel, LivingEntity caster) { | ||
return 8 + (int) ((spellLevel - 1) * getEntityPowerMultiplier(caster)); | ||
} | ||
|
||
public int getDurationTicks(int spellLevel, LivingEntity caster) { | ||
return (int) ((20 + (2 * (spellLevel - 1) * getEntityPowerMultiplier(caster))) * 20); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+18.4 KB
src/main/resources/assets/irons_spellbooks/sounds/small_lightning.ogg
Binary file not shown.
Binary file added
BIN
+28.1 KB
src/main/resources/assets/irons_spellbooks/sounds/thunderstorm_prepare.ogg
Binary file not shown.