2020-04-15 14:22:03 +02:00
|
|
|
package com.minelittlepony.unicopia.ability;
|
2020-01-16 12:35:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
2020-04-25 15:37:17 +02:00
|
|
|
import com.minelittlepony.unicopia.ability.data.Hit;
|
2020-09-22 15:11:20 +02:00
|
|
|
import com.minelittlepony.unicopia.ability.magic.spell.DisguiseSpell;
|
|
|
|
import com.minelittlepony.unicopia.entity.player.Pony;
|
|
|
|
import com.minelittlepony.unicopia.particle.UParticles;
|
2020-04-15 14:22:03 +02:00
|
|
|
import com.minelittlepony.unicopia.util.VecHelper;
|
2020-01-16 12:35:46 +01:00
|
|
|
|
|
|
|
import net.minecraft.block.BlockState;
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.FallingBlockEntity;
|
|
|
|
import net.minecraft.entity.LightningEntity;
|
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
|
|
import net.minecraft.sound.SoundCategory;
|
|
|
|
import net.minecraft.sound.SoundEvents;
|
|
|
|
import net.minecraft.util.hit.BlockHitResult;
|
|
|
|
import net.minecraft.util.hit.EntityHitResult;
|
|
|
|
import net.minecraft.util.hit.HitResult;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
|
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-04-25 15:37:17 +02:00
|
|
|
return Hit.INSTANCE;
|
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-01-16 12:35:46 +01:00
|
|
|
PlayerEntity player = iplayer.getOwner();
|
|
|
|
HitResult trace = VecHelper.getObjectMouseOver(player, 10, 1);
|
|
|
|
|
|
|
|
Entity looked = null;
|
|
|
|
|
|
|
|
if (trace.getType() == HitResult.Type.BLOCK) {
|
|
|
|
BlockPos pos = ((BlockHitResult)trace).getBlockPos();
|
|
|
|
|
|
|
|
if (!iplayer.getWorld().isAir(pos)) {
|
|
|
|
BlockState state = iplayer.getWorld().getBlockState(pos);
|
|
|
|
|
|
|
|
looked = new FallingBlockEntity(player.getEntityWorld(), 0, 0, 0, state);
|
|
|
|
}
|
|
|
|
} else if (trace.getType() == HitResult.Type.ENTITY) {
|
|
|
|
looked = ((EntityHitResult)trace).getEntity();
|
|
|
|
|
|
|
|
if (looked instanceof PlayerEntity) {
|
2020-04-15 18:12:00 +02:00
|
|
|
looked = Pony.of((PlayerEntity)looked)
|
2020-09-24 14:49:02 +02:00
|
|
|
.getSpellOrEmpty(DisguiseSpell.class)
|
2020-01-27 17:37:22 +01:00
|
|
|
.map(DisguiseSpell::getDisguise)
|
2020-01-16 12:35:46 +01:00
|
|
|
.orElse(looked);
|
|
|
|
}
|
|
|
|
|
2020-09-22 15:11:20 +02:00
|
|
|
if (looked instanceof LightningEntity) {
|
2020-01-16 12:35:46 +01:00
|
|
|
looked = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-22 16:28:20 +02:00
|
|
|
player.getEntityWorld().playSound(null, player.getBlockPos(), SoundEvents.ENTITY_PARROT_IMITATE_RAVAGER, SoundCategory.PLAYERS, 1.4F, 0.4F);
|
2020-01-16 12:35:46 +01:00
|
|
|
|
2020-09-24 14:49:02 +02:00
|
|
|
iplayer.getSpellOrEmpty(DisguiseSpell.class).orElseGet(() -> {
|
2020-01-27 17:37:22 +01:00
|
|
|
DisguiseSpell disc = new DisguiseSpell();
|
2020-01-16 12:35:46 +01:00
|
|
|
|
2020-05-28 18:27:30 +02:00
|
|
|
iplayer.setSpell(disc);
|
2020-01-16 12:35:46 +01:00
|
|
|
return disc;
|
|
|
|
}).setDisguise(looked);
|
|
|
|
|
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) {
|
|
|
|
player.getMagicalReserves().addEnergy(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-04-26 19:33:10 +02:00
|
|
|
player.getMagicalReserves().setEnergy(0);
|
2020-01-16 12:35:46 +01:00
|
|
|
player.spawnParticles(UParticles.CHANGELING_MAGIC, 5);
|
|
|
|
}
|
|
|
|
}
|