tAPI [Discontinued] tAPI - A Mod To Make Mods

Status
Not open for further replies.
You need to add more curly braces at the end. Make sure you count how many curly braces you open up so that you can tell how many to close at the end. It also helps if you indent for any code inside curly braces.
Is there any code that gets called when you switch off an item in your inventory slot? like say I have an item in slot 1, is there something I can do to make the code activate when I switch to another slot (2,3,4 etc)?
 
Is there any code that gets called when you switch off an item in your inventory slot? like say I have an item in slot 1, is there something I can do to make the code activate when I switch to another slot (2,3,4 etc)?
Digging around the source code, I found this:
Code:
(Main.mouseState.ScrollWheelValue - Main.oldMouseState.ScrollWheelValue) / 120
I assume that tells you how much the mouse wheel was scrolled. But there are no hooks in the part the actually switches the selected slot. So you'll have to take advantage of that code in every game update.
 
Same problem again, another tile isn't placing.
{
"displayName": "Spell Shrine",
"size": [3,2],
"frameWidth": 16,
"frameHeight": 16,
"solid": false,
"solidTop": false,
"blocksLight": false,
"blocksSun": false,
"mergeDirt": false,
"placementConditions": "flatGround",
"drop": "MageMod:SpellShrine",
"breaksByPick": true,
"dust": 13,
"sound": 1,
"soundGroup": 21,
"mapColor": [100, 0, 0 ],
"mapHoverText": "Shrine"
}
{
"displayName": "Spell Shrine",
"size": [40,30],
"maxStack": 250,
"value": [0,1,0,0],
"rare": 2,
"useStyle": 1,
"useAnimation": 15,
"useTime": 10,
"autoReuse": true,
"useTurn": true,
"tooltip": "Used to Create Powerful Spells",
"createTile": "MageMod:Shrine",
"consumable": true,
"recipes":
[{
"items": { "g:Tier5Bar": 5, "g:Tier2Bar": 5 },
"tiles": [ "Anvil" ],
"creates": 1
}]
}
 

Attachments

  • SpellShrine.png
    SpellShrine.png
    17.7 KB · Views: 113
  • Shrine.png
    Shrine.png
    15.2 KB · Views: 113
Same problem again, another tile isn't placing.
{
"displayName": "Spell Shrine",
"size": [3,2],
"frameWidth": 16,
"frameHeight": 16,
"solid": false,
"solidTop": false,
"blocksLight": false,
"blocksSun": false,
"mergeDirt": false,
"placementConditions": "flatGround",
"drop": "MageMod:SpellShrine",
"breaksByPick": true,
"dust": 13,
"sound": 1,
"soundGroup": 21,
"mapColor": [100, 0, 0 ],
"mapHoverText": "Shrine"
}
{
"displayName": "Spell Shrine",
"size": [40,30],
"maxStack": 250,
"value": [0,1,0,0],
"rare": 2,
"useStyle": 1,
"useAnimation": 15,
"useTime": 10,
"autoReuse": true,
"useTurn": true,
"tooltip": "Used to Create Powerful Spells",
"createTile": "MageMod:Shrine",
"consumable": true,
"recipes":
[{
"items": { "g:Tier5Bar": 5, "g:Tier2Bar": 5 },
"tiles": [ "Anvil" ],
"creates": 1
}]
}
that's because in the tile sprite there needs to be pink lines at the very bottom too

and, the placement is placed in the top left corner, to put it at the bottom center you need to add this to the tile's json file

"placementOrigin": [1,1],

1,1 means that it's moving the placement 1 tile right and 1 tile down.
 
What are some good, efficient ways I can improve this method of judging if the current player is somewhere in the 'great outdoors'?

