2018-09-20 16:28:17 +02:00
|
|
|
package com.minelittlepony.unicopia.power;
|
|
|
|
|
|
|
|
import org.lwjgl.input.Keyboard;
|
|
|
|
|
|
|
|
import com.minelittlepony.unicopia.Race;
|
2019-02-02 17:50:48 +01:00
|
|
|
import com.minelittlepony.unicopia.entity.EntityCloud;
|
2018-09-20 16:28:17 +02:00
|
|
|
import com.minelittlepony.unicopia.player.IPlayer;
|
|
|
|
import com.minelittlepony.unicopia.power.data.Hit;
|
|
|
|
import com.minelittlepony.util.vector.VecHelper;
|
|
|
|
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
|
|
|
import net.minecraft.network.play.server.SPacketSetPassengers;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
public class PowerCarry implements IPower<Hit> {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getKeyName() {
|
|
|
|
return "unicopia.power.carry";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getKeyCode() {
|
|
|
|
return Keyboard.KEY_K;
|
|
|
|
}
|
|
|
|
|
|
|
|
@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();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected EntityLivingBase findRider(EntityPlayer player, World w) {
|
|
|
|
Entity hit = VecHelper.getLookedAtEntity(player, 10);
|
|
|
|
|
|
|
|
if (hit instanceof EntityLivingBase && !player.isRidingOrBeingRiddenBy(hit)) {
|
2019-02-02 17:50:48 +01:00
|
|
|
if (!(hit instanceof EntityCloud)) {
|
|
|
|
return (EntityLivingBase)hit;
|
|
|
|
}
|
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) {
|
|
|
|
EntityPlayer player = iplayer.getOwner();
|
|
|
|
EntityLivingBase rider = findRider(player, iplayer.getWorld());
|
2018-09-20 16:28:17 +02:00
|
|
|
|
|
|
|
if (rider != null) {
|
|
|
|
rider.startRiding(player, true);
|
|
|
|
} else {
|
|
|
|
player.removePassengers();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (player instanceof EntityPlayerMP) {
|
|
|
|
((EntityPlayerMP)player).getServerWorld().getEntityTracker().sendToTrackingAndSelf(player, new SPacketSetPassengers(player));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void preApply(IPlayer player) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void postApply(IPlayer player) {
|
|
|
|
}
|
|
|
|
}
|