You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

tModLoader 1.4自定义剑配方报错求助

tModLoader 1.4 自定义合成剑配方报错解决方案

问题场景

在tModLoader 1.4中制作自定义合成剑,需求为:通过铁砧+8个TutorialItem合成TutorialSword,使用作弊指令测试物品。

代码展示

TutorialItem 代码

using Terraria.ModLoader;
using Terraria.ID;
using Terraria.GameContent.Creative;
using Microsoft.Xna.Framework;

namespace OverpoweredStuff.Content.Items
{
    internal class TutorialItem : ModItem
    {
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("Tutorial Item");
            Tooltip.SetDefault("pog");
            CreativeItemSacrificesCatalog.Instance.SacrificeCountNeededByItemId[Type] = 100;
        }

        public override void SetDefaults()
        {
            Item.width = 16;
            Item.height = 16;

            Item.value = Item.buyPrice(copper: 5);
            Item.maxStack = 999;
        }
    }
}

TutorialSword 代码

using Terraria;
using Terraria.ModLoader;
using Terraria.ID;
using Terraria.GameContent.Creative;

namespace TutorialMod.Content.Items.Weapons
{
    internal class TutorialSword : ModItem
    {
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("Tutorial Sword");
            Tooltip.SetDefault("This is a modded Broadsword");
            CreativeItemSacrificesCatalog.Instance.SacrificeCountNeededByItemId[Type] = 1;
        }

        public override void SetDefaults()
        {
            Item.width = 32;
            Item.height = 32;

            Item.useStyle = ItemUseStyleID.Swing;
            Item.useTime  = 20;
            Item.useAnimation = 20;
            Item.autoReuse = true;

            Item.DamageType = DamageClass.Melee;
            Item.damage = 69;
            Item.knockBack = 3.5f;
            Item.crit = 5;

            Item.value = Item.buyPrice(silver: 80, copper: 50);
            Item.rare = ItemRarityID.Blue;

            Item.UseSound = SoundID.Item1;
        }

        public override void AddRecipes()
        {
            CreateRecipe()
                .AddIngredients(ModContent.ItemType<TutorialItem>(), 8)
                .AddTile(TileID.Anvils)
                .Register();
        }
    } 
}

错误情况

  1. 最初报错:编译器无法识别TutorialItem类型
  2. 文件结构:TutorialItem属于OverpoweredStuff模组,TutorialSword属于TutorialMod模组,两个模组独立
  3. 修正尖括号后新错误:仍无法解析TutorialItem类型
  4. 改用原版材料.AddIngredient(2, 8)时,触发与最初相同的编译错误

解决方案

1. 修复命名空间引用问题

TutorialItem和TutorialSword分属两个不同模组的命名空间,需要在TutorialSword的代码顶部添加引用:

using OverpoweredStuff.Content.Items;

同时确保两个模组都在tModLoader中启用,且OverpoweredStuff模组在加载顺序中优先于TutorialMod。

2. 合并到同一模组(更推荐)

将TutorialItem的代码移到TutorialMod.Content.Items命名空间下,修改其命名空间:

namespace TutorialMod.Content.Items
{
    // ... 原有代码不变
}

这样无需跨模组引用,避免加载顺序和命名空间的问题。

3. 修正配方方法拼写错误

配方代码中的AddIngredients是错误的,正确方法名为单数AddIngredient:

CreateRecipe()
    .AddIngredient(ModContent.ItemType<TutorialItem>(), 8)
    .AddTile(TileID.Anvils)
    .Register();

4. 确保作弊指令正确

获取TutorialItem的作弊指令需指定模组名(如果跨模组):

/give [你的用户名] OverpoweredStuff/TutorialItem 8

如果合并到同一模组,指令为:

/give [你的用户名] TutorialMod/TutorialItem 8

内容的提问来源于stack exchange,提问作者Hchap

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 16:10:31