SuperCrafter integration?Solved

Hello WhiteThunder,

Requesting integration of "API_CanCraft" call for SuperCrafter. SuperCrafter allows players to craft from their base resources + inventory. Due to the nature of SuperCrafter I wanted to allow customers to limit "spam" crafting to reduce harmfull repetative network calls.

bool CanCraft(ItemCrafter itemCrafter, ItemBlueprint bp, int amount)

The above fuction is used in both SuperCrafter and ItemRetriever. But a warning message appears when our plugins disagree. I'm requesting a couple small edits almost exactly how you added for "InstantCraft".

1st Edit:

    [Info("Item Retriever", "WhiteThunder", "0.7.5")]
    [Description("Allows players to build, craft, reload and more using items from external containers.")]
    internal class ItemRetriever : CovalencePlugin
    {
        #region Fields

        [PluginReference]
        private readonly Plugin InstantCraft;

// NEW CODE START
        [PluginReference]
        private readonly Plugin SuperCrafter;
// NEW CODE END

        private static ItemRetriever _instance;

....

2nd Edit:

        private object CanCraft(ItemCrafter itemCrafter, ItemBlueprint blueprint, int amount, bool free)
        {
            if (_isBlockedByInstantCraft?.Invoke(blueprint.targetItem) == true)
                return null;

// New Code Start
            object canCraftResult = SuperCrafter?.Call("API_CanCraft", itemCrafter, blueprint, amount);
            if (canCraftResult is bool && (bool)canCraftResult == false)
                return false;
// New Code End

            var basePlayer = itemCrafter.baseEntity;
            ExposedHooks.OnIngredientsDetermine(_overridenIngredients, blueprint, amount, basePlayer);

            if (_overridenIngredients.Count > 0)
            {
                foreach (var entry in _overridenIngredients)
                {
                    if (entry.Value <= 0)
                        continue;

                    var itemQuery = new ItemIdQuery(entry.Key);
                    if (SumPlayerItems(basePlayer, ref itemQuery) < entry.Value)
                        return False;
                }
            }
            else
            {
                for (var i = 0; i < blueprint.ingredients.Count; i++)
                {
                    var ingredient = blueprint.ingredients[i];
                    var itemQuery = new ItemIdQuery(ingredient.itemid);
                    if (SumPlayerItems(basePlayer, ref itemQuery) < ingredient.amount * amount)
                        return False;
                }
            }

            return True;
        }

If you have a cleaner, better, sexier way we can achieve the same result please feel free. I will follow suit.

Lastly, if you need a copy of SuperCrafter hit me up on Discord @ "vergbergler"

This looks fine, I'll add this. Thanks!

Locked automatically