net.minecraft.item.crafting.ShapelessRecipes Java Examples

The following examples show how to use net.minecraft.item.crafting.ShapelessRecipes. 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: ItemBookCode.java    From Minecoprocessors with GNU General Public License v3.0 6 votes vote down vote up
@SubscribeEvent
public static void registerRecipes(final RegistryEvent.Register<IRecipe> event) {
  NonNullList<Ingredient> lst = NonNullList.create();
  lst.add(Ingredient.fromItem(Items.WRITABLE_BOOK));
  lst.add(Ingredient.fromItem(BlockMinecoprocessor.ITEM_INSTANCE));
  event.getRegistry().register(new ShapelessRecipes("", new ItemStack(ItemBookCode.INSTANCE), lst) {
    @Override
    public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv) {
      NonNullList<ItemStack> l = NonNullList.withSize(inv.getSizeInventory(), ItemStack.EMPTY);

      for (int i = 0; i < l.size(); ++i) {
        ItemStack stack = inv.getStackInSlot(i);

        if (stack.getItem() == BlockMinecoprocessor.ITEM_INSTANCE) {
          ItemStack returnStack = stack.copy();
          returnStack.setCount(1);
          l.set(i, returnStack);
          return l;
        }
      }

      throw new RuntimeException("Item to return not found in inventory");
    }
  }.setRegistryName(ItemBookCode.REGISTRY_NAME));
}
 
Example #2
Source File: ShapelessRecipe.java    From customstuff4 with GNU General Public License v3.0 6 votes vote down vote up
private boolean matchesInput(ShapelessRecipes recipe)
{
    if (isOreRecipe())
        return false;
    if (recipe.recipeItems.size() != getRecipeSize())
        return false;

    Object[] input = getRecipeInput();

    for (int i = 0; i < recipe.recipeItems.size(); i++)
    {
        Ingredient target = recipe.recipeItems.get(i);
        ItemStack source = (ItemStack) input[i];

        if (!target.apply(source))
            return false;
    }

    return true;
}
 
Example #3
Source File: ShapelessOreRecipeTFC.java    From TFC2 with GNU General Public License v3.0 6 votes vote down vote up
ShapelessOreRecipeTFC(ShapelessRecipes recipe, Map<ItemStack, String> replacements)
{
	output = recipe.getRecipeOutput();

	for(ItemStack ingredient : recipe.recipeItems)
	{
		Object finalObj = ingredient;
		for(Entry<ItemStack, String> replace : replacements.entrySet())
		{
			if(OreDictionary.itemMatches(replace.getKey(), ingredient, false))
			{
				finalObj = OreDictionary.getOres(replace.getValue());
				break;
			}
		}
		input.add(finalObj);
	}
}
 
Example #4
Source File: ShapelessRecipeHandler.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() == ShapelessRecipeHandler.class) {
        List<IRecipe> allrecipes = CraftingManager.getInstance().getRecipeList();
        for (IRecipe irecipe : allrecipes) {
            CachedShapelessRecipe recipe = null;
            if (irecipe instanceof ShapelessRecipes) {
                recipe = shapelessRecipe((ShapelessRecipes) irecipe);
            } else if (irecipe instanceof ShapelessOreRecipe) {
                recipe = forgeShapelessRecipe((ShapelessOreRecipe) irecipe);
            }

            if (recipe == null) {
                continue;
            }

            arecipes.add(recipe);
        }
    } else {
        super.loadCraftingRecipes(outputId, results);
    }
}
 
Example #5
Source File: ShapelessRecipeHandler.java    From NotEnoughItems with MIT License 6 votes vote down vote up
@Override
public void loadCraftingRecipes(ItemStack result) {
    List<IRecipe> allrecipes = CraftingManager.getInstance().getRecipeList();
    for (IRecipe irecipe : allrecipes) {
        if (NEIServerUtils.areStacksSameTypeCrafting(irecipe.getRecipeOutput(), result)) {
            CachedShapelessRecipe recipe = null;
            if (irecipe instanceof ShapelessRecipes) {
                recipe = shapelessRecipe((ShapelessRecipes) irecipe);
            } else if (irecipe instanceof ShapelessOreRecipe) {
                recipe = forgeShapelessRecipe((ShapelessOreRecipe) irecipe);
            }

            if (recipe == null) {
                continue;
            }

            arecipes.add(recipe);
        }
    }
}
 
