2020-01-17 14:27:26 +01:00
|
|
|
package com.minelittlepony.unicopia.ability;
|
2018-09-20 16:28:17 +02:00
|
|
|
|
2020-01-16 12:35:46 +01:00
|
|
|
import org.lwjgl.glfw.GLFW;
|
2018-09-20 16:28:17 +02:00
|
|
|
|
|
|
|
import com.minelittlepony.unicopia.Race;
|
2020-01-17 14:27:26 +01:00
|
|
|
import com.minelittlepony.unicopia.entity.capabilities.IPlayer;
|
2020-01-16 12:35:46 +01:00
|
|
|
import com.minelittlepony.util.VecHelper;
|
2018-09-20 16:28:17 +02:00
|
|
|
|
2020-01-16 12:35:46 +01:00
|
|
|
import net.minecraft.client.network.packet.EntityPassengersSetS2CPacket;
|
2018-09-20 16:28:17 +02: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;
|
|
|
|
import net.minecraft.server.network.ServerPlayerEntity;
|
2018-09-20 16:28:17 +02:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
public class PowerCarry implements IPower<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;
|
2018-09-20 16:28:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getWarmupTime(IPlayer player) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getCooldownTime(IPlayer player) {
|
|
|
|
return 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canUse(Race playerSpecies) {
|
|
|
|
return playerSpecies.canFly();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-02-03 10:45:45 +01:00
|
|
|
public Hit tryActivate(IPlayer player) {
|
2018-09-20 16:28:17 +02:00
|
|
|
return new Hit();
|
|
|
|
}
|
|
|
|
|
2020-01-16 12:35:46 +01:00
|
|
|
protected LivingEntity findRider(PlayerEntity player, World w) {
|
2018-09-20 16:28:17 +02:00
|
|
|
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;
|
2019-02-02 17:50:48 +01:00
|
|
|
}
|
2018-09-20 16:28:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Class<Hit> getPackageType() {
|
|
|
|
return Hit.class;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-02-03 10:45:45 +01:00
|
|
|
public void apply(IPlayer iplayer, Hit data) {
|
2020-01-16 12:35:46 +01:00
|
|
|
PlayerEntity player = iplayer.getOwner();
|
|
|
|
LivingEntity rider = findRider(player, iplayer.getWorld());
|
2018-09-20 16:28:17 +02:00
|
|
|
|
|
|
|
if (rider != null) {
|
|
|
|
rider.startRiding(player, true);
|
|
|
|
} else {
|
2020-01-16 12:35:46 +01:00
|
|
|
player.removeAllPassengers();
|
2018-09-20 16:28:17 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
public void preApply(IPlayer player) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void postApply(IPlayer player) {
|
|
|
|
}
|
2020-01-16 12:35:46 +01:00
|
|
|
|
|
|
|
public interface IPickupImmuned {
|
|
|
|
|
|
|
|
}
|
2018-09-20 16:28:17 +02:00
|
|
|
}
|