Standalone [1.3] tModLoader - A Modding API

Is it a katana that can be used to kill the player in order to prevent loss of coins?

Whoops, I slipped one of my own ideas away...

Credit me.

Nope, I actually want rocket jumps, just for the sake of fun. :indifferent:
It's still possible in certain ways, but the self-damage detection would be the best.
 
Now I'm getting invisible table o_O

Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.DataStructures;
using Terraria.Enums;
using Terraria.ModLoader;
using Terraria.ObjectData;

namespace Tremor.Tiles {
public class WoodenTVRack : ModTile
{
    public override void SetDefaults()
    {
        Main.tileSolidTop[Type] = true;
        Main.tileFrameImportant[Type] = true;
        Main.tileNoAttach[Type] = true;
        Main.tileTable[Type] = true;
        Main.tileLavaDeath[Type] = true;
TileObjectData.newTile.Width = 3;
TileObjectData.newTile.Height = 1;
TileObjectData.newTile.Origin = new Point16(0, 1);
TileObjectData.newTile.AnchorBottom = new AnchorData(AnchorType.SolidTile, TileObjectData.newTile.Width, 0);
        TileObjectData.newTile.CoordinateHeights = new int[]{18};
        TileObjectData.addTile(Type);
        AddToArray(ref TileID.Sets.RoomNeeds.CountsAsTable);
        mapColor = new Color(179, 146, 113);
        mapName = "WoodenTVRack";
    }

    public override void KillMultiTile(int i, int j, int frameX, int frameY)
    {
        Item.NewItem(i * 16, j * 16, 32, 16, mod.ItemType("WoodenTVRack"));
    }
}}

Code:
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Tremor.Items {
public class WoodenTVRack : ModItem
{
    public override void SetDefaults()
    {
        item.name = "Wooden TVRack";
        item.width = 44;
        item.height = 16;
        item.maxStack = 99;
        AddTooltip("");
        item.useTurn = true;
        item.autoReuse = true;
        item.useAnimation = 15;
        item.useTime = 10;
        item.useStyle = 1;
        item.consumable = true;
        item.value = 150;
        item.createTile = mod.TileType("WoodenTVRack");
    }

    public override void AddRecipes()
    {
        ModRecipe recipe = new ModRecipe(mod);
        recipe.AddIngredient(ItemID.DirtBlock, 1);
        recipe.SetResult(this);
        recipe.AddRecipe();
    }
}}
I believe you have to specify how many pixels each tile frame is; this like this:

Code:
TileObjectData.newTile.Height = 5;
        TileObjectData.newTile.CoordinateHeights = new int[]
        {
            16,
            16,
            16,
            16,
            16
        };
 
\My Games\Terraria\ModLoader\Mod Sources\A mod\DependentMod\DependentMod.cs(19,9) : error CS0103: The name 'SetGlobalItem' does not exist in the current context
?
try'n to load example mod
 
\My Games\Terraria\ModLoader\Mod Sources\A mod\DependentMod\DependentMod.cs(19,9) : error CS0103: The name 'SetGlobalItem' does not exist in the current context
?
try'n to load example mod
Oh, woops, I forgot to update the DependentMod to the most recent version :p
I'll fix that for the next update.
 
Hi! I'm trying to recreate Nero's Devil Bringer from DMC4 in the form of Evil Legacy. It is a grappling hook type item.
Problem is, most ModItem methods apparently do not work when item is in the hook slot.

Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace StylishCombat.Items
{
    public class EvilLegacy : ModItem
    {
        private int lastGripX =- 1;
        private int lastGripY = -1;
      
        public override void SetDefaults()
        {
            item.name = "Evil Legacy";
            item.width = 28;
            item.height = 26;
            item.toolTip = "Creates Grim Grip attach point at cursor location";
            item.value = 50000;
            item.rare = 4;
            item.noMelee = true;
            item.useTime = 20;
            item.noUseGraphic = true;
            item.melee = true;
            item.damage = 30;
            item.knockBack = 7f;
            item.useStyle = 5;
            item.shootSpeed = 11.5f;
            item.shoot = 13;
            item.useSound = 1;
            item.useAnimation = 20;
        }
      
        public override void UpdateInventory(Player player)        // <-- Here's the problem
        {
            if (player.controlHook && player.releaseHook)
            {
                Vector2 pos = Main.screenPosition;
                pos.X += Main.mouseX;
                pos.Y += player.gravDir == 1 ? Main.mouseY : Main.screenHeight - Main.mouseY;
              
                int tileCheckX = (int)(pos.X / 16f);
                int tileCheckY  = (int)(pos.Y / 16f);
              
                if(CheckTerrain(tileCheckX, tileCheckY) && Math.Sqrt(Math.Pow(pos.X - player.Center.X,2) + Math.Pow(pos.Y - player.Center.Y,2))/16f < 18f)
                {
                    WorldGen.PlaceTile(tileCheckX, tileCheckY, mod.TileType("Grim Grip"), false, false, player.whoAmI, 0);
                    for(int k=0; k<5; k++)
                    {
                        int dust = Dust.NewDust(pos,3,3,113,0f,0f,0, default(Color), 1.5f);
                        Main.dust[dust].noGravity = true;
                    }
                    Main.PlaySound(2, (int)pos.X, (int)pos.Y, 44);
                    if((lastGripX != -1 && lastGripY != -1) && Main.tile[lastGripX, lastGripY].type == mod.TileType("Grim Grip"))
                    {
                        WorldGen.KillTile(lastGripX,lastGripY,false,false,true);
                    }
                    lastGripX = tileCheckX;
                    lastGripY = tileCheckY;
                }
            }
        }
      
        private bool CheckTerrain(int x, int y)
        {
            if((x > Main.maxTilesX) || (x < 0) || (y < 0) || (y > Main.maxTilesY)) return false;
          
            for(int i = x - 1; i <= x + 1; i++)
            {
                if(i > Main.maxTilesX) i = Main.maxTilesX;
                if(i < 0) i = 0;
              
                for(int j = y - 1; j <= y + 2; j++)
                {
                    if(j > Main.maxTilesY) j = Main.maxTilesY;
                    if(j < 0) j = 0;
                  
                    if(Main.tile[i, j].type != 0)
                    {
                        return false;
                    }
                }
            }
            return true;
        }
      
        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient("Crystal Ball",1);          
            recipe.AddIngredient("Bone",50);
            recipe.AddIngredient("Soul of Night",10);  
            recipe.AddTile(TileID.DemonAltar);
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
    }
}

I tried "Shoot", "UseItem", "UpdateInventory", "UpdateEquip" and "UpdateAccessory" methods, but none of them worked.
With "UpdateInventory" method, it works, but item must be in main inventory and hook slot must be empty,
since game will prioritize hook slot over main inventory with 'Use Hook' hotkey.

@bluemagic123, are above methods implemented for hook slot? If not, how can I work around this?
 
Hi! I'm trying to recreate Nero's Devil Bringer from DMC4 in the form of Evil Legacy. It is a grappling hook type item.
Problem is, most ModItem methods apparently do not work when item is in the hook slot.

Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace StylishCombat.Items
{
    public class EvilLegacy : ModItem
    {
        private int lastGripX =- 1;
        private int lastGripY = -1;
     
        public override void SetDefaults()
        {
            item.name = "Evil Legacy";
            item.width = 28;
            item.height = 26;
            item.toolTip = "Creates Grim Grip attach point at cursor location";
            item.value = 50000;
            item.rare = 4;
            item.noMelee = true;
            item.useTime = 20;
            item.noUseGraphic = true;
            item.melee = true;
            item.damage = 30;
            item.knockBack = 7f;
            item.useStyle = 5;
            item.shootSpeed = 11.5f;
            item.shoot = 13;
            item.useSound = 1;
            item.useAnimation = 20;
        }
     
        public override void UpdateInventory(Player player)        // <-- Here's the problem
        {
            if (player.controlHook && player.releaseHook)
            {
                Vector2 pos = Main.screenPosition;
                pos.X += Main.mouseX;
                pos.Y += player.gravDir == 1 ? Main.mouseY : Main.screenHeight - Main.mouseY;
             
                int tileCheckX = (int)(pos.X / 16f);
                int tileCheckY  = (int)(pos.Y / 16f);
             
                if(CheckTerrain(tileCheckX, tileCheckY) && Math.Sqrt(Math.Pow(pos.X - player.Center.X,2) + Math.Pow(pos.Y - player.Center.Y,2))/16f < 18f)
                {
                    WorldGen.PlaceTile(tileCheckX, tileCheckY, mod.TileType("Grim Grip"), false, false, player.whoAmI, 0);
                    for(int k=0; k<5; k++)
                    {
                        int dust = Dust.NewDust(pos,3,3,113,0f,0f,0, default(Color), 1.5f);
                        Main.dust[dust].noGravity = true;
                    }
                    Main.PlaySound(2, (int)pos.X, (int)pos.Y, 44);
                    if((lastGripX != -1 && lastGripY != -1) && Main.tile[lastGripX, lastGripY].type == mod.TileType("Grim Grip"))
                    {
                        WorldGen.KillTile(lastGripX,lastGripY,false,false,true);
                    }
                    lastGripX = tileCheckX;
                    lastGripY = tileCheckY;
                }
            }
        }
     
        private bool CheckTerrain(int x, int y)
        {
            if((x > Main.maxTilesX) || (x < 0) || (y < 0) || (y > Main.maxTilesY)) return false;
         
            for(int i = x - 1; i <= x + 1; i++)
            {
                if(i > Main.maxTilesX) i = Main.maxTilesX;
                if(i < 0) i = 0;
             
                for(int j = y - 1; j <= y + 2; j++)
                {
                    if(j > Main.maxTilesY) j = Main.maxTilesY;
                    if(j < 0) j = 0;
                 
                    if(Main.tile[i, j].type != 0)
                    {
                        return false;
                    }
                }
            }
            return true;
        }
     
        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient("Crystal Ball",1);         
            recipe.AddIngredient("Bone",50);
            recipe.AddIngredient("Soul of Night",10); 
            recipe.AddTile(TileID.DemonAltar);
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
    }
}

