2021-01-11 23:39:19 +01:00
|
|
|
package de.ellpeck.naturesaura.recipes;
|
|
|
|
|
|
|
|
import com.google.gson.JsonObject;
|
|
|
|
import de.ellpeck.naturesaura.ModConfig;
|
|
|
|
import de.ellpeck.naturesaura.NaturesAura;
|
2021-12-08 00:31:29 +01:00
|
|
|
import net.minecraft.resources.ResourceLocation;
|
|
|
|
import net.minecraft.util.GsonHelper;
|
2024-02-03 14:56:07 +01:00
|
|
|
import net.neoforged.neoforge.common.ModConfigSpec;
|
|
|
|
import net.neoforged.neoforge.common.crafting.conditions.ICondition;
|
|
|
|
import net.neoforged.neoforge.common.crafting.conditions.IConditionSerializer;
|
2021-01-11 23:39:19 +01:00
|
|
|
|
|
|
|
public class EnabledCondition implements ICondition {
|
2021-12-08 00:31:29 +01:00
|
|
|
|
2021-01-11 23:39:19 +01:00
|
|
|
private static final ResourceLocation NAME = new ResourceLocation(NaturesAura.MOD_ID, "enabled");
|
2024-02-03 14:56:07 +01:00
|
|
|
private ModConfigSpec.ConfigValue<Boolean> config;
|
2021-01-11 23:39:19 +01:00
|
|
|
private final String name;
|
|
|
|
|
2021-12-08 00:31:29 +01:00
|
|
|
@SuppressWarnings("unchecked")
|
2021-01-11 23:39:19 +01:00
|
|
|
public EnabledCondition(String name) {
|
|
|
|
this.name = name;
|
|
|
|
try {
|
2024-02-03 14:56:07 +01:00
|
|
|
this.config = (ModConfigSpec.ConfigValue<Boolean>) ModConfig.class.getField(name).get(ModConfig.instance);
|
2021-01-11 23:39:19 +01:00
|
|
|
} catch (IllegalAccessException | NoSuchFieldException e) {
|
|
|
|
NaturesAura.LOGGER.error(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ResourceLocation getID() {
|
2022-06-27 15:24:04 +02:00
|
|
|
return EnabledCondition.NAME;
|
2021-01-11 23:39:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-06-27 15:24:04 +02:00
|
|
|
public boolean test(IContext context) {
|
2021-01-11 23:39:19 +01:00
|
|
|
return this.config != null && this.config.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class Serializer implements IConditionSerializer<EnabledCondition> {
|
2021-12-08 00:31:29 +01:00
|
|
|
|
2021-01-11 23:39:19 +01:00
|
|
|
@Override
|
|
|
|
public void write(JsonObject json, EnabledCondition value) {
|
|
|
|
json.addProperty("config", value.name);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EnabledCondition read(JsonObject json) {
|
2021-12-08 00:31:29 +01:00
|
|
|
return new EnabledCondition(GsonHelper.getAsString(json, "config"));
|
2021-01-11 23:39:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ResourceLocation getID() {
|
|
|
|
return EnabledCondition.NAME;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|