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

93 lines
2.3 KiB
Java
Raw Normal View History

package com.minelittlepony.unicopia.ability;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.ability.data.Hit;
import com.minelittlepony.unicopia.entity.Living;
import com.minelittlepony.unicopia.entity.player.Pony;
2022-10-01 18:20:53 +02:00
import com.minelittlepony.unicopia.util.TraceHelper;
2020-01-16 12:35:46 +01:00
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.world.World;
/**
* Pegasi ability to pick up and carry other players
*/
2020-04-25 15:46:29 +02:00
public class CarryAbility implements Ability<Hit> {
@Override
2020-04-15 18:12:00 +02:00
public int getWarmupTime(Pony player) {
return 5;
}
@Override
2020-04-15 18:12:00 +02:00
public int getCooldownTime(Pony player) {
return 10;
}
@Override
public double getCostEstimate(Pony player) {
return 0;
}
@Override
public boolean canUse(Race race) {
return race.canFly();
}
@Override
2020-04-15 18:12:00 +02:00
public Hit tryActivate(Pony player) {
return Hit.INSTANCE;
}
2020-01-16 12:35:46 +01:00
protected LivingEntity findRider(PlayerEntity player, World w) {
2022-10-01 18:20:53 +02:00
return TraceHelper.<LivingEntity>findEntity(player, 10, 1, hit -> {
2020-09-27 20:07:55 +02:00
return hit instanceof LivingEntity && !player.isConnectedThroughVehicle(hit) && !(hit instanceof IPickupImmuned);
}).orElse(null);
}
@Override
public Hit.Serializer<Hit> getSerializer() {
return Hit.SERIALIZER;
}
@Override
public boolean onQuickAction(Pony player, ActivationType type) {
if (type == ActivationType.TAP && player.getPhysics().isFlying()) {
player.getPhysics().dashForward((float)player.asWorld().random.nextTriangular(1, 0.3F));
return true;
}
return false;
}
@Override
2020-04-15 18:12:00 +02:00
public void apply(Pony iplayer, Hit data) {
PlayerEntity player = iplayer.asEntity();
LivingEntity rider = findRider(player, iplayer.asWorld());
if (player.hasPassengers()) {
player.removeAllPassengers();
}
if (rider != null) {
rider.startRiding(player, true);
}
Living.transmitPassengers(player);
}
@Override
public void preApply(Pony player, AbilitySlot slot) {
}
@Override
public void postApply(Pony player, AbilitySlot slot) {
}
2020-01-16 12:35:46 +01:00
public interface IPickupImmuned {
}
}