(Base mod) Idglibrary - a Library for Coders

Not open for further replies.
This mod, will be getting a proper github when SGAmod releases, and on that note

I've been having quite a few people only wanting the code for their own mods.
Please don't directly copy code from Idglib to avoid using it as a dependency
I made this library largely from edited vanilla code, and what code I did borrow I have permission to use, if you really want to avoid using the library but use code from it please just credit me somewhere as well or write your own; this isn't asking much ;/
If your taking like one function and leaving credit that's fine and I can understand that, but if you start taking several functions for the sole reason of the above, then we have a problem.

Oh and, don't take the DrawSkeletronLikeArms and credit me, that code was made by @direwolf420 and you'd have to get his permission for it! I have permission to use it in IDGLib.

If this continues I'll be forced to close-source not only this mod, but all my mods, and I DON'T want to do that!

Thank you for understanding!

Hello everyone, I am happy to announce I have just launched my Base Mod to the mobrowser that'll house functions for all future mods of mine. But, I have made this detailed thread so anyone can use Idglib:
It should go without saying this is only for coders who know what they are doing. And have covered more than just the basics.
First and for most, make sure you read Blushiemagic's tutorial on cross mod content here before we get started: blushiemagic/tModLoader
I will be updating this as I add more functions

First thing you need to do is add the mod as a dependancy to your build.txt file, to do this, add this line in said text file at the bottom.

modReferences = Idglibrary

Now, in order to use this in your mod, you will first need to add
using Idglibrary;
to every .cs file that will call functions from this.

Now you should be ready to use these functions:

Idglib.Chat(string message,byte color1,byte color2,byte color3); returns nothing
This is pretty much the same as Main.NewText, but it also accommodates for networking and broadcasts messages to clients.
Idglib.FindClosestTarget(int targettype,Vector2 loc,Vector2 size,bool block,bool friendlycheck); returns a int
This allows you to find the closest object from a specified location (loc)
Targettype is the 0 for npc, or 1 for player.
size is a Vector2 consisting of half the width and half the height of the npc/player ideally. But it can be anything, it's used for the Centerpoint.
Block (optional) allows you to filter out targets behind solid blocks (on by default)
friendlycheck (optional, only works on Targettype=0) checks if the npc is friendly or not. It allows you to only target friendy NPCs if set to false (if you wanted to get the closest town NPC, for example)
Idglib.LookAt(Vector2 here, Vector2 there); returns a float
This is a bit of ease-of-bytes type code, that gets the angle from here to there, the game might have one of these built in, but I never found one.
Idglib.Shattershots(Vector2 here,Vector2 there,Vector2 widthheight,int type,int damage,float Speed,float spread,int count,bool centershot,float globalangularoffset,bool tilecollidez,int timeleft) returns a list consisting of all the Terraria.Projectile class created
This code creates a fan of projectiles of your choice, and returns a list of all projectiles created from it. Projectiles created with function will automatically have hostile set to true.
centershot is whether or not a center shot is created
globalangularoffset allows you add an angle to all projectiles, say if you want them to spin in a circle.
spread is half the angle that projectiles will fan out.
widthheight is again, the centerpoint like with FindClosestTarget
Idglib.DrawTether(string Tex,Vector2 Start,Vector2 End,int Alpha = 255); returns nothing
Draws a tether-like sprite similar to Plantera's hooks and Wall of Flesh's Hungry. This function will only work in Draw events.
Tex is the string of the texture you wish to use as the tether
this function does not stretch the texture, it will repeat it and seamlessly crop it to prevent it from overextending.
alpha is optional; it defaults to 255
Idglib.DrawSkeletronLikeArms(SpriteBatch spriteBatch, string texString, Vector2 selfPos, Vector2 centerPos, float selfPad = 0f, float centerPad = 0f, float direction = 0f); returns nothing
Draws skeletron-like arms with any texture of your choice!
selfPos is the "hand" and centerPos is the 'head"
the rest is trial and error to see what looks best.
This was contributed by @direwolf420 who took apart the vanilla code and made something workable with it! So major thanks to him!
Idglib.ColorText(Color color,string text); returns a string with a color code.
Converts colors into a hexadecimal color code for text!
Idglib.RaycastDown(int x, int y)
Casts a ray down from the location and returns where it hits, keep in mind this is in tile space, so you need to use a 1/16 of the coord value your really checking!

---non-general functions---

