2018-09-12 01:29:49 +02:00
|
|
|
package com.minelittlepony.unicopia.power;
|
|
|
|
|
2019-02-02 17:50:15 +01:00
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
2018-09-12 01:29:49 +02:00
|
|
|
import com.minelittlepony.unicopia.Race;
|
|
|
|
import com.minelittlepony.unicopia.input.IKeyBind;
|
2019-01-28 18:42:18 +01:00
|
|
|
import com.minelittlepony.unicopia.particle.Particles;
|
2018-09-12 01:29:49 +02:00
|
|
|
import com.minelittlepony.unicopia.player.IPlayer;
|
2018-09-12 22:37:06 +02:00
|
|
|
import com.minelittlepony.util.shape.IShape;
|
|
|
|
import com.minelittlepony.util.shape.Sphere;
|
2018-09-12 01:29:49 +02:00
|
|
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.util.DamageSource;
|
2018-09-12 22:37:06 +02:00
|
|
|
import net.minecraft.util.math.Vec3d;
|
2018-09-12 01:29:49 +02:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
public interface IPower<T extends IData> extends IKeyBind {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Subtracts a given food amount from the player.
|
|
|
|
* Harms the player if there is not enough enough hunger available.
|
|
|
|
*/
|
|
|
|
static boolean takeFromPlayer(EntityPlayer player, double foodSubtract) {
|
|
|
|
if (!player.capabilities.isCreativeMode) {
|
|
|
|
int food = (int)(player.getFoodStats().getFoodLevel() - foodSubtract);
|
|
|
|
if (food < 0) {
|
|
|
|
player.getFoodStats().addStats(-player.getFoodStats().getFoodLevel(), 0);
|
|
|
|
player.attackEntityFrom(DamageSource.MAGIC, -food);
|
|
|
|
} else {
|
|
|
|
player.getFoodStats().addStats((int)-foodSubtract, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return player.getHealth() > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static double getPlayerEyeYPos(EntityPlayer player) {
|
|
|
|
if (player.getEntityWorld().isRemote) {
|
|
|
|
return player.posY + player.getEyeHeight() - player.getYOffset();
|
|
|
|
}
|
|
|
|
return player.posY + player.getEyeHeight() - 1;
|
|
|
|
}
|
|
|
|
|
2018-09-13 14:04:24 +02:00
|
|
|
static void spawnParticles(int particleId, IPlayer player, int count) {
|
2018-09-12 22:37:06 +02:00
|
|
|
|
2018-09-13 14:04:24 +02:00
|
|
|
EntityPlayer entity = player.getOwner();
|
|
|
|
|
|
|
|
double halfDist = entity.getEyeHeight() / 1.5;
|
|
|
|
double middle = entity.getEntityBoundingBox().minY + halfDist;
|
2018-09-12 01:29:49 +02:00
|
|
|
|
2018-09-12 22:37:06 +02:00
|
|
|
IShape shape = new Sphere(false, (float)halfDist);
|
|
|
|
|
2018-09-12 01:29:49 +02:00
|
|
|
for (int i = 0; i < count; i++) {
|
2018-09-13 14:04:24 +02:00
|
|
|
Vec3d point = shape.computePoint(entity.getEntityWorld().rand);
|
2018-09-12 01:29:49 +02:00
|
|
|
|
|
|
|
Particles.instance().spawnParticle(particleId, false,
|
2018-09-13 14:04:24 +02:00
|
|
|
entity.posX + point.x,
|
2018-09-12 22:37:06 +02:00
|
|
|
middle + point.y,
|
2018-09-13 14:04:24 +02:00
|
|
|
entity.posZ + point.z,
|
2018-09-12 22:37:06 +02:00
|
|
|
0, 0, 0);
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
default String getKeyCategory() {
|
|
|
|
return "unicopia.category.name";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the number of ticks the player must hold the ability key to trigger this ability.
|
|
|
|
*/
|
|
|
|
int getWarmupTime(IPlayer player);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the number of ticks allowed for cooldown
|
|
|
|
*/
|
|
|
|
int getCooldownTime(IPlayer player);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called to check preconditions for activating the ability.
|
|
|
|
*
|
|
|
|
* @param w The world
|
|
|
|
* @param player The player
|
|
|
|
* @return True to allow activation
|
|
|
|
*/
|
|
|
|
default boolean canActivate(World w, IPlayer player) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given race is permitted to use this ability
|
|
|
|
* @param playerSpecies The player's species
|
|
|
|
*/
|
|
|
|
boolean canUse(Race playerSpecies);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called on the client to activate the ability.
|
|
|
|
*
|
|
|
|
* @param player The player activating the ability
|
|
|
|
* @param w The player's world
|
|
|
|
* @return Data to be sent, or null if activation failed
|
|
|
|
*/
|
2019-02-02 17:50:15 +01:00
|
|
|
@Nullable
|
2018-09-12 01:29:49 +02:00
|
|
|
T tryActivate(EntityPlayer player, World w);
|
|
|
|
|
|
|
|
Class<T> getPackageType();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called to actually apply the ability.
|
|
|
|
* Only called on the server side.
|
|
|
|
*
|
|
|
|
* @param player The player that triggered the ability
|
|
|
|
* @param data Data previously sent from the client
|
|
|
|
*/
|
|
|
|
void apply(EntityPlayer player, T data);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called just before the ability is activated.
|
|
|
|
* @param player The current player
|
|
|
|
*/
|
2018-09-13 14:04:24 +02:00
|
|
|
void preApply(IPlayer player);
|
2018-09-12 01:29:49 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called every tick until the cooldown timer runs out.
|
|
|
|
* @param player The current player
|
|
|
|
*/
|
2018-09-13 14:04:24 +02:00
|
|
|
void postApply(IPlayer player);
|
2018-09-12 01:29:49 +02:00
|
|
|
|
|
|
|
}
|