public static void PutModItemInInventory(this Player player, ModItem item, int selItem = -1) { for (int i = 0; i < 58; i++) { Item inventoryItem = player.inventory[i]; if (inventoryItem.stack > 0 && inventoryItem.type == item.item.type && inventoryItem.stack < inventoryItem.maxStack) { inventoryItem.stack++; return; } } if (selItem >= 0 && (player.inventory[selItem].type == 0 || player.inventory[selItem].stack <= 0)) { ModItem newItem = item.Clone(); newItem.item.maxStack = 1; player.inventory[selItem].SetDefaults(newItem.item.type, false); typeof(Item).GetField("modItem", BindingFlags.Public | BindingFlags.Instance).SetValue(player.inventory[selItem], newItem); return; } ModItem newModItem = item.Clone(); newModItem.item.maxStack = 1; player.inventory[selItem].SetDefaults(newModItem.item.type, false); Item newItem2 = new Item(); newItem2.SetDefaults(item.item.type, false); typeof(Item).GetField("modItem", BindingFlags.Public | BindingFlags.Instance).SetValue(newItem2, newModItem); Item item3 = player.GetItem(player.whoAmI, newItem2, false, false); if (item3.stack > 0) { int number = Item.NewItem((int)player.position.X, (int)player.position.Y, player.width, player.height, item.item.type, 1, false, 0, true, false); if (Main.netMode == 1) { NetMessage.SendData(21, -1, -1, null, number, 1f, 0f, 0f, 0, 0, 0); return; } } else { newItem2.position.X = player.Center.X - (float)(newItem2.width / 2); newItem2.position.Y = newItem2.Center.Y - (float)(newItem2.height / 2); newItem2.active = true; ItemText.NewText(newItem2, 0, false, false); } }
public override BaseModule Deserialize(TagCompound tag) { if (ModContent.TryFind(tag.GetString("Mod"), tag.GetString("Name"), out BaseModule ModItem)) { BaseModule module = ModItem.Clone(); module.Load(tag.GetCompound("Data")); return(module); } // todo: UnloadedModule throw new Exception(); }