useSand() public method

public useSand ( int invType, int reqType ) : bool
invType int
reqType int
return bool
Beispiel #1
0
        static KeyValuePair<ItemUnion, int>? UsesItem(Recipe r, int netID)
        {
            if (netID == 0)
                return null;

            if (r.P_GroupDef as RecipeDef != null)
            {
                var rd = (RecipeDef)r.P_GroupDef;

                foreach (var id in rd.RequiredItems)
                {
                    var e = RefEq(netID);

                    if (id.Key.Match(e, ig => ig.Any(e)))
                        return id;
                }
            }
            else
                for (int i = 0; i < r.requiredItem.Length && !r.requiredItem[i].IsEmpty(); i++)
                {
                    var it = r.requiredItem[i];

                    if (it.netID == netID ||
                            r.useWood         (netID, it.type) ||
                            r.useSand         (netID, it.type) ||
                            r.useIronBar      (netID, it.type) ||
                            r.useFragment     (netID, it.type) ||
                            r.usePressurePlate(netID, it.type))
                        return new KeyValuePair<ItemUnion, int>(ItemUnion.NewRight(ItemDef.Defs[it.netID]), it.stack);
                }

            return null;
        }
Beispiel #2
0
        public static void ApiCreate(this Terraria.Recipe recipe)
        {
            for (int requirementIndex = 0; requirementIndex < Terraria.Recipe.maxRequirements; requirementIndex++)
            {
                Item requiredItem = recipe.requiredItem[requirementIndex];
                if (requiredItem.type == ItemID.None)
                {
                    break;
                }
                int requiredAmount = requiredItem.stack;
                if (recipe is ModRecipe modRecipe)
                {
                    requiredAmount = modRecipe.ConsumeItem(requiredItem.type, requiredItem.stack);
                }
                if (recipe.alchemy && Main.player[Main.myPlayer].alchemyTable)
                {
                    if (requiredAmount > 1)
                    {
                        int num2 = 0;
                        for (int j = 0; j < requiredAmount; j++)
                        {
                            if (Main.rand.Next(3) == 0)
                            {
                                num2++;
                            }
                        }
                        requiredAmount -= num2;
                    }
                    else if (Main.rand.Next(3) == 0)
                    {
                        requiredAmount = 0;
                    }
                }

                if (requiredAmount <= 0)
                {
                    continue;
                }

                Item[] array = Main.player[Main.myPlayer].inventory;
                InvLogic(recipe, array, requiredItem, requiredAmount);
                PlayerCharacter character = Main.LocalPlayer.GetModPlayer <PlayerCharacter>();
                for (int j = 0; j < character.Inventories.Length; j += 1)
                {
                    if (character.ActiveInvPage != j)
                    {
                        array = character.Inventories[j];
                        InvLogic(recipe, array, requiredItem, requiredAmount);
                    }
                }

                if (Main.player[Main.myPlayer].chest == -1)
                {
                    continue;
                }
                if (Main.player[Main.myPlayer].chest > -1)
                {
                    array = Main.chest[Main.player[Main.myPlayer].chest].item;
                }
                else
                {
                    switch (Main.player[Main.myPlayer].chest)
                    {
                    case -2:
                        array = Main.player[Main.myPlayer].bank.item;
                        break;

                    case -3:
                        array = Main.player[Main.myPlayer].bank2.item;
                        break;

                    case -4:
                        array = Main.player[Main.myPlayer].bank3.item;
                        break;
                    }
                }

                for (int l = 0; l < 40; l++)
                {
                    Item item3 = array[l];
                    if (requiredAmount <= 0)
                    {
                        break;
                    }

                    if (!item3.IsTheSameAs(requiredItem) && !recipe.useWood(item3.type, requiredItem.type) &&
                        !recipe.useSand(item3.type, requiredItem.type) && !recipe.useIronBar(item3.type, requiredItem.type) &&
                        !recipe.usePressurePlate(item3.type, requiredItem.type) && !recipe.useFragment(item3.type, requiredItem.type) &&
                        !recipe.AcceptedByItemGroups(item3.type, requiredItem.type))
                    {
                        continue;
                    }
                    if (item3.stack > requiredAmount)
                    {
                        item3.stack -= requiredAmount;
                        if (Main.netMode == NetmodeID.MultiplayerClient && Main.player[Main.myPlayer].chest >= 0)
                        {
                            NetMessage.SendData(32, -1, -1, null, Main.player[Main.myPlayer].chest, l);
                        }
                        requiredAmount = 0;
                    }
                    else
                    {
                        requiredAmount -= item3.stack;
                        array[l]        = new Item();
                        if (Main.netMode == NetmodeID.MultiplayerClient && Main.player[Main.myPlayer].chest >= 0)
                        {
                            NetMessage.SendData(32, -1, -1, null, Main.player[Main.myPlayer].chest, l);
                        }
                    }
                }
            }

            AchievementsHelper.NotifyItemCraft(recipe);
            AchievementsHelper.NotifyItemPickup(Main.player[Main.myPlayer], recipe.createItem);
            FindRecipes();
        }