mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-23 21:38:00 +01:00
Implement casting via the staff for the mind swap spell
This commit is contained in:
parent
fbf96005ae
commit
514ce8f984
8 changed files with 50 additions and 18 deletions
|
@ -103,7 +103,7 @@ public class UnicornCastingAbility extends AbstractSpellCastingAbility {
|
||||||
}, true);
|
}, true);
|
||||||
player.subtractEnergyCost(removed ? 2 : 4);
|
player.subtractEnergyCost(removed ? 2 : 4);
|
||||||
if (!removed) {
|
if (!removed) {
|
||||||
Spell s = spell.apply(player, CastingMethod.GEM);
|
Spell s = spell.apply(player, CastingMethod.DIRECT);
|
||||||
if (s == null) {
|
if (s == null) {
|
||||||
player.spawnParticles(ParticleTypes.LARGE_SMOKE, 6);
|
player.spawnParticles(ParticleTypes.LARGE_SMOKE, 6);
|
||||||
player.playSound(USounds.SPELL_CAST_FAIL, 1, 0.5F);
|
player.playSound(USounds.SPELL_CAST_FAIL, 1, 0.5F);
|
||||||
|
|
|
@ -4,15 +4,15 @@ public enum CastingMethod {
|
||||||
/**
|
/**
|
||||||
* Casting from a gem or a unicorn's equipped spell.
|
* Casting from a gem or a unicorn's equipped spell.
|
||||||
*/
|
*/
|
||||||
GEM,
|
DIRECT,
|
||||||
/**
|
/**
|
||||||
* Casting a projectile form from a gem or unicorn's equipped spell
|
* Casting a projectile form from a gem or unicorn's equipped spell
|
||||||
*/
|
*/
|
||||||
GEM_PROJECTILE,
|
STORED,
|
||||||
/**
|
/**
|
||||||
* Result of a projectile impact
|
* Result of a projectile impact
|
||||||
*/
|
*/
|
||||||
PROJECTILE,
|
INDIRECT,
|
||||||
/**
|
/**
|
||||||
* Casting from a magic staff
|
* Casting from a magic staff
|
||||||
*/
|
*/
|
||||||
|
@ -20,5 +20,21 @@ public enum CastingMethod {
|
||||||
/**
|
/**
|
||||||
* Result of an entities innate ability
|
* Result of an entities innate ability
|
||||||
*/
|
*/
|
||||||
INNATE
|
INNATE;
|
||||||
|
|
||||||
|
public boolean isIndirectCause() {
|
||||||
|
return this == STAFF || this == STORED;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isIndirectEffect() {
|
||||||
|
return this == INDIRECT;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDirect() {
|
||||||
|
return this == DIRECT || this == INNATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isTool() {
|
||||||
|
return this == STAFF;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -64,7 +64,7 @@ public final class ThrowableSpell extends AbstractDelegatingSpell {
|
||||||
projectile.setPosition(entity.getX(), entity.getEyeY() - 0.1F, entity.getZ());
|
projectile.setPosition(entity.getX(), entity.getEyeY() - 0.1F, entity.getZ());
|
||||||
projectile.setOwner(entity);
|
projectile.setOwner(entity);
|
||||||
projectile.setItem(UItems.GEMSTONE.getDefaultStack(spell.getType()));
|
projectile.setItem(UItems.GEMSTONE.getDefaultStack(spell.getType()));
|
||||||
spell.prepareForCast(caster, CastingMethod.PROJECTILE).apply(projectile);
|
spell.prepareForCast(caster, CastingMethod.STORED).apply(projectile);
|
||||||
projectile.setVelocity(entity, entity.getPitch(), entity.getYaw(), 0, 1.5F, divergance);
|
projectile.setVelocity(entity, entity.getPitch(), entity.getYaw(), 0, 1.5F, divergance);
|
||||||
projectile.setNoGravity(true);
|
projectile.setNoGravity(true);
|
||||||
configureProjectile(projectile, caster);
|
configureProjectile(projectile, caster);
|
||||||
|
|
|
@ -146,7 +146,7 @@ public class AttractiveSpell extends ShieldSpell implements HomingSpell, TimedSp
|
||||||
public void onImpact(MagicProjectileEntity projectile, EntityHitResult hit) {
|
public void onImpact(MagicProjectileEntity projectile, EntityHitResult hit) {
|
||||||
if (!isDead() && getTraits().get(Trait.CHAOS) > 0) {
|
if (!isDead() && getTraits().get(Trait.CHAOS) > 0) {
|
||||||
setDead();
|
setDead();
|
||||||
Caster.of(hit.getEntity()).ifPresent(caster -> getTypeAndTraits().apply(caster, CastingMethod.PROJECTILE));
|
Caster.of(hit.getEntity()).ifPresent(caster -> getTypeAndTraits().apply(caster, CastingMethod.INDIRECT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -153,7 +153,7 @@ public class BubbleSpell extends AbstractSpell implements TimedSpell,
|
||||||
@Override
|
@Override
|
||||||
public void onImpact(MagicProjectileEntity projectile, EntityHitResult hit) {
|
public void onImpact(MagicProjectileEntity projectile, EntityHitResult hit) {
|
||||||
Caster.of(hit.getEntity()).ifPresent(caster -> {
|
Caster.of(hit.getEntity()).ifPresent(caster -> {
|
||||||
getTypeAndTraits().apply(caster, CastingMethod.PROJECTILE);
|
getTypeAndTraits().apply(caster, CastingMethod.INDIRECT);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,7 @@ public class LightSpell extends AbstractSpell implements TimedSpell, ProjectileD
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onImpact(MagicProjectileEntity projectile) {
|
public void onImpact(MagicProjectileEntity projectile) {
|
||||||
Caster.of(projectile.getMaster()).ifPresent(caster -> getTypeAndTraits().apply(caster, CastingMethod.PROJECTILE));
|
Caster.of(projectile.getMaster()).ifPresent(caster -> getTypeAndTraits().apply(caster, CastingMethod.INDIRECT));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -5,17 +5,22 @@ import java.util.Optional;
|
||||||
import com.minelittlepony.unicopia.USounds;
|
import com.minelittlepony.unicopia.USounds;
|
||||||
import com.minelittlepony.unicopia.ability.magic.Caster;
|
import com.minelittlepony.unicopia.ability.magic.Caster;
|
||||||
import com.minelittlepony.unicopia.ability.magic.spell.CastingMethod;
|
import com.minelittlepony.unicopia.ability.magic.spell.CastingMethod;
|
||||||
|
import com.minelittlepony.unicopia.ability.magic.spell.HomingSpell;
|
||||||
import com.minelittlepony.unicopia.ability.magic.spell.Situation;
|
import com.minelittlepony.unicopia.ability.magic.spell.Situation;
|
||||||
|
import com.minelittlepony.unicopia.ability.magic.spell.Spell;
|
||||||
import com.minelittlepony.unicopia.entity.EntityReference;
|
import com.minelittlepony.unicopia.entity.EntityReference;
|
||||||
import com.minelittlepony.unicopia.entity.behaviour.EntitySwap;
|
import com.minelittlepony.unicopia.entity.behaviour.EntitySwap;
|
||||||
import com.minelittlepony.unicopia.entity.behaviour.Inventory;
|
import com.minelittlepony.unicopia.entity.behaviour.Inventory;
|
||||||
|
import com.minelittlepony.unicopia.projectile.MagicProjectileEntity;
|
||||||
|
import com.minelittlepony.unicopia.projectile.ProjectileDelegate;
|
||||||
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.entity.LivingEntity;
|
||||||
import net.minecraft.nbt.NbtCompound;
|
import net.minecraft.nbt.NbtCompound;
|
||||||
import net.minecraft.nbt.NbtElement;
|
import net.minecraft.nbt.NbtElement;
|
||||||
|
import net.minecraft.util.hit.EntityHitResult;
|
||||||
|
|
||||||
public class MindSwapSpell extends MimicSpell {
|
public class MindSwapSpell extends MimicSpell implements ProjectileDelegate.EntityHitListener {
|
||||||
|
|
||||||
private final EntityReference<LivingEntity> counterpart = new EntityReference<>();
|
private final EntityReference<LivingEntity> counterpart = new EntityReference<>();
|
||||||
|
|
||||||
|
@ -28,6 +33,10 @@ public class MindSwapSpell extends MimicSpell {
|
||||||
super(type);
|
super(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Spell prepareForCast(Caster<?> caster, CastingMethod method) {
|
||||||
|
return method == CastingMethod.STAFF ? toThrowable() : this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyed(Caster<?> caster) {
|
public void onDestroyed(Caster<?> caster) {
|
||||||
|
@ -57,6 +66,10 @@ public class MindSwapSpell extends MimicSpell {
|
||||||
@Override
|
@Override
|
||||||
public boolean tick(Caster<?> caster, Situation situation) {
|
public boolean tick(Caster<?> caster, Situation situation) {
|
||||||
|
|
||||||
|
if (situation != Situation.BODY) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (!caster.isClient()) {
|
if (!caster.isClient()) {
|
||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
initialized = true;
|
initialized = true;
|
||||||
|
@ -66,7 +79,7 @@ public class MindSwapSpell extends MimicSpell {
|
||||||
|
|
||||||
setDisguise(e);
|
setDisguise(e);
|
||||||
Caster<?> other = Caster.of(e).get();
|
Caster<?> other = Caster.of(e).get();
|
||||||
SpellType.MIMIC.withTraits().apply(other, CastingMethod.PROJECTILE).setDisguise(master);
|
SpellType.MIMIC.withTraits().apply(other, CastingMethod.INDIRECT).setDisguise(master);
|
||||||
|
|
||||||
EntitySwap.ALL.accept(master, e);
|
EntitySwap.ALL.accept(master, e);
|
||||||
Inventory.swapInventories(
|
Inventory.swapInventories(
|
||||||
|
@ -100,6 +113,16 @@ public class MindSwapSpell extends MimicSpell {
|
||||||
return super.tick(caster, situation);
|
return super.tick(caster, situation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onImpact(MagicProjectileEntity projectile, EntityHitResult hit) {
|
||||||
|
Caster.of(projectile.getMaster()).ifPresent(master -> {
|
||||||
|
if (getTypeAndTraits().apply(master, CastingMethod.DIRECT) instanceof HomingSpell homing) {
|
||||||
|
homing.setTarget(hit.getEntity());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setTarget(Entity target) {
|
public boolean setTarget(Entity target) {
|
||||||
if (target instanceof LivingEntity living && Caster.of(target).isPresent()) {
|
if (target instanceof LivingEntity living && Caster.of(target).isPresent()) {
|
||||||
|
|
|
@ -7,9 +7,7 @@ import java.util.function.Supplier;
|
||||||
import com.minelittlepony.unicopia.USounds;
|
import com.minelittlepony.unicopia.USounds;
|
||||||
import com.minelittlepony.unicopia.ability.magic.Caster;
|
import com.minelittlepony.unicopia.ability.magic.Caster;
|
||||||
import com.minelittlepony.unicopia.ability.magic.spell.AbstractAreaEffectSpell;
|
import com.minelittlepony.unicopia.ability.magic.spell.AbstractAreaEffectSpell;
|
||||||
import com.minelittlepony.unicopia.ability.magic.spell.CastingMethod;
|
|
||||||
import com.minelittlepony.unicopia.ability.magic.spell.Situation;
|
import com.minelittlepony.unicopia.ability.magic.spell.Situation;
|
||||||
import com.minelittlepony.unicopia.ability.magic.spell.Spell;
|
|
||||||
import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait;
|
import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait;
|
||||||
import com.minelittlepony.unicopia.entity.Creature;
|
import com.minelittlepony.unicopia.entity.Creature;
|
||||||
import com.minelittlepony.unicopia.entity.EntityReference;
|
import com.minelittlepony.unicopia.entity.EntityReference;
|
||||||
|
@ -88,11 +86,6 @@ public class NecromancySpell extends AbstractAreaEffectSpell implements Projecti
|
||||||
super(type);
|
super(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Spell prepareForCast(Caster<?> caster, CastingMethod method) {
|
|
||||||
return method == CastingMethod.GEM ? toPlaceable() : super.prepareForCast(caster, method);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean tick(Caster<?> source, Situation situation) {
|
public boolean tick(Caster<?> source, Situation situation) {
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue