tModLoader v2022.09
A mod to make and play Terraria mods
Terraria.Utils Class Reference

Public Member Functions

delegate Color ColorLerpMethod (float percent)
 
delegate void LaserLineFraming (int stage, Vector2 currentPosition, float distanceLeft, Rectangle lastFrame, out float distanceCovered, out Rectangle frame, out Vector2 origin, out Color color)
 
delegate bool TileActionAttempt (int x, int y)
 

Static Public Member Functions

static float AngleFrom (this Vector2 Origin, Vector2 Target)
 
static float AngleLerp (this float curAngle, float targetAngle, float amount)
 
static float AngleTo (this Vector2 Origin, Vector2 Target)
 
static float AngleTowards (this float curAngle, float targetAngle, float maxChange)
 
static bool Between (this Vector2 vec, Vector2 minimum, Vector2 maximum)
 
static Vector2 Bottom (this Rectangle r)
 
static Vector2 BottomLeft (this Rectangle r)
 
static Vector2 BottomRight (this Rectangle r)
 
static Vector2 Center (this Rectangle r)
 
static Rectangle CenteredRectangle (Vector2 center, Vector2 size)
 
static T Clamp< T > (T value, T min, T max)
 
static void ClampWithinWorld (ref int minX, ref int minY, ref int maxX, ref int maxY, bool lastValuesInclusiveToIteration=false, int fluffX=0, int fluffY=0)
 
static Vector2 ClosestPointInRect (this Rectangle r, Vector2 point)
 
static Vector2 ClosestPointOnLine (this Vector2 P, Vector2 A, Vector2 B)
 
static long CoinsCombineStacks (out bool overFlowing, params long[] coinCounts)
 
static long CoinsCount (out bool overFlowing, Item[] inv, params int[] ignoreSlots)
 
static int[] CoinsSplit (long count)
 
static Color ColorLerp_BlackToWhite (float percent)
 
static string[] ConvertMonoArgsToDotNet (string[] brokenArgs)
 
static bool deepCompare (this int[] firstArray, int[] secondArray)
 
static Vector2 DirectionFrom (this Vector2 Origin, Vector2 Target)
 
static Vector2 DirectionTo (this Vector2 Origin, Vector2 Target)
 
static float Distance (this Rectangle r, Vector2 point)
 
static float Distance (this Vector2 Origin, Vector2 Target)
 
static float DistanceSQ (this Vector2 Origin, Vector2 Target)
 
static Vector2 DrawBorderString (SpriteBatch sb, string text, Vector2 pos, Color color, float scale=1f, float anchorx=0f, float anchory=0f, int maxCharactersDisplayed=-1)
 
static Vector2 DrawBorderStringBig (SpriteBatch spriteBatch, string text, Vector2 pos, Color color, float scale=1f, float anchorx=0f, float anchory=0f, int maxCharactersDisplayed=-1)
 
static void DrawBorderStringFourWay (SpriteBatch sb, DynamicSpriteFont font, string text, float x, float y, Color textColor, Color borderColor, Vector2 origin, float scale=1f)
 
static void DrawCursorSingle (SpriteBatch sb, Color color, float rot=float.NaN, float scale=1f, Vector2 manualPosition=default(Vector2), int cursorSlot=0, int specialMode=0)
 
static void DrawInvBG (SpriteBatch sb, float x, float y, float w, float h, Color c=default(Color))
 
static void DrawInvBG (SpriteBatch sb, int x, int y, int w, int h, Color c=default(Color))
 
static void DrawInvBG (SpriteBatch sb, Rectangle R, Color c=default(Color))
 
static void DrawLaser (SpriteBatch sb, Texture2D tex, Vector2 start, Vector2 end, Vector2 scale, LaserLineFraming framing)
 
static void DrawLine (SpriteBatch spriteBatch, Point start, Point end, Color color)
 
static void DrawLine (SpriteBatch spriteBatch, Vector2 start, Vector2 end, Color color)
 
static void DrawLine (SpriteBatch spriteBatch, Vector2 start, Vector2 end, Color colorStart, Color colorEnd, float width)
 
static void DrawPanel (Texture2D texture, int edgeWidth, int edgeShove, SpriteBatch spriteBatch, Vector2 position, float width, Color color)
 
static void DrawRect (SpriteBatch spriteBatch, Rectangle rect, Color color)
 
static void DrawRect (SpriteBatch spriteBatch, Vector2 start, Vector2 end, Color color)
 
static void DrawRect (SpriteBatch spriteBatch, Vector2 topLeft, Vector2 topRight, Vector2 bottomRight, Vector2 bottomLeft, Color color)
 
static void DrawRectangle (SpriteBatch sb, Vector2 start, Vector2 end, Color colorStart, Color colorEnd, float width)
 
static void DrawRectForTilesInWorld (SpriteBatch spriteBatch, Point start, Point end, Color color)
 
static void DrawRectForTilesInWorld (SpriteBatch spriteBatch, Rectangle rect, Color color)
 
static void DrawSettings2Panel (SpriteBatch spriteBatch, Vector2 position, float width, Color color)
 
static void DrawSettingsPanel (SpriteBatch spriteBatch, Vector2 position, float width, Color color)
 
static void DrawSplicedPanel (SpriteBatch sb, Texture2D texture, int x, int y, int w, int h, int leftEnd, int rightEnd, int topEnd, int bottomEnd, Color c)
 
static bool FloatIntersect (float r1StartX, float r1StartY, float r1Width, float r1Height, float r2StartX, float r2StartY, float r2Width, float r2Height)
 
static Vector2 Floor (this Vector2 vec)
 
static string FormatWith (string original, object obj)
 
static Rectangle Frame (this Asset< Texture2D > tex, int horizontalFrames=1, int verticalFrames=1, int frameX=0, int frameY=0, int sizeOffsetX=0, int sizeOffsetY=0)
 
static Rectangle Frame (this Texture2D tex, int horizontalFrames=1, int verticalFrames=1, int frameX=0, int frameY=0, int sizeOffsetX=0, int sizeOffsetY=0)
 
static float GetDayTimeAs24FloatStartingFromMidnight ()
 
static Vector2 GetDayTimeAsDirectionIn24HClock ()
 
static Vector2 GetDayTimeAsDirectionIn24HClock (float timeFrom0To24)
 
static double GetLerpValue (double from, double to, double t, bool clamped=false)
 
static float GetLerpValue (float from, float to, float t, bool clamped=false)
 
static List< int > GetTrueIndexes (params bool[][] arrays)
 
static List< int > GetTrueIndexes (this bool[] array)
 
static bool HasNaNs (this Vector2 vec)
 
static int Height (this Asset< Texture2D > asset)
 
static string Hex3 (this Color color)
 
static string Hex4 (this Color color)
 
static bool IndexInRange< T > (this List< T > t, int index)
 
static bool IndexInRange< T > (this T[] t, int index)
 
static bool IsPowerOfTwo (int x)
 
static Vector2 Left (this Rectangle r)
 
static void LogAndConsoleErrorMessage (string message)
 
static void LogAndConsoleInfoMessage (string message)
 
static Version MajorMinor (this Version v)
 
static Version MajorMinorBuild (this Version v)
 
static T Max< T > (params T[] args)
 
static Rectangle Modified (this Rectangle r, int x, int y, int w, int h)
 
static int ModulusPositive (this int myInteger, int modulusNumber)
 
static Vector2 MoveTowards (this Vector2 currentPosition, Vector2 targetPosition, float maxAmountAllowedToMove)
 
static float MultiLerp (float percent, params float[] floats)
 
static Color MultiplyRGB (this Color firstColor, Color secondColor)
 
static Color MultiplyRGBA (this Color firstColor, Color secondColor)
 
static int Next (this UnifiedRandom random, IntRange range)
 
static T Next< T > (this UnifiedRandom r, IList< T > list)
 Returns a random element from the provided list. More...
 
static T Next< T > (this UnifiedRandom r, T[] array)
 Returns a random element from the provided array. More...
 
static bool NextBool (this UnifiedRandom r)
 Returns true or false randomly with equal chance. More...
 
static bool NextBool (this UnifiedRandom r, int antecedent, int consequent)
 Returns true X out of Y times.
 
static bool NextBool (this UnifiedRandom r, int consequent)
 Returns true 1 out of X times.
 
static T NextEnum< T > (this T src)
 
static float NextFloat (this UnifiedRandom r)
 Generates a random value between 0f (inclusive) and 1f (exclusive).
It will not return 1f. More...
 
static float NextFloat (this UnifiedRandom r, float maxValue)
 Generates a random value between 0f (inclusive) and maxValue (exclusive).
It will not return maxValue . More...
 
static float NextFloat (this UnifiedRandom r, float minValue, float maxValue)
 Generates a random value between minValue (inclusive) and maxValue (exclusive).
It will not return maxValue . More...
 
static float NextFloat (this UnifiedRandom random, FloatRange range)
 
static float NextFloatDirection (this UnifiedRandom r)
 
static T NextFromCollection< T > (this UnifiedRandom random, List< T > objs)
 
static T NextFromList< T > (this UnifiedRandom random, params T[] objs)
 
