2020-04-15 14:22:03 +02:00
|
|
|
package com.minelittlepony.unicopia.ability;
|
2018-09-20 16:28:17 +02:00
|
|
|
|
2022-12-25 19:37:04 +01:00
|
|
|
import java.util.List;
|
2023-01-09 01:27:22 +01:00
|
|
|
import java.util.UUID;
|
2022-12-25 19:37:04 +01:00
|
|
|
import java.util.stream.StreamSupport;
|
|
|
|
|
2020-04-15 14:22:03 +02:00
|
|
|
import com.minelittlepony.unicopia.Race;
|
2020-04-25 15:37:17 +02:00
|
|
|
import com.minelittlepony.unicopia.ability.data.Hit;
|
2022-10-03 23:44:30 +02:00
|
|
|
import com.minelittlepony.unicopia.entity.Living;
|
2020-09-22 15:11:20 +02:00
|
|
|
import com.minelittlepony.unicopia.entity.player.Pony;
|
2022-10-01 18:20:53 +02:00
|
|
|
import com.minelittlepony.unicopia.util.TraceHelper;
|
2021-01-27 12:16:05 +01:00
|
|
|
|
2022-12-25 19:37:04 +01:00
|
|
|
import net.minecraft.entity.Entity;
|
2020-01-16 12:35:46 +01:00
|
|
|
import net.minecraft.entity.LivingEntity;
|
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
2018-09-20 16:28:17 +02:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
2020-01-27 17:37:22 +01:00
|
|
|
/**
|
|
|
|
* Pegasi ability to pick up and carry other players
|
|
|
|
*/
|
2020-04-25 15:46:29 +02:00
|
|
|
public class CarryAbility implements Ability<Hit> {
|
2018-09-20 16:28:17 +02:00
|
|
|
|
|
|
|
@Override
|
2020-04-15 18:12:00 +02:00
|
|
|
public int getWarmupTime(Pony player) {
|
2022-09-26 21:13:58 +02:00
|
|
|
return 5;
|
2018-09-20 16:28:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-04-15 18:12:00 +02:00
|
|
|
public int getCooldownTime(Pony player) {
|
2018-09-20 16:28:17 +02:00
|
|
|
return 10;
|
|
|
|
}
|
|
|
|
|
2020-10-09 19:05:12 +02:00
|
|
|
@Override
|
|
|
|
public double getCostEstimate(Pony player) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-20 16:28:17 +02:00
|
|
|
@Override
|
2020-05-10 17:18:45 +02:00
|
|
|
public boolean canUse(Race race) {
|
|
|
|
return race.canFly();
|
2018-09-20 16:28:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@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;
|
2018-09-20 16:28:17 +02:00
|
|
|
}
|
|
|
|
|
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);
|
2018-09-20 16:28:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-04-25 15:37:17 +02:00
|
|
|
public Hit.Serializer<Hit> getSerializer() {
|
|
|
|
return Hit.SERIALIZER;
|
2018-09-20 16:28:17 +02:00
|
|
|
}
|
|
|
|
|
2022-09-26 21:13:58 +02:00
|
|
|
@Override
|
|
|
|
public boolean onQuickAction(Pony player, ActivationType type) {
|
|
|
|
|
|
|
|
if (type == ActivationType.TAP && player.getPhysics().isFlying()) {
|
2022-12-19 18:13:15 +01:00
|
|
|
player.getPhysics().dashForward((float)player.asWorld().random.nextTriangular(1, 0.3F));
|
2022-09-26 21:13:58 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-20 16:28:17 +02:00
|
|
|
@Override
|
2020-04-15 18:12:00 +02:00
|
|
|
public void apply(Pony iplayer, Hit data) {
|
2022-12-19 16:03:35 +01:00
|
|
|
PlayerEntity player = iplayer.asEntity();
|
2022-12-19 18:13:15 +01:00
|
|
|
LivingEntity rider = findRider(player, iplayer.asWorld());
|
2018-09-20 16:28:17 +02:00
|
|
|
|
2021-01-27 09:15:13 +01:00
|
|
|
if (player.hasPassengers()) {
|
2022-12-25 19:37:04 +01:00
|
|
|
List<Entity> passengers = StreamSupport.stream(player.getPassengersDeep().spliterator(), false).toList();
|
2021-01-27 09:15:13 +01:00
|
|
|
player.removeAllPassengers();
|
2022-12-25 19:37:04 +01:00
|
|
|
for (Entity passenger : passengers) {
|
|
|
|
passenger.refreshPositionAfterTeleport(player.getPos());
|
2023-01-09 01:27:22 +01:00
|
|
|
Living<?> l = Living.living(passenger);
|
|
|
|
if (l != null) {
|
|
|
|
l.setCarrier((UUID)null);
|
|
|
|
}
|
2022-12-25 19:37:04 +01:00
|
|
|
}
|
2021-01-27 09:15:13 +01:00
|
|
|
}
|
|
|
|
|
2018-09-20 16:28:17 +02:00
|
|
|
if (rider != null) {
|
|
|
|
rider.startRiding(player, true);
|
2022-12-25 19:36:43 +01:00
|
|
|
Living.getOrEmpty(rider).ifPresent(living -> living.setCarrier(player));
|
2018-09-20 16:28:17 +02:00
|
|
|
}
|
|
|
|
|
2022-10-03 23:44:30 +02:00
|
|
|
Living.transmitPassengers(player);
|
2018-09-20 16:28:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-05-10 20:45:07 +02:00
|
|
|
public void preApply(Pony player, AbilitySlot slot) {
|
2018-09-20 16:28:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-05-10 20:45:07 +02:00
|
|
|
public void postApply(Pony player, AbilitySlot slot) {
|
2018-09-20 16:28:17 +02:00
|
|
|
}
|
2020-01-16 12:35:46 +01:00
|
|
|
|
|
|
|
public interface IPickupImmuned {
|
|
|
|
|
|
|
|
}
|
2018-09-20 16:28:17 +02:00
|
|
|
}
|