private void FindMatchingRecipe() { ItemStack[] inputstacks = new ItemStack[] { inventory[0].Itemstack, inventory[1].Itemstack }; CurrentRecipe = null; foreach (var recipe in api.World.BarrelRecipes) { int outsize; if (recipe.Matches(api.World, inputstacks, out outsize)) { ignoreChange = true; if (recipe.SealHours > 0) { CurrentRecipe = recipe; CurrentOutSize = outsize; } else { ItemStack mixedStack = recipe.Output.ResolvedItemstack.Clone(); mixedStack.StackSize = outsize; if (BlockLiquidContainerBase.GetStackProps(mixedStack) != null) { inventory[0].Itemstack = null; inventory[1].Itemstack = mixedStack; } else { inventory[1].Itemstack = null; inventory[0].Itemstack = mixedStack; } inventory[0].MarkDirty(); inventory[1].MarkDirty(); MarkDirty(true); api.World.BlockAccessor.MarkBlockEntityDirty(pos); } invDialog?.UpdateContents(); if (api?.Side == EnumAppSide.Client) { currentMesh = GenMesh(); MarkDirty(true); } ignoreChange = false; return; } } }
/// <summary> /// Registers a new barrel mixing recipe. These are sent to the client during connect, so only need to register them on the server side. /// </summary> /// <param name="recipe"></param> public void RegisterBarrelRecipe(BarrelRecipe recipe) { if (recipe.Code == null) { throw new ArgumentException("Barrel recipes must have a non-null code! (choose freely)"); } foreach (var ingred in recipe.Ingredients) { if (ingred.ConsumeQuantity != null && ingred.ConsumeQuantity > ingred.Quantity) { throw new ArgumentException("Barrel recipe with code {0} has an ingredient with ConsumeQuantity > Quantity. Not a valid recipe!"); } } BarrelRecipes.Add(recipe); }
private void FindMatchingRecipe() { ItemSlot[] inputSlots = new ItemSlot[] { inventory[0], inventory[1] }; CurrentRecipe = null; foreach (var recipe in Api.World.BarrelRecipes) { int outsize; if (recipe.Matches(Api.World, inputSlots, out outsize)) { ignoreChange = true; if (recipe.SealHours > 0) { CurrentRecipe = recipe; CurrentOutSize = outsize; } else { if (Api?.Side == EnumAppSide.Server) { recipe.TryCraftNow(Api, 0, inputSlots); MarkDirty(true); Api.World.BlockAccessor.MarkBlockEntityDirty(Pos); } } invDialog?.UpdateContents(); if (Api?.Side == EnumAppSide.Client) { currentMesh = GenMesh(); MarkDirty(true); } ignoreChange = false; return; } } }
public static void RegisterBarrelRecipe(this ICoreServerAPI api, BarrelRecipe r) { api.ModLoader.GetModSystem <RecipeRegistrySystem>().RegisterBarrelRecipe(r); }