static Vector2 NextVector2Circular (this UnifiedRandom r, float circleHalfWidth, float circleHalfHeight)
 
static Vector2 NextVector2CircularEdge (this UnifiedRandom r, float circleHalfWidth, float circleHalfHeight)
 
static Vector2 NextVector2FromRectangle (this UnifiedRandom r, Rectangle rect)
 
static Vector2 NextVector2Square (this UnifiedRandom r, float min, float max)
 
static Vector2 NextVector2Unit (this UnifiedRandom r, float startRotation=0f, float rotationRange=(float) Math.PI *2f)
 
static Rectangle OffsetSize (this Rectangle rect, int xSize, int ySize)
 
static void OpenFolder (string folderPath)
 
static void OpenToURL (string url)
 
static Vector2 OriginFlip (this Rectangle rect, Vector2 origin, SpriteEffects effects)
 
static Dictionary< string, string > ParseArguements (string[] args)
 
static float PingPongFrom01To010 (float value)
 
static bool PlotLine (Point p0, Point p1, TileActionAttempt plot, bool jump=true)
 
static bool PlotLine (Point16 p0, Point16 p1, TileActionAttempt plot, bool jump=true)
 
static bool PlotTileArea (int x, int y, TileActionAttempt plot)
 
static bool PlotTileLine (Vector2 start, Vector2 end, float width, TileActionAttempt plot)
 
static bool PlotTileTale (Vector2 start, Vector2 end, float width, TileActionAttempt plot)
 
static void PoofOfSmoke (Vector2 position)
 
static bool PressingControl (this KeyboardState kb)
 
static bool PressingShift (this KeyboardState kb)
 
static string PrettifyPercentDisplay (float percent, string originalFormat)
 
static T PreviousEnum< T > (this T src)
 
static int RandomConsecutive (double random, int odds)
 
static float RandomFloat (ref ulong seed)
 
static int RandomInt (ref ulong seed, int max)
 
static int RandomInt (ref ulong seed, int min, int max)
 
static int RandomNext (ref ulong seed, int bits)
 
static ulong RandomNextSeed (ulong seed)
 
static Vector2 RandomVector2 (UnifiedRandom random, float min, float max)
 
static string ReadEmbeddedResource (string path)
 
static Vector2 ReadPackedVector2 (this BinaryReader bb)
 
static Color ReadRGB (this BinaryReader bb)
 
static Vector2 ReadVector2 (this BinaryReader bb)
 
static BitArray ReceiveBitArray (int BitArrLength, BinaryReader reader)
 Receives the result of SendBitArray, and returns the corresponding BitArray
 
static bool RectangleLineCollision (Vector2 rectTopLeft, Vector2 rectBottomRight, Vector2 lineStart, Vector2 lineEnd)
 
static float Remap (float fromValue, float fromMin, float fromMax, float toMin, float toMax, bool clamped=true)
 
static int Repeat (int value, int length)
 
static Vector2 Right (this Rectangle r)
 
static Vector2 RotatedBy (this Vector2 spinningpoint, double radians, Vector2 center=default(Vector2))
 
static Vector2 RotatedByRandom (this Vector2 spinninpoint, double maxRadians)
 
static Vector2 RotateRandom (this Vector2 spinninpoint, double maxRadians)
 
static Vector2 rotateTowards (Vector2 currentPosition, Vector2 currentVelocity, Vector2 targetPosition, float maxChange)
 
static Vector2 Round (Vector2 input)
 
static Vector2 SafeNormalize (this Vector2 v, Vector2 defaultValue)
 
static T SelectRandom< T > (UnifiedRandom random, params T[] choices)
 
static void SendBitArray (BitArray arr, BinaryWriter writer)
 Bit packs a BitArray in to a Byte Array and then sends the byte array
 
static void ShowFancyErrorMessage (string message, int returnToMenu)
 
static Vector2 Size (this Asset< Texture2D > tex)
 
static Vector2 Size (this Rectangle r)
 
static Vector2 Size (this Texture2D tex)
 
static float SmoothStep (float min, float max, float x)
 
static void Swap< T > (ref T t1, ref T t2)
 
static byte[] ToByteArray (this string str)
 
static int ToDirectionInt (this bool value)
 
static int ToInt (this bool value)
 
static Vector2 Top (this Rectangle r)
 
static Vector2 TopLeft (this Rectangle r)
 
static Point ToPoint (this Point16 p)
 
static Point ToPoint (this Vector2 v)
 
static Point16 ToPoint16 (this Vector2 v)
 
static Vector2 TopRight (this Rectangle r)
 
static float ToRotation (this Vector2 v)
 
static Vector2 ToRotationVector2 (this float f)
 
