public override void OnCraft(Item item) { Player player = Main.LocalPlayer; for (int i = 0; i < partKeys.Count; i++) { for (int j = 0; j < player.inventory.Length; j++) { Item currentItem = player.inventory[j]; if (currentItem.type != ModContent.ItemType <ConstructPart>()) { continue; } ConstructPart partItem = currentItem.modItem as ConstructPart; if (partItem.partKey == partKeys[i] && GHelper.GetPartType(partItem.partKey).type == partTypes[i]) { currentItem.TurnToAir(); break; } } } (item.modItem as ConstructTool).parts = partKeys; (item.modItem as ConstructTool).itemType = itemType; (item.modItem as ConstructTool).effects = new Dictionary <string, int>(); foreach (Dictionary <string, int> effect in effectsToAdd) { GHelper.AddEffectsToItem(item, effect); //(item.modItem as ConstructTool).effects.AddRange(effect); } (item.modItem as ConstructTool).SetDefaults(); FindRecipes(); RecipeAvailable(); }
public override void ModifyInterfaceLayers(List <GameInterfaceLayer> layers) { int inventoryIndex = layers.FindIndex(layer => layer.Name.Equals("Vanilla: Inventory")); if (inventoryIndex != -1) { layers.Insert(inventoryIndex, new LegacyGameInterfaceLayer( "Gunplay: Dismantle UI", delegate { DismantleUserInterface.Draw(Main.spriteBatch, new GameTime()); return(true); }, InterfaceScaleType.UI) ); layers.Insert(inventoryIndex, new LegacyGameInterfaceLayer( "Gunplay: Cheat Dismantle UI", delegate { CheatDismantleUserInterface.Draw(Main.spriteBatch, new GameTime()); return(true); }, InterfaceScaleType.UI) ); } int mouseItemIndex = layers.FindIndex(layer => layer.Name.Equals("Vanilla: Interact Item Icon")); if (mouseItemIndex != -1 && Main.LocalPlayer.HeldItem.type == ModContent.ItemType <ConstructTool>()) { layers.RemoveAt(mouseItemIndex); layers.Insert(mouseItemIndex, new LegacyGameInterfaceLayer ("TerrariaConstruct:ItemIcon", delegate { Item heldItem = Main.LocalPlayer.inventory[Main.LocalPlayer.selectedItem]; if (heldItem.type == ModContent.ItemType <ConstructTool>() && Main.LocalPlayer.showItemIcon) { Main.LocalPlayer.showItemIcon = false; Main.LocalPlayer.showItemIconR = false; List <Texture2D> textures = new List <Texture2D>(); foreach (string key in (heldItem.modItem as ConstructTool).parts) { try { Texture2D tex = ModContent.GetTexture(GHelper.GetPartType(key).useTexture); textures.Add(tex); } catch (Exception e) { Gunplay.Instance.Logger.Error("Something failed when getting invTexture in PreDrawInInventory! " + e.Message); } } foreach (Texture2D texture in textures) { Main.spriteBatch.Draw(texture, new Vector2(Main.mouseX + 10, Main.mouseY + 10), new Rectangle(0, 0, texture.Width, texture.Height), Color.White, 0f, default, Main.cursorScale, SpriteEffects.None, 0f);
public override bool RecipeAvailable() { partKeys = new List <string>(); effectsToAdd = new List <Dictionary <string, int> >(); bool[] found = new bool[partTypes.Count]; Player player = Main.LocalPlayer; for (int i = 0; i < partTypes.Count; i++) { for (int j = 0; j < player.inventory.Length; j++) { Item currentItem = player.inventory[j]; if (currentItem.type != ModContent.ItemType <ConstructPart>()) { continue; } ConstructPart part = currentItem.modItem as ConstructPart; if (GHelper.GetPartType(part.partKey).type == partTypes[i]) { found[i] = true; partKeys.Add(part.partKey); effectsToAdd.Add(GHelper.GetPartType(part.partKey).effects); break; } } } Recipe recipe = Main.recipe[RecipeIndex]; if (found.All(x => x)) { for (int i = 0; i < recipe.requiredItem.Length; i++) { if (recipe.requiredItem[i].type != ModContent.ItemType <ConstructPart>()) { continue; } else { (recipe.requiredItem[i].modItem as ConstructPart).partKey = partKeys[i]; } } (recipe.createItem.modItem as ConstructTool).parts = partKeys; (recipe.createItem.modItem as ConstructTool).itemType = itemType; (recipe.createItem.modItem as ConstructTool).effects = new Dictionary <string, int>(); foreach (Dictionary <string, int> effect in effectsToAdd) { GHelper.AddEffectsToItem(recipe.createItem, effect); //(recipe.createItem.modItem as ConstructTool).effects.AddRange(effect); } (recipe.createItem.modItem as ConstructTool).SetDefaults(); return(base.RecipeAvailable()); } else { //for (int i = 0; i < recipe.requiredItem.Length; i++) //{ // if (recipe.requiredItem[i].type != ItemType<ConstructPart>()) // { // continue; // } // else // { // (recipe.requiredItem[i].modItem as ConstructPart).partKey = "TerrariaConstruct:UnknownPart"; // } //} return(false); } }