2020-09-22 15:11:20 +02:00
|
|
|
package com.minelittlepony.unicopia.entity;
|
2020-01-16 12:35:46 +01:00
|
|
|
|
2021-02-14 16:53:44 +01:00
|
|
|
import java.util.Optional;
|
2022-12-25 16:01:12 +01:00
|
|
|
import java.util.function.Predicate;
|
2021-02-14 16:53:44 +01:00
|
|
|
|
2021-08-04 15:38:03 +02:00
|
|
|
import org.jetbrains.annotations.Nullable;
|
2020-04-15 18:12:00 +02:00
|
|
|
|
2022-12-19 16:03:35 +01:00
|
|
|
import com.minelittlepony.unicopia.EntityConvertable;
|
2020-04-15 14:22:03 +02:00
|
|
|
import com.minelittlepony.unicopia.Race;
|
2021-03-06 10:58:44 +01:00
|
|
|
import com.minelittlepony.unicopia.projectile.ProjectileImpactListener;
|
2020-04-15 18:12:00 +02:00
|
|
|
import com.minelittlepony.unicopia.util.NbtSerialisable;
|
2021-08-04 15:38:03 +02:00
|
|
|
import com.minelittlepony.unicopia.util.Tickable;
|
2020-01-16 12:35:46 +01:00
|
|
|
|
2020-04-15 18:12:00 +02:00
|
|
|
import net.minecraft.entity.Entity;
|
2020-01-16 12:35:46 +01:00
|
|
|
|
2022-12-19 16:03:35 +01:00
|
|
|
public interface Equine<T extends Entity> extends NbtSerialisable, Tickable, ProjectileImpactListener, EntityConvertable<T> {
|
2020-05-10 17:18:45 +02:00
|
|
|
Physics getPhysics();
|
2020-01-16 12:35:46 +01:00
|
|
|
|
2022-12-25 16:01:12 +01:00
|
|
|
Race getSpecies();
|
2020-01-16 12:35:46 +01:00
|
|
|
|
2022-12-25 16:01:12 +01:00
|
|
|
void setSpecies(Race race);
|
2020-01-16 12:35:46 +01:00
|
|
|
|
2023-09-01 20:09:13 +02:00
|
|
|
default Race.Composite getCompositeRace() {
|
2023-09-03 12:06:44 +02:00
|
|
|
return getSpecies().composite();
|
2023-09-01 20:09:13 +02:00
|
|
|
}
|
|
|
|
|
2020-01-16 12:35:46 +01:00
|
|
|
/**
|
2020-01-27 11:05:22 +01:00
|
|
|
* Called at the beginning of an update cycle.
|
2020-01-16 12:35:46 +01:00
|
|
|
*/
|
2022-12-25 16:01:12 +01:00
|
|
|
boolean beforeUpdate();
|
2020-01-16 12:35:46 +01:00
|
|
|
|
2022-12-25 16:01:12 +01:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
static <E extends Entity, T extends Equine<? extends E>> Optional<T> of(@Nullable E entity) {
|
|
|
|
return entity instanceof Container ? Optional.of(((Container<T>)entity).get()) : Optional.empty();
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|
|
|
|
|
2022-12-25 16:01:12 +01:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
static <E extends Entity, T> Optional<T> of(@Nullable E entity, Predicate<Object> typeCheck) {
|
|
|
|
return entity instanceof Container
|
|
|
|
? (Optional<T>)Optional.of((Object)((Container<?>)entity).get()).filter(typeCheck)
|
|
|
|
: Optional.empty();
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|
2020-04-15 18:12:00 +02:00
|
|
|
|
2022-12-25 16:01:12 +01:00
|
|
|
interface Container<T extends Equine<?>> {
|
|
|
|
Equine<?> create();
|
2021-02-14 16:53:44 +01:00
|
|
|
|
2022-12-25 16:01:12 +01:00
|
|
|
T get();
|
2020-04-15 18:12:00 +02:00
|
|
|
}
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|