Java 类net.minecraftforge.common.crafting.JsonContext 实例源码

项目:Torched    文件:RecipeTorchGun.java   
@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);
}
项目:Randores2    文件:RandoresForgeUpgradeRecipeFactory.java   
@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);
}
项目:CompositeGear    文件:IC2IngredientFactory.java   
@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);
}
项目:Wizardry    文件:RecipeShapelessFluidFactory.java   
@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;
}
项目:Malgra    文件:ExtractorIngredientFactory.java   
@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);
}
项目:CodeChickenLib    文件:AbstractForgeConfigConditionalFactory.java   
@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()));
    }
}
项目:Bonfires    文件:EstusFlaskIngredientFactory.java   
@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);
}
项目:Survivalist    文件:ConfigurationCondition.java   
@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;
}
项目:SecurityCraft    文件:KeycardConditionFactory.java   
@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;
}
项目:Industrial-Foregoing    文件:ConfigurationConditionFactory.java   
@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;
}
项目:MeeCreeps    文件:InsertCartridgeFactory.java   
@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);
}
项目:MeeCreeps    文件:RemoveCartridgeFactory.java   
@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);
}
项目:customstuff4    文件:DamageableShapelessOreRecipe.java   
@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);
}
项目:CompositeGear    文件:ModLoadedCondition.java   
@Override
public BooleanSupplier parse(JsonContext context, JsonObject json)
{
    String modid = JsonUtils.getString(json, "modid");

    return () -> Loader.isModLoaded(modid);
}
项目:RecipeManipulator    文件:RecipeManipulator.java   
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);
    }
}
项目:Wizardry    文件:IngredientFluidStackFactory.java   
@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);
}
项目:CodeChickenLib    文件:ConditionalIngredientFactory.java   
@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);
}
项目:CodeChickenLib    文件:AbstractConfigConditionalFactory.java   
@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;
}
项目:MC-Prefab    文件:RecipeCondition.java   
@Override
public BooleanSupplier parse(JsonContext context, JsonObject json)
{   
    this.recipeKey = json.get(recipeKeyName).getAsString();

    return () -> this.determineActiveRecipe();
}
项目:Survivalist    文件:ConfigurationToggledIngredient.java   
@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);
}
项目:Kingdom-Keys-Re-Coded    文件:SynthesisMaterialFactory.java   
@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);
}
项目:Ender-Rift    文件:ConfigurationCondition.java   
@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;
}
项目:Lanolin    文件:RecipeLanolinFactory.java   
@Override
public IRecipe parse(JsonContext context, JsonObject json) {
    Lanolin.logger.log(Level.DEBUG,"Loaded Lanolin Crafting");
    return new RecipeLanolin();
}
项目:pnc-repressurized    文件:AlwaysInvalidShapelessRecipeFactory.java   
@Override
public IRecipe parse(JsonContext context, JsonObject json){
    ShapelessOreRecipe dummy = ShapelessOreRecipe.factory(context, json);
    return new AlwaysInvalidShapelessOreRecipe(dummy);
}
项目:MooncakeCraft    文件:RemainBottleRecipeFactory.java   
@Override
public IRecipe parse(JsonContext context, JsonObject json) {
    ShapelessOreRecipe recipe = ShapelessOreRecipe.factory(context, json);

    return new RemainBottleRecipe("mooncakecraft:remain_bottle", recipe.getRecipeOutput(), recipe.getIngredients());
}
项目:Randores2    文件:RandoresTomeRecipeFactory.java   
@Override
public IRecipe parse(JsonContext context, JsonObject json) {
    return new RandoresTomeRecipe(CraftingHelper.getIngredient(json.get("book"), context));
}
项目:Randores2    文件:RandoresRecipeFactory.java   
@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;
}
项目:CodeChickenLib    文件:OreExistsConditionalFactory.java   
@Override
public BooleanSupplier parse(JsonContext context, JsonObject json) {
    String ore = JsonUtils.getString(json, "ore");
    return () -> OreDictionary.doesOreNameExist(ore);
}
项目:OpenModsLib    文件:EnchantingRecipe.java   
@Override
public BooleanSupplier parse(JsonContext context, JsonObject json) {
    final String enchId = JsonUtils.getString(json, "id");
    return () -> Enchantment.REGISTRY.containsKey(new ResourceLocation(enchId));
}
项目:iChunUtil    文件:ConditionalIngredient.java   
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);
}
项目:iChunUtil    文件:RecipeCompactPorkchop.java   
@Override
public IRecipe parse(JsonContext context, JsonObject json)
{
    return ConditionalRecipe.defaultParserWithCondition(() -> iChunUtil.config.enableCompactPorkchop == 1, context, json);
}