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

37 lines
886 B
Java
Raw Normal View History

package com.minelittlepony.unicopia.entity;
2020-04-15 18:12:00 +02:00
import java.util.Optional;
import javax.annotation.Nullable;
import com.minelittlepony.unicopia.ability.magic.Caster;
2020-04-15 18:12:00 +02:00
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
public interface PonyContainer<T extends Equine<?>> {
2020-04-15 18:12:00 +02:00
Equine<?> create();
2020-04-15 18:12:00 +02:00
T get();
@SuppressWarnings("unchecked")
@Nullable
default <E extends LivingEntity> Caster<E> getCaster() {
T ientity = get();
if (ientity instanceof Caster) {
return (Caster<E>)ientity;
}
return null;
}
@SuppressWarnings("unchecked")
static <E extends Entity, T extends Equine<?>> Optional<PonyContainer<T>> of(Entity entity) {
2020-04-15 18:12:00 +02:00
if (entity instanceof PonyContainer) {
return Optional.of(((PonyContainer<T>)entity));
}
return Optional.empty();
}
}