package com.minelittlepony.unicopia.ducks; import java.util.Optional; import javax.annotation.Nullable; import com.minelittlepony.unicopia.equine.Ponylike; import com.minelittlepony.unicopia.magic.Caster; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; public interface PonyContainer> { Ponylike create(); T get(); @SuppressWarnings("unchecked") @Nullable default Caster getCaster() { T ientity = get(); if (ientity instanceof Caster) { return (Caster)ientity; } return null; } @SuppressWarnings("unchecked") static > Optional> of(Entity entity) { if (entity instanceof PonyContainer) { return Optional.of(((PonyContainer)entity)); } return Optional.empty(); } }