Code:
    public static int CountBlocksAt( int x_beg, int x_end, int y_beg, int y_end,
            int? minimum_count = null, ushort? tile_type = null, ushort? wall_type = null, byte? liquid_type = null ) {
        int count = 0;

        if( tile_type == null && wall_type == null && liquid_type == null ) {
            tile_type = 0;    // Empty, air blocks
            wall_type = 0;
            liquid_type = 0;
        }

        for( int i = x_beg; i < x_end; i++ ) {
            for( int j = y_beg; j < y_end; j++ ) {
                if( minimum_count != null && count >= minimum_count ) { break; }

                Tile tile = Main.tile[i, j];
                if( tile_type != null && tile.type != tile_type ) { continue; }
                if( wall_type != null && tile.wall != wall_type ) { continue; }
                if( liquid_type != null && tile.liquid != liquid_type ) { continue; }

                count++;
            }
        }

        return count;
    }


    public static int CountBlocksAtPlayer( Player player, int? minimum_count = null,
            ushort? tile_type = null, ushort? wall_type = null, byte? liquid_type = null ) {
            //int? min_x = null, int? max_x = null, int? min_y = null, int? max_y = null ) {
        Vector2 my_center = player.Center;

        int x_beg = ((int)my_center.X - (Main.maxScreenW / 2)) / 16;
        int x_end = ((int)my_center.X + (Main.maxScreenW / 2)) / 16;
        int y_beg = ((int)my_center.Y - (Main.maxScreenH / 2)) / 16;
        int y_end = ((int)my_center.Y + (Main.maxScreenH / 2)) / 16;

        int count = CountBlocksAt( x_beg, x_end, y_beg, y_end, minimum_count, tile_type, wall_type, liquid_type );
        return count;
    }


    public static bool IsPlayerOutdoors( Player player ) {
        //if( !player.zone["Surface"] ) { return false; }
        if( (double)player.position.Y >= (double)(Main.worldSurface * 16.0) ) { return false; }

        int total_blocks = (Main.maxScreenW / 16) * (Main.maxScreenH / 16);
        int req_blocks = total_blocks / 3;

        return CountBlocksAtPlayer( player, req_blocks ) >= req_blocks;
    }

Code:
    public static bool IsCurrentPlayerGreatOutdoors( float percent_solid_tiles = 0.23f ) {
        Player player = Main.localPlayer;
        if( !player.active ) { return false; }

        if( !player.zone["Surface"] ) { return false; }

        int offscreen = 23;
        if( Lighting.lightMode < 2 ) { offscreen = 40; }
        int x_beg = (int)(Main.screenPosition.X / 16f) - (offscreen + 1);
        int x_end = (int)((Main.screenPosition.X + (float)Main.screenWidth) / 16f) + (offscreen + 2);
        int y_beg = (int)(Main.screenPosition.Y / 16f) - (offscreen + 1);
        int y_end = (int)((Main.screenPosition.Y + (float)Main.screenHeight) / 16f) + (offscreen + 2);

        int total_screen_tile_count = (x_end - x_beg) * (y_end - y_beg);
        int solid_screen_tile_count = 0;

        for( int i = 0; i < WorldGen.tileCount.Length; i++ ) {
            if( WorldGen.tileCount[i] <= 0 ) { continue; }
            //if( !TileDef.solid[i] ) { continue; }
            if( !TileDef.blocksSun[i] ) { continue; }

            solid_screen_tile_count += WorldGen.tileCount[i];
        }

        float solid_percent = (float)solid_screen_tile_count / (float)total_screen_tile_count;
        return solid_percent <= minimum_percent_solid_tiles;
    }

Updated. I get a vaguely accurate result with the parameter set to 0.23f (23%). Still doesn't seem quite right...

Updated again. This seems much more solid, and now works for any arbitrary player! Probably not as CPU performance-friendly, though...
 
Last edited:
i found an error with servers in tAPI; i have one mod on (thorium+) and i get chunks not loading, items duplicating, and more. not sure how to fix, but its a bug report that i would love if it got fixed. im hosting it via hamachi and its only me and 1 other person on there. might be a bug with the mod, but i doubt it.
 
Forgot to say, I did the same as you, I found the code for hellstone and did that, but to no avail. I'll keep trying other things. :p Thanks anyway

I make a wand which spawn water by using this code
Main.tile[i, j].liquidType(0);
Main.tile[i, j].liquid = 255;
WorldGen.SquareTileFrame(i, j, true);
if (Main.netMode == 1)
NetMessage.sendWater(i, j);

Hope this will help you.

I am trying to spawn Wall of Flesh by this code but it failed.

namespace SuperTools.Items
{
public class WofCaller : ModItem
{

public override bool? UseItem(Player p)
{
NPC.SpawnWOF(p.position);
return true;
}
}
}

Anyone has any idea?
 
Hello.
I know this has been asked a lot of times, but i could not find a proper answer yet. Will in the future there ever be a way to edit vanilla items through .json files or at least assign ModItem classes to vanilla items through code? Or is there a way to do that already? I need to assign one script(ModItem) to almost every sword(bow/gun) in the game, because i'm doing a giant combat overhaul(dodges,2-3 attack types,blocking,guns reloading...)and i don't really want to move the whole code to ModPlayer.
(my english is probably bad :c)
 
It works for me. Your item must have "melee"/"consumable"/"ranged" atrribute set to true and "noMelee" to false(false by default) in .json file for UseItem() to work. And OBVIOUSLY wall of flesh will only spawn in hell.
( "consumable": true )

