tModLoader API開発者チュートリアル 2025
ModItem、ModNPCをカバーする包括的なAPIチュートリアル, and advanced development techniques with practical examples.
コアAPIクラスの概要
ModItem
カスタム武器、ツール、アクセサリー、消耗品を作成
- • SetDefaults() - Define item properties
- • AddRecipes() - Create crafting recipes
- • UseItem() - Custom use behavior
ModNPC
敵、町のNPC、カスタムAIのボスを作成
- • SetDefaults() - NPC stats and behavior
- • AI() - Custom artificial intelligence
- • ModifyNPCLoot() - Define drop tables
例:高度な魔法武器の作成
public class AdvancedStaff : ModItem
{
public override void SetDefaults()
{
Item.damage = 75;
Item.DamageType = DamageClass.Magic;
Item.mana = 15;
Item.width = 40;
Item.height = 40;
Item.useTime = 30;
Item.useAnimation = 30;
Item.useStyle = ItemUseStyleID.Shoot;
Item.knockBack = 5;
Item.value = Item.buyPrice(gold: 10);
Item.rare = ItemRarityID.Pink;
Item.UseSound = SoundID.Item20;
Item.autoReuse = true;
Item.shoot = ModContent.ProjectileType<MagicBolt>();
Item.shootSpeed = 16f;
}
public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source,
Vector2 position, Vector2 velocity, int type, int damage, float knockback)
{
// Shoot 3 projectiles in a spread
for (int i = 0; i < 3; i++)
{
Vector2 newVelocity = velocity.RotatedByRandom(MathHelper.ToRadians(15));
Projectile.NewProjectile(source, position, newVelocity, type, damage, knockback, player.whoAmI);
}
return false; // Don't shoot the default projectile
}
}
This creates a staff that shoots 3 magic bolts in a spread pattern, demonstrating advanced projectile mechanics.
API ベストプラクティス 2025
✅ Do's
- • Use ModContent.ItemType<T>() for item references
- • Implement proper null checking
- • Follow C# naming conventions
- • Test in multiplayer environment
- • Document your code with comments
❌ Don'ts
- • Don't hardcode item IDs
- • Don't access Main.player directly in MP
- • Don't ignore compiler warnings
- • Don't use heavy operations in AI()
- • Don't modify vanilla content unnecessarily
学び続ける
This tutorial covers the basics. For comprehensive API documentation and advanced examples, check out these resources: