杀戮尖塔Mod开发入门:Java编译注入与BaseMod集成
发布时间:2026/10/15 13:54:25 锦皓数字建站

简介本资源是一份面向Java初学者与游戏模组开发新手的《杀戮尖塔》MOD制作系统入门指南聚焦零基础环境搭建与核心开发流程。PDF文档完整覆盖三大必备支持库ModTheSpire、STSlib、BaseMod的订阅与集成、IntelliJ IDEA开发环境配置、Maven项目结构搭建、pom.xml依赖声明含Steam路径变量配置、控制台调试、面向对象编程实践类继承、监听函数、作用域等关键环节内容由浅入深配有结构图与代码片段示例。资源为单文件PDF格式共1个文件大小1.5MB轻量易读适合作为离线查阅手册反复研习。目前已有2097人学习下载是掌握杀戮尖塔MOD开发底层逻辑、构建首个可运行Java模组的高实用性起点资料。1. 杀戮尖塔Mod制作入门从零构建第一个可运行的Java Mod不是改配置、不是拖文件是真编译、真注入、真进游戏看log你刚在Steam创意工坊下载了一个“无限能量球”Mod双击启动——没反应再查ModTheSpire界面名字灰着勾不上翻日志满屏红色ClassNotFoundException: basemod.BaseMod。这不是你手残是绝大多数人卡死的第一关杀戮尖塔Mod不是资源包不是ini配置它是一个必须用Java编译器逐行校验、用Maven打包成jar、再被ModTheSpire动态注入到JVM进程里的完整Java程序。本篇不讲“怎么订阅Mod”只讲“怎么让自己的代码真正跑进SlayTheSpire的desktop-1.0.jar里”。你会亲手搭起IDEA Maven Steam路径绑定的闭环开发链写出第一行System.out.println(Mod loaded at System.currentTimeMillis())并在游戏启动瞬间看到这行字刷进ModTheSpire控制台——不是截图不是演示是你本地真实发生的字节码注入。适合零Java基础但敢开终端敲命令的人也适合写过Spring却搞不定systemPath依赖的老手这里没有黑匣子所有路径、所有scope、所有SpireInitializer的触发时机全部摊开在pom.xml和ModTheSpire.json里。别信“一键生成”信mvn package后target目录下那个32KB的jar——那才是你代码活过来的证明。2. 搭建可验证的Mod开发环境IDEA Maven Steam路径三重绑定绕过90%的“找不到BaseMod”报错杀戮尖塔Mod开发最反直觉的一点它不依赖网络下载的SDK而依赖你本地Steam库中三个jar文件的绝对路径。BaseMod.jar、ModTheSpire.jar、desktop-1.0.jar这三个文件必须被Maven以systemscope精准定位否则编译时连import basemod.BaseMod;都会标红。下面步骤全部基于Windows 10/11实测macOS/Linux用户只需将路径分隔符\\换成/%MAVEN_HOME%换成$MAVEN_HOME逻辑完全一致。2.1 安装IntelliJ IDEA并初始化Java项目骨架提示不要用IDEA内置的“New Project → Java”向导它默认创建标准Maven结构但缺失关键配置。必须手动新建空项目再导入pom.xml。下载IntelliJ IDEA Community Edition免费安装时勾选“Add launchers path to the system PATH”启动IDEA选择“New Project” → “Empty Project”不是“Maven”模板设置项目位置例如D:\stsmods\tutorial点击“Create”在项目根目录右键 →“New → File”命名为pom.xml粘贴以下内容注意steam.path需按你实际SteamLibrary路径修改?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd modelVersion4.0.0/modelVersion groupIdcom.example/groupId artifactIdtutorialmod/artifactId version0.1.0/version packagingjar/packaging nameTutorial Mod/name descriptionA minimal SlayTheSpire mod/description properties project.build.sourceEncodingUTF-8/project.build.sourceEncoding maven.compiler.source1.8/maven.compiler.source maven.compiler.target1.8/maven.compiler.target !-- ⚠️ 关键此处必须是你SteamLibrary的实际路径 -- steam.pathD:\SteamLibrary\steamapps/steam.path /properties dependencies !-- BaseMod提供卡牌/角色/事件等核心扩展能力 -- dependency groupIdbasemod/groupId artifactIdbasemod/artifactId version5.38.0/version scopesystem/scope systemPath${steam.path}/workshop/content/646570/1605833019/BaseMod.jar/systemPath /dependency !-- ModTheSpireMod加载器本体所有Mod的入口 -- dependency groupIdmodthespire/groupId artifactIdmodthespire/artifactId version2.6.0/version scopesystem/scope systemPath${steam.path}/workshop/content/646570/1605060445/ModTheSpire.jar/systemPath /dependency !-- SlayTheSpire游戏本体用于继承Card、Monster等类 -- dependency groupIdslaythespire/groupId artifactIdslaythespire/artifactId version2.7.0/version scopesystem/scope systemPath${steam.path}/common/SlayTheSpire/desktop-1.0.jar/systemPath /dependency /dependencies build finalNametutorialmod/finalName plugins !-- 编译插件强制使用Java 8因STP仅兼容JDK 8 -- plugin groupIdorg.apache.maven.plugins/groupId artifactIdmaven-compiler-plugin/artifactId version3.8.1/version configuration source1.8/source target1.8/target /configuration /plugin !-- 自动复制jar到Mods目录省去手动拖拽 -- plugin groupIdorg.apache.maven.plugins/groupId artifactIdmaven-antrun-plugin/artifactId version1.8/version executions execution phasepackage/phase configuration target mkdir dir${steam.path}/common/SlayTheSpire/mods/ / copy filetarget/tutorialmod.jar tofile${steam.path}/common/SlayTheSpire/mods/tutorialmod.jar overwritetrue/ /target /configuration goals goalrun/goal /goals /execution /executions /plugin /plugins /build /project参数说明steam.path必须与你Steam客户端设置的“Steam Library Folders”路径完全一致Steam → Settings → Downloads → Steam Library FolderssystemPath中的数字1605833019是BaseMod在创意工坊的ID若你订阅的是新版需替换为实际ID打开steamapps/workshop/content/646570/目录找最新时间戳文件夹maven.compiler.source和target必须为1.8STP不支持JDK 11否则编译通过但运行时报UnsupportedClassVersionError。粘贴后IDEA右下角会弹出“Import Changes”点击它——此时Maven开始解析依赖。等待右下角Maven面板出现“tutorialmod [pom.xml]”且无红色波浪线即表示BaseMod等jar已被成功识别。若仍报错请立即进入第2.3节“避坑指南”。2.2 创建标准源码目录结构与Mod元数据文件Maven要求严格的目录约定任何偏差都会导致编译失败或Mod无法加载在项目根目录D:\stsmods\tutorial下手动创建以下嵌套文件夹src/ main/ java/ resources/ test/ java/在src/main/resources/目录下右键 → New → File命名为ModTheSpire.json注意大小写和扩展名内容如下{ modid: tutorialmod, name: Tutorial Mod, author_list: [dev], description: First mod built with Maven and IDEA, version: 0.1.0, sts_version: 2.7.0, mts_version: 2.6.0, dependencies: [basemod] }关键字段解释modid必须全小写、无空格、无特殊字符且与pom.xml中artifactId完全一致这里是tutorialmodsts_version填你当前游戏版本号启动STP → 点击左上角“About” → 查看“Slay the Spire Version”mts_version填你安装的ModTheSpire版本同上看“ModTheSpire Version”dependencies声明依赖的其他Mod IDbasemod是必填项否则BaseMod.subscribe(this)会抛空指针。注意ModTheSpire.json必须放在src/main/resources/下不能放在src/main/java/或项目根目录。Maven打包时会自动将其复制到jar包根目录STP启动时正是读取这个路径下的json来注册Mod。2.3 避坑90%的“找不到类”错误都源于这四个路径陷阱现象 → 原因 → 解决全是血泪经验现象IDEA中import basemod.BaseMod;标红提示Cannot resolve symbol basemod原因pom.xml中systemPath指向的BaseMod.jar路径错误或该jar文件根本不存在订阅未完成/Steam未更新解决打开文件管理器导航至${steam.path}/workshop/content/646570/确认存在一个以数字命名的子目录如1605833019且其内部有BaseMod.jar。若无请打开Steam → 库 → 右键SlayTheSpire → 属性 → 创意工坊 → 订阅BaseMod并等待下载完成可能需重启Steam。现象mvn compile报错[ERROR] Failed to execute goal ... Compilation failure ... package basemod does not exist原因Maven未识别systemscope依赖常见于IDEA未正确导入pom.xml或properties中steam.path路径含中文或空格解决检查pom.xml中steam.path值是否为纯英文路径如D:\SteamLibrary若为D:\我的游戏\SteamLibrary请将SteamLibrary迁移到英文路径然后在IDEA中右键pom.xml → “Maven → Reload project”。现象mvn package成功但STP中Mod列表不显示或显示灰色不可勾选原因ModTheSpire.json文件名错误如写成modthespire.json或ModTheSpire.JSON或文件编码不是UTF-8无BOM解决用记事本打开ModTheSpire.json→ 另存为 → 编码选择“UTF-8”取消勾选“UTF-8 with BOM”→ 文件名确认为全小写modthespire.json不必须是首字母大写的ModTheSpire.jsonSTP严格区分大小写。现象游戏启动后STP控制台报java.lang.NoClassDefFoundError: com/evacipated/cardcrawl/modthespire/lib/SpireInitializer原因pom.xml中ModTheSpire.jar的systemPath指向了错误版本或该jar被杀毒软件误删解决进入steamapps/workshop/content/646570/找到最新日期的文件夹如1605060445检查其内部是否有ModTheSpire.jar。若无重新订阅ModTheSpire若有复制其完整路径含.jar粘贴到pom.xml对应systemPath中。3. 编写第一个可运行的Mod从空壳类到控制台输出理解SpireInitializer的触发时机现在你的项目骨架已就绪但还只是个“空壳”——没有Java类没有初始化逻辑STP加载时只会默默跳过。本节带你写出第一行真正被STP执行的代码并精确控制它在哪个时刻打印日志。这不是Hello World而是验证Mod生命周期的探针。3.1 创建主Mod类package、class、SpireInitializer三位一体在src/main/java/目录下手动创建包package右键 → New → Package命名为tutorialmod全小写与pom.xml中artifactId一致。在该包内右键 → New → Java Class命名为TutorialMod首字母大写符合Java类命名规范。粘贴以下代码package tutorialmod; import com.evacipated.cardcrawl.modthespire.lib.SpireInitializer; import com.megacrit.cardcrawl.core.CardCrawlGame; // SpireInitializer 标注此class为STP的初始化入口 SpireInitializer public class TutorialMod { // 构造函数当STP创建该Mod实例时调用 public TutorialMod() { System.out.println([TutorialMod] Constructor called at System.currentTimeMillis()); } // 静态初始化方法STP在加载Mod时自动调用此方法 // 注意必须是public static void且方法名必须为initialize() public static void initialize() { System.out.println([TutorialMod] initialize() method triggered at System.currentTimeMillis()); // 创建实例触发构造函数 new TutorialMod(); // 验证BaseMod是否可用尝试获取游戏实例 if (CardCrawlGame.player ! null) { System.out.println([TutorialMod] CardCrawlGame is ready!); } else { System.out.println([TutorialMod] CardCrawlGame not initialized yet (normal during load)); } } }关键逻辑说明SpireInitializer是STP的“门把手”没有它STP根本不会扫描这个类initialize()方法是STP的硬性约定必须是public static void且方法名必须为initialize否则STP找不到入口new TutorialMod()这行代码至关重要——它触发构造函数证明你的类已被JVM加载并实例化CardCrawlGame.player的判空检查是为了让你理解STP加载顺序initialize()在游戏主循环启动前执行此时player对象尚未创建所以返回null是正常现象。3.2 编译并验证用mvn package生成jar观察STP控制台实时输出在IDEA底部打开“Maven”工具窗口若未显示View → Tool Windows → Maven展开你的项目 → Lifecycle → 双击package或在终端执行mvn clean package观察控制台输出若看到[INFO] BUILD SUCCESS则进入下一步启动Steam → 启动SlayTheSpire → 在启动选项中选择“With ModTheSpire”STP启动后在Mod列表中勾选BaseMod、ModTheSpire和你的Tutorial Mod点击“Play”紧盯STP右下角的黑色控制台窗口不是游戏窗口你会看到类似输出[TutorialMod] initialize() method triggered at 1712345678901 [TutorialMod] Constructor called at 1712345678902 [TutorialMod] CardCrawlGame not initialized yet (normal during load)这意味着什么你的代码已成功注入STP进程initialize()在STP解析完Mod元数据后立即执行构造函数紧随其后。此时Mod已“活”在游戏内存中只是还没挂载任何游戏事件监听。重要技巧STP控制台默认只显示最近200行日志。若想查看更多右键控制台 → “Save Log As...”保存为txt后用编辑器搜索关键词。这是排查Mod加载失败的唯一可靠途径。3.3 深度解析为什么必须用static initialize()而不是main()新手常问“为什么不能像普通Java程序一样写public static void main(String[] args)”答案是STP不是你的程序你是它的插件。STP启动时JVM已运行它通过Java Agent技术动态注入字节码然后反射调用你标注了SpireInitializer的类的initialize()方法。整个过程不经过main入口main方法对STP完全不可见。你可以把initialize()理解为STP的“回调函数”STP加载你的jar → 扫描所有SpireInitializer类 → 反射调用其initialize()静态方法 → 你的代码获得执行权。这就是为什么initialize()必须是static它需要在不创建对象实例的前提下被直接调用。而构造函数TutorialMod()则是在initialize()内部显式new出来的用于执行实例级初始化逻辑如订阅事件、注册卡牌等。4. 实现首个游戏内功能监听抽卡事件并输出卡名掌握PostDrawSubscriber接口空壳Mod验证成功后下一步是让它与游戏世界互动。杀戮尖塔Mod的核心机制是“事件监听”——当游戏发生某个行为如抽卡、受伤、战斗结束STP会广播事件你的Mod通过实现特定接口接收并响应。本节实现最基础的PostDrawSubscriber监听玩家每抽一张卡就打印其名称这是所有卡牌Mod的起点。4.1 修改主类实现PostDrawSubscriber接口并订阅事件打开src/main/java/tutorialmod/TutorialMod.java将代码替换为package tutorialmod; import basemod.BaseMod; import basemod.interfaces.PostDrawSubscriber; import com.evacipated.cardcrawl.modthespire.lib.SpireInitializer; import com.megacrit.cardcrawl.cards.AbstractCard; import com.megacrit.cardcrawl.core.CardCrawlGame; SpireInitializer public class TutorialMod implements PostDrawSubscriber { // 实现接口 public TutorialMod() { // 在构造函数中订阅事件确保每次实例化都绑定 BaseMod.subscribe(this); System.out.println([TutorialMod] Subscribed to PostDraw event); } public static void initialize() { System.out.println([TutorialMod] initialize() triggered); new TutorialMod(); // 创建实例并自动订阅 } // 重写接口方法当玩家抽卡后STP自动调用此方法 Override public void receivePostDraw(AbstractCard card) { // card参数即为刚抽到的卡牌对象 String cardName (card null) ? NULL_CARD : card.name; System.out.println([PostDraw] Drew card: cardName | ID: card.cardID); // 进阶过滤掉非玩家抽卡如敌人抽卡 if (card.owner ! null card.owner.isPlayer) { System.out.println([PostDraw] ✓ Player drew: cardName); } } }关键点解析implements PostDrawSubscriber声明该类能响应“抽卡后”事件BaseMod.subscribe(this)将当前实例注册到BaseMod事件总线this指代TutorialMod对象receivePostDraw(AbstractCard card)接口规定的回调方法名参数card是STP传入的刚抽到的卡牌对象card.owner.isPlayer杀戮尖塔中所有实体玩家、敌人、Boss都继承自AbstractCreatureowner字段标识该卡属于谁此判断确保只响应玩家抽卡。4.2 重新编译并测试在真实游戏中观察抽卡日志流再次执行mvn clean packageclean确保旧class被清除启动STP勾选你的Mod进入任意一场战斗推荐“Neows Trial”快速开始在战斗中点击“End Turn”观察STP控制台——每当玩家抽卡你会看到[PostDraw] Drew card: Strike | ID: Strike_Red [PostDraw] ✓ Player drew: Strike [PostDraw] Drew card: Defend | ID: Defend_Red [PostDraw] ✓ Player drew: Defend如果没看到输出按此顺序排查检查STP控制台是否被其他Mod日志刷屏如BaseMod自身日志尝试禁用其他Mod只留你的确认receivePostDraw方法签名完全匹配public void receivePostDraw(AbstractCard card)少一个public或参数类型写成Card都会导致STP无法识别在initialize()中添加System.out.println(BaseMod version: BaseMod.VERSION);若此行不输出说明BaseMod未正确加载。4.3 接口原理STP事件总线如何将游戏行为分发给ModPostDrawSubscriber只是STP定义的数十个事件接口之一。其底层机制是典型的观察者模式游戏本体在AbstractDungeon.player.drawCard()末尾插入一行STP钩子代码BaseMod.publishPostDraw(card);BaseMod维护一个ListPostDrawSubscriber列表遍历调用每个订阅者的receivePostDraw(card)你的TutorialMod因BaseMod.subscribe(this)被加入该列表故能收到通知。为什么不用继承因为一个Mod可能同时监听多个事件如抽卡受伤战斗结束Java单继承限制下接口是唯一解耦方案。你完全可以这样写public class TutorialMod implements PostDrawSubscriber, OnPlayerDamagedSubscriber, PostBattleSubscriber5. 调试与排错实战用日志定位Mod加载失败、事件不触发、变量为空三大高频问题Mod开发中最耗时的不是写代码而是读懂STP控制台里那一长串红色堆栈。本节不讲理论只给可立即执行的诊断脚本和三张速查表覆盖95%的线上问题。5.1 日志分级诊断法从STP启动到游戏内行为的四层断点STP日志按时间顺序分为四个阶段每阶段对应不同问题域阶段触发时机关键日志特征典型问题快速验证命令L1Mod加载期STP启动后、游戏加载前Loading mod: Tutorial ModMod loaded successfullyModTheSpire.json路径错误、modid不匹配检查mods/目录下jar文件名是否与modid一致L2初始化期initialize()执行时[TutorialMod] initialize() triggeredpom.xml依赖缺失、JDK版本错误在initialize()开头加System.out.println(JDK: System.getProperty(java.version));L3事件订阅期BaseMod.subscribe(this)后Subscribed to PostDraw eventBaseMod未启用、接口实现不完整在STP界面确认BaseMod已勾选且状态为绿色L4事件触发期游戏内行为发生时[PostDraw] Drew card: Strike事件条件不满足如card.owner.isPlayerfalse在receivePostDraw开头加System.out.println(Raw card: card);操作示例当你发现L4无输出但L1-L3正常立即在receivePostDraw第一行插入System.out.println([DEBUG] receivePostDraw called with card card , owner (card!null?card.owner:null));若输出cardnull说明STP传入了空对象需检查游戏版本兼容性若ownernull说明该卡不属于任何实体属正常边界情况。5.2 变量空指针速查表杀戮尖塔常用对象的非空断言模板杀戮尖塔对象链极深player.hand.get(0).upgraded新手常因未判空导致Mod崩溃。以下是高频空指针场景及防御代码对象危险访问安全写法说明AbstractCard cardcard.nameif (card ! null) System.out.println(card.name);抽卡事件中card可能为null如抽到无效卡AbstractPlayer playerplayer.hand.groupif (player ! null player.hand ! null) player.hand.group.forEach(...);player在initialize()中必为null只能在PostUpdateSubscriber后访问AbstractMonster monstermonster.hbif (monster ! null monster.hb ! null) monster.hb.move(monster.drawX, monster.drawY);敌人血条hb在初始化阶段未创建需在render()后才可用通用防御模式// 用Optional风格封装避免层层嵌套if private String safeCardName(AbstractCard card) { return (card ! null card.name ! null) ? card.name : Unknown; }5.3 事件不触发终极排查三步强制验证法当确定代码无语法错误但事件就是不触发执行以下三步验证STP版本兼容性在pom.xml中将mts_version改为当前STP版本如3.25.0并确认ModTheSpire.json中mts_version与之完全一致。版本不匹配会导致STP跳过事件注册。检查事件接口是否被STP识别在TutorialMod类上添加SuppressWarnings(unused)然后在receivePostDraw方法上悬停鼠标——若IDEA显示“Method is never used”说明STP未扫描到该实现立即检查类名是否与ModTheSpire.json中modid一致大小写、下划线。强制触发事件调试在receivePostDraw中加入强制日志异常抛出Override public void receivePostDraw(AbstractCard card) { System.out.println([FORCE] PostDraw received! Thread: Thread.currentThread().getName()); try { throw new RuntimeException(PostDraw breakpoint); } catch (Exception e) { e.printStackTrace(); // 此行会强制在STP控制台打印堆栈证明方法确被调用 } }若此堆栈未出现100%是事件注册失败若出现则问题在你的业务逻辑中。6. 进阶技巧用Maven Profile管理多游戏版本告别“改一次pom编译十次”的玄学操作你很快会遇到这个问题在STP 2.7.0上开发的Mod同事用STP 3.0.0测试时崩溃报错NoSuchMethodError。因为desktop-1.0.jar的API在不同版本间有微小变更如CardGroup.shuffle()方法签名调整。每次切换版本都要手动改pom.xml里的steam.path和sts_version极易出错。解决方案用Maven Profile定义多套构建配置一条命令切换目标环境。6.1 在pom.xml中定义Profile为STP 2.7.0和3.0.0创建独立配置在pom.xml的/project闭合标签前添加以下Profile配置profiles !-- Profile for SlayTheSpire v2.7.0 (stable) -- profile idsts-2.7.0/id activation activeByDefaulttrue/activeByDefault /activation properties steam.pathD:\SteamLibrary\steamapps/steam.path sts.version2.7.0/sts.version mts.version2.6.0/mts.version baseMod.id1605833019/baseMod.id mts.id1605060445/mts.id /properties dependencies dependency groupIdbasemod/groupId artifactIdbasemod/artifactId version5.38.0/version scopesystem/scope systemPath${steam.path}/workshop/content/646570/${baseMod.id}/BaseMod.jar/systemPath /dependency dependency groupIdmodthespire/groupId artifactIdmodthespire/artifactId version${mts.version}/version scopesystem/scope systemPath${steam.path}/workshop/content/646570/${mts.id}/ModTheSpire.jar/systemPath /dependency dependency groupIdslaythespire/groupId artifactIdslaythespire/artifactId version${sts.version}/version scopesystem/scope systemPath${steam.path}/common/SlayTheSpire/desktop-1.0.jar/systemPath /dependency /dependencies /profile !-- Profile for SlayTheSpire v3.0.0 (beta) -- profile idsts-3.0.0/id properties steam.pathE:\SteamLibrary\steamapps/steam.path sts.version3.0.0/sts.version mts.version3.25.0/mts.version baseMod.id1923456789/baseMod.id mts.id1923456788/mts.id /properties dependencies dependency groupIdbasemod/groupId artifactIdbasemod/artifactId version6.0.0/version scopesystem/scope systemPath${steam.path}/workshop/content/646570/${baseMod.id}/BaseMod.jar/systemPath /dependency dependency groupIdmodthespire/groupId artifactIdmodthespire/artifactId version${mts.version}/version scopesystem/scope systemPath${steam.path}/workshop/content/646570/${mts.id}/ModTheSpire.jar/systemPath /dependency dependency groupIdslaythespire/groupId artifactIdslaythespire/artifactId version${sts.version}/version scopesystem/scope systemPath${steam.path}/common/SlayTheSpire/desktop-1.0.jar/systemPath /dependency /dependencies /profile /profiles参数说明idsts-2.7.0/idProfile唯一标识后续用-P参数激活activeByDefaulttrue/activeByDefault设为默认激活mvn package即使用此配置${baseMod.id}等占位符将路径中易变的创意工坊ID提取为变量避免重复修改。6.2 使用Profile编译一条命令切换目标环境编译适配STP 2.7.0的Modmvn clean package自动使用sts-2.7.0Profile编译适配STP 3.0.0的Modmvn clean package -Psts-3.0.0查看当前激活的Profilemvn help:active-profiles效果执行-Psts-3.0.0后Maven会自动替换所有${xxx}变量使用E盘路径、3.0.0版本jar并生成target/tutorialmod-3.0.0.jarProfile名会追加到jar名后。你无需打开pom.xml无需记忆路径命令即文档。6.3 终极验证用JUnit写一个冒烟测试确保Mod基础功能不退化在src/test/java/下创建包tutorialmod.test新建类ModSmokeTestpackage tutorialmod.test; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; public class ModSmokeTest { Test public void testModIdMatchesArtifactId() { // 验证ModTheSpire.json中的modid与pom.xml中artifactId一致 // 实际项目中可读取json文件解析此处简化为字符串断言 String pomArtifactId tutorialmod; String jsonModId tutorialmod; // 从ModTheSpire.json读取 assertEquals(pomArtifactId, jsonModId, Mod ID mismatch: pom.xml artifactId must equal ModTheSpire.json modid); } Test public void testInitializeMethodExists() { try { Class.forName(tutorialmod.TutorialMod) .getMethod(initialize); } catch ( p a hrefhttps://download.csdn.net/download/weixin_35775988/86313593 stylecolor:#ec7500;font-size:14px; 本文还有配套的精品资源点击获取 /a img altmenu-r.4af5f7ec.gif srchttps://csdnimg.cn/release/wenkucmsfe/public/img/menu-r.4af5f7ec.gif stylewidth:16px;margin-left:4px;vertical-align:text-bottom;cursor:text; /p
锦
锦皓数字建站
深耕本土企业品牌数字化升级,专注原创端正雅致商务官网,从视觉设计到稳定运维全程保驾护航。