Files
Mekanism-Community-Edition/src/main/java/mekanism/common/recipe/MekanismRecipeEnabledCondition.java
T
Tom Elfring 5dd3dbb8a9 Code cleanup
Redundent assignments
Wrong comparison of string with MRL
Unneeded reflection
Try with resources
Metallurgy compat deleted (was outcommented) not updated since MC 1.7.10
2017-08-06 13:38:32 +02:00

39 lines
1.3 KiB
Java

package mekanism.common.recipe;
import com.google.gson.JsonObject;
import mekanism.common.config.MekanismConfig;
import net.minecraft.util.JsonUtils;
import net.minecraftforge.common.crafting.IConditionFactory;
import net.minecraftforge.common.crafting.JsonContext;
import java.util.function.BooleanSupplier;
/**
* Used as a condition in mekanism _factories.json
*
* WARNING: Only one of these values could apply!
*/
public class MekanismRecipeEnabledCondition implements IConditionFactory
{
@Override
public BooleanSupplier parse(JsonContext context, JsonObject json)
{
if(JsonUtils.hasField(json, "machineType"))
{
return () -> MekanismConfig.general.machinesManager.isEnabled(JsonUtils.getString(json, "machineType"));
}
if(JsonUtils.hasField(json, "generatorType"))
{
return () -> MekanismConfig.generators.generatorsManager.isEnabled(JsonUtils.getString(json, "generatorType"));
}
if(JsonUtils.hasField(json, "circuitOredict"))
{
return () -> MekanismConfig.general.controlCircuitOreDict;
}
throw new IllegalStateException("Config defined with recipe_enabled condition without a valid field defined! Valid values: \"machineType\", \"generatorType\" and \"circuitOredict\"");
}
}