Stack Size Changer

Here you will find the documentation on the features in the Stack Size Changer part of the framework.

Documentation may be incomplete and might need additions, we will update this when we can.

Usage:

            
        using Eco.EM.Framework;
        

The Stack Size Changer has been given its own dedicated section because this is a very useful tool and we wanted to keep everything clear to read.

This part of EM Framework will allow you to set it so server owners will be able to adjust the stack sizes of your items.

There is a few pre-requisites you will need in order to use this properly:

  • You need to make sure all your items have the [MaxStackSize(int)] Attribute otherwise it won't work.
  • Even if you want to use the default max stack size of 100 you still will need to specify it like so: [MaxStackSize(100)]
  • You will need to setup a Config For your mod, this does not require the File Manager, this can be done with the Vanilla Config Generator - I will supply a default config below to use it.

To get Started we will first specify our config:

This a basic file setup for you:

            
    using Eco.Core.Plugins;
    using Eco.Core.Plugins.Interfaces;
    using Eco.Core.Utils;
    using Eco.EM.Framework;
    using Eco.Shared.Localization;

    namespace Eco.Mods.TechTree
    {
        public class MyModBaseConfig : IStackSizeConfig
        {
            [LocDescription("Stacks")]
            public SerializedSynchronizedCollection<StackSizeElement>
            StackSizes { get; set; } = new SerializedSynchronizedCollection <StackSizeElement>();
        }
    }
                

We have now implemented our basic config for the stack sizes, now to implement it so it works in the server.

As an additional note this part:
[LocDescription("Stack Sizes: Editing stacksizes here requires a server restart. Changing the stack size of some items may have no ingame effect due to item data.")]

You should use that as the description for it because changing the stack sizes will require a server reboot regardless

                
    using Eco.Core.Plugins;
    using Eco.Core.Plugins.Interfaces;
    using Eco.Core.Utils;
    using Eco.EM.Framework;
    using Eco.Shared.Localization;

    namespace Eco.Mods.TechTree
    {
        public class MyModBaseConfig : IStackSizeConfig
        {
            [LocDescription("Stack Sizes: Editing stacksizes here requires a server restart. 
            Changing the stack size of some items may have no ingame effect due to item data.")]
            public SerializedSynchronizedCollection<StackSizeElement>
            StackSizes { get; set; } = new SerializedSynchronizedCollection<StackSizeElement>();
        }

        public class MyModPlugin : IInitializablePlugin, IModKitPlugin, IConfigurablePlugin
        {
            public string GetStatus() => "Doing Awesome Things!"; //This is a status of your mod

            public override string ToString() => Localizer.DoStr("My Awesome Mod"); //This adjusts the display inside the GUI

            public void Initialize(TimedTask timer)
            {
                StackSizeController.Obj.InitializeStackConfig(Config); //This is where the server will implement the new stack size changes
            }

            public MyModPlugin()
            {
                this.config = new PluginConfig<MyModBaseConfig>("MyConfig");
            }

            private PluginConfig<MyModBaseConfig> config;
            public IPluginConfig PluginConfig => this.config;
            public MyModBaseConfig Config => this.config.Config;
            public ThreadSafeAction<object, string>
            ParamChanged { get; set; } = new ThreadSafeAction<object, string>();
            public object GetEditObject() => this.config.Config;
            public void OnEditObjectChanged(object o, string param) => this.SaveConfig();
        }
    }
                

This is the completed file for implementing the stack size changer for your mod, You can also make these additions to your config file if it already exists, you just need to update your config class and add the stack size changer.

This stack size changer will then output a file to the Configs folder with the name you chose here: this.config = new PluginConfig<MyModBaseConfig>("MyConfig");

All your items will appear in a List so you can find the item by its name and change its max stack size.