IdgNPC.AddBuffBypass(int npcid, int type, int time); returns nothing
Basic code that bypasses buff immunities for NPCs; is otherwise the same as AddBuff
IdgNpc.FindNPCs(int npctype); returns of a list consisting of all the Terraria.NPC classes that matched the type
IdgNPC.FindNPCsMultitype(ushort[] npctypes); returns of a list consisting of all the Terraria.NPC classes that matched the ushort array
this code allows you to return a list of different types. an example:
List<NPC> myzombies = Idglib.FindNPCsMultitype(new ushort[] {(ushort)NPCID.ZombieElf,(ushort)NPCID.BaldZombie});
IdgNPC.AddOnHitBuff(int npcid,int buff, int time); returns nothing
IdgProjectile.AddOnHitBuff(int projectileid,int buff, int time); returns nothing
allows you to add any buff with any time to an npc or projectile that inflicted on a player it hits. This function is synced online automatically.
IdgProjectile.Sync(int projectileid); returns nothing
This is a client-side function that gets basic projectile data (position, velocity, damage, timeLeft) from the server's projectile and syncs it over to the projectile on the client's end. I made this after discovering New projectiles arn't synced automatically and a way to deal with randomness factors like velocity.
Only call this on creation or in few cases as it's not very light.

---bonus stuff!---

Idglib has a custom item class called ProjectileSpearBase that you can use to easily make a customized and simple spear projectile, when I get a github I can go more into detail on this.

Idglib adds a few built in debuffs that other mods can use easily:
IdgPlayer.AddRadiationDebuff(Player player,int time,int level=0,bool quiet=false); returns nothing, last 2 arguments are optional
Easy way to give a player Radiation, this debuff comes in 3 tiers (named "RadiationOne","RadiationTwo",RadiationThree" lastly) that you can pick with a level of 0-2.

This debuff functions like its Starbound counterpart, lowering player max HP, however, the lowered hp will slowly recover over time if not radiated and persists through saving and quiting.

--Idglib also adds a bunch of debug tools and weapons that i made to basically help me make other mods and things that other mods while testing my own mods' features didn't have for debugging purposes, they start with IDG so you can find them via cheatsheet if you want.
Last edited:
Thanks alot mate, it means lot <3

I've restructured the way functions are called. Instead of everything being called from Idglib, things like npcs and projectile related functions are now called from IdgNpc and IdgProjectile, as they will be sharing alot of functions otherwise.


Shattershots is being reworked and moved as well, hopefully no one was using that extensively. Sorry for any inconvenience.

Main topic has been updated.
Hey, it's been awhile, I've been working on other projects but I manged to, hopefully, push a stable build of Idglib's next feature:

Idglib.EasyShop, a basic api to add items to npc shops universally.

This feature might still be unstable, please report what you find.
PS: Loading older saves made in worlds before Idglib tends to cause errors and even a crash sometimes when exiting out, but after that point it may work...
odd. Really is.

PS#2: While it did for a time, it tended to bug out greatly after every update. So atleast for now, the ability to save easyshops has been disabled. The function now only makes temporary ones.

PS#3: Ok, this feature, and the netcode involved with it seems to be very unstable and, rather breaking. This feature was very limited anyways, so I'm going to remove it, really sorry everyone who downloaded this during that time.
Last edited:
do you have a github for this mod? I`m curious cause I have implemented like half of those functions for myself aswell and would like to have a comparison/reference
It has been a "long" time since I last updated this!
I am happy to say now that I'm back into modding, I just added some new features
Before SGAmod comes out Idglib is going to feature some experimental features of sorts that will become part of that mod, so a heads up
Alright, pretty small update: added RaycastDown and fixed a non-functional method (this was awhile ago so I already forgot which one it was)
Updated the front page to help explain "how" to use the library as a depenency better.

Really, this library was made for myself and I choose to share it. It's a bit more, advanced use, and I wouldn't recommend using it for 1 single function (But I also wouldn't recommend *stealing* the code either to avoid using it)
That's all for now, SGAmod is well underway so this library will be seeing a far larger use soon.
Updated the front page with new info, but not new functions just yet.
Yes, I am getting pretty tired of people once again, stealing code.

And also some other personal things like @direwolf420 just flat out ignoring ANYTHING I say to him on discord when I really thought we were buddy buddies and after he helped me here.
Like, I seriously can't get that off my mind, I hate being betrayed by people I trusted.

EDIT: Realized I typed personal things in an open space, oh well I guess I could have posted via status updates. I don't hate Direwolf or anything I just don't understand what I did to make him treat me this way. I'm not even being blocked or anything just straight treated like I don't exist...
Last edited:
Not open for further replies.
Top Bottom