2020-04-15 14:22:03 +02:00
|
|
|
package com.minelittlepony.unicopia.ability;
|
2018-09-20 16:28:17 +02:00
|
|
|
|
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;
|
2020-09-22 15:11:20 +02:00
|
|
|
import com.minelittlepony.unicopia.entity.player.Pony;
|
2020-09-27 20:07:55 +02:00
|
|
|
import com.minelittlepony.unicopia.util.RayTraceHelper;
|
2021-01-27 12:16:05 +01:00
|
|
|
|
2020-01-16 12:35:46 +01:00
|
|
|
import net.minecraft.entity.LivingEntity;
|
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
2020-06-26 11:44:47 +02:00
|
|
|
import net.minecraft.network.packet.s2c.play.EntityPassengersSetS2CPacket;
|
2020-01-16 12:35:46 +01:00
|
|
|
import net.minecraft.server.network.ServerPlayerEntity;
|
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) {
|
2018-09-20 16:28:17 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@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) {
|
2020-09-27 20:07:55 +02:00
|
|
|
return RayTraceHelper.<LivingEntity>findEntity(player, 10, 1, hit -> {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
|
|
LivingEntity rider = findRider(player, iplayer.getWorld());
|
2018-09-20 16:28:17 +02:00
|
|
|
|
2021-01-27 09:15:13 +01:00
|
|
|
if (player.hasPassengers()) {
|
|
|
|
player.removeAllPassengers();
|
|
|
|
}
|
|
|
|
|
2018-09-20 16:28:17 +02:00
|
|
|
if (rider != null) {
|
|
|
|
rider.startRiding(player, true);
|
|
|
|
}
|
|
|
|
|
2020-01-16 12:35:46 +01:00
|
|
|
if (player instanceof ServerPlayerEntity) {
|
|
|
|
((ServerPlayerEntity)player).networkHandler.sendPacket(new EntityPassengersSetS2CPacket(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
|
|
|
}
|