2020-04-15 14:22:03 +02:00
|
|
|
package com.minelittlepony.unicopia.ability;
|
2020-01-16 12:35:46 +01:00
|
|
|
|
|
|
|
|
2021-08-04 15:38:03 +02:00
|
|
|
import org.jetbrains.annotations.Nullable;
|
2020-01-16 12:35:46 +01:00
|
|
|
|
2022-01-04 23:43:07 +01:00
|
|
|
import com.minelittlepony.unicopia.USounds;
|
2020-04-25 15:37:17 +02:00
|
|
|
import com.minelittlepony.unicopia.ability.data.Hit;
|
2021-12-22 15:43:06 +01:00
|
|
|
import com.minelittlepony.unicopia.ability.magic.SpellPredicate;
|
|
|
|
import com.minelittlepony.unicopia.ability.magic.spell.AbstractDisguiseSpell;
|
2021-11-05 14:18:32 +01:00
|
|
|
import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
|
2021-12-22 15:43:06 +01:00
|
|
|
import com.minelittlepony.unicopia.entity.behaviour.EntityAppearance;
|
2020-09-22 15:11:20 +02:00
|
|
|
import com.minelittlepony.unicopia.entity.player.Pony;
|
|
|
|
import com.minelittlepony.unicopia.particle.UParticles;
|
2020-09-27 20:07:55 +02:00
|
|
|
import com.minelittlepony.unicopia.util.RayTraceHelper;
|
2020-01-16 12:35:46 +01:00
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.FallingBlockEntity;
|
|
|
|
import net.minecraft.entity.LightningEntity;
|
2021-12-28 01:58:07 +01:00
|
|
|
import net.minecraft.entity.decoration.AbstractDecorationEntity;
|
2020-01-16 12:35:46 +01:00
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
2020-09-27 20:07:55 +02:00
|
|
|
import net.minecraft.predicate.entity.EntityPredicates;
|
2020-01-16 12:35:46 +01:00
|
|
|
import net.minecraft.sound.SoundCategory;
|
|
|
|
|
2020-01-27 17:37:22 +01:00
|
|
|
/**
|
|
|
|
* Changeling ability to disguise themselves as other players.
|
|
|
|
*/
|
2020-04-15 17:22:29 +02:00
|
|
|
public class ChangelingDisguiseAbility extends ChangelingFeedAbility {
|
2020-01-16 12:35:46 +01:00
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
2020-04-15 18:12:00 +02:00
|
|
|
public Hit tryActivate(Pony player) {
|
2020-10-10 19:12:40 +02:00
|
|
|
if (player.getMaster().isCreative() || player.getMagicalReserves().getMana().getPercentFill() >= 0.9F) {
|
2020-10-01 17:04:48 +02:00
|
|
|
return Hit.INSTANCE;
|
|
|
|
}
|
|
|
|
return null;
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-04-15 18:12:00 +02:00
|
|
|
public void apply(Pony iplayer, Hit data) {
|
2020-10-08 19:22:20 +02:00
|
|
|
PlayerEntity player = iplayer.getMaster();
|
2020-01-16 12:35:46 +01:00
|
|
|
|
2020-10-10 19:12:40 +02:00
|
|
|
if (!player.isCreative() && iplayer.getMagicalReserves().getMana().getPercentFill() < 0.9F) {
|
2020-10-01 17:04:48 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-12-31 14:36:31 +01:00
|
|
|
RayTraceHelper.Trace trace = RayTraceHelper.doTrace(player, 10, 1, EntityPredicates.CAN_COLLIDE.and(e -> !(e instanceof LightningEntity)));
|
2020-01-16 12:35:46 +01:00
|
|
|
|
2021-12-28 01:58:07 +01:00
|
|
|
Entity looked = trace.getEntity().filter(e -> !(e instanceof AbstractDecorationEntity)).map(e -> {
|
2020-09-27 20:07:55 +02:00
|
|
|
return e instanceof PlayerEntity ? Pony.of((PlayerEntity)e)
|
2021-03-03 10:33:23 +01:00
|
|
|
.getSpellSlot()
|
2021-12-22 15:43:06 +01:00
|
|
|
.get(SpellPredicate.IS_DISGUISE, true)
|
|
|
|
.map(AbstractDisguiseSpell::getDisguise)
|
|
|
|
.map(EntityAppearance::getAppearance)
|
2020-09-27 20:07:55 +02:00
|
|
|
.orElse(e) : e;
|
|
|
|
}).orElseGet(() -> trace.getBlockPos().map(pos -> {
|
2020-01-16 12:35:46 +01:00
|
|
|
if (!iplayer.getWorld().isAir(pos)) {
|
2020-09-27 20:07:55 +02:00
|
|
|
return new FallingBlockEntity(player.getEntityWorld(), 0, 0, 0, iplayer.getWorld().getBlockState(pos));
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|
2020-09-27 20:07:55 +02:00
|
|
|
return null;
|
|
|
|
}).orElse(null));
|
2020-01-16 12:35:46 +01:00
|
|
|
|
2022-01-04 23:43:07 +01:00
|
|
|
player.getEntityWorld().playSound(null, player.getBlockPos(), USounds.ENTITY_PLAYER_CHANGELING_TRANSFORM, SoundCategory.PLAYERS, 1.4F, 0.4F);
|
2020-01-16 12:35:46 +01:00
|
|
|
|
2021-12-22 15:43:06 +01:00
|
|
|
iplayer.getSpellSlot().get(SpellType.CHANGELING_DISGUISE, true)
|
2021-12-23 17:52:40 +01:00
|
|
|
.orElseGet(() -> SpellType.CHANGELING_DISGUISE.withTraits().apply(iplayer))
|
2021-03-07 10:04:32 +01:00
|
|
|
.setDisguise(looked);
|
2020-01-16 12:35:46 +01:00
|
|
|
|
2020-10-10 19:12:40 +02:00
|
|
|
if (!player.isCreative()) {
|
|
|
|
iplayer.getMagicalReserves().getMana().multiply(0.1F);
|
|
|
|
}
|
2020-10-01 17:04:48 +02:00
|
|
|
|
2020-09-27 20:07:55 +02:00
|
|
|
player.calculateDimensions();
|
2020-05-10 17:18:45 +02:00
|
|
|
iplayer.setDirty();
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-05-10 20:45:07 +02:00
|
|
|
public void preApply(Pony player, AbilitySlot slot) {
|
2020-10-01 17:04:48 +02:00
|
|
|
player.getMagicalReserves().getEnergy().add(20);
|
2020-01-16 12:35:46 +01:00
|
|
|
player.spawnParticles(UParticles.CHANGELING_MAGIC, 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-05-10 20:45:07 +02:00
|
|
|
public void postApply(Pony player, AbilitySlot slot) {
|
2020-10-01 17:04:48 +02:00
|
|
|
player.getMagicalReserves().getEnergy().set(0);
|
2020-01-16 12:35:46 +01:00
|
|
|
player.spawnParticles(UParticles.CHANGELING_MAGIC, 5);
|
|
|
|
}
|
|
|
|
}
|