@Override public IRecipe parse(JsonContext context, JsonObject json) { String group = JsonUtils.getString(json, "group", ""); NonNullList<Ingredient> ings = NonNullList.create(); for(JsonElement ele : JsonUtils.getJsonArray(json, "ingredients")) ings.add(CraftingHelper.getIngredient(ele, context)); if(ings.isEmpty()) throw new JsonParseException("No ingredients for shapeless recipe"); if(ings.size() > 9) throw new JsonParseException("Too many ingredients for shapeless recipe"); ItemStack itemstack = CraftingHelper.getItemStack(JsonUtils.getJsonObject(json, "result"), context); return new RecipeTorchGun(group, itemstack, ings); }
@Override public IRecipe parse(JsonContext context, JsonObject json) { int clamp = JsonUtils.getInt(json, "clamp"); boolean combining = JsonUtils.getBoolean(json, "combining"); JsonArray upgradeList = JsonUtils.getJsonArray(json, "upgrades"); Map<Ingredient, Double> upgrades = new LinkedHashMap<>(); int n = 0; for (JsonElement element : upgradeList) { if (element.isJsonObject()) { JsonObject upgrade = element.getAsJsonObject(); double amount = JsonUtils.getFloat(upgrade, "amount"); Ingredient ingredient = CraftingHelper.getIngredient(upgrade.get("ingredient"), context); upgrades.put(ingredient, amount); } else { throw new JsonSyntaxException("Expected " + n + " to be a JsonObject, was " + JsonUtils.toString(json)); } n++; } return new RandoresForgeUpgradeRecipe(clamp, combining, upgrades); }
@Override public Ingredient parse(JsonContext context, JsonObject json) { String name = JsonUtils.getString(json, "name"); ItemStack stack = null; // If item with variant. if (name.contains("#")) { String[] parts = name.split("#"); stack = IC2Items.getItem(parts[0], parts[1]); } else { stack = IC2Items.getItem(name); } if (stack == null) throw new JsonSyntaxException("IC2 item with name " + name + " could not be found"); return Ingredient.fromStacks(stack); }
@Override public IRecipe parse(JsonContext context, JsonObject json) { String group = JsonUtils.getString(json, "group", ""); NonNullList<Ingredient> ingredients = NonNullList.create(); for (JsonElement element : JsonUtils.getJsonArray(json, "ingredients")) ingredients.add(CraftingHelper.getIngredient(element, context)); if (ingredients.isEmpty()) throw new JsonParseException("No ingredients in shapeless recipe"); ItemStack result = CraftingHelper.getItemStack(JsonUtils.getJsonObject(json, "result"), context); RecipeShapelessFluid recipe = new RecipeShapelessFluid(group.isEmpty() ? null : new ResourceLocation(group), result, ingredients); return recipe; }
@Nonnull @Override public Ingredient parse(JsonContext context, JsonObject json) { final ItemStack stack = CraftingHelper.getItemStack(json, context); Item tip = JsonUtils.getItem(json, "tip"); Item container = JsonUtils.getItem(json, "container"); stack.setTagCompound(new NBTTagCompound()); if (stack.getTagCompound() != null) { stack.getTagCompound().setString("tip", tip.getRegistryName().getResourcePath()); stack.getTagCompound().setString("uses", container.getRegistryName().getResourcePath()); } return new IngredientNBT(stack); }
@Override public BooleanSupplier parse(JsonContext context, JsonObject json) { String category = JsonUtils.getString(json, "category"); String key = JsonUtils.getString(json, "key"); boolean flip = JsonUtils.getBoolean(json, "flip", false); if (config.hasCategory(category)) { ConfigCategory cat = config.getCategory(category); if (cat.containsKey(key) && cat.get(key).isBooleanValue()) { return () -> flip != cat.get(key).getBoolean(); } else { throw new JsonParseException(String.format("Key doesn't exist on category or is not of a boolean type. Category: %s, Key: %s", category, key)); } } else { throw new JsonParseException(String.format("Category doesn't exist on config file. Category: %s, Config: %s", category, config.getConfigFile().getAbsolutePath())); } }
@Nonnull @Override public Ingredient parse(JsonContext context, JsonObject json) { final ItemStack stack = CraftingHelper.getItemStack(json, context); int estus = JsonUtils.getInt(json, "estus", 0); int uses = JsonUtils.getInt(json, "uses", 0); stack.setTagCompound(new NBTTagCompound()); if (stack.getTagCompound() != null) { stack.getTagCompound().setInteger("estus", estus); stack.getTagCompound().setInteger("uses", uses); } return new IngredientNBT(stack); }
@Override public BooleanSupplier parse(JsonContext context, JsonObject json) { JsonPrimitive categoryName = json.getAsJsonPrimitive("category"); JsonPrimitive keyName = json.getAsJsonPrimitive("key"); ConfigCategory category = ConfigManager.instance.config.getCategory(categoryName.getAsString()); Property property = category != null ? category.get(keyName.getAsString()) : null; if (property == null) { Survivalist.logger.error("Property not found! {} / {}", categoryName.getAsString(), keyName.getAsString()); return () -> false; } return property::getBoolean; }
@Override public BooleanSupplier parse(JsonContext context, JsonObject json) { String type = JsonUtils.getString(json, "type"); if(type.equals("securitycraft_toggle_keycard_1")) return () -> SecurityCraft.config.ableToCraftKeycard1; else if(type.equals("securitycraft_toggle_keycard_2")) return () -> SecurityCraft.config.ableToCraftKeycard2; else if(type.equals("securitycraft_toggle_keycard_3")) return () -> SecurityCraft.config.ableToCraftKeycard3; else if(type.equals("securitycraft_toggle_keycard_4")) return () -> SecurityCraft.config.ableToCraftKeycard4; else if(type.equals("securitycraft_toggle_keycard_5")) return () -> SecurityCraft.config.ableToCraftKeycard5; else if(type.equals("securitycraft_toggle_lu_keycard")) return () -> SecurityCraft.config.ableToCraftLUKeycard; else return () -> true; }
@Override public BooleanSupplier parse(JsonContext context, JsonObject json) { if (json.has("value") && CustomConfiguration.configValues.containsKey(json.get("value").getAsString())) { return () -> CustomConfiguration.configValues.get(json.get("value").getAsString()); } return () -> false; }
@Override public IRecipe parse(JsonContext context, JsonObject json) { ShapedOreRecipe recipe = ShapedOreRecipe.factory(context, json); ShapedPrimer primer = new ShapedPrimer(); primer.width = recipe.getWidth(); primer.height = recipe.getHeight(); primer.mirrored = JsonUtils.getBoolean(json, "mirrored", true); primer.input = recipe.getIngredients(); return new InsertCartridgeRecipe(new ResourceLocation(MeeCreeps.MODID, "insert_cartridge_factory"), recipe.getRecipeOutput(), primer); }
@Override public IRecipe parse(JsonContext context, JsonObject json) { ShapedOreRecipe recipe = ShapedOreRecipe.factory(context, json); ShapedPrimer primer = new ShapedPrimer(); primer.width = recipe.getWidth(); primer.height = recipe.getHeight(); primer.mirrored = JsonUtils.getBoolean(json, "mirrored", true); primer.input = recipe.getIngredients(); return new RemoveCartridgeRecipe(new ResourceLocation(MeeCreeps.MODID, "remove_cartridge_factory"), recipe.getRecipeOutput(), primer); }
@Override public IRecipe parse(JsonContext context, JsonObject json) { String group = JsonUtils.getString(json, "group", ""); NonNullList<Ingredient> ings = NonNullList.create(); for (JsonElement ele : JsonUtils.getJsonArray(json, "ingredients")) ings.add(CraftingHelper.getIngredient(ele, context)); if (ings.isEmpty()) throw new JsonParseException("No ingredients for shapeless recipe"); ItemStack itemstack = CraftingHelper.getItemStack(JsonUtils.getJsonObject(json, "result"), context); int[] damage = new int[ings.size()]; if (JsonUtils.hasField(json, "damage")) { JsonArray array = JsonUtils.getJsonArray(json, "damage"); if (array.size() > damage.length) throw new JsonParseException("Too many values for damage array: got " + array.size() + ", expected " + damage.length); for (int i = 0; i < array.size(); i++) { JsonElement element = array.get(i); if (!element.isJsonPrimitive() || !element.getAsJsonPrimitive().isNumber()) throw new JsonSyntaxException("Entry in damage array is not a number, got " + element); damage[i] = element.getAsJsonPrimitive().getAsInt(); } } return new DamageableShapelessOreRecipe(group.isEmpty() ? null : new ResourceLocation(group), damage, ings, itemstack); }
@Override public BooleanSupplier parse(JsonContext context, JsonObject json) { String modid = JsonUtils.getString(json, "modid"); return () -> Loader.isModLoaded(modid); }
private static void loadConstants(JsonContext context, JsonObject[] json) { try { if (loadConstantsMethod == null) { for (Method method : context.getClass().getDeclaredMethods()) { if (method.getName().equals("loadConstants")) { loadConstantsMethod = method; loadConstantsMethod.setAccessible(true); } } } loadConstantsMethod.invoke(context, new Object[] { json }); } catch (IllegalAccessException | InvocationTargetException e) { throw new Error("Failed to read constants", e); } }
@Nonnull @Override public Ingredient parse(JsonContext context, JsonObject json) { String name = JsonUtils.getString(json, "fluid"); int amount = JsonUtils.getInt(json, "amount", 1000); Fluid fluid = FluidRegistry.getFluid(name); if (fluid == null) throw new JsonSyntaxException("Fluid with name " + name + " could not be found"); return new IngredientFluidStack(fluid, amount); }
@Nonnull @Override public Ingredient parse(JsonContext context, JsonObject json) { if (!CraftingHelper.processConditions(JsonUtils.getJsonArray(json, "conditions"), context)) { if (json.has("fail")) { CraftingHelper.getIngredient(JsonUtils.getJsonObject(json, "failed_condition"), context); } return Ingredient.EMPTY; } return CraftingHelper.getIngredient(JsonUtils.getJsonObject(json, "pass"), context); }
@Override public BooleanSupplier parse(JsonContext context, JsonObject json) { String tag = JsonUtils.getString(json, "tag"); boolean flip = tag.startsWith("!"); if (flip) { tag = tag.substring(1); } String[] parts; if (tag.contains(".")) { parts = tag.split("\\."); } else { parts = new String[] { tag }; } ConfigTag t = config; for (String p : parts) { if (t.hasTag(p)) { t = t.getTagIfPresent(p); } else { throw new RuntimeException("Tag: " + tag + " does not exist in the specified config."); } } if (t.getType() != TagType.BOOLEAN) { throw new RuntimeException("Unable to use non boolean tag as conditional."); } boolean value = t.getBoolean(); return () -> flip != value; }
@Override public BooleanSupplier parse(JsonContext context, JsonObject json) { this.recipeKey = json.get(recipeKeyName).getAsString(); return () -> this.determineActiveRecipe(); }
@Override public Ingredient parse(JsonContext context, JsonObject json) { JsonPrimitive categoryName = json.getAsJsonPrimitive("category"); JsonPrimitive keyName = json.getAsJsonPrimitive("key"); ConfigCategory category = ConfigManager.instance.config.getCategory(categoryName.getAsString()); Property property = category.get(keyName.getAsString()); if (property.getBoolean()) return CraftingHelper.getIngredient(json.getAsJsonObject("then"), context); return CraftingHelper.getIngredient(json.getAsJsonObject("else"), context); }
@Nonnull @Override public Ingredient parse(JsonContext context, JsonObject json) { final ItemStack stack = new ItemStack(ModItems.SynthesisMaterial); String material = JsonUtils.getString(json, "material", ""); String rank = JsonUtils.getString(json, "rank", ""); stack.setTagCompound(new NBTTagCompound()); if (stack.getTagCompound() != null) { stack.getTagCompound().setString("material", material); stack.getTagCompound().setString("rank", rank); } return new IngredientSynthesisMaterial(stack); }
@Override public BooleanSupplier parse(JsonContext context, JsonObject json) { JsonPrimitive categoryName = json.getAsJsonPrimitive("category"); JsonPrimitive keyName = json.getAsJsonPrimitive("key"); ConfigCategory category = ConfigValues.config.getCategory(categoryName.getAsString()); Property property = category.get(keyName.getAsString()); return property::getBoolean; }
@Override public IRecipe parse(JsonContext context, JsonObject json) { Lanolin.logger.log(Level.DEBUG,"Loaded Lanolin Crafting"); return new RecipeLanolin(); }
@Override public IRecipe parse(JsonContext context, JsonObject json){ ShapelessOreRecipe dummy = ShapelessOreRecipe.factory(context, json); return new AlwaysInvalidShapelessOreRecipe(dummy); }
@Override public IRecipe parse(JsonContext context, JsonObject json) { ShapelessOreRecipe recipe = ShapelessOreRecipe.factory(context, json); return new RemainBottleRecipe("mooncakecraft:remain_bottle", recipe.getRecipeOutput(), recipe.getIngredients()); }
@Override public IRecipe parse(JsonContext context, JsonObject json) { return new RandoresTomeRecipe(CraftingHelper.getIngredient(json.get("book"), context)); }
@Override public IRecipe parse(JsonContext context, JsonObject json) { JsonArray pattern = JsonUtils.getJsonArray(json, "pattern"); List<String> strs = new ArrayList<>(); for (JsonElement element : pattern) { strs.add(element.getAsString()); } char[][] grid = new char[strs.size()][]; for (int i = 0; i < strs.size(); i++) { grid[i] = strs.get(i).toCharArray(); } if (grid.length > 3 || (grid.length > 0 && grid[0].length > 3)) { throw new JsonSyntaxException("Pattern may not be larger than 3x3"); } Map<Character, Ingredient> ingredientMap = new HashMap<>(); if (json.has("key")) { JsonObject keys = JsonUtils.getJsonObject(json, "key"); keys.entrySet().forEach(entry -> { String key = entry.getKey(); if (key.length() != 1) { throw new JsonSyntaxException("Keys must be 1 character, was: " + key); } else if (key.equals(" ")) { throw new JsonSyntaxException("' ' is a reserved key"); } else if (key.equals("#")) { throw new JsonSyntaxException("'#' is a reserved key"); } Ingredient ingredient = CraftingHelper.getIngredient(entry.getValue(), context); ingredientMap.put(key.charAt(0), ingredient); }); } String component = JsonUtils.getString(json, "component"); CraftableType type = CraftableTypeRegistry.instance().get(component); if (type == null) { throw new JsonSyntaxException("Unknown component " + component); } RandoresItemRecipe recipe = new RandoresItemRecipe(ingredientMap, type, grid, JsonUtils.getInt(json, "quantity")); RECIPES.put(type, recipe); return recipe; }
@Override public BooleanSupplier parse(JsonContext context, JsonObject json) { String ore = JsonUtils.getString(json, "ore"); return () -> OreDictionary.doesOreNameExist(ore); }
@Override public BooleanSupplier parse(JsonContext context, JsonObject json) { final String enchId = JsonUtils.getString(json, "id"); return () -> Enchantment.REGISTRY.containsKey(new ResourceLocation(enchId)); }
public static ConditionalIngredient parseWithCondition(BooleanSupplier condition, JsonContext context, JsonObject json) { ItemStack stackMet = ConditionalIngredient.parseItemStack(json, "met"); ItemStack stackNotMet = ConditionalIngredient.parseItemStack(json, "notmet"); return new ConditionalIngredient(condition, stackMet, stackNotMet); }
@Override public IRecipe parse(JsonContext context, JsonObject json) { return ConditionalRecipe.defaultParserWithCondition(() -> iChunUtil.config.enableCompactPorkchop == 1, context, json); }