-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update/Create builder interfaces * Oop fix names * Cleanup/Finalize all builder changes * Cleanup main recipe classes * Keep function names consistent * Keep function names consistent pt 2 * Rename Name to Identifier to match up inline with mojang * Make sure Identifier uses an internal setter * Oop fix that * Smithing recipes don't have groups * Refactor ShapelessRecipeBuilder and IIngredientRecipe
- Loading branch information
Showing
25 changed files
with
267 additions
and
347 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using Obsidian.API.Crafting.Builders.Interfaces; | ||
|
||
namespace Obsidian.API.Crafting.Builders; | ||
public abstract class BaseRecipeBuilder<TRecipe> : IGroupedRecipe<TRecipe>, INamedRecipe<TRecipe>, IRecipeResult<TRecipe>, | ||
IRecipeBuilder<TRecipe> where TRecipe : IRecipe | ||
{ | ||
protected string Identifier { get; set; } | ||
|
||
protected string? Group { get; set; } | ||
|
||
protected ItemStack Result { get; set; } | ||
|
||
public virtual IRecipeResult<TRecipe> WithIdentifier(string identifier) | ||
{ | ||
ArgumentNullException.ThrowIfNull(identifier); | ||
|
||
this.Identifier = identifier; | ||
|
||
return this; | ||
} | ||
|
||
public virtual IRecipeBuilder<TRecipe> WithResult(ItemStack result) | ||
{ | ||
ArgumentNullException.ThrowIfNull(result); | ||
|
||
this.Result = result; | ||
|
||
return this; | ||
} | ||
|
||
public virtual INamedRecipe<TRecipe> InGroup(string group) | ||
{ | ||
this.Group = group; | ||
|
||
return this; | ||
} | ||
|
||
public virtual INamedRecipe<TRecipe> HasNoGroup() => this; | ||
|
||
public abstract TRecipe Build(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using Obsidian.API.Crafting.Builders.Interfaces; | ||
|
||
namespace Obsidian.API.Crafting.Builders; | ||
|
||
public sealed class CookingRecipeBuilder : BaseRecipeBuilder<SmeltingRecipe>, IIngredientRecipe<ICookingRecipe>, ICookingRecipe | ||
{ | ||
private readonly CookingBookCategory category; | ||
|
||
private readonly SmeltingType type; | ||
|
||
private Ingredient ingredient = new(); | ||
|
||
private float experience; | ||
|
||
private int cookingTime; | ||
|
||
private CookingRecipeBuilder(CookingBookCategory category, SmeltingType type) | ||
{ | ||
this.category = category; | ||
this.type = type; | ||
} | ||
|
||
public static IIngredientRecipe<ICookingRecipe> Create(CookingBookCategory category, SmeltingType type) => new CookingRecipeBuilder(category, type); | ||
|
||
public ICookingRecipe WithIngredient(params ItemStack[] items) | ||
{ | ||
foreach (var item in items) | ||
this.ingredient.Add(item); | ||
|
||
return this; | ||
} | ||
|
||
public ICookingRecipe GivesExperience(float exp) | ||
{ | ||
this.experience += exp;//Just add if this function gets called again | ||
|
||
return this; | ||
} | ||
|
||
public IGroupedRecipe<SmeltingRecipe> WithCookingTime(int cookingTime) | ||
{ | ||
this.cookingTime = cookingTime; | ||
|
||
return this; | ||
} | ||
public override SmeltingRecipe Build() | ||
{ | ||
CraftingType type = this.type switch | ||
{ | ||
SmeltingType.Default => CraftingType.Smelting, | ||
SmeltingType.Blasting => CraftingType.Blasting, | ||
SmeltingType.Smoking => CraftingType.Smoking, | ||
SmeltingType.CampfireCooking => CraftingType.CampfireCooking, | ||
_ => throw new NotImplementedException() | ||
}; | ||
|
||
if (this.ingredient.Count <= 0) | ||
throw new InvalidOperationException("Recipe must atleast have 1 item as an ingredient"); | ||
|
||
return new SmeltingRecipe | ||
{ | ||
Identifier = this.Identifier ?? throw new NullReferenceException("Recipe must have a name"), | ||
Type = type, | ||
Group = this.Group, | ||
Result = this.Result != null ? new Ingredient { this.Result } : throw new NullReferenceException("Result is not set."), | ||
Ingredient = this.ingredient, | ||
Experience = this.experience, | ||
CookingTime = this.cookingTime, | ||
Category = this.category | ||
}; | ||
} | ||
} | ||
|
||
public enum SmeltingType | ||
{ | ||
Default, | ||
Blasting, | ||
Smoking, | ||
CampfireCooking | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
Obsidian.API/Crafting/Builders/Interfaces/IBaseIngredientRecipe.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Obsidian.API.Crafting.Builders.Interfaces; | ||
public interface IBaseIngredientRecipe<TRecipe> | ||
{ | ||
public IUpgradeIngredientRecipe<TRecipe> WithBaseIngredient(params ItemStack[] items); | ||
} | ||
|
||
public interface IUpgradeIngredientRecipe<TRecipe> | ||
{ | ||
public INamedRecipe<TRecipe> WithUpgradeIngredient(params ItemStack[] items); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Obsidian.API.Crafting.Builders.Interfaces; | ||
public interface ICookingRecipe | ||
{ | ||
public ICookingRecipe GivesExperience(float exp); | ||
|
||
public IGroupedRecipe<SmeltingRecipe> WithCookingTime(int time); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Obsidian.API.Crafting.Builders.Interfaces; | ||
public interface IGroupedRecipe<TRecipe> | ||
{ | ||
public INamedRecipe<TRecipe> InGroup(string group); | ||
|
||
public INamedRecipe<TRecipe> HasNoGroup(); | ||
} |
10 changes: 10 additions & 0 deletions
10
Obsidian.API/Crafting/Builders/Interfaces/IIngredientRecipe.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Obsidian.API.Crafting.Builders.Interfaces; | ||
public interface IIngredientRecipe<TBuilder> | ||
{ | ||
public TBuilder WithIngredient(params ItemStack[] items); | ||
} | ||
|
||
public interface IShapelessIngredientRecipe<TRecipe> | ||
{ | ||
public IGroupedRecipe<TRecipe> AddIngredients(params Ingredient[] ingredients); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
namespace Obsidian.API.Crafting.Builders.Interfaces; | ||
public interface INamedRecipe<TRecipe> | ||
{ | ||
public IRecipeResult<TRecipe> WithIdentifier(string name); | ||
} |
5 changes: 5 additions & 0 deletions
5
Obsidian.API/Crafting/Builders/Interfaces/IOutputCountRecipe.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
namespace Obsidian.API.Crafting.Builders.Interfaces; | ||
public interface IOutputCountRecipe<TRecipe> | ||
{ | ||
public IGroupedRecipe<TRecipe> WithOutputCount(int count); | ||
} |
7 changes: 7 additions & 0 deletions
7
Obsidian.API/Crafting/Builders/Interfaces/IPatternedRecipe.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Obsidian.API.Crafting.Builders.Interfaces; | ||
public interface IPatternedRecipe | ||
{ | ||
public IPatternedRecipe WithKey(char key, params ItemStack[] items); | ||
|
||
public IGroupedRecipe<ShapedRecipe> WithPattern(params string[] pattern); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
namespace Obsidian.API.Crafting.Builders.Interfaces; | ||
public interface IRecipeBuilder<TRecipe> | ||
{ | ||
public TRecipe Build(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Obsidian.API.Crafting.Builders.Interfaces; | ||
|
||
public interface IRecipeResult<TRecipe> | ||
{ | ||
public IRecipeBuilder<TRecipe> WithResult(ItemStack result); | ||
} |
Oops, something went wrong.