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

项目: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);
}
项目:PurificatiMagicae    文件:MagibenchShapelessRecipe.java   
public MagibenchShapelessRecipe(@Nonnull ItemStack result, int minTier, String entryId, Object... recipe)
{
    setTier(minTier);
    setEntry(entryId);
    out = result.copy();
    for (Object in : recipe)
    {
        Ingredient ing = CraftingHelper.getIngredient(in);
        if (ing != null)
        {
            ingredients.add(ing);
            this.simple &= ing.isSimple();
        }
        else
        {
            StringBuilder ret = new StringBuilder("Invalid shapeless ore recipe: ");
            for (Object tmp :  recipe)
            {
                ret.append(tmp).append(", ");
            }
            ret.append(out);
            throw new RuntimeException(ret.toString());
        }
    }
}
项目: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);
}
项目:UsefulNullifiers    文件:CraftingRegistry.java   
/**
 *  Converts an object array into a NonNullList of Ingredients
 */
private static NonNullList<Ingredient> buildInput (Object[] input) {
    NonNullList<Ingredient> list = NonNullList.create();
    for(Object obj : input){
        if(obj instanceof Ingredient){
            list.add((Ingredient) obj);
        } else {
            Ingredient ingredient = CraftingHelper.getIngredient(obj);
            if(ingredient == null){
                ingredient = Ingredient.EMPTY;
            }
            list.add(ingredient);
        }
    }
    return list;
}
项目: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);
}
项目:Cyclic    文件:RecipeRegistry.java   
private static NonNullList<Ingredient> convertToNonNullList(Object[] input) {
  NonNullList<Ingredient> list = NonNullList.create();
  for (Object any : input) {
    if (any instanceof Ingredient) {
      list.add((Ingredient) any);
    }
    else {
      Ingredient ing = CraftingHelper.getIngredient(any);
      if (ing == null) {
        ing = Ingredient.EMPTY;// EMPTY/.. same as new Ingredient(new ItemStack[0])
      }
      list.add(ing);
    }
  }
  return list;
}
项目:pnc-repressurized    文件:RecipeAmadronTablet.java   
RecipeAmadronTablet() {
    super("amadron_tablet_actual");

    this.primer = CraftingHelper.parseShaped("ppp", "pgp", "pcp",
            'p', new ItemStack(Itemss.PLASTIC, 1, ItemPlastic.GREY),
            'g', Itemss.GPS_TOOL,
            'c', new ItemStack(Itemss.AIR_CANISTER, 1, OreDictionary.WILDCARD_VALUE));
    this.recipe = new ShapedOreRecipe(RL("matcher_amadron_tablet"),
            new ItemStack(Itemss.AMADRON_TABLET, 1, Itemss.AMADRON_TABLET.getMaxDamage()), primer);
}
项目:pnc-repressurized    文件:RecipeGun.java   
public RecipeGun(String dyeName, Item output) {
    super(output.getRegistryName().getResourcePath() + "_actual");
    this.output = output;
    this.primer = CraftingHelper.parseShaped("idi", "c  ", "ili",
            'd', dyeName, 'i', Itemss.INGOT_IRON_COMPRESSED, 'l', Blocks.LEVER,
            'c', new ItemStack(Itemss.AIR_CANISTER, 1, OreDictionary.WILDCARD_VALUE));
    this.recipe = new ShapedOreRecipe(RL("matcher_" + output.getRegistryName().getResourcePath()), getRecipeOutput(), primer);
}
项目:Industrial-Foregoing    文件:CommonProxy.java   
public void preInit(FMLPreInitializationEvent event) {
    IFRegistries.poke();

    CraftingHelper.register(new ResourceLocation(Reference.MOD_ID, "configuration_value"), new ConfigurationConditionFactory());
    random = new Random();

    FluidsRegistry.registerFluids();
    BlockRegistry.poke();

    MinecraftForge.EVENT_BUS.register(new BlockRegistry());
    MinecraftForge.EVENT_BUS.register(new ItemRegistry());
    MinecraftForge.EVENT_BUS.register(new StrawRegistry());
    MinecraftForge.EVENT_BUS.register(new MeatFeederTickHandler());
    MinecraftForge.EVENT_BUS.register(new MobDeathHandler());
    MinecraftForge.EVENT_BUS.register(new WorldTickHandler());
    MinecraftForge.EVENT_BUS.register(new PlantRecollectableRegistryHandler());
    MinecraftForge.EVENT_BUS.register(new FakePlayerRideEntityHandler());
    MinecraftForge.EVENT_BUS.register(new PlantInteractorHarvestDropsHandler());

    NetworkRegistry.INSTANCE.registerGuiHandler(IndustrialForegoing.instance, new GuiHandler());

    CustomConfiguration.config = new Configuration(event.getSuggestedConfigurationFile());
    CustomConfiguration.config.load();
    CustomConfiguration.sync();
    CustomConfiguration.configValues = new HashMap<>();
    CustomConfiguration.configValues.put("useTEFrames", CustomConfiguration.config.getBoolean("useTEFrames", Configuration.CATEGORY_GENERAL, true, "Use Thermal Expansion Machine Frames instead of Tesla Core Lib"));

    if (Loader.isModLoaded("crafttweaker")) CraftTweakerHelper.register();

    EntityRegistry.registerModEntity(new ResourceLocation(Reference.MOD_ID, "pink_slime"), EntityPinkSlime.class, "pink_slime", 135135, IndustrialForegoing.instance, 32, 1, false, 10485860, 16777215);
    PINK_SLIME_LOOT = LootTableList.register(new ResourceLocation(Reference.MOD_ID, "entities/pink_slime"));
}
项目:PurificatiMagicae    文件:MagibenchRecipe.java   
public MagibenchRecipe(ItemStack out, int minTier, String entryId, CraftingHelper.ShapedPrimer primer)
{
    setEntry(entryId);
    setTier(minTier);
    this.out = out.copy();
    this.width = primer.width;
    this.height = primer.height;
    this.ingredients = primer.input;
    this.mirrored = primer.mirrored;
}
项目: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);
}
项目: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);
}
项目:UsefulNullifiers    文件:CraftingRegistry.java   
/**
 * Adds a basic shaped recipe
 *
 * @param output The stack that should be produced
 */
public static void addShapedRecipe(ItemStack output, Object... params) {
    ResourceLocation location = getNameForRecipe(output);
    CraftingHelper.ShapedPrimer primer = CraftingHelper.parseShaped(params);
    ShapedRecipes recipe = new ShapedRecipes(output.getItem().getRegistryName().toString(), primer.width, primer.height, primer.input, output);
    recipe.setRegistryName(location);
       GameData.register_impl(recipe);
}
项目:MC-Prefab    文件:ModRegistry.java   
/**
 * This should only be used for registering recipes for vanilla objects and not mod-specific objects.
 * @param name The name of the recipe. ModID is pre-pended to it.
 * @param stack The output of the recipe.
 * @param recipeComponents The recipe components.
 */
public static ShapedRecipes AddShapedRecipe(String name, String groupName, ItemStack stack, Object... recipeComponents)
{   
    name = Prefab.MODID.toLowerCase().replace(' ', '_') + ":" + name;

    ShapedPrimer primer = CraftingHelper.parseShaped(recipeComponents);
    ShapedRecipes shapedrecipes = new ShapedRecipes(groupName, primer.width, primer.height, primer.input, stack);
    shapedrecipes.setRegistryName(name);
    ForgeRegistries.RECIPES.register(shapedrecipes);

    return shapedrecipes;
}
项目: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);
}
项目:Hard-Science    文件:VolumetricIngredientList.java   
public VolumetricIngredient(String ingredient, long nanoLitersPerItem)
{
    this.ingredient = CraftingHelper.getIngredient(ingredient);

    if(this.ingredient == Ingredient.EMPTY)
        Log.warn("VolumetricIngredient encountered invalid (empty) input ingredient.  This is a bug.");

    this.nanoLitersPerItem = nanoLitersPerItem;
}
项目:Hard-Science    文件:VolumetricIngredientList.java   
public VolumetricIngredient(Matter matter, CubeSize size)
{
    this.ingredient = CraftingHelper.getIngredient(matter.getCube(size));

    if(this.ingredient == Ingredient.EMPTY)
        Log.warn("VolumetricIngredient encountered invalid (empty) input ingredient.  This is a bug.");

    this.nanoLitersPerItem = size.nanoLiters;
}
项目:AbyssalCraft    文件:MiscHandler.java   
private void addShapelessRecipe(IForgeRegistry<IRecipe> reg, ResourceLocation name, ResourceLocation group, @Nonnull ItemStack output, Object... params)
{
    NonNullList<Ingredient> lst = NonNullList.create();
    for (Object i : params)
        lst.add(CraftingHelper.getIngredient(i));
    reg.register(new ShapelessRecipes(group == null ? "" : group.toString(), output, lst).setRegistryName(name));
}
项目: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;
}
项目:PurificatiMagicae    文件:MagibenchRecipe.java   
public MagibenchRecipe(Item out, int minTier, String entryId, Object... recipe)
{
    this(new ItemStack(out), minTier, entryId, CraftingHelper.parseShaped(recipe));
}
项目:PurificatiMagicae    文件:MagibenchRecipe.java   
public MagibenchRecipe(Block out, int minTier, String entryId, Object... recipe)
{
    this(new ItemStack(out), minTier, entryId, CraftingHelper.parseShaped(recipe));
}
项目:PurificatiMagicae    文件:MagibenchRecipe.java   
public MagibenchRecipe(ItemStack out, int minTier, String entryId, Object... recipe)
{
    this(out, minTier, entryId, CraftingHelper.parseShaped(recipe));
}
项目:customstuff4    文件:DamageableShapedOreRecipe.java   
private DamageableShapedOreRecipe(@Nullable ResourceLocation group, int[] damageAmounts, @Nonnull ItemStack result, CraftingHelper.ShapedPrimer primer)
{
    super(group, result, primer);
    this.damageAmounts = damageAmounts;
    mirroredDamageAmounts = mirror(damageAmounts);
}
项目:Overlord    文件:SealRecipe.java   
public SealRecipe(ResourceLocation loc, @Nonnull ItemStack result, CraftingHelper.ShapedPrimer recipe) {
    super(loc, result, recipe);
}
项目:AbyssalCraft    文件:MiscHandler.java   
private void addShapedRecipe(IForgeRegistry<IRecipe> reg, ResourceLocation name, ResourceLocation group, @Nonnull ItemStack output, Object... params)
{
    ShapedPrimer primer = CraftingHelper.parseShaped(params);
    reg.register(new ShapedRecipes(group == null ? "" : group.toString(), primer.width, primer.height, primer.input, output).setRegistryName(name));
}
项目:AbyssalCraft    文件:MiscHandler.java   
private void addShapedNBTRecipe(IForgeRegistry<IRecipe> reg, ResourceLocation name, ResourceLocation group, @Nonnull ItemStack output, Object... params)
{
    ShapedPrimer primer = CraftingHelper.parseShaped(params);
    reg.register(new ShapedNBTRecipe(group == null ? "" : group.toString(), primer.width, primer.height, primer.input, output).setRegistryName(name));
}
项目:Cyclic    文件:RecipeRegistry.java   
/**
 * thin wrapper for addShapedRecipe
 * 
 * @param output
 * @param params
 * @return
 */
private static IRecipe _addShapedRecipe(ItemStack output, Object... params) {
  CraftingHelper.ShapedPrimer primer = CraftingHelper.parseShaped(params);
  ShapedRecipes recipe = new ShapedRecipes(output.getItem().getRegistryName().toString(), primer.width, primer.height, primer.input, output);
  add(recipe, Util1pt12.buildName(output));
  return recipe;
}