mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-11-04 20:39:09 +01:00
53 lines
1.7 KiB
Java
53 lines
1.7 KiB
Java
|
package de.ellpeck.naturesaura.recipes;
|
||
|
|
||
|
import com.google.gson.JsonObject;
|
||
|
import de.ellpeck.naturesaura.ModConfig;
|
||
|
import de.ellpeck.naturesaura.NaturesAura;
|
||
|
import net.minecraft.util.JSONUtils;
|
||
|
import net.minecraft.util.ResourceLocation;
|
||
|
import net.minecraftforge.common.ForgeConfigSpec;
|
||
|
import net.minecraftforge.common.crafting.conditions.ICondition;
|
||
|
import net.minecraftforge.common.crafting.conditions.IConditionSerializer;
|
||
|
|
||
|
public class EnabledCondition implements ICondition {
|
||
|
private static final ResourceLocation NAME = new ResourceLocation(NaturesAura.MOD_ID, "enabled");
|
||
|
private ForgeConfigSpec.ConfigValue<Boolean> config;
|
||
|
private final String name;
|
||
|
|
||
|
public EnabledCondition(String name) {
|
||
|
this.name = name;
|
||
|
try {
|
||
|
this.config = (ForgeConfigSpec.ConfigValue<Boolean>) ModConfig.class.getField(name).get(ModConfig.instance);
|
||
|
} catch (IllegalAccessException | NoSuchFieldException e) {
|
||
|
NaturesAura.LOGGER.error(e);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public ResourceLocation getID() {
|
||
|
return NAME;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public boolean test() {
|
||
|
return this.config != null && this.config.get();
|
||
|
}
|
||
|
|
||
|
public static class Serializer implements IConditionSerializer<EnabledCondition> {
|
||
|
@Override
|
||
|
public void write(JsonObject json, EnabledCondition value) {
|
||
|
json.addProperty("config", value.name);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public EnabledCondition read(JsonObject json) {
|
||
|
return new EnabledCondition(JSONUtils.getString(json, "config"));
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public ResourceLocation getID() {
|
||
|
return EnabledCondition.NAME;
|
||
|
}
|
||
|
}
|
||
|
}
|