I tried "Shoot", "UseItem", "UpdateInventory", "UpdateEquip" and "UpdateAccessory" methods, but none of them worked.
With "UpdateInventory" method, it works, but item must be in main inventory and hook slot must be empty,
since game will prioritize hook slot over main inventory with 'Use Hook' hotkey.

@bluemagic123, are above methods implemented for hook slot? If not, how can I work around this?
Hm, I haven't looked into grappling hook items yet actually. However, I think that custom grappling hooks also require custom projectiles, so I'll need to finish that up first.
 
Now im getting this error: c:\Users\Ethan\Documents\My Games\Terraria\ModLoader\Mod Sources\TestMod\Items\TShield.cs(9,26) : error CS0115: 'TestMod.Items.TShield.Autoload(ref string, ref string, ref Terraria.ModLoader.EquipType?)': no suitable method found to override
The items worked fine before this latest update, any help?
 
To fix the DependentMod on your own, you can just get rid of that line since it should be autoloaded now.
Thank you, that fixed that, but i have this problem now

Missing texture ExampleMod/Dusts/Sparkle
at Terraria.ModLoader.ModLoader.GetTexture(String name)
at Terraria.ModLoader.Mod.AddDust(String name, ModDust dust, String texture)
at Terraria.ModLoader.Mod.AutoloadDust(Type type)
at Terraria.ModLoader.Mod.Autoload()
at Terraria.ModLoader.ModLoader.do_Load(Object threadContext)
 
Now im getting this error: c:\Users\Ethan\Documents\My Games\Terraria\ModLoader\Mod Sources\TestMod\Items\TShield.cs(9,26) : error CS0115: 'TestMod.Items.TShield.Autoload(ref string, ref string, ref Terraria.ModLoader.EquipType?)': no suitable method found to override
The items worked fine before this latest update, any help?
The autoload method for items changed:
https://github.com/bluemagic123/tMo...name-ref-string-texture-ilistequiptype-equips
You'll also have to include "using System.Collections.Generic;" at the top, and replace "equip = EquipType.Whatever" with "equips.Add(EquipType.Whatever)".

Thank you, that fixed that, but i have this problem now

Missing texture ExampleMod/Dusts/Sparkle
at Terraria.ModLoader.ModLoader.GetTexture(String name)
at Terraria.ModLoader.Mod.AddDust(String name, ModDust dust, String texture)
at Terraria.ModLoader.Mod.AutoloadDust(Type type)
at Terraria.ModLoader.Mod.Autoload()
at Terraria.ModLoader.ModLoader.do_Load(Object threadContext)
Huh, did you somehow lose the Sparkle.png file that was in the Dusts folder?
 
So, i downloaded the mod and installed it - nothing funny until then. But when i run it, it says i have no mods installed (even though i have 3) and only shows me 1 of my characters on character selection screen, and none of my worlds. I've checked all respective folders, and the files are there.
 
No, in the dusts folder there is Sparkle.cs and Sparkle.png
Huh, that's pretty weird. Does rebuilding the mod help anything?

So, i downloaded the mod and installed it - nothing funny until then. But when i run it, it says i have no mods installed (even though i have 3) and only shows me 1 of my characters on character selection screen, and none of my worlds. I've checked all respective folders, and the files are there.
Just to make sure, you have a ModLoader folder that contains Players, Worlds, and Mods folders, and the tmod files are in the Mods folder, right?
 
Back
Top Bottom