net.minecraft.item.crafting.ShapedRecipes Java Examples

The following examples show how to use net.minecraft.item.crafting.ShapedRecipes. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CraftShapedRecipe.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
public void addToCraftingManager() {
    String[] shape = this.getShape();
    Map<Character, ItemStack> ingred = this.getIngredientMap();
    int width = shape[0].length();
    NonNullList<Ingredient> data = NonNullList.withSize(shape.length * width, Ingredient.EMPTY);

    for (int i = 0; i < shape.length; i++) {
        String row = shape[i];
        for (int j = 0; j < row.length(); j++) {
            data.set(i * width + j, Ingredient.fromStacks(new net.minecraft.item.ItemStack[]{CraftItemStack.asNMSCopy(ingred.get(row.charAt(j)))}));
        }
    }
    // TODO: Check if it's correct way to register recipes
    ForgeRegistries.RECIPES.register(new ShapedRecipes("", width, shape.length, data, CraftItemStack.asNMSCopy(this.getResult())));
    // CraftingManager.register(CraftNamespacedKey.toMinecraft(this.getKey()), new ShapedRecipes("", width, shape.length, data, CraftItemStack.asNMSCopy(this.getResult())));
}
 
Example #2
Source File: ShapedBloodOrbRecipe.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
ShapedBloodOrbRecipe(ShapedRecipes recipe, Map<ItemStack, String> replacements) {
	output = recipe.getRecipeOutput();
	width = recipe.recipeWidth;
	height = recipe.recipeHeight;

	input = new Object[recipe.recipeItems.length];

	for (int i = 0; i < input.length; i++) {
		ItemStack ingred = recipe.recipeItems[i];

		if (ingred == null)
			continue;

		input[i] = recipe.recipeItems[i];

		for (Entry<ItemStack, String> replace : replacements.entrySet()) {
			if (OreDictionary.itemMatches(replace.getKey(), ingred, true)) {
				input[i] = OreDictionary.getOres(replace.getValue());
				break;
			}
		}
	}
}
 
Example #3
Source File: ShapedOreRecipeTFC.java    From TFC2 with GNU General Public License v3.0 6 votes vote down vote up
ShapedOreRecipeTFC(ShapedRecipes recipe, Map<ItemStack, String> replacements)
{
	output = recipe.getRecipeOutput();
	width = recipe.recipeWidth;
	height = recipe.recipeHeight;

	input = new ArrayList<Object>(recipe.recipeItems.length);

	for(int i = 0; i < recipe.recipeItems.length; i++)
	{
		ItemStack ingredient = recipe.recipeItems[i];

		if(ingredient == null) continue;

		input.add(recipe.recipeItems[i]);

		for(Entry<ItemStack, String> replace : replacements.entrySet())
		{
			if(OreDictionary.itemMatches(replace.getKey(), ingredient, true))
			{
				input.set(i, OreDictionary.getOres(replace.getValue()));
				break;
			}
		}
	}
}
 
Example #4
Source File: RecipeSorterTFC.java    From TFC2 with GNU General Public License v3.0 6 votes vote down vote up
public int compareRecipes(IRecipe irecipe, IRecipe irecipe1)
{
	if (irecipe instanceof ShapelessRecipes && irecipe1 instanceof ShapedRecipes)
	{
		return 1;
	}
	if (irecipe1 instanceof ShapelessRecipes && irecipe instanceof ShapedRecipes)
	{
		return -1;
	}
	if (irecipe1.getRecipeSize() < irecipe.getRecipeSize())
	{
		return -1;
	}
	return irecipe1.getRecipeSize() <= irecipe.getRecipeSize() ? 0 : 1;
}
 
Example #5
Source File: ShapedRecipeHandler.java    From NotEnoughItems with MIT License 6 votes vote down vote up
@Override
public void loadUsageRecipes(ItemStack ingredient) {
    for (IRecipe irecipe : (List<IRecipe>) CraftingManager.getInstance().getRecipeList()) {
        CachedShapedRecipe recipe = null;
        if (irecipe instanceof ShapedRecipes)
            recipe = new CachedShapedRecipe((ShapedRecipes) irecipe);
        else if (irecipe instanceof ShapedOreRecipe)
            recipe = forgeShapedRecipe((ShapedOreRecipe) irecipe);

        if (recipe == null || !recipe.contains(recipe.ingredients, ingredient.getItem()))
            continue;

        recipe.computeVisuals();
        if (recipe.contains(recipe.ingredients, ingredient)) {
            recipe.setIngredientPermutation(recipe.ingredients, ingredient);
            arecipes.add(recipe);
        }
    }
}
 
Example #6
Source File: ShapedRecipeHandler.java    From NotEnoughItems with MIT License 6 votes vote down vote up
@Override
public void loadCraftingRecipes(String outputId, Object... results) {
    if (outputId.equals("crafting") && getClass() == ShapedRecipeHandler.class) {
        for (IRecipe irecipe : CraftingManager.getInstance().getRecipeList()) {
            CachedShapedRecipe recipe = null;
            if (irecipe instanceof ShapedRecipes) {
                recipe = new CachedShapedRecipe((ShapedRecipes) irecipe);
            } else if (irecipe instanceof ShapedOreRecipe) {
                recipe = forgeShapedRecipe((ShapedOreRecipe) irecipe);
            }

            if (recipe == null) {
                continue;
            }

            recipe.computeVisuals();
            arecipes.add(recipe);
        }
    } else {
        super.loadCraftingRecipes(outputId, results);
    }
}
 
Example #7
Source File: ShapedRecipeHandler.java    From NotEnoughItems with MIT License 6 votes vote down vote up
@Override
public void loadCraftingRecipes(ItemStack result) {
    for (IRecipe irecipe : CraftingManager.getInstance().getRecipeList()) {
        if (NEIServerUtils.areStacksSameTypeCrafting(irecipe.getRecipeOutput(), result)) {
            CachedShapedRecipe recipe = null;
            if (irecipe instanceof ShapedRecipes) {
                recipe = new CachedShapedRecipe((ShapedRecipes) irecipe);
            } else if (irecipe instanceof ShapedOreRecipe) {
                recipe = forgeShapedRecipe((ShapedOreRecipe) irecipe);
            }

            if (recipe == null) {
                continue;
            }

            recipe.computeVisuals();
            arecipes.add(recipe);
        }
    }
}
 
Example #8
Source File: ShapedRecipeHandler.java    From NotEnoughItems with MIT License 6 votes vote down vote up
@Override
public void loadUsageRecipes(ItemStack ingredient) {
    for (IRecipe irecipe : CraftingManager.getInstance().getRecipeList()) {
        CachedShapedRecipe recipe = null;
        if (irecipe instanceof ShapedRecipes) {
            recipe = new CachedShapedRecipe((ShapedRecipes) irecipe);
        } else if (irecipe instanceof ShapedOreRecipe) {
            recipe = forgeShapedRecipe((ShapedOreRecipe) irecipe);
        }

        if (recipe == null || !recipe.contains(recipe.ingredients, ingredient.getItem())) {
            continue;
        }

        recipe.computeVisuals();
        if (recipe.contains(recipe.ingredients, ingredient)) {
            recipe.setIngredientPermutation(recipe.ingredients, ingredient);
            arecipes.add(recipe);
        }
    }
}
 
Example #9
Source File: ShapedRecipeHandler.java    From NotEnoughItems with MIT License 6 votes vote down vote up
@Override
public void loadCraftingRecipes(ItemStack result) {
    for (IRecipe irecipe : (List<IRecipe>) CraftingManager.getInstance().getRecipeList()) {
        if (NEIServerUtils.areStacksSameTypeCrafting(irecipe.getRecipeOutput(), result)) {
            CachedShapedRecipe recipe = null;
            if (irecipe instanceof ShapedRecipes)
                recipe = new CachedShapedRecipe((ShapedRecipes) irecipe);
            else if (irecipe instanceof ShapedOreRecipe)
                recipe = forgeShapedRecipe((ShapedOreRecipe) irecipe);

            if (recipe == null)
                continue;

            recipe.computeVisuals();
            arecipes.add(recipe);
        }
    }
}
 
Example #10
Source File: ShapedRecipeHandler.java    From NotEnoughItems with MIT License 6 votes vote down vote up
@Override
public void loadCraftingRecipes(String outputId, Object... results) {
    if (outputId.equals("crafting") && getClass() == ShapedRecipeHandler.class) {
        for (IRecipe irecipe : (List<IRecipe>) CraftingManager.getInstance().getRecipeList()) {
            CachedShapedRecipe recipe = null;
            if (irecipe instanceof ShapedRecipes)
                recipe = new CachedShapedRecipe((ShapedRecipes) irecipe);
            else if (irecipe instanceof ShapedOreRecipe)
                recipe = forgeShapedRecipe((ShapedOreRecipe) irecipe);

            if (recipe == null)
                continue;

            recipe.computeVisuals();
            arecipes.add(recipe);
        }
    } else {
        super.loadCraftingRecipes(outputId, results);
    }
}
 
Example #11
Source File: CraftingRegistrator.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Adds recipes like 9 gold ingot --> 1 gold block, and 1 gold block --> 9 gold ingots.
 */
public static void addPressureChamberStorageBlockRecipes(){
    List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
    for(IRecipe recipe : recipes) {
        if(recipe instanceof ShapedRecipes) {
            ShapedRecipes shaped = (ShapedRecipes)recipe;
            ItemStack[] input = shaped.recipeItems;
            ItemStack ref = input[0];
            if(ref == null || input.length < 9) continue;
            boolean valid = true;
            for(int i = 0; i < 9; i++) {
                if(input[i] == null || !input[i].isItemEqual(ref)) {
                    valid = false;
                    break;
                }
            }
            if(valid) {
                ItemStack inputStack = ref.copy();
                inputStack.stackSize = 9;
                PressureChamberRecipe.chamberRecipes.add(new PressureChamberRecipe(new ItemStack[]{inputStack}, 1.0F, new ItemStack[]{shaped.getRecipeOutput()}, false));

                ItemStack inputStack2 = shaped.getRecipeOutput().copy();
                inputStack2.stackSize = 1;
                PressureChamberRecipe.chamberRecipes.add(new PressureChamberRecipe(new ItemStack[]{inputStack2}, -0.5F, new ItemStack[]{inputStack}, false));

            }
        }
    }
}
 
Example #12
Source File: RecipeHandlerRollingMachineShaped.java    From NEI-Integration with MIT License 5 votes vote down vote up
private CachedRollingMachineShapedRecipe getCachedRecipe(IRecipe irecipe, boolean genPerms) {
    CachedRollingMachineShapedRecipe recipe = null;
    if (irecipe instanceof ShapedRecipes) {
        recipe = new CachedRollingMachineShapedRecipe((ShapedRecipes) irecipe, genPerms);
    } else if (irecipe instanceof ShapedOreRecipe) {
        recipe = this.getCachedOreRecipe((ShapedOreRecipe) irecipe, genPerms);
    }
    return recipe;
}
 
Example #13
Source File: ShapedBloodOrbRecipe.java    From Framez with GNU General Public License v3.0 5 votes vote down vote up
ShapedBloodOrbRecipe(ShapedRecipes recipe, Map<ItemStack, String> replacements)
{
    output = recipe.getRecipeOutput();
    width = recipe.recipeWidth;
    height = recipe.recipeHeight;

    input = new Object[recipe.recipeItems.length];

    for (int i = 0; i < input.length; i++)
    {
        ItemStack ingred = recipe.recipeItems[i];

        if (ingred == null)
            continue;

        input[i] = recipe.recipeItems[i];

        for (Entry<ItemStack, String> replace : replacements.entrySet())
        {
            if (OreDictionary.itemMatches(replace.getKey(), ingred, true))
            {
                input[i] = OreDictionary.getOres(replace.getValue());
                break;
            }
        }
    }
}
 
Example #14
Source File: ValkyrienSkiesMod.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
private static void registerRecipe(RegistryEvent.Register<IRecipe> event,
    String registryName, ItemStack out, Object... in) {
    CraftingHelper.ShapedPrimer primer = CraftingHelper.parseShaped(in);
    event.getRegistry()
        .register(new ShapedRecipes(ValkyrienSkiesMod.MOD_ID, primer.width, primer.height,
            primer.input, out)
            .setRegistryName(ValkyrienSkiesMod.MOD_ID, registryName));
}
 
Example #15
Source File: Module.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@Deprecated
public static void registerRecipe(RegistryEvent.Register<IRecipe> event, String registryName,
    ItemStack out, Object... in) {
    CraftingHelper.ShapedPrimer primer = CraftingHelper.parseShaped(in);
    event.getRegistry()
        .register(new ShapedRecipes(ValkyrienSkiesMod.MOD_ID, primer.width, primer.height,
            primer.input, out).setRegistryName(ValkyrienSkiesMod.MOD_ID, registryName));
}
 
Example #16
Source File: ShapedRecipeTests.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
private List<IRecipe> createTestRecipes(Item result)
{
    return Lists.newArrayList(new ShapedRecipes("group", 1, 1, NonNullList.from(Ingredient.EMPTY, Ingredient.fromItem(Items.ITEM_FRAME)), new ItemStack(result)),
                              new ShapedRecipes("group", 2, 2,
                                                NonNullList.from(Ingredient.EMPTY,
                                                                 Ingredient.fromStacks(new ItemStack(Blocks.STONE)), Ingredient.fromStacks(new ItemStack(Blocks.STONE)),
                                                                 Ingredient.fromStacks(new ItemStack(Blocks.LOG)), Ingredient.fromStacks(new ItemStack(Blocks.LOG))),
                                                new ItemStack(result)));
}
 
Example #17
Source File: ShapedRecipe.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
private boolean matchesInput(ShapedRecipes recipe)
{
    if (isOreRecipe())
        return false;
    if (recipe.recipeWidth != getRecipeWidth())
        return false;
    if (recipe.recipeHeight != getRecipeHeight())
        return false;

    return isSameInputs(recipe.recipeItems);
}
 
Example #18
Source File: ShapedRecipe.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
private boolean matchesInput(IRecipe recipe)
{
    if (recipe instanceof ShapedRecipes)
    {
        return matchesInput((ShapedRecipes) recipe);
    } else if (recipe instanceof ShapedOreRecipe)
    {
        return matchesInput((ShapedOreRecipe) recipe);
    }

    return false;
}
 
Example #19
Source File: ShapedRecipeHandler.java    From NotEnoughItems with MIT License 4 votes vote down vote up
public CachedShapedRecipe(ShapedRecipes recipe) {
    this(recipe.recipeWidth, recipe.recipeHeight, recipe.recipeItems, recipe.getRecipeOutput());
}
 
Example #20
Source File: ShapedRecipeHandler.java    From NotEnoughItems with MIT License 4 votes vote down vote up
public CachedShapedRecipe(ShapedRecipes recipe) {
    this(recipe.recipeWidth, recipe.recipeHeight, recipe.recipeItems, recipe.getRecipeOutput());
}
 
Example #21
Source File: RecipeHandlerRollingMachineShaped.java    From NEI-Integration with MIT License 4 votes vote down vote up
public CachedRollingMachineShapedRecipe(ShapedRecipes recipe, boolean genPerms) {
    this(recipe.recipeWidth, recipe.recipeHeight, recipe.recipeItems, recipe.getRecipeOutput(), genPerms);
}
 
Example #22
Source File: RecipeHandlerRollingMachineShaped.java    From NEI-Integration with MIT License 4 votes vote down vote up
public CachedRollingMachineShapedRecipe(ShapedRecipes recipe) {
    this(recipe, false);
}
 
Example #23
Source File: CraftShapedRecipe.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public CraftShapedRecipe(ItemStack result, ShapedRecipes recipe) {
    this(CraftNamespacedKey.fromMinecraft(recipe.key), result);
    this.recipe = recipe;
}