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

123 lines
2.8 KiB
Java
Raw Normal View History

package com.minelittlepony.unicopia.ability;
2018-09-12 01:29:49 +02:00
import javax.annotation.Nullable;
2020-04-15 17:22:29 +02:00
import com.google.gson.annotations.Expose;
2020-04-15 15:55:18 +02:00
import com.minelittlepony.unicopia.IKeyBinding;
import com.minelittlepony.unicopia.Race;
2020-04-15 18:12:00 +02:00
import com.minelittlepony.unicopia.entity.player.Pony;
2018-09-12 01:29:49 +02:00
2020-04-15 17:22:29 +02:00
import net.minecraft.util.math.BlockPos;
2020-01-16 12:35:46 +01:00
import net.minecraft.world.World;
2018-09-12 01:29:49 +02:00
2020-04-15 17:22:29 +02:00
public interface Ability<T extends Ability.IData> extends IKeyBinding {
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.
*/
2020-04-15 18:12:00 +02:00
int getWarmupTime(Pony player);
2018-09-12 01:29:49 +02:00
/**
* Returns the number of ticks allowed for cooldown
*/
2020-04-15 18:12:00 +02:00
int getCooldownTime(Pony player);
2018-09-12 01:29:49 +02:00
/**
* Called to check preconditions for activating the ability.
*
* @param w The world
* @param player The player
* @return True to allow activation
*/
2020-04-15 18:12:00 +02:00
default boolean canActivate(World w, Pony player) {
2018-09-12 01:29:49 +02:00
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
* @return Data to be sent, or null if activation failed
*/
@Nullable
2020-04-15 18:12:00 +02:00
T tryActivate(Pony player);
2018-09-12 01:29:49 +02:00
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
*/
2020-04-15 18:12:00 +02:00
void apply(Pony player, T data);
2018-09-12 01:29:49 +02:00
/**
2019-02-03 10:45:45 +01:00
* Called every tick until the warmup timer runs out.
2018-09-12 01:29:49 +02:00
* @param player The current player
*/
2020-04-15 18:12:00 +02:00
void preApply(Pony player);
2018-09-12 01:29:49 +02:00
/**
* Called every tick until the cooldown timer runs out.
* @param player The current player
*/
2020-04-15 18:12:00 +02:00
void postApply(Pony player);
2018-09-12 01:29:49 +02:00
public interface IData {
}
2020-04-15 17:22:29 +02:00
class Pos implements Ability.IData {
@Expose
public int x;
@Expose
public int y;
@Expose
public int z;
public Pos(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public Pos(BlockPos pos) {
x = pos.getX();
y = pos.getY();
z = pos.getZ();
}
public BlockPos pos() {
return new BlockPos(x, y, z);
}
}
class Hit implements Ability.IData {
}
class Numeric implements IData {
@Expose
public int type;
public Numeric(int t) {
type = t;
}
}
2018-09-12 01:29:49 +02:00
}