Utilities

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.Utils;

Some of these utilities could be found in the Previous Asphalt MDK, we have incorporated some of their ideas into EM Framework because we seen them as valuable assets to be used.

Credit Goes to the Original Authors for some of these additions. You can find the Open Source versions of these utils here: Github

As far as we know Asphalt MDK is no longer supported or maintained And with some information of the Devs may not be supported again due to security implementations they are adding as Asphalt Uses Harmony Which does require Injection methods to function.

Injection is no longer allowed on eco so Asphalt MDK may no longer retain support from modders.


Affine Transformation

Affine Transformation is very technical and should only be used by those with advanced knowledge in C# and willing to learn how it works.

If you are interested in learning what it does and how it works check out this link:
JavaGeom
Or this Link: JavaGeom Tutorial

To see an implementation of this check out the World Edit Plugin here: World Edit


Block Utils

The block utils only contains 1 method.

This Method just allows you to get the block type from a string.

It performs a matching check to find the closest match and returns that type:

BlockUtils.GetBlockType(string BlockName);

This checks your string and trys to find out if its one of the following:

  • FloorBlock
  • It iself as a block
  • Block

Here is an example on how to use it effectivly:

[ChatCommand("/set", "", ChatAuthorizationLevel.Admin)]
public static void Set(User user, string pTypeName)
{
    cleanTypeName = pTypeName.Replace(" ", "").Trim(); //we do this because we are using a string
    //alternatively you can use
    cleanTypeName = Base.Sanitise(pTypeName.Replace(" ", "");
    //or
    cleanTypeName = Base.CleanSanitize(pTypeName);

    Type blockType = BlockUtils.GetBlockType(cleanTypeName); //this will then pass the string to check and see if its a block

    if (blockType == null)
    {
        user.Player.MsgLoc($"No BlockType with name {pTypeName} found!");
        return;
    }
    user.Player.MsgLoc($"BlockType with name {pTypeName} found! We Found {blockType.ToString()}");
    return;
}

The reason we use .Replace() and .Trim() is so the command can be used like this:

/set hewn log wall

it will then use the text: hewn log wall and change it to: hewnlogwall and use that to type match which gives us a better result.

Which would give you the Type: HewnLogWallBlock which is the logical term in eco for a Wall block

You don't need to convert your string to lower as the BlockUtils will do this for you.


ItemUtils - Incomplete

Item Utils will Allow you to get an items Type from a string the same as the block utils.

To use this you will need to use a Static Using so there are no conflicts:

using static Eco.EM.Framework.Utils.ItemUtils;

This will then let you just do the following:

GetTypeFromString(itemType);

Once completed The Item Utils will allow you to check if its a Tag and return a list of all items in that tag or just an Actual Item.

More info on this utility will be available when its completed.


Colored Text

The colored text util is just a simple way to return a string with the color tags for eco.

The colored text util has 8 usable methods:

ColoredText.RedText(string msg);
ColoredText.BlueText(string msg);
ColoredText.YellowText(string msg);
ColoredText.CustomText(string color, string msg);
ColoredText.CustomMultiText(string color, string msg, string color2, string msg2);
ColoredText.CustomMultiText(string color, string msg, string color2, string msg2, string color3, string msg3);
ColoredText.CustomMultiText(string color, string msg, string color2, string msg2, string color3, string msg3, string color4, string msg4);

Same as the ItemUtils you can use the Static Reference to make use shorter.

Here is an example of using these methods:

using static Eco.EM.Framework.Utils.ColoredText;

[ChatCommand("/msg", "", ChatAuthorizationLevel.Admin)]
public static void MyMessage(User user)
{
    string text = "green colored";
    user.Player.MsgLoc($"This is how you can print {GreenText(text)} text!");
    return;
}

this will then output like this:

This is how you can print green colored text!

Another way to do this is:

using static Eco.EM.Framework.Utils.ColoredText;

[ChatCommand("/msg", "", ChatAuthorizationLevel.Admin)]
public static void MyMessage(User user)
{
    string text = GreenText("green colored");
    user.Player.MsgLoc($"This is how you can print {text} text!");
    return;
}

This will give you the same result as the first just simpler.

this will then output like this:

This is how you can print green colored text!

The CustomText() Allows you to specify the color you would like either with a hex code or name input:

using static Eco.EM.Framework.Utils.ColoredText;

[ChatCommand("/msg", "", ChatAuthorizationLevel.Admin)]
public static void MyMessage(User user)
{
string text = CustomText("086BA4", "colored");
user.Player.MsgLoc($"This is how you can print {text} text!");
return;
}

this will then output like this:

This is how you can print colored text!

Using the CustomMultiText() is quite different at this time, here is how its used and its output:

using static Eco.EM.Framework.Utils.ColoredText;

[ChatCommand("/msg", "", ChatAuthorizationLevel.Admin)]
public static void MyMessage(User user)
{
    string text = CustomMultiText("#086BA4", "some multi colored", "red", "text!");
    user.Player.MsgLoc($"This is how you can print {text}");
    return;
}

this will then output like this:

This is how you can print some multi colored text!

I have plans to change it to an array setup to allow you to extend it as far as you like, so you can do rainbow text if you like, this is still in the works though


Console Colors

The Console Colors util allows you to print to the eco server with different colors with up too 4 inputs.

It works very similar to the ColoredText Util but uses ConsoleColor instead of a hex code or a string.

The Console Colors util has 4 usable methods:

PrintConsoleColored(string input, ConsoleColor color);
PrintConsoleColored(string input, ConsoleColor color, string input2, ConsoleColor color2);
PrintConsoleColored(string input, ConsoleColor color, string input2, ConsoleColor color2, string input3, ConsoleColor color3);
PrintConsoleColored(string input, ConsoleColor color, string input2, ConsoleColor color2, string input3, ConsoleColor color3, string input4, ConsoleColor color4);

Here is an example of using these methods:

using static Eco.EM.Framework.Utils.ConsoleColors;

[ChatCommand("/msg", "", ChatAuthorizationLevel.Admin)]
public static void MyMessage(User user)
{
    string text = "green colored text";
    PrintConsoleColored(text, ConsoleColor.Green);
    return;
}

this will then output like this to the server console:

[19.23.22] green colored text

The First part is the date time in Hours Minutes Seconds then your message so it looks clean in the console.

If you would like to print multiple texts with multiple colors you can do it like this:

using static Eco.EM.Framework.Utils.ConsoleColors;

[ChatCommand("/msg", "", ChatAuthorizationLevel.Admin)]
public static void MyMessage(User user)
{
    string text = "[Your Mod Name]";
    string output = "Some Text To Output";
    PrintConsoleColored(text, ConsoleColor.Green, output, ConsoleColor.White);
    return;
}

this will then output like this to the server console:

[19.23.22] [Your Mod Name] Some Text To Output

In order to use ConsoleColor.Color you will need a using reference to System.

using System;

Direction Utils

The Direction Utils can be used to get the players specific looking directions:

Such as:

  • Up
  • Down
  • Left
  • Rgiht
  • Forward
  • Backward

We have 3 methods for you to use, but you could just use 1 if you like unless you are after something specific:

Direction GetLookingDirecton(User user);
Direction GetDirection(string direction);
Direction GetDirectionOrLooking(User user, [string direction])

If you don't mind either way then GetDirectionOrLooking() will be the better method to use.

GetDirectionOrLooking() will auto swap between GetLookingDirection() or GetDirection() Depending on if you Leave the string direction empty or not.

These Methods will just return to you the direction the player is facing which can be used to spawn objects in front of them, behind them etc.


Skills Utils

The Skills Util is just a simple way of checking if either: Player has a skill level of a certain skill, or getting the Users Skill Level for a specified skill.

The 2 Methods for you to use are:

bool HasSkillLevel(User user, Type skillType, int level);
int  GetSkillLevel(User user, Type skillType);

HasSkillLevel will return true or false and you can act based on that.

GetSkillLevel will return the level of the requested skill and you can act based on that as well.

here is a short example:

var isHighEnoughSkill = SkillsUtil.HasSkillLevel(user, CarpentrySkill, 5);
if(isHighEnoughSkill)
{
user.Player.MsgLoc($"Congratulations You are a High Enough Level!");
}

var userSkillLvl = SkillsUtil.GetSkillLevel(user, CarpentrySkill);
if(userSkillLvl >= 3)
{
//do something
}
else if(userSkillLvl <=2)
{
//do something else
}

World Utils

on my todo list