Unicopia/src/main/java/com/minelittlepony/unicopia/entity/Equine.java

45 lines
1.4 KiB
Java
Raw Normal View History

package com.minelittlepony.unicopia.entity;
2020-01-16 12:35:46 +01:00
import java.util.Optional;
import java.util.function.Predicate;
2021-08-04 15:38:03 +02:00
import org.jetbrains.annotations.Nullable;
2020-04-15 18:12:00 +02:00
import com.minelittlepony.unicopia.EntityConvertable;
2023-10-15 17:51:57 +02:00
import com.minelittlepony.unicopia.EquineContext;
import com.minelittlepony.unicopia.Race;
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
2023-10-15 17:51:57 +02:00
public interface Equine<T extends Entity> extends NbtSerialisable, Tickable, ProjectileImpactListener, EntityConvertable<T>, EquineContext {
Physics getPhysics();
2020-01-16 12:35:46 +01:00
void setSpecies(Race race);
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
*/
boolean beforeUpdate();
2020-01-16 12:35:46 +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
}
@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
interface Container<T extends Equine<?>> {
Equine<?> create();
T get();
2020-04-15 18:12:00 +02:00
}
2020-01-16 12:35:46 +01:00
}