Unicopia/src/main/java/com/minelittlepony/unicopia/EquineContext.java

55 lines
1.5 KiB
Java
Raw Normal View History

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;
}
default boolean collidesWithClouds() {
return getCompositeRace().canInteractWithClouds() || getCloudWalkingStrength() >= 1;
}
2024-03-28 16:32:21 +01:00
default boolean hasFeatherTouch() {
return false;
}
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()) {
2024-04-26 17:40:43 +02:00
return InteractionManager.getInstance().getEquineContext();
2023-10-18 19:52:59 +02:00
}
2024-03-28 16:32:21 +01:00
EquineContext result = context instanceof Container c ? c.get() : ABSENT;
return result == null ? ABSENT : result;
2023-10-15 17:51:57 +02:00
}
static EquineContext of(ItemUsageContext context) {
return MoreObjects.firstNonNull(Pony.of(context.getPlayer()), ABSENT);
}
static EquineContext of(Entity entity) {
if (entity instanceof EquineContext c) {
return c;
}
2023-10-15 17:51:57 +02:00
return MoreObjects.firstNonNull(Equine.of(entity).orElse(null), ABSENT);
}
2024-03-28 16:32:21 +01:00
interface Container {
EquineContext get();
}
2023-10-15 17:51:57 +02:00
}