static Vector2 ToScreenPosition (this Vector2 worldPosition)
 
static Point ToTileCoordinates (this Vector2 vec)
 
static Point16 ToTileCoordinates16 (this Vector2 vec)
 
static Vector2 ToVector2 (this Point p)
 
static Vector2 ToVector2 (this Point16 p)
 
static Vector2 ToWorldCoordinates (this Point p, float autoAddX=8f, float autoAddY=8f)
 
static Vector2 ToWorldCoordinates (this Point p, Vector2 autoAddXY)
 
static Vector2 ToWorldCoordinates (this Point16 p, float autoAddX=8f, float autoAddY=8f)
 
static Vector2 ToWorldCoordinates (this Point16 p, Vector2 autoAddXY)
 
static Vector2 ToWorldCoordinates (this Vector2 v, float autoAddX=8f, float autoAddY=8f)
 
static Vector2 ToWorldCoordinates (this Vector2 v, Vector2 autoAddXY)
 
static void TrimTextIfNeeded (ref string text, DynamicSpriteFont font, float scale, float maxWidth)
 
static bool TryCreatingDirectory (string folderPath)
 
static float Turn01ToCyclic010 (float value)
 
static float UnclampedSmoothStep (float min, float max, float x)
 
static DateTime UnixTimeStampToDateTime (long unixTimeStamp)
 
static Vector2 Vector2FromElipse (Vector2 angleVector, Vector2 elipseSizes)
 
static int Width (this Asset< Texture2D > asset)
 
static bool WithinRange (this Vector2 Origin, Vector2 Target, float MaxRange)
 
static string[] WordwrapString (string text, DynamicSpriteFont font, int maxWidth, int maxLines, out int lineAmount)
 
static List< List< TextSnippet > > WordwrapStringSmart (string text, Color c, DynamicSpriteFont font, int maxWidth, int maxLines)
 
static float WrappedLerp (float value1, float value2, float percent)
 
static void WritePackedVector2 (this BinaryWriter bb, Vector2 v)
 
static void WriteRGB (this BinaryWriter bb, Color c)
 
static void WriteVector2 (this BinaryWriter bb, Vector2 v)
 
static Vector2 XY (this Vector4 vec)
 
static Vector3 XZW (this Vector4 vec)
 
static Vector3 YZW (this Vector4 vec)
 
static Vector2 ZW (this Vector4 vec)
 

Static Public Attributes

static Dictionary< DynamicSpriteFont, float[]> charLengths = new Dictionary<DynamicSpriteFont, float[]>()
 
const long MaxCoins = 999999999L
 

Member Function Documentation

◆ Clamp< T >()

static T Terraria.Utils.Clamp< T > ( value,
min,
max 
)
static
Type Constraints
T :IComparable<T> 

◆ Max< T >()

static T Terraria.Utils.Max< T > ( params T[]  args)
static
Type Constraints
T :IComparable 

◆ Next< T >() [1/2]

static T Terraria.Utils.Next< T > ( this UnifiedRandom  r,
IList< T >  list 
)
static

Returns a random element from the provided list.

Template Parameters
T
Parameters
r
list
Returns

◆ Next< T >() [2/2]

static T Terraria.Utils.Next< T > ( this UnifiedRandom  r,
T[]  array 
)
static

Returns a random element from the provided array.

Template Parameters
T
Parameters
r
array
Returns

◆ NextBool()

static bool Terraria.Utils.NextBool ( this UnifiedRandom  r)
static

Returns true or false randomly with equal chance.

Parameters
r
Returns

◆ NextEnum< T >()

static T Terraria.Utils.NextEnum< T > ( this T  src)
static
Type Constraints
T :struct 

◆ NextFloat() [1/3]

static float Terraria.Utils.NextFloat ( this UnifiedRandom  r)
static

Generates a random value between 0f (inclusive) and 1f (exclusive).
It will not return 1f.

Parameters
r
Returns

◆ NextFloat() [2/3]

static float Terraria.Utils.NextFloat ( this UnifiedRandom  r,
float  maxValue 
)
static

Generates a random value between 0f (inclusive) and maxValue (exclusive).
It will not return maxValue .

Parameters
r
maxValue
Returns

◆ NextFloat() [3/3]

static float Terraria.Utils.NextFloat ( this UnifiedRandom  r,
float  minValue,
float  maxValue 
)
static

Generates a random value between minValue (inclusive) and maxValue (exclusive).
It will not return maxValue .

Parameters
r
minValue
maxValue
Returns

◆ PreviousEnum< T >()

static T Terraria.Utils.PreviousEnum< T > ( this T  src)
static
Type Constraints
T :struct