It did not work. Here is my code in the json file.
{
"displayName": "WoFCaller",
"size": [20,20],
"maxStack": 1,
"value": [0,0,10,0],
"rare": 3,
"useStyle": 1,
"useAnimation": 15,
"useTime": 15,
"ranged": true,
"noMelee": false,
"melee": true,
"consumable": true,
"autoReuse": false,
"useTurn": true,
"tooltip": "Calling Wall of Flesh",

"recipes":
[{
"items": { "Ash Block": 300 },
"tiles": [ "Work Bench" ],
"creates": 1
}]
}
 
It did not work. Here is my code in the json file.
This works
WoFCaller.json
Code:
{
  "displayName": "WoFCaller",
  "code": "YOURMODFOLDERNAMEHERE.Items.WoFCaller",
  "size": [20,20],
  "maxStack": 1,
  "value": [0,0,10,0],
  "texture": "Items/Pistol",
  "rare": 3,
  "useStyle": 4,
  "useAnimation": 45,
  "useTime": 45,
  "summon": true,
  "consumable": true,
  "tooltip": "Calls the Wall of Flesh",

  "recipes":
  [{
  "items": { "Ash Block": 300 },
  "tiles": [ "Work Bench" ],
  "creates": 1
  }]
}
WoFCaller.cs
Code:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using TAPI;
using Terraria;

namespace YOURMODFOLDERNAMEHERE.Items
{
    public class WoFCaller : ModItem
    {
  public override bool? UseItem(Player player)
  {
   Main.NewText("Callin' Wall of Flesh");
   NPC.SpawnWOF(player.position);
   return true;
  }
}
}
Replace YOURMODFOLDERNAMEHERE in both files with your ... mod folder name in ..\tAPI\Mods\Sources\
also your internalName in ModInfo should be same as that folder's name.
 
Last edited:
This works
WoFCaller.json
Code:
{
    "displayName": "WoFCaller",
"code": "YOURMODFOLDERNAMEHERE.Items.WoFCaller",
    "size": [20,20],
    "maxStack": 1,
    "value": [0,0,10,0],
    "texture": "Items/Pistol",
    "rare": 3,
    "useStyle": 4,
    "useAnimation": 45,
    "useTime": 45,
    "summon": true,
"consumable": true,
    "tooltip": "Calls the Wall of Flesh",

    "recipes":
    [{
    "items": { "Ash Block": 300 },
    "tiles": [ "Work Bench" ],
    "creates": 1
    }]
}
WoFCaller.cs
Code:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using TAPI;
using Terraria;

namespace YOURMODFOLDERNAMEHERE.Items
{
    public class WoFCaller : ModItem
    {
  public override bool? UseItem(Player player)
  {
   Main.NewText("Callin' Wall of Flesh");
   NPC.SpawnWOF(player.position);
   return true;
  }
}
}
Replace YOURMODFOLDERNAMEHERE in both files with your ... mod folder name in ..\tAPI\Mods\Sources\

Some of the code is not very necessary. For "code", the code is already handled if you have the CS file the same name as your JSON file, so it really is unnecessary unless you use that code for multiple other items. The same for texture, if your PNG file name is the same as your JSON file, tAPI handles that also. "summon" is only used for when the item is a summon based weapon (spawns minions) so it scales with summon based multipliers. Other than that, it is fine.
 
Tile still placing as little pink squares.
{
"displayName": "Spell Shrine",
"size": [3,2],
"frameWidth": 16,
"frameHeight": 16,
"solid": false,
"solidTop": false,
"blocksLight": false,
"blocksSun": false,
"mergeDirt": false,
"placementConditions": "flatGround",
"placementOrigin": [1,1],
"drop": "MageMod:SpellShrine",
"breaksByPick": true,
"dust": 13,
"sound": 1,
"soundGroup": 21,
"mapColor": [100, 0, 0 ],
"mapHoverText": "Shrine"
}
 

Attachments

  • Shrine.png
    Shrine.png
    18.1 KB · Views: 112
Tile still placing as little pink squares.
{
"displayName": "Spell Shrine",
"size": [3,2],
"frameWidth": 16,
"frameHeight": 16,
"solid": false,
"solidTop": false,
"blocksLight": false,
"blocksSun": false,
"mergeDirt": false,
"placementConditions": "flatGround",
"placementOrigin": [1,1],
"drop": "MageMod:SpellShrine",
"breaksByPick": true,
"dust": 13,
"sound": 1,
"soundGroup": 21,
"mapColor": [100, 0, 0 ],
"mapHoverText": "Shrine"
}
Try adding...
"frameImportant": true
To your tiles JSON file
 
