From 8e65a265f90654b0d254f16b1e53ddc8536962f2 Mon Sep 17 00:00:00 2001 From: Sollace Date: Wed, 14 Sep 2022 11:45:19 +0200 Subject: [PATCH] Change spell constructors to use CustomisedSpellType --- .../magic/spell/AbstractAreaEffectSpell.java | 8 ++--- .../magic/spell/AbstractDelegatingSpell.java | 5 +-- .../magic/spell/AbstractDisguiseSpell.java | 8 ++--- .../ability/magic/spell/CompoundSpell.java | 7 ++-- .../magic/spell/DispersableDisguiseSpell.java | 7 ++-- .../ability/magic/spell/PlaceableSpell.java | 7 ++-- .../magic/spell/RainboomAbilitySpell.java | 8 ++--- .../unicopia/ability/magic/spell/Spell.java | 8 ++--- .../ability/magic/spell/ThrowableSpell.java | 7 ++-- .../magic/spell/effect/AbstractSpell.java | 22 ++++++++----- .../magic/spell/effect/AttractiveSpell.java | 9 +++--- .../magic/spell/effect/AwkwardSpell.java | 5 ++- .../magic/spell/effect/CatapultSpell.java | 4 +-- .../spell/effect/ChillingBreathSpell.java | 4 +-- .../spell/effect/CustomisedSpellType.java | 20 ++++++++++-- .../magic/spell/effect/DarkVortexSpell.java | 4 +-- .../spell/effect/DisperseIllusionSpell.java | 5 ++- .../magic/spell/effect/FeatherFallSpell.java | 6 ++-- .../magic/spell/effect/FireBoltSpell.java | 6 ++-- .../ability/magic/spell/effect/FireSpell.java | 4 +-- .../ability/magic/spell/effect/IceSpell.java | 4 +-- .../magic/spell/effect/InfernoSpell.java | 5 ++- .../magic/spell/effect/LightSpell.java | 6 ++-- .../magic/spell/effect/NecromancySpell.java | 5 ++- .../magic/spell/effect/ScorchSpell.java | 5 ++- .../magic/spell/effect/ShieldSpell.java | 4 +-- .../magic/spell/effect/SiphoningSpell.java | 5 ++- .../ability/magic/spell/effect/SpellType.java | 32 +++---------------- .../spell/effect/TransformationSpell.java | 5 ++- 29 files changed, 104 insertions(+), 121 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/AbstractAreaEffectSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/AbstractAreaEffectSpell.java index c92c596e..374a9049 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/AbstractAreaEffectSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/AbstractAreaEffectSpell.java @@ -1,13 +1,11 @@ package com.minelittlepony.unicopia.ability.magic.spell; import com.minelittlepony.unicopia.ability.magic.Caster; -import com.minelittlepony.unicopia.ability.magic.spell.effect.AbstractSpell; -import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType; -import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits; +import com.minelittlepony.unicopia.ability.magic.spell.effect.*; public abstract class AbstractAreaEffectSpell extends AbstractSpell { - protected AbstractAreaEffectSpell(SpellType type, SpellTraits traits) { - super(type, traits); + protected AbstractAreaEffectSpell(CustomisedSpellType type) { + super(type); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/AbstractDelegatingSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/AbstractDelegatingSpell.java index 52dad1f5..af96c4ed 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/AbstractDelegatingSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/AbstractDelegatingSpell.java @@ -8,6 +8,7 @@ import java.util.stream.Stream; import com.minelittlepony.unicopia.Affinity; import com.minelittlepony.unicopia.ability.magic.Caster; +import com.minelittlepony.unicopia.ability.magic.spell.effect.CustomisedSpellType; import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType; import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits; import com.minelittlepony.unicopia.projectile.MagicProjectileEntity; @@ -26,8 +27,8 @@ public abstract class AbstractDelegatingSpell implements ProjectileSpell { private final SpellType type; - public AbstractDelegatingSpell(SpellType type, SpellTraits traits) { - this.type = type; + public AbstractDelegatingSpell(CustomisedSpellType type) { + this.type = type.type(); } public abstract Collection getDelegates(); diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/AbstractDisguiseSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/AbstractDisguiseSpell.java index 542e5600..85d9db0c 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/AbstractDisguiseSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/AbstractDisguiseSpell.java @@ -3,9 +3,7 @@ package com.minelittlepony.unicopia.ability.magic.spell; import java.util.Optional; import com.minelittlepony.unicopia.ability.magic.Caster; -import com.minelittlepony.unicopia.ability.magic.spell.effect.AbstractSpell; -import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType; -import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits; +import com.minelittlepony.unicopia.ability.magic.spell.effect.*; import com.minelittlepony.unicopia.entity.behaviour.Disguise; import com.minelittlepony.unicopia.entity.behaviour.EntityAppearance; import com.minelittlepony.unicopia.entity.player.Pony; @@ -21,8 +19,8 @@ public abstract class AbstractDisguiseSpell extends AbstractSpell implements Dis private final EntityAppearance disguise = new EntityAppearance(); - public AbstractDisguiseSpell(SpellType type, SpellTraits traits) { - super(type, traits); + public AbstractDisguiseSpell(CustomisedSpellType type) { + super(type); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/CompoundSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/CompoundSpell.java index 92d56ba3..d47ecb64 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/CompoundSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/CompoundSpell.java @@ -4,8 +4,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; -import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType; -import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits; +import com.minelittlepony.unicopia.ability.magic.spell.effect.CustomisedSpellType; import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtElement; @@ -13,8 +12,8 @@ import net.minecraft.nbt.NbtElement; public class CompoundSpell extends AbstractDelegatingSpell { private final List spells = new ArrayList<>(); - public CompoundSpell(SpellType type, SpellTraits traits) { - super(type, traits); + public CompoundSpell(CustomisedSpellType type) { + super(type); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/DispersableDisguiseSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/DispersableDisguiseSpell.java index e94c4195..85a12121 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/DispersableDisguiseSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/DispersableDisguiseSpell.java @@ -4,8 +4,7 @@ import java.util.Optional; import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.IllusionarySpell; -import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType; -import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits; +import com.minelittlepony.unicopia.ability.magic.spell.effect.CustomisedSpellType; import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait; import com.minelittlepony.unicopia.entity.behaviour.EntityAppearance; import com.minelittlepony.unicopia.entity.player.Pony; @@ -24,8 +23,8 @@ public class DispersableDisguiseSpell extends AbstractDisguiseSpell implements I private int suppressionCounter; - public DispersableDisguiseSpell(SpellType type, SpellTraits traits) { - super(type, traits); + public DispersableDisguiseSpell(CustomisedSpellType type) { + super(type); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/PlaceableSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/PlaceableSpell.java index 0f7af61d..312dfee3 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/PlaceableSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/PlaceableSpell.java @@ -5,8 +5,7 @@ import java.util.*; import org.jetbrains.annotations.Nullable; import com.minelittlepony.unicopia.ability.magic.Caster; -import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType; -import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits; +import com.minelittlepony.unicopia.ability.magic.spell.effect.CustomisedSpellType; import com.minelittlepony.unicopia.entity.CastSpellEntity; import com.minelittlepony.unicopia.entity.EntityReference; import com.minelittlepony.unicopia.entity.UEntities; @@ -49,8 +48,8 @@ public class PlaceableSpell extends AbstractDelegatingSpell { */ private Spell spell; - public PlaceableSpell(SpellType type, SpellTraits traits) { - super(type, traits); + public PlaceableSpell(CustomisedSpellType type) { + super(type); } public PlaceableSpell setSpell(Spell spell) { diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/RainboomAbilitySpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/RainboomAbilitySpell.java index b4be5215..904d4fc9 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/RainboomAbilitySpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/RainboomAbilitySpell.java @@ -2,9 +2,7 @@ package com.minelittlepony.unicopia.ability.magic.spell; import com.minelittlepony.unicopia.UTags; import com.minelittlepony.unicopia.ability.magic.Caster; -import com.minelittlepony.unicopia.ability.magic.spell.effect.AbstractSpell; -import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType; -import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits; +import com.minelittlepony.unicopia.ability.magic.spell.effect.*; import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.particle.OrientedBillboardParticleEffect; import com.minelittlepony.unicopia.particle.ParticleHandle; @@ -36,8 +34,8 @@ public class RainboomAbilitySpell extends AbstractSpell { private int age; - public RainboomAbilitySpell(SpellType type, SpellTraits traits) { - super(type, traits); + public RainboomAbilitySpell(CustomisedSpellType type) { + super(type); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/Spell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/Spell.java index 8ff10e08..3be19ffc 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/Spell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/Spell.java @@ -96,14 +96,14 @@ public interface Spell extends NbtSerialisable, Affine { * Returns a compound spell representing the union of this and the other spell. */ default Spell combineWith(Spell other) { - return SpellType.COMPOUND_SPELL.create(SpellTraits.EMPTY).combineWith(this).combineWith(other); + return SpellType.COMPOUND_SPELL.withTraits().create().combineWith(this).combineWith(other); } /** * Converts this spell into a placeable spell. */ default PlaceableSpell toPlaceable() { - return SpellType.PLACED_SPELL.create(SpellTraits.EMPTY).setSpell(this); + return SpellType.PLACED_SPELL.withTraits().create().setSpell(this); } /** @@ -111,13 +111,13 @@ public interface Spell extends NbtSerialisable, Affine { * @return */ default ThrowableSpell toThrowable() { - return SpellType.THROWN_SPELL.create(SpellTraits.EMPTY).setSpell(this); + return SpellType.THROWN_SPELL.withTraits().create().setSpell(this); } @Nullable static Spell readNbt(@Nullable NbtCompound compound) { if (compound != null && compound.contains("effect_id")) { - Spell effect = SpellType.getKey(compound).create(SpellTraits.EMPTY); + Spell effect = SpellType.getKey(compound).withTraits().create(); if (effect != null) { effect.fromNBT(compound); diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/ThrowableSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/ThrowableSpell.java index 14175a07..ec0eb75c 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/ThrowableSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/ThrowableSpell.java @@ -6,8 +6,7 @@ import java.util.Optional; import com.minelittlepony.unicopia.USounds; import com.minelittlepony.unicopia.ability.magic.Caster; -import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType; -import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits; +import com.minelittlepony.unicopia.ability.magic.spell.effect.CustomisedSpellType; import com.minelittlepony.unicopia.entity.UEntities; import com.minelittlepony.unicopia.item.GemstoneItem; import com.minelittlepony.unicopia.item.UItems; @@ -21,8 +20,8 @@ public final class ThrowableSpell extends AbstractDelegatingSpell { private Spell spell; - public ThrowableSpell(SpellType type, SpellTraits traits) { - super(type, traits); + public ThrowableSpell(CustomisedSpellType type) { + super(type); } public ThrowableSpell setSpell(Spell spell) { diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AbstractSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AbstractSpell.java index f991efb6..100cab90 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AbstractSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AbstractSpell.java @@ -14,15 +14,12 @@ public abstract class AbstractSpell implements Spell { private boolean isDead; private boolean isDirty; - private final SpellType type; - - private SpellTraits traits; + private CustomisedSpellType type; private UUID uuid = UUID.randomUUID(); - protected AbstractSpell(SpellType type, SpellTraits traits) { + protected AbstractSpell(CustomisedSpellType type) { this.type = type; - this.traits = traits; } @Override @@ -31,13 +28,17 @@ public abstract class AbstractSpell implements Spell { } @Override - public SpellType getType() { + public final SpellType getType() { + return type.type(); + } + + public final CustomisedSpellType getTypeAndTraits() { return type; } @Override public final SpellTraits getTraits() { - return traits == null ? SpellTraits.EMPTY : traits; + return type.traits(); } @Override @@ -85,7 +86,12 @@ public abstract class AbstractSpell implements Spell { } isDead = compound.getBoolean("dead"); if (compound.contains("traits")) { - traits = SpellTraits.fromNbt(compound.getCompound("traits")).orElse(SpellTraits.EMPTY); + type = type.type().withTraits(SpellTraits.fromNbt(compound.getCompound("traits")).orElse(SpellTraits.EMPTY)); } } + + @Override + public final String toString() { + return "Spell[uuid=" + uuid + ", dead=" + isDead + ", type=" + getType() + "]"; + } } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AttractiveSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AttractiveSpell.java index 7992a357..ccaf9863 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AttractiveSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AttractiveSpell.java @@ -2,7 +2,6 @@ package com.minelittlepony.unicopia.ability.magic.spell.effect; import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.spell.*; -import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits; import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait; import com.minelittlepony.unicopia.entity.EntityReference; import com.minelittlepony.unicopia.particle.FollowingParticleEffect; @@ -25,9 +24,9 @@ public class AttractiveSpell extends ShieldSpell implements ProjectileSpell, Hom private int age; private int duration; - protected AttractiveSpell(SpellType type, SpellTraits traits) { - super(type, traits); - duration = 120 + (int)(traits.get(Trait.FOCUS, 0, 160) * 19); + protected AttractiveSpell(CustomisedSpellType type) { + super(type); + duration = 120 + (int)(getTraits().get(Trait.FOCUS, 0, 160) * 19); } @Override @@ -140,7 +139,7 @@ public class AttractiveSpell extends ShieldSpell implements ProjectileSpell, Hom public void onImpact(MagicProjectileEntity projectile, Entity entity) { if (!isDead() && getTraits().get(Trait.CHAOS) > 0) { setDead(); - Caster.of(entity).ifPresent(getType().create(getTraits())::apply); + Caster.of(entity).ifPresent(getTypeAndTraits()::apply); } } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AwkwardSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AwkwardSpell.java index 24f203bc..6bba451e 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AwkwardSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AwkwardSpell.java @@ -5,7 +5,6 @@ import java.util.List; import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.spell.Situation; -import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits; import com.minelittlepony.unicopia.util.shape.Sphere; import net.minecraft.particle.ParticleEffect; @@ -18,8 +17,8 @@ import net.minecraft.util.registry.Registry; public class AwkwardSpell extends AbstractSpell { - protected AwkwardSpell(SpellType type, SpellTraits traits) { - super(type, traits); + protected AwkwardSpell(CustomisedSpellType type) { + super(type); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/CatapultSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/CatapultSpell.java index 133b35bd..1cb9dfd5 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/CatapultSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/CatapultSpell.java @@ -39,8 +39,8 @@ public class CatapultSpell extends AbstractSpell implements ProjectileSpell { private static final float HORIZONTAL_VARIANCE = 0.25F; private static final float MAX_STRENGTH = 120; - protected CatapultSpell(SpellType type, SpellTraits traits) { - super(type, traits); + protected CatapultSpell(CustomisedSpellType type) { + super(type); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/ChillingBreathSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/ChillingBreathSpell.java index 2b51d37a..3cd2fad1 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/ChillingBreathSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/ChillingBreathSpell.java @@ -14,8 +14,8 @@ public class ChillingBreathSpell extends AbstractSpell implements HomingSpell { .with(Trait.ICE, 15) .build(); - protected ChillingBreathSpell(SpellType type, SpellTraits traits) { - super(type, traits); + protected ChillingBreathSpell(CustomisedSpellType type) { + super(type); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/CustomisedSpellType.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/CustomisedSpellType.java index 2399dfcb..b00053f4 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/CustomisedSpellType.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/CustomisedSpellType.java @@ -21,12 +21,28 @@ public record CustomisedSpellType ( } public T create() { - return type.create(traits); + try { + return type.getFactory().create(this); + } catch (Exception e) { + e.printStackTrace(); + } + + return null; } + @Nullable public T apply(Caster caster) { - return type.apply(caster, traits); + if (isEmpty()) { + return null; + } + + T spell = create(); + if (spell != null && spell.apply(caster)) { + return spell; + } + + return null; } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/DarkVortexSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/DarkVortexSpell.java index b3892a39..4a577688 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/DarkVortexSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/DarkVortexSpell.java @@ -54,8 +54,8 @@ public class DarkVortexSpell extends AttractiveSpell implements ProjectileSpell private int age = 0; private float accumulatedMass = 0; - protected DarkVortexSpell(SpellType type, SpellTraits traits) { - super(type, traits); + protected DarkVortexSpell(CustomisedSpellType type) { + super(type); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/DisperseIllusionSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/DisperseIllusionSpell.java index fae9828e..4806d10d 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/DisperseIllusionSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/DisperseIllusionSpell.java @@ -5,7 +5,6 @@ import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.SpellPredicate; import com.minelittlepony.unicopia.ability.magic.spell.AbstractAreaEffectSpell; import com.minelittlepony.unicopia.ability.magic.spell.Situation; -import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits; import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait; import com.minelittlepony.unicopia.particle.MagicParticleEffect; import com.minelittlepony.unicopia.util.shape.Sphere; @@ -16,8 +15,8 @@ import net.minecraft.util.math.Vec3d; * An area-effect spell that disperses illussions. */ public class DisperseIllusionSpell extends AbstractAreaEffectSpell { - protected DisperseIllusionSpell(SpellType type, SpellTraits traits) { - super(type, traits); + protected DisperseIllusionSpell(CustomisedSpellType type) { + super(type); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/FeatherFallSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/FeatherFallSpell.java index d2d879df..412c3505 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/FeatherFallSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/FeatherFallSpell.java @@ -37,9 +37,9 @@ public class FeatherFallSpell extends AbstractSpell { private int duration; - protected FeatherFallSpell(SpellType type, SpellTraits traits) { - super(type, traits); - duration = (int)(traits.get(Trait.FOCUS, 0, 160) * 19); + protected FeatherFallSpell(CustomisedSpellType type) { + super(type); + duration = (int)(getTraits().get(Trait.FOCUS, 0, 160) * 19); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/FireBoltSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/FireBoltSpell.java index 53c0a4b2..a4ca21d5 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/FireBoltSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/FireBoltSpell.java @@ -30,8 +30,8 @@ public class FireBoltSpell extends AbstractSpell implements ProjectileSpell, Hom private final EntityReference target = new EntityReference<>(); - protected FireBoltSpell(SpellType type, SpellTraits traits) { - super(type, traits); + protected FireBoltSpell(CustomisedSpellType type) { + super(type); } @Override @@ -62,7 +62,7 @@ public class FireBoltSpell extends AbstractSpell implements ProjectileSpell, Hom } for (int i = 0; i < getNumberOfBalls(caster); i++) { - getType().create(getTraits()).toThrowable().throwProjectile(caster, 2).ifPresent(c -> { + getTypeAndTraits().create().toThrowable().throwProjectile(caster, 2).ifPresent(c -> { target.ifPresent(caster.getReferenceWorld(), c::setHomingTarget); }); diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/FireSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/FireSpell.java index e9f764d0..377a0038 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/FireSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/FireSpell.java @@ -43,8 +43,8 @@ public class FireSpell extends AbstractAreaEffectSpell implements ProjectileSpel .with(Trait.FIRE, 15) .build(); - protected FireSpell(SpellType type, SpellTraits traits) { - super(type, traits); + protected FireSpell(CustomisedSpellType type) { + super(type); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/IceSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/IceSpell.java index 63092859..e9943532 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/IceSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/IceSpell.java @@ -34,8 +34,8 @@ public class IceSpell extends AbstractSpell { private final int rad = 3; private final Shape outerRange = new Sphere(false, rad); - protected IceSpell(SpellType type, SpellTraits traits) { - super(type, traits); + protected IceSpell(CustomisedSpellType type) { + super(type); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/InfernoSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/InfernoSpell.java index 49f23209..41c24c57 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/InfernoSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/InfernoSpell.java @@ -2,7 +2,6 @@ package com.minelittlepony.unicopia.ability.magic.spell.effect; import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.spell.Situation; -import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits; import com.minelittlepony.unicopia.block.state.BlockStateConverter; import com.minelittlepony.unicopia.block.state.StateMaps; import com.minelittlepony.unicopia.util.MagicalDamageSource; @@ -21,8 +20,8 @@ import net.minecraft.world.World; */ public class InfernoSpell extends FireSpell { - protected InfernoSpell(SpellType type, SpellTraits traits) { - super(type, traits); + protected InfernoSpell(CustomisedSpellType type) { + super(type); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/LightSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/LightSpell.java index 41d57573..f0f7b4fe 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/LightSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/LightSpell.java @@ -29,9 +29,9 @@ public class LightSpell extends AbstractSpell { private final List> lights = new ArrayList<>(); - protected LightSpell(SpellType type, SpellTraits traits) { - super(type, traits); - duration = 120 + (int)(traits.get(Trait.FOCUS, 0, 160) * 19); + protected LightSpell(CustomisedSpellType type) { + super(type); + duration = 120 + (int)(getTraits().get(Trait.FOCUS, 0, 160) * 19); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/NecromancySpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/NecromancySpell.java index 59be0428..9ce0a4cb 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/NecromancySpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/NecromancySpell.java @@ -6,7 +6,6 @@ import java.util.List; import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.spell.AbstractAreaEffectSpell; import com.minelittlepony.unicopia.ability.magic.spell.Situation; -import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits; import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait; import com.minelittlepony.unicopia.entity.Creature; import com.minelittlepony.unicopia.entity.EntityReference; @@ -44,8 +43,8 @@ public class NecromancySpell extends AbstractAreaEffectSpell { private int spawnCountdown; - protected NecromancySpell(SpellType type, SpellTraits traits) { - super(type, traits); + protected NecromancySpell(CustomisedSpellType type) { + super(type); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/ScorchSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/ScorchSpell.java index 2844940e..5649d089 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/ScorchSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/ScorchSpell.java @@ -2,7 +2,6 @@ package com.minelittlepony.unicopia.ability.magic.spell.effect; import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.spell.Situation; -import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits; import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait; import com.minelittlepony.unicopia.block.state.StateMaps; import com.minelittlepony.unicopia.particle.MagicParticleEffect; @@ -16,8 +15,8 @@ import net.minecraft.util.math.Vec3d; public class ScorchSpell extends FireSpell { - protected ScorchSpell(SpellType type, SpellTraits traits) { - super(type, traits); + protected ScorchSpell(CustomisedSpellType type) { + super(type); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/ShieldSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/ShieldSpell.java index 6c347700..806ce8e7 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/ShieldSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/ShieldSpell.java @@ -41,8 +41,8 @@ public class ShieldSpell extends AbstractSpell { private final TargetSelecter targetSelecter = new TargetSelecter(this); - protected ShieldSpell(SpellType type, SpellTraits traits) { - super(type, traits); + protected ShieldSpell(CustomisedSpellType type) { + super(type); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/SiphoningSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/SiphoningSpell.java index 21aa2e8f..efc3ada5 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/SiphoningSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/SiphoningSpell.java @@ -9,7 +9,6 @@ import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.spell.AbstractAreaEffectSpell; import com.minelittlepony.unicopia.ability.magic.spell.Situation; -import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits; import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait; import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.particle.FollowingParticleEffect; @@ -35,8 +34,8 @@ public class SiphoningSpell extends AbstractAreaEffectSpell { private int ticksUpset; - protected SiphoningSpell(SpellType type, SpellTraits traits) { - super(type, traits); + protected SiphoningSpell(CustomisedSpellType type) { + super(type); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/SpellType.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/SpellType.java index 2f847780..3353d224 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/SpellType.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/SpellType.java @@ -10,7 +10,6 @@ import org.jetbrains.annotations.Nullable; import com.minelittlepony.unicopia.Affinity; import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.ability.magic.Affine; -import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.SpellPredicate; import com.minelittlepony.unicopia.ability.magic.spell.AbstractDisguiseSpell; import com.minelittlepony.unicopia.ability.magic.spell.CompoundSpell; @@ -33,7 +32,7 @@ import net.minecraft.util.registry.Registry; public final class SpellType implements Affine, SpellPredicate { public static final Identifier EMPTY_ID = Unicopia.id("none"); - public static final SpellType EMPTY_KEY = new SpellType<>(EMPTY_ID, Affinity.NEUTRAL, 0xFFFFFF, false, SpellTraits.EMPTY, (t, c) -> null); + public static final SpellType EMPTY_KEY = new SpellType<>(EMPTY_ID, Affinity.NEUTRAL, 0xFFFFFF, false, SpellTraits.EMPTY, t -> null); public static final Registry> REGISTRY = Registries.createSimple(Unicopia.id("spells")); private static final Map>> BY_AFFINITY = new EnumMap<>(Affinity.class); @@ -138,29 +137,8 @@ public final class SpellType implements Affine, SpellPredicate< return traits.isEmpty() ? withTraits() : new CustomisedSpellType<>(this, traits); } - @Nullable - public T create(SpellTraits traits) { - try { - return factory.create(this, traits); - } catch (Exception e) { - e.printStackTrace(); - } - - return null; - } - - @Nullable - public T apply(Caster caster, SpellTraits traits) { - if (isEmpty()) { - return null; - } - - T spell = create(traits); - if (spell.apply(caster)) { - return spell; - } - - return null; + public Factory getFactory() { + return factory; } @Override @@ -178,7 +156,7 @@ public final class SpellType implements Affine, SpellPredicate< @Override public String toString() { - return getTranslationKey(); + return "SpellType[" + getTranslationKey() + "]"; } @Deprecated(forRemoval = true) @@ -216,6 +194,6 @@ public final class SpellType implements Affine, SpellPredicate< } public interface Factory { - T create(SpellType type, SpellTraits traits); + T create(CustomisedSpellType type); } } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/TransformationSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/TransformationSpell.java index 8bf4e82d..ceeae78f 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/TransformationSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/TransformationSpell.java @@ -10,7 +10,6 @@ import com.minelittlepony.unicopia.UTags; import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.spell.Situation; import com.minelittlepony.unicopia.ability.magic.spell.ProjectileSpell; -import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits; import com.minelittlepony.unicopia.entity.UEntities; import com.minelittlepony.unicopia.particle.ParticleUtils; import com.minelittlepony.unicopia.projectile.MagicProjectileEntity; @@ -28,8 +27,8 @@ import net.minecraft.world.World; * Transforms whatever entity it strikes into a random other entity. */ public class TransformationSpell extends AbstractSpell implements ProjectileSpell { - protected TransformationSpell(SpellType type, SpellTraits traits) { - super(type, traits); + protected TransformationSpell(CustomisedSpellType type) { + super(type); } @Override