<commit_before>package reborncore.common.crafting;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.tag.ItemTags;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import org.apache.commons.lang3.Validate;

import java.util.HashMap;
import java.util.function.Function;

public final class ConditionManager {

	private static final HashMap<Identifier, RecipeCondition<?>> RECIPE_CONDITIONS = new HashMap<>();
	private static final HashMap<Identifier, Class<?>> RECIPE_CONDITION_TYPES = new HashMap<>();

	static {
		//Only loads the recipe in a development env
		register("development", Boolean.class, (bool) -> bool == FabricLoader.getInstance().isDevelopmentEnvironment());

		//Only loads the recipe when the item is registered
		register("item", Identifier.class, Registry.ITEM::containsId);

		//Only loads the recipe when the fluid is registered
		register("fluid", Identifier.class, Registry.FLUID::containsId);

		//Only loads the recipe when the tag is loaded
		register("tag", Identifier.class, s -> ItemTags.getContainer().getEntries().containsKey(s));

		//Only load the recipe if the provided mod is loaded
		register("mod", String.class, s -> FabricLoader.getInstance().isModLoaded(s));
	}

	public static <T> void register(String name, Class<T> type, RecipeCondition<T> recipeCondition){
		register(new Identifier("reborncore", name), type, recipeCondition);
	}

	public static <T> void register(Identifier identifier, Class<T> type, RecipeCondition<T> recipeCondition){
		Validate.isTrue(!RECIPE_CONDITIONS.containsKey(identifier), "Recipe condition already registered");
		RECIPE_CONDITIONS.put(identifier, recipeCondition);
		RECIPE_CONDITION_TYPES.put(identifier, type);
	}

	public static RecipeCondition<?> getRecipeCondition(Identifier identifier){
		RecipeCondition<?> condition = RECIPE_CONDITIONS.get(identifier);
		if(condition == null){
			throw new UnsupportedOperationException("Could not find recipe condition for " + identifier.toString());
		}
		return condition;
	}

	public static boolean shouldLoadRecipe(JsonObject jsonObject){
		if(!jsonObject.has("conditions")) return true;
		return jsonObject.get("conditions").getAsJsonObject().entrySet().stream()
			.allMatch(entry -> shouldLoad(entry.getKey(), entry.getValue()));
	}<commit_msg>Fix server issues, thanks mojang for making containsId client side only...<commit_after>package reborncore.common.crafting;

import java.util.HashMap;
import java.util.function.Function;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.minecraft.tag.ItemTags;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.SimpleRegistry;
import org.apache.commons.lang3.Validate;

import net.fabricmc.loader.api.FabricLoader;

public final class ConditionManager {

	private static final HashMap<Identifier, RecipeCondition<?>> RECIPE_CONDITIONS = new HashMap<>();
	private static final HashMap<Identifier, Class<?>> RECIPE_CONDITION_TYPES = new HashMap<>();

	static {
		//Only loads the recipe in a development env
		register("development", Boolean.class, (bool) -> bool == FabricLoader.getInstance().isDevelopmentEnvironment());

		//Only loads the recipe when the item is registered
		register("item", Identifier.class, (id) -> registryContains(Registry.ITEM, id));

		//Only loads the recipe when the fluid is registered
		register("fluid", Identifier.class, (id) -> registryContains(Registry.FLUID, id));

		//Only loads the recipe when the tag is loaded
		register("tag", Identifier.class, s -> ItemTags.getContainer().getEntries().containsKey(s));

		//Only load the recipe if the provided mod is loaded
		register("mod", String.class, s -> FabricLoader.getInstance().isModLoaded(s));
	}

	private static boolean registryContains(SimpleRegistry<?> registry, Identifier ident) {
		return registry.get(ident) != null;
	}

	public static <T> void register(String name, Class<T> type, RecipeCondition<T> recipeCondition){
		register(new Identifier("reborncore", name), type, recipeCondition);
	}

	public static <T> void register(Identifier identifier, Class<T> type, RecipeCondition<T> recipeCondition){
		Validate.isTrue(!RECIPE_CONDITIONS.containsKey(identifier), "Recipe condition already registered");
		RECIPE_CONDITIONS.put(identifier, recipeCondition);
		RECIPE_CONDITION_TYPES.put(identifier, type);
	}

	public static RecipeCondition<?> getRecipeCondition(Identifier identifier){
		RecipeCondition<?> condition = RECIPE_CONDITIONS.get(identifier);
		if(condition == null){
			throw new UnsupportedOperationException("Could not find recipe condition for " + identifier.toString());
		}
		return condition;
	}

	public static boolean shouldLoadRecipe(JsonObject jsonObject){
		if(!jsonObject.has("conditions")) return true;
		return jsonObject.get("conditions").getAsJsonObject().entrySet().stream()
			.allMatch(entry -> shouldLoad(entry.getKey(), entry.getValue()));
	}
{'fraction_non_alphanumeric': 0.1194236083695223, 'fraction_numerical': 0.00039478878799842083, 'mean_word_length': 6.057103064066852, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3749482', 'n_tokens_mistral': 1465, 'n_tokens_neox': 1389, 'n_words': 372}