Tile still placing as little pink squares.
{
"displayName": "Spell Shrine",
"size": [3,2],
"frameWidth": 16,
"frameHeight": 16,
"solid": false,
"solidTop": false,
"blocksLight": false,
"blocksSun": false,
"mergeDirt": false,
"placementConditions": "flatGround",
"placementOrigin": [1,1],
"drop": "MageMod:SpellShrine",
"breaksByPick": true,
"dust": 13,
"sound": 1,
"soundGroup": 21,
"mapColor": [100, 0, 0 ],
"mapHoverText": "Shrine"
}
The top 3 tiles in the sprite are 16x16, which is what their suppose to be.
However, the bottom 3 tiles are 16x18. This is most likely your problem...
Another thing you can try is add "frameImportant": true to your json file, but I don't know how much that might help. (Edit: Ninja'd)
 
The top 3 tiles in the sprite are 16x16, which is what their suppose to be.
However, the bottom 3 tiles are 16x18. This is most likely your problem...
Another thing you can try is add "frameImportant": true to your json file, but I don't know how much that might help. (Edit: Ninja'd)
Take a look at this code snippet from tAPI...
Code:
        public static void PlaceCustom(int x, int y, int type, int placeStyle) {
            
            if (!frameImportant[type]) {

                Main.tile[x, y].active(true);
                Main.tile[x, y].type = (ushort)type;
                return;

            }

            ........

        }
When a custom tile is placed, if frameImportant is false, only one tile is changed and then the function returns. Any tile that is not size 1x1 must have frameImportant set to true. Also, any 1x1 tile that uses placeStyle, such as the bottle tile, must also have frameImportant set to true. The only tiles that shouldn't have this are tiles such as dirt, stone, mud, etc.
 
This works
WoFCaller.json
Code:
{
  "displayName": "WoFCaller",
  "code": "YOURMODFOLDERNAMEHERE.Items.WoFCaller",
  "size": [20,20],
  "maxStack": 1,
  "value": [0,0,10,0],
  "texture": "Items/Pistol",
  "rare": 3,
  "useStyle": 4,
  "useAnimation": 45,
  "useTime": 45,
  "summon": true,
  "consumable": true,
  "tooltip": "Calls the Wall of Flesh",

  "recipes":
  [{
  "items": { "Ash Block": 300 },
  "tiles": [ "Work Bench" ],
  "creates": 1
  }]
}
WoFCaller.cs
Code:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using TAPI;
using Terraria;

namespace YOURMODFOLDERNAMEHERE.Items
{
    public class WoFCaller : ModItem
    {
  public override bool? UseItem(Player player)
  {
   Main.NewText("Callin' Wall of Flesh");
   NPC.SpawnWOF(player.position);
   return true;
  }
}
}
Replace YOURMODFOLDERNAMEHERE in both files with your ... mod folder name in ..\tAPI\Mods\Sources\
also your internalName in ModInfo should be same as that folder's name.

Thank you. It work!
 
I've been playing Terraria for a long time now, but tAPI is what brought me to the forums. Thank you very much. Never modded this game with tconfig, as I was playing thru the Legit way. My Son got interested in the game and asked if there was a way to have "Halo Armor"(yes he said something far more specific, being a Red vs Blue fan), so I started out hunting a way to sprite in "Halo armor" for my son, turned out gmod (http://forums.terraria.org/index.php?members/gmod.4452/) already had a mod in the released section being worked on, that had the armor already... so friggin' awesome. All thanks to gmod on that one. I still haven't started to sprite anything, due to the free with gold Terraria on my 360, and attempting to port MY map from my pc over to the 360(many failed attempts, can get other peoples maps off the net and Modio to work but MINE won't, it's driving me a lil crazy, got a lot of time into that map). I'm sure I'll eventually be posting some sprites after I figure out all the format(sizes etc.) issues n such. You guys rock, I love the fact that you're in on the modding and take suggestions from the players where as most companies get mad if you alter their game and rarely take as much input as you guys do. Keep up the good work and push the halo mod thru (gmods armor at the very least, he did a great job on it.) for 1.3 content. Also DivermanSam(http://forums.terraria.org/index.php?members/divermansam.884/) has posted what plays out to be one of the best things I've found in all my Terraria experiences, the Thorium Mod really all needs to be 1.3 content as well. I hope to one day put together a Mod half as worthy. :D
 
Last edited:
Status
Not open for further replies.
Back
Top Bottom