Unicopia/src/main/java/com/minelittlepony/unicopia/ability/ChangelingDisguiseAbility.java

83 lines
2.9 KiB
Java
Raw Normal View History

package com.minelittlepony.unicopia.ability;
2020-01-16 12:35:46 +01:00
2023-08-16 00:18:41 +02:00
import java.util.Optional;
2021-08-04 15:38:03 +02:00
import org.jetbrains.annotations.Nullable;
2020-01-16 12:35:46 +01:00
2022-10-01 18:20:53 +02:00
import com.minelittlepony.unicopia.EquinePredicates;
2022-01-04 23:43:07 +01:00
import com.minelittlepony.unicopia.USounds;
import com.minelittlepony.unicopia.ability.data.Hit;
import com.minelittlepony.unicopia.ability.magic.spell.AbstractDisguiseSpell;
import com.minelittlepony.unicopia.ability.magic.spell.CastingMethod;
import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
import com.minelittlepony.unicopia.entity.behaviour.Disguise;
import com.minelittlepony.unicopia.entity.player.Pony;
2022-03-26 20:34:15 +01:00
import com.minelittlepony.unicopia.mixin.MixinFallingBlockEntity;
import com.minelittlepony.unicopia.particle.UParticles;
2022-10-01 18:20:53 +02:00
import com.minelittlepony.unicopia.util.Trace;
2020-01-16 12:35:46 +01:00
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.sound.SoundCategory;
/**
* 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
2023-08-16 00:18:41 +02:00
public Optional<Hit> prepare(Pony player) {
return Hit.of(player.asEntity().isCreative() || player.getMagicalReserves().getMana().getPercentFill() >= 0.9F);
2020-01-16 12:35:46 +01:00
}
@Override
2023-08-16 00:18:41 +02:00
public boolean apply(Pony iplayer, Hit data) {
PlayerEntity player = iplayer.asEntity();
2020-01-16 12:35:46 +01:00
2023-08-16 00:18:41 +02:00
if (prepare(iplayer).isEmpty()) {
return false;
2020-10-01 17:04:48 +02:00
}
2022-10-01 18:20:53 +02:00
Trace trace = Trace.create(player, 10, 1, EquinePredicates.VALID_FOR_DISGUISE);
2020-01-16 12:35:46 +01:00
2022-10-01 18:20:53 +02:00
Entity looked = trace.getEntity().map(AbstractDisguiseSpell::getAppearance).orElseGet(() -> trace.getBlockPos().map(pos -> {
if (!iplayer.asWorld().isAir(pos)) {
return MixinFallingBlockEntity.createInstance(player.getEntityWorld(), 0, 0, 0, iplayer.asWorld().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
Disguise currentDisguise = iplayer.getSpellSlot().get(SpellType.CHANGELING_DISGUISE, true)
.orElseGet(() -> SpellType.CHANGELING_DISGUISE.withTraits().apply(iplayer, CastingMethod.INNATE));
if (currentDisguise.isOf(looked)) {
looked = null;
}
currentDisguise.setDisguise(looked);
2020-01-16 12:35:46 +01: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();
iplayer.setDirty();
2023-08-16 00:18:41 +02:00
return true;
2020-01-16 12:35:46 +01:00
}
@Override
2023-08-16 00:18:41 +02:00
public void warmUp(Pony player, AbilitySlot slot) {
player.getMagicalReserves().getEnergy().add(2F);
2020-01-16 12:35:46 +01:00
player.spawnParticles(UParticles.CHANGELING_MAGIC, 5);
}
@Override
2023-08-16 00:18:41 +02:00
public void coolDown(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);
}
}