internal static void Create(Recipe r) { if (r.P_GroupDef as RecipeDef == null) { r.CreateBasic(); } else { r.CreateUnion(); } AchievementsHelper.NotifyItemCraft(r); AchievementsHelper.NotifyItemPickup(Main.player[Main.myPlayer], r.createItem); Recipe.FindRecipes(); }
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(); }