/// <summary>
        /// Called on Mod.Load
        /// </summary>
        public void Load()
        {
            if (!Main.dedServ)
            {
                interfaces = new Dictionary <string, UserInterface>();
                states     = new Dictionary <string, MachineUI>();

                var types = TechMod.types;
                foreach (var type in types)
                {
                    //Ignore abstract classes
                    if (type.IsAbstract)
                    {
                        continue;
                    }

                    if (typeof(MachineUI).IsAssignableFrom(type))
                    {
                        //Not abstract and doesn't have a parameterless ctor?  Throw an exception
                        if (type.GetConstructor(Type.EmptyTypes) is null)
                        {
                            throw new TypeLoadException($"Machine UI type \"{type.FullName}\" does not have a parameterless constructor.");
                        }

                        //Machine UI type.  Try to link the UI to the machine
                        MachineUI state   = Activator.CreateInstance(type) as MachineUI;
                        ModTile   machine = ModContent.GetModTile(state.TileType);

                        if (machine is null)
                        {
                            throw new TypeLoadException($"Machine UI type \"{type.FullName}\" had an invalid return value for its \"TileType\" getter property.");
                        }

                        //Register the UI
                        string name = machine.GetType().Name;
                        state.MachineName = name;
                        interfaces.Add(name, new UserInterface());
                        states.Add(name, state);
                    }
                }

                // Activate calls Initialize() on the UIState if not initialized, then calls OnActivate and then calls Activate on every child element
                foreach (var state in states.Values)
                {
                    state.Activate();
                }
            }
        }
        public void HideUI(string name)
        {
            MachineUI machineState = states[name];

            machineState.PlayCloseSound();

            machineState.PreClose();

            machineState.UIEntity.SaveSlots();
            machineState.ClearSlots();
            machineState.UIEntity.ParentState = null;
            machineState.UIEntity             = null;

            machineState.CheckedForSavedItemCount = false;
            machineState.Active = false;

            interfaces[name].SetState(null);
        }
        public void ShowUI(string name, MachineEntity entity)
        {
            MachineUI machineState = states[name];

            machineState.PlayOpenSound();

            machineState.Active               = true;
            machineState.UIEntity             = entity;
            machineState.UIEntity.ParentState = machineState;
            machineState.UIEntity.MachineName = machineState.MachineName;
            machineState.UIDelay              = 10;

            if (!machineState.CheckedForSavedItemCount)
            {
                machineState.CheckedForSavedItemCount = true;

                machineState.DoSavedItemsCheck();

                machineState.UIEntity.LoadSlots();
            }

            interfaces[name].SetState(machineState);
        }