public static Item CreateItem(string itemName, int stack = 0) { Item item = new Item(); item.RealSetDefaults(itemName); if (stack > 0) item.stack = stack; return item; }
internal static void OnSetDefaults(Item item, int type, bool noMatCheck) { Dictionary<string, BinBuffer> data = null; if (item.P_BHandler != null) data = ((ItemBHandler)item.P_BHandler).data; item.P_BHandler = null; item.P_UseSound = null; if (ModLoader.Reloading && !RecipeDefHandler.SettingUpRecipes) { item.RealSetDefaults(type, noMatCheck); if (!FillingVanilla) Logging.LogWarning("Tried to call SetDefaults on an Item while [re|un]?loading mods."); return; } ItemBHandler h = null; // will be set to <non-null> only if a behaviour handler will be attached item.RealSetDefaults(0, noMatCheck); if (Handler.ItemDef.DefsByType.ContainsKey(type)) { var d = Handler.ItemDef.DefsByType[type]; item.type = item.netID = type; item.width = item.height = 16; item.stack = item.maxStack = 1; Handler.ItemDef.CopyDefToEntity(d, item); if (RecipeDefHandler.SettingUpRecipes) return; if (d.CreateBehaviour != null) { h = new ItemBHandler(); var b = d.CreateBehaviour(); if (b != null) { b.Mod = d.Mod == PrismApi.VanillaInfo ? null : ModData.mods[d.Mod]; h.behaviours.Add(b); } } } else item.RealSetDefaults(type, noMatCheck); if (RecipeDefHandler.SettingUpRecipes) return; var bs = ModData.mods.Values .Select(m => new KeyValuePair<ModDef, ItemBehaviour>(m, m.ContentHandler.CreateGlobalItemBInternally())) .Where(kvp => kvp.Value != null) .Select(kvp => { kvp.Value.Mod = kvp.Key; return kvp.Value; }); if (!bs.IsEmpty() && h == null) h = new ItemBHandler(); if (h != null) { h.behaviours.AddRange(bs); if (data != null) h.data = data; h.Create(); item.P_BHandler = h; foreach (var b in h.Behaviours) b.Entity = item; h.OnInit(); } }
private void AddItem(string name) { Item item = new Item(); item.RealSetDefaults(name); AddItem(item); }
private void AddItem(int type) { Item item = new Item(); item.RealSetDefaults(type, true); AddItem(item); }