2023-10-15 17:51:57 +02:00
|
|
|
package com.minelittlepony.unicopia;
|
|
|
|
|
|
|
|
import com.google.common.base.MoreObjects;
|
|
|
|
import com.minelittlepony.unicopia.entity.Equine;
|
|
|
|
import com.minelittlepony.unicopia.entity.player.Pony;
|
|
|
|
|
|
|
|
import net.minecraft.block.ShapeContext;
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.item.ItemUsageContext;
|
|
|
|
|
|
|
|
public interface EquineContext {
|
|
|
|
EquineContext ABSENT = () -> Race.UNSET;
|
|
|
|
|
|
|
|
Race getSpecies();
|
|
|
|
|
|
|
|
default Race.Composite getCompositeRace() {
|
|
|
|
return getSpecies().composite();
|
|
|
|
}
|
|
|
|
|
2023-10-18 19:52:59 +02:00
|
|
|
default float getCloudWalkingStrength() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-10-21 21:30:13 +02:00
|
|
|
default boolean collidesWithClouds() {
|
|
|
|
return getCompositeRace().any(Race::canInteractWithClouds);
|
|
|
|
}
|
|
|
|
|
2023-10-15 17:51:57 +02:00
|
|
|
static EquineContext of(ShapeContext context) {
|
2023-10-18 19:52:59 +02:00
|
|
|
if (context == ShapeContext.absent()) {
|
|
|
|
return Unicopia.SIDE.getPony().map(EquineContext.class::cast).orElse(ABSENT);
|
|
|
|
}
|
2023-10-15 17:51:57 +02:00
|
|
|
return context instanceof EquineContext c ? c : ABSENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static EquineContext of(ItemUsageContext context) {
|
|
|
|
return MoreObjects.firstNonNull(Pony.of(context.getPlayer()), ABSENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static EquineContext of(Entity entity) {
|
2023-10-20 00:13:41 +02:00
|
|
|
if (entity instanceof EquineContext c) {
|
|
|
|
return c;
|
|
|
|
}
|
2023-10-15 17:51:57 +02:00
|
|
|
return MoreObjects.firstNonNull(Equine.of(entity).orElse(null), ABSENT);
|
|
|
|
}
|
|
|
|
}
|