mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-11-16 07:24:32 +01:00
cf3ef8c229
- Remove AllColorHandlers as it was empty - Organize imports
39 lines
944 B
Java
39 lines
944 B
Java
package com.simibubi.create.compat;
|
|
|
|
import java.util.Optional;
|
|
import java.util.function.Supplier;
|
|
|
|
import net.minecraftforge.fml.ModList;
|
|
|
|
/**
|
|
* For compatibility with and without another mod present, we have to define load conditions of the specific code
|
|
*/
|
|
public enum Mods {
|
|
DYNAMICTREES;
|
|
|
|
/**
|
|
* @return a boolean of whether the mod is loaded or not based on mod id
|
|
*/
|
|
public boolean isLoaded() {
|
|
return ModList.get().isLoaded(asId());
|
|
}
|
|
|
|
/**
|
|
* @return the mod id
|
|
*/
|
|
public String asId() {
|
|
return name().toLowerCase();
|
|
}
|
|
|
|
/**
|
|
* Simple hook to run code if a mod is installed
|
|
* @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
|
|
*/
|
|
public <T> Optional<T> runIfInstalled(Supplier<Supplier<T>> toRun) {
|
|
if (isLoaded())
|
|
return Optional.of(toRun.get().get());
|
|
return Optional.empty();
|
|
}
|
|
}
|