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() {
|
2024-09-25 20:42:10 +02:00
|
|
|
return getCompositeRace().canInteractWithClouds() || getCloudWalkingStrength() >= 1;
|
2023-10-21 21:30:13 +02:00
|
|
|
}
|
|
|
|
|
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) {
|
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);
|
|
|
|
}
|
2024-03-28 16:32:21 +01:00
|
|
|
|
|
|
|
interface Container {
|
|
|
|
EquineContext get();
|
|
|
|
}
|
2023-10-15 17:51:57 +02:00
|
|
|
}
|