44 lines
1.5 KiB
Java
44 lines
1.5 KiB
Java
package net.fretux.ascend.compat;
|
|
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraftforge.fml.ModList;
|
|
|
|
/** Optional Mind & Motion bridge with all foreign types isolated in Loaded. */
|
|
public final class AscendMMCompat {
|
|
private AscendMMCompat() {}
|
|
|
|
public static boolean isMindMotionPresent() {
|
|
return ModList.get().isLoaded("mindmotion");
|
|
}
|
|
|
|
public static boolean consumeClearMind(Player player) {
|
|
return isMindMotionPresent() && Loaded.consumeClearMind(player);
|
|
}
|
|
|
|
public static void restoreMind(Player player) {
|
|
if (isMindMotionPresent()) Loaded.restoreMind(player);
|
|
}
|
|
|
|
private static final class Loaded {
|
|
private static boolean consumeClearMind(Player player) {
|
|
final boolean[] success = {false};
|
|
player.getCapability(net.fretux.mindmotion.player.PlayerCapabilityProvider.SANITY).ifPresent(sanity -> {
|
|
if (sanity.getMaxSanity() > 0 && sanity.getSanity() / sanity.getMaxSanity() >= 0.90f) {
|
|
sanity.setSanity(0);
|
|
sanity.setInsanity(0);
|
|
success[0] = true;
|
|
}
|
|
});
|
|
return success[0];
|
|
}
|
|
|
|
private static void restoreMind(Player player) {
|
|
player.getCapability(net.fretux.mindmotion.player.PlayerCapabilityProvider.SANITY).ifPresent(sanity -> {
|
|
sanity.setSanity(sanity.getMaxSanity());
|
|
sanity.setInsanity(0);
|
|
});
|
|
}
|
|
|
|
}
|
|
}
|