Example #6
Source File: ShapelessRecipeHandler.java    From NotEnoughItems with MIT License 6 votes vote down vote up
@Override
public void loadUsageRecipes(ItemStack ingredient) {
    List<IRecipe> allrecipes = CraftingManager.getInstance().getRecipeList();
    for (IRecipe irecipe : allrecipes) {
        CachedShapelessRecipe recipe = null;
        if (irecipe instanceof ShapelessRecipes) {
            recipe = shapelessRecipe((ShapelessRecipes) irecipe);
        } else if (irecipe instanceof ShapelessOreRecipe) {
            recipe = forgeShapelessRecipe((ShapelessOreRecipe) irecipe);
        }

        if (recipe == null) {
            continue;
        }

        if (recipe.contains(recipe.ingredients, ingredient)) {
            recipe.setIngredientPermutation(recipe.ingredients, ingredient);
            arecipes.add(recipe);
        }
    }
}
 
Example #7
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 #8
Source File: ShapelessRecipeHandler.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() == ShapelessRecipeHandler.class) {
        List<IRecipe> allrecipes = CraftingManager.getInstance().getRecipeList();
        for (IRecipe irecipe : allrecipes) {
            CachedShapelessRecipe recipe = null;
            if (irecipe instanceof ShapelessRecipes)
                recipe = shapelessRecipe((ShapelessRecipes) irecipe);
            else if (irecipe instanceof ShapelessOreRecipe)
                recipe = forgeShapelessRecipe((ShapelessOreRecipe) irecipe);

            if (recipe == null)
                continue;

            arecipes.add(recipe);
        }
    } else {
        super.loadCraftingRecipes(outputId, results);
    }
}
 
Example #9
Source File: ShapelessRecipeHandler.java    From NotEnoughItems with MIT License 6 votes vote down vote up
@Override
public void loadCraftingRecipes(ItemStack result) {
    List<IRecipe> allrecipes = CraftingManager.getInstance().getRecipeList();
    for (IRecipe irecipe : allrecipes) {
        if (NEIServerUtils.areStacksSameTypeCrafting(irecipe.getRecipeOutput(), result)) {
            CachedShapelessRecipe recipe = null;
            if (irecipe instanceof ShapelessRecipes)
                recipe = shapelessRecipe((ShapelessRecipes) irecipe);
            else if (irecipe instanceof ShapelessOreRecipe)
                recipe = forgeShapelessRecipe((ShapelessOreRecipe) irecipe);

            if (recipe == null)
                continue;

            arecipes.add(recipe);
        }
    }
}
 
Example #10
Source File: ShapelessRecipeHandler.java    From NotEnoughItems with MIT License 6 votes vote down vote up
@Override
public void loadUsageRecipes(ItemStack ingredient) {
    List<IRecipe> allrecipes = CraftingManager.getInstance().getRecipeList();
    for (IRecipe irecipe : allrecipes) {
        CachedShapelessRecipe recipe = null;
        if (irecipe instanceof ShapelessRecipes)
            recipe = shapelessRecipe((ShapelessRecipes) irecipe);
        else if (irecipe instanceof ShapelessOreRecipe)
            recipe = forgeShapelessRecipe((ShapelessOreRecipe) irecipe);

        if (recipe == null)
            continue;

        if (recipe.contains(recipe.ingredients, ingredient)) {
            recipe.setIngredientPermutation(recipe.ingredients, ingredient);
            arecipes.add(recipe);
        }
    }
}
 
Example #11
Source File: ShapelessBloodOrbRecipe.java    From Framez with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
ShapelessBloodOrbRecipe(ShapelessRecipes recipe, Map<ItemStack, String> replacements)
{
    output = recipe.getRecipeOutput();

    for (ItemStack ingred : ((List<ItemStack>) recipe.recipeItems))
    {
        Object finalObj = ingred;
        for (Entry<ItemStack, String> replace : replacements.entrySet())
        {
            if (OreDictionary.itemMatches(replace.getKey(), ingred, false))
            {
                finalObj = OreDictionary.getOres(replace.getValue());
                break;
            }
        }
        input.add(finalObj);
    }
}
 
Example #12
Source File: ShapelessRecipeHandler.java    From NotEnoughItems with MIT License 5 votes vote down vote up
private CachedShapelessRecipe shapelessRecipe(ShapelessRecipes recipe) {
    if (recipe.recipeItems == null) //because some mod subclasses actually do this
    {
        return null;
    }

    return new CachedShapelessRecipe(recipe.recipeItems, recipe.getRecipeOutput());
}
 
Example #13
Source File: ShapelessBloodOrbRecipe.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
ShapelessBloodOrbRecipe(ShapelessRecipes recipe, Map<ItemStack, String> replacements) {
	output = recipe.getRecipeOutput();

	for (ItemStack ingred : ((List<ItemStack>) recipe.recipeItems)) {
		Object finalObj = ingred;
		for (Entry<ItemStack, String> replace : replacements.entrySet()) {
			if (OreDictionary.itemMatches(replace.getKey(), ingred, false)) {
				finalObj = OreDictionary.getOres(replace.getValue());
				break;
			}
		}
		input.add(finalObj);
	}
}
 
Example #14
Source File: RecipeHandlerRollingMachineShapeless.java    From NEI-Integration with MIT License 5 votes vote down vote up
private CachedRollingMachineShapelessRecipe getCachedRecipe(IRecipe irecipe, boolean genPerms) {
    CachedRollingMachineShapelessRecipe recipe = null;
    if (irecipe instanceof ShapelessRecipes) {
        recipe = new CachedRollingMachineShapelessRecipe(((ShapelessRecipes) irecipe).recipeItems, ((ShapelessRecipes) irecipe).getRecipeOutput());
    } else if (irecipe instanceof ShapelessOreRecipe) {
        recipe = this.getCachedOreRecipe((ShapelessOreRecipe) irecipe, genPerms);
    }
    return recipe;
}
 
Example #15
Source File: ShapelessRecipe.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
private boolean matchesInput(IRecipe recipe)
{
    if (recipe instanceof ShapelessRecipes)
    {
        return matchesInput((ShapelessRecipes) recipe);
    } else if (recipe instanceof ShapelessOreRecipe)
    {
        return matchesInput((ShapelessOreRecipe) recipe);
    }

    return false;
}
 
Example #16
Source File: CraftShapelessRecipe.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public void addToCraftingManager() {
    List<ItemStack> ingred = this.getIngredientList();
    NonNullList<Ingredient> data = NonNullList.withSize(ingred.size(), Ingredient.EMPTY);
    for (int i = 0; i < ingred.size(); i++) {
        data.set(i, Ingredient.fromStacks(new net.minecraft.item.ItemStack[]{CraftItemStack.asNMSCopy(ingred.get(i))}));
    }
    // TODO: Check if it's correct way to register recipes
    ForgeRegistries.RECIPES.register(new ShapelessRecipes("", CraftItemStack.asNMSCopy(this.getResult()), data));
    // CraftingManager.a(CraftNamespacedKey.toMinecraft(this.getKey()), new ShapelessRecipes("", CraftItemStack.asNMSCopy(this.getResult()), data));
}
 
Example #17
Source File: ShapelessRecipeHandler.java    From NotEnoughItems with MIT License 4 votes vote down vote up
private CachedShapelessRecipe shapelessRecipe(ShapelessRecipes recipe) {
    if(recipe.recipeItems == null) //because some mod subclasses actually do this
        return null;

    return new CachedShapelessRecipe(recipe.recipeItems, recipe.getRecipeOutput());
}
 
Example #18
Source File: CraftShapelessRecipe.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public CraftShapelessRecipe(ItemStack result, ShapelessRecipes recipe) {
    this(CraftNamespacedKey.fromMinecraft(recipe.key), result);
    this.recipe = recipe;
}
 
Example #19
Source File: ShapelessRecipeTests.java    From customstuff4 with GNU General Public License v3.0 4 votes vote down vote up
private List<IRecipe> createTestRecipes(Item result)
{
    return Lists.newArrayList(new ShapelessRecipes("group", new ItemStack(result), NonNullList.from(Ingredient.EMPTY, Ingredient.fromItem(Items.ITEM_FRAME))),
                              new ShapelessRecipes("group", new ItemStack(result), NonNullList.from(Ingredient.EMPTY, Ingredient.fromStacks(new ItemStack(Blocks.STONE)), Ingredient.fromStacks(new ItemStack(Blocks.LOG)))));
}