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

96 lines
2.3 KiB
Java
Raw Normal View History

package com.minelittlepony.unicopia.ability;
2020-01-16 12:35:46 +01:00
import org.lwjgl.glfw.GLFW;
import com.minelittlepony.unicopia.Race;
2020-04-15 18:12:00 +02:00
import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.util.VecHelper;
2020-01-16 12:35:46 +01:00
import net.minecraft.client.network.packet.EntityPassengersSetS2CPacket;
import net.minecraft.entity.Entity;
2020-01-16 12:35:46 +01:00
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.world.World;
/**
* Pegasi ability to pick up and carry other players
*/
2020-04-15 17:22:29 +02:00
public class PegasusCarryAbility implements Ability<Ability.Hit> {
@Override
public String getKeyName() {
return "unicopia.power.carry";
}
@Override
public int getKeyCode() {
2020-01-16 12:35:46 +01:00
return GLFW.GLFW_KEY_K;
}
@Override
2020-04-15 18:12:00 +02:00
public int getWarmupTime(Pony player) {
return 0;
}
@Override
2020-04-15 18:12:00 +02:00
public int getCooldownTime(Pony player) {
return 10;
}
@Override
public boolean canUse(Race playerSpecies) {
return playerSpecies.canFly();
}
@Override
2020-04-15 18:12:00 +02:00
public Hit tryActivate(Pony player) {
return new Hit();
}
2020-01-16 12:35:46 +01:00
protected LivingEntity findRider(PlayerEntity player, World w) {
Entity hit = VecHelper.getLookedAtEntity(player, 10);
2020-01-16 12:35:46 +01:00
if (hit instanceof LivingEntity && !player.isConnectedThroughVehicle(hit)) {
if (!(hit instanceof IPickupImmuned)) {
return (LivingEntity)hit;
}
}
return null;
}
@Override
public Class<Hit> getPackageType() {
return Hit.class;
}
@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();
LivingEntity rider = findRider(player, iplayer.getWorld());
if (rider != null) {
rider.startRiding(player, true);
} else {
2020-01-16 12:35:46 +01:00
player.removeAllPassengers();
}
2020-01-16 12:35:46 +01:00
if (player instanceof ServerPlayerEntity) {
((ServerPlayerEntity)player).networkHandler.sendPacket(new EntityPassengersSetS2CPacket(player));
}
}
@Override
2020-04-15 18:12:00 +02:00
public void preApply(Pony player) {
}
@Override
2020-04-15 18:12:00 +02:00
public void postApply(Pony player) {
}
2020-01-16 12:35:46 +01:00
public interface IPickupImmuned {
}
}