2021-05-20 08:31:35 +02:00
|
|
|
package com.simibubi.create.compat;
|
|
|
|
|
|
|
|
import java.util.Optional;
|
|
|
|
import java.util.function.Supplier;
|
|
|
|
|
2021-08-25 13:46:53 +02:00
|
|
|
import com.simibubi.create.foundation.utility.Lang;
|
|
|
|
|
2021-07-08 20:17:35 +02:00
|
|
|
import net.minecraftforge.fml.ModList;
|
|
|
|
|
2021-05-20 08:31:35 +02:00
|
|
|
/**
|
|
|
|
* For compatibility with and without another mod present, we have to define load conditions of the specific code
|
|
|
|
*/
|
|
|
|
public enum Mods {
|
2021-08-25 13:46:53 +02:00
|
|
|
DYNAMICTREES,
|
|
|
|
TCONSTRUCT;
|
2021-05-20 08:31:35 +02:00
|
|
|
|
|
|
|
/**
|
2021-05-20 08:39:22 +02:00
|
|
|
* @return a boolean of whether the mod is loaded or not based on mod id
|
2021-05-20 08:31:35 +02:00
|
|
|
*/
|
|
|
|
public boolean isLoaded() {
|
|
|
|
return ModList.get().isLoaded(asId());
|
|
|
|
}
|
|
|
|
|
2021-05-20 08:39:22 +02:00
|
|
|
/**
|
|
|
|
* @return the mod id
|
|
|
|
*/
|
2021-05-20 08:31:35 +02:00
|
|
|
public String asId() {
|
2021-08-25 13:46:53 +02:00
|
|
|
return Lang.asId(name());
|
2021-05-20 08:31:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Simple hook to run code if a mod is installed
|
2021-05-20 08:39:22 +02:00
|
|
|
* @param toRun will be run only if the mod is loaded
|
|
|
|
* @return Optional.empty() if the mod is not loaded, otherwise an Optional of the return value of the given supplier
|
2021-05-20 08:31:35 +02:00
|
|
|
*/
|
|
|
|
public <T> Optional<T> runIfInstalled(Supplier<Supplier<T>> toRun) {
|
|
|
|
if (isLoaded())
|
|
|
|
return Optional.of(toRun.get().get());
|
|
|
|
return Optional.empty();
|
|
|
|
}
|
|
|
|
}
|