1. For issues you find with the Switch and Console releases, please follow this link and give as much detail as possible. This is the speediest way to get info to Pipeworks and get a hotfix in the works.
    Dismiss Notice

tModLoader GlowMaskAPI - A library to help you easily add a glowMask to your items

Discussion in 'Released' started by ZephaniahNoah, Mar 6, 2019.

  1. ZephaniahNoah

    ZephaniahNoah Terrarian

    According to this guide, showing how a glowmask is applied to dropped items, it is not easy to add a glowmask to "weapons being held" in the current version of tModLoader. However, this library makes it easy for developers to add a glow mask to their items. Simply add the GlowMaskAPI.dll file to your references. And add modReferences = GlowMaskAPI to your build.txt...

    Below is an example of how you would use GlowMaskAPI to add a glow mask to a sword.
    Code:
    namespace ExampleMod.Items
    {
        public class ExampleSword : ModItem
        {
    
            public static short glowMask;
    
            public override void SetStaticDefaults()
            {
                DisplayName.SetDefault("Example Sword");
                if (Main.netMode != NetmodeID.Server)
                    glowMask=GlowMaskAPI.Tools.instance.AddGlowMask(mod.GetTexture("Items/ExampleSwordGlow"));
            }
    
            public override void SetDefaults()
            {
                item.damage=20;
                item.melee=true;
                item.width=64;
                item.height=64;
                item.useTime=30;
                item.useAnimation=30;
                item.useStyle=1;
                item.glowMask=glowMask;
            }
        }
    }
    
    ExampleSwordGlow.png would be your glowmask.

    Note that AddGlowMask is happening inside SetStaticDefaults. We are not doing this in SetDefaults because it runs several times while the game is running. We only need to load the texture once.
    Also, regarding the guide I mentioned at the beginning, there is no need to use the PostDrawInWorld hook they suggest to add a glowmask to dropped items. This library will add a glowmask to your item regardless of where it is.

    Anyone playing your mod will also need to download and enable GlowMaskAPI from the mod browser.

    GlowMaskAPI may be incompatible with other mods that use hacky methods to apply glowmasks.

    In the near future I would like to improve GlowMaskAPI allowing users to apply a glowmask with only one line of code instead of three.

    Latest version: 1.6
     
    Last edited: Jul 14, 2019
    direwolf420 likes this.
  2. ZephaniahNoah

    ZephaniahNoah Terrarian

    I created a video tutorial for GlowMaskAPI.
     
  3. Lithium

    Lithium Spazmatism

    You are a RAD DUDE. I assume I have permission to use this in my mod?
    It doesn't exactly have a 'credits section' per se, but I will add a thanks to you to the forum post.

    Oh, also- is there any chance of adding a 'fire effect' functionality, like what's used with the Onyx Blaster?
     
  4. Lithium

    Lithium Spazmatism

    There's just one error- it doesn't seem to want to compile. I have added the line "modReferences = GlowMaskAPI" to my build.txt, and the file itself shows no errors in Visual Studio.
    The code:
    using System;
    using System.Collections.Generic;
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Graphics;
    using Terraria;
    using Terraria.ID;
    using Terraria.ModLoader;

    namespace LithosArmory.Items.Weapons
    {
    public class AetherBlaster : ModItem
    {
    public static short glowMask;

    public override void SetStaticDefaults()
    {
    DisplayName.SetDefault("Aether Blaster");
    Tooltip.SetDefault("Musket balls fired become Zephyrs\nZephyrs have homing, explode, and leave behind damaging clouds as they fly\n'A semi-automatic gift from the Aether'");
    glowMask = GlowMaskAPI.Tools.instance.AddGlowMask(mod.GetTexture("Items/Glowmasks/AetherBlasterGlow"));
    }

    public override void SetDefaults()
    {
    item.damage = 40;
    item.ranged = true;
    item.width = 24;
    item.height = 24;
    item.useAnimation = 11;
    item.useTime = 11;
    item.useStyle = 5;
    item.noMelee = true; //so the item's animation doesn't do damage
    item.knockBack = 3f;
    item.value = 250000;
    item.rare = 4;
    if (!Main.dedServ)
    {
    item.UseSound = mod.GetLegacySoundSlot(SoundType.Item, "Sounds/Item/PistolFire2").WithPitchVariance(0.25f);
    }
    item.shoot = 10; //idk why but all the guns in the vanilla source have this
    item.shootSpeed = 14f;
    item.useAmmo = AmmoID.Bullet;

    item.glowMask = glowMask;
    }

    public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
    {
    if (type == ProjectileID.Bullet)
    {
    type = mod.ProjectileType("AetherBlastBullet");
    }
    return true;
    }

    public override void AddRecipes()
    {
    ModRecipe recipe = new ModRecipe(mod);
    recipe.AddIngredient(ItemID.PhoenixBlaster, 1);
    recipe.AddIngredient(ItemID.LightShard, 2);
    recipe.AddIngredient(ItemID.SoulofLight, 10);
    recipe.AddTile(TileID.MythrilAnvil);
    recipe.SetResult(this);
    recipe.AddRecipe();
    }

    // Help, my gun isn't being held at the handle! Adjust these 2 numbers until it looks right.
    public override Vector2? HoldoutOffset()
    {
    return new Vector2(-3, 0);
    }
    }
    }
    error.png
    Edit: The main question I have here is that, as far as I could tell, the references used in my Visual Studio project have no impact on how the mod compiles. I'm therefore not sure where to add such a reference, especially considering that apparently, no such reference needs to exist judging by your tutorial.
     
    Last edited: Apr 19, 2019
  5. ZephaniahNoah

    ZephaniahNoah Terrarian

    The way I compile is a bit odd because tModloader doesn't work very well on Linux. I compile with my IDE then tModloader just builds the mod because noCompile = true in my build.txt. So I think it ignores my .csproj file which has the references. However! I don't know how it works on Windows. But, I'm assuming that it actually does use the .csproj (used by Visual Studio) file for references. I don't think this is an issue with GlowMaskAPI and I've never came across this issue myself. But I will try to help you. Can I see your references? P.S. Sorry this is so late. P.P.S. Yes you have permission to use this for any mods. Thanks for the credit!
     
  6. Lithium

    Lithium Spazmatism

    Well, in order to further work on the mod I removed them, and I'm not quite sure if you want to references from the AetherBlaster.cs file or not.
    I know that my Tmodloader doesn't factor in the Visual Studio references at all(since changing them has no impact on building), so they have absolutely no bearing on how the mod compiles.
    Importantly, I don't get any errors within VS itself- it sees the entire glowmask thing as perfectly valid, meaning that I probably have to add some sort of reference in my code or something.
    Edit: I'm really, really inexperienced with C#, so I'm not even entirely sure what an assembly reference even is. All that I know comes from a few basic classes on it and experimenting with TModloader.
     
    Last edited: Apr 23, 2019
  7. ZephaniahNoah

    ZephaniahNoah Terrarian

    I'm not sure how C# code is compiled. But it would make sense that it doesn't need the references. But that begs the question, why did an error occur "while compiling" asking you to add a reference? Does your mod compile without referencing or calling GlowMaskAPI?
     
  8. Lithium

    Lithium Spazmatism

    If you mean whether it compiles when I remove anything relating to your glowmask mod, then yes- it compiles and builds fine.
    I did try adding your dll to "dllReferences" as detailed in this page.
    blushiemagic/tModLoader
    I did put it in a lib folder and not use the .dll extension. Trying to reference your mod, though, tells me that they're duplicate references and that I need to somehow load them simultaneously or something...? I don't know if that would even work.

    But, referencing your mod with just dllReferences gets me this compiling error.
    If I switch it to modReferences, it gets me the same error as I got with that first post.
    error2.png
     
  9. ZephaniahNoah

    ZephaniahNoah Terrarian

    I just figured it out. Linux uses FNA. Not XNA. A friend just told me that tModloader devs knew this so they made tModloader make 2 integrated dlls. But if you compile on Linux it doesn't do that. This is crappy :/... I have no choice but to develop mods on Windows. I'll fix this as soon as I can.
     
  10. Lithium

    Lithium Spazmatism

    Oof... Well, that's a pain in the arse. At least we figured that out, right?
     
  11. ZephaniahNoah

    ZephaniahNoah Terrarian

    Hmmm. idk. The windows dll was compiled on windows. But not the mod itself. So it should work. I'm a bit confused. Go to your Terraria\ModCompile folder and move FNA.dll one directory up. So that FNA.dll is in the same folder as the Terraria exe file. If that doesn't work I'll compile the tmod itself on Windows.
    EDIT: Copy it. Not move it.
     
    Last edited: Apr 23, 2019
  12. Lithium

    Lithium Spazmatism

    Uh, I don't have a ModCompile folder...
    Edit: Wait, I thought you meant the Documents Terraria folder. It's here.
    --- Double Post Merged, Apr 23, 2019, Original Post Date: Apr 23, 2019 ---
    Nope, that didn't work.
     
  13. ZephaniahNoah

    ZephaniahNoah Terrarian

    Alright. Try version 1.5.
    EDIT: I noticed while compiling on Windows tModloader said, "Compiling for Windows" then, "Compiling for Mono" which is what Mac and Linux uses. This confirms what I said earlier. I wonder why the Linux version doesn't do that.
    RE-EDIT: I think it's because noCompile needs to be false for the mod to build properly.
     
    Last edited: Apr 23, 2019
  14. Lithium

    Lithium Spazmatism

    glowprev.png
    YES! YES!
    The mod works perfectly now, and the glowmask functions!
     
  15. ZephaniahNoah

    ZephaniahNoah Terrarian

    Awesome! I'm glad it's working. I hope the tModloader devs fix all these Linux/Mac issues in tModloader 0.11. If you need any more help you know what to do. Happy modding!
     
  16. Lithium

    Lithium Spazmatism

    Hey, I've noticed a fairly large problem- items that animate as staves don't seem to work with glowmasks at all. It's not that it's misaligned or something- the glowmask just doesn't show up. This happens with every item set to animate like a staff.
    using System;
    using System.Collections.Generic;
    using Microsoft.Xna.Framework;
    using Terraria;
    using Terraria.ID;
    using Terraria.ModLoader;

    namespace LithosArmory.Items.Weapons
    {
    public class Bloodshard : ModItem
    {
    public static short glowMask;

    public override void SetStaticDefaults()
    {
    DisplayName.SetDefault("Bloodshard");
    Tooltip.SetDefault("Casts a controllable bloodshard which flies back and forth\nThe shard can hit an infinite amount of times, steals life, and has a chance to skewer the hit enemy briefly\n'Gross.'");

    glowMask = GlowMaskAPI.Tools.instance.AddGlowMask(mod.GetTexture("Items/Glowmasks/BloodshardGlow"));
    Item.staff[item.type] = true; //this makes the useStyle animate as a staff instead of as a gun
    }

    public override void SetDefaults()
    {
    item.damage = 26;
    item.magic = true;
    item.channel = true;
    item.width = 26;
    item.height = 26;
    item.useAnimation = 20;
    item.useTime = 20;
    item.mana = 7;
    item.useStyle = 5;
    item.noMelee = true; //so the item's animation doesn't do damage
    item.knockBack = 5f;
    item.value = 54000;
    item.rare = 3;
    item.UseSound = mod.GetLegacySoundSlot(SoundType.Item, "Sounds/Item/SpellPewCast");
    item.shoot = mod.ProjectileType("Bloodshard");
    item.shootSpeed = 5.25f;

    item.glowMask = glowMask;
    }

    public override void AddRecipes()
    {
    ModRecipe recipe = new ModRecipe(mod);
    recipe.AddIngredient(null, "ViciousDart", 1);
    recipe.AddIngredient(ItemID.MagicMissile, 1);
    recipe.AddIngredient(ItemID.Flamelash, 1);
    recipe.AddIngredient(null, "StingerWand", 1);
    recipe.AddTile(TileID.DemonAltar);
    recipe.SetResult(this);
    recipe.AddRecipe();
    }
    }
    }
     
  17. ZephaniahNoah

    ZephaniahNoah Terrarian

    Yea, there are still a few different kinds of items that it doesn't work with. Might add support for them later. idk
    EDIT: There might be an easy fix for animated items. I'll look into it.
     
  18. Lithium

    Lithium Spazmatism

    Do staves count as animated items? I'd love to be able to use this for them.
     
  19. Lithium

    Lithium Spazmatism

    Heyo, someone who downloaded my mod's update with GlowMaskAPI has had some issues using my mod in Multiplayer- my mod gets auto-disabled and it says it can't find GlowMaskAPI, but it's definitely enabled.

    Quote from TSNTakumi
     
  20. Lithium

    Lithium Spazmatism

    Further update- since apparently this mod also makes slimes lose their color, I think it might be best if I left it out of my mod until it's more stable... sorry.