2020-04-15 18:12:00 +02:00
|
|
|
package com.minelittlepony.unicopia.ducks;
|
|
|
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
2020-06-26 11:44:47 +02:00
|
|
|
import com.minelittlepony.unicopia.equine.Ponylike;
|
2020-04-15 18:12:00 +02:00
|
|
|
import com.minelittlepony.unicopia.magic.Caster;
|
|
|
|
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.LivingEntity;
|
|
|
|
|
2020-05-10 17:18:45 +02:00
|
|
|
public interface PonyContainer<T extends Ponylike<?>> {
|
2020-04-15 18:12:00 +02:00
|
|
|
|
2020-05-10 17:18:45 +02:00
|
|
|
Ponylike<?> 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")
|
2020-05-10 17:18:45 +02:00
|
|
|
static <E extends Entity, T extends Ponylike<?>> 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();
|
|
|
|
}
|
|
|
|
}
|