Advanced API Example - Uristqwerty/CraftGuide GitHub Wiki

A recipe containing fluids and output probability using the older Slot API

Here is a modified version of the API usage example that demonstrates more of the slot types provided by the API.

class DoohickeyRecipes extends CraftGuideAPIObject implements RecipeProvider
{
	@Override
	public void generateRecipes(RecipeGenerator generator)
	{
		ItemStack doohickeyMachine = MyAPI.getBlockItem("doohickey");
		
		RecipeTemplate template = generator.createRecipeTemplate(
			new Slot[]{
				new ItemSlot(12, 12, 16, 16, true).drawOwnBackground(true),
				new LiquidSlot(12, 30),
				new ItemSlot(50, 13, 16, 16, true).setSlotType(SlotType.OUTPUT_SLOT).drawOwnBackground(true),
				new ChanceSlot(50, 30, 16, 16).setSlotType(SlotType.OUTPUT_SLOT).drawOwnBackground(true)
				new ItemSlot(31, 21, 16, 16, true).setSlotType(SlotType.MACHINE_SLOT).drawOwnBackground(false),
			}, doohickeyMachine);
			
		for(DoohickeyRecipe recipe: MyAPI.getDoohickeyRecipes())
		{
			recipeGenerator.addRecipe(template,
				new Object[] {
					recipe.getInputItem(),
					recipe.getInputFluidStack(),
					recipe.getPrimaryOutput(),
					new Object[] {
						recipe.getSecondaryOutput(),
						recipe.getSecondaryChance(),
					},
					doohickeyMachine
			});
		}
	}
}

A 4x4 vanilla-style crafting recipe with the Builder API

class DoohickeyRecipes extends CraftGuideAPIObject implements RecipeProvider
{
	@Override
	public void generateRecipes(RecipeGenerator generator)
	{
		ItemStack crafting = new ItemStack(MyMod.expanded_crafting_table);
		ConstructedRecipeTemplate shapeless = generator.buildTemplate(crafting)
			.shapelessItemGrid(4, 4)
			.nextColumn(1) // 1px gap between input and output columns. Purely a personal convention.
			.outputItem()
			.machineItem()
			.finishTemplate();
	
		ConstructedRecipeTemplate shaped = generator.buildTemplate(crafting)
			.shapedItemGrid(4, 4)
			.nextColumn(1)
			.outputItem()
			.machineItem()
			.finishTemplate();
	
		for(IRecipe recipe: MyMod.craftingRecipes().getRecipeList())
		{
			if(recipe instanceof ShapelessRecipe)
			{
				ShapelessRecipe r = (ShapelessRecipe)recipe;
				shapeless.buildRecipe()
					.shapelessItemGrid(r.getInputs())
					.item(r.getOutput())
					.item(crafting)
					.addRecipe(generator);
			}
			else if(recipe instanceof ShapedRecipe)
			{
				ShapedRecipe r = (ShapedRecipe)recipe;
				shaped.buildRecipe()
					.shapedItemGrid(r.width(), r.height(), r.getInputs())
					.item(r.getOutput())
					.item(crafting)
					.addRecipe(generator);
			}
		}
	}
}

The recipe containing fluids and output probability converted to the newer Builder API

class DoohickeyRecipes extends CraftGuideAPIObject implements RecipeProvider
{
	@Override
	public void generateRecipes(RecipeGenerator generator)
	{
		ItemStack doohickeyMachine = MyAPI.getBlockItem("doohickey");

		ConstructedRecipeTemplate template = generator.buildTemplate(doohickeyMachine)
			.item().liquid().nextColumn(1)
			.machineItem().nextColumn(1)
			.nextSlotType(TemplateBuilderSlotType.OUTPUT)
			.item().chanceItem().finishTemplate();
			
		for(DoohickeyRecipe recipe: MyAPI.getDoohickeyRecipes())
		{
			template.buildRecipe()
				.item(recipe.getInputItem())
				.liquid(recipe.getInputFluidStack())
				.item(doohickeyMachine)
				.item(recipe.getPrimaryOutput())
				.chanceItem(recipe.getSecondaryOutput(), recipe.getSecondaryChance()
				.addRecipe(generator);
		}
	}
}