Files
CustomNPC-Plus/build.gradle
T
KAMKEEL 5f49d28f7c Generate CustomNPC+ save data without launching the game
Scribe needs fixtures to test its readers against, and the only fixtures worth
having are ones CustomNPC+ wrote. A hand-authored factions.dat asserts what its
author believed the format to be, so a reader checked against it proves only
that the two agree.

So this drives the shipping data classes' own writeToNBT/writeNBT against a
bootstrapped-but-unlaunched Minecraft. What is copied rather than executed is
only the layout -- which file, under which directory -- because the controllers
reach that through getWorldSaveDirectory(), which returns null with no server,
and every save* fires SyncController into a network stack that is not there.
Each method names the controller it was copied from.

Two obstacles, both worth recording.

Item stacks needed the registry, and populating it goes through Forge:
FMLControlledNamespacedRegistry -> GameData.addPrefix, which asks
Loader.instance() for the active mod's namespace, and constructing a Loader
casts its classloader to LaunchWrapper's. Rather than reimplement the naming
rule, the singleton is filled with an unconstructed Loader so activeModContainer
returns null and addPrefix takes its own "no mod container, assume minecraft"
branch -- the branch real vanilla registration takes anyway. Verified against
minecraft:diamond as it appears in the worlds under run/saves, so the shortcut
is measured rather than assumed.

Second, nothing was reproducible: PlayerMail.writeNBT stamps TimePast from the
wall clock, and a PlayerMail hangs off every dialog and quest whether or not
mail was configured, so all 67 files differed between runs. Pinned to zero,
which is the only key here rewritten after CustomNPC+ produced it, and the count
is printed every run so it cannot spread quietly. Two runs now diff clean.

Branched from 8612d444 rather than dev, because dev's tip does not compile --
1.11.2-beta1 calls PlayerData.flushEffects() and save(boolean), neither of which
exists -- and because that commit is the baseline Scribe pins as specification.

70 files across four worlds: maximal walks every enum and flag, defaults is what
a fresh world gets, edge is legal content readers get wrong, and legacy ages
documents by removing keys to exercise the upgrade path. Dialogs and factions
so far; the remaining systems follow.
2026-08-14 00:10:02 -04:00

151 lines
5.1 KiB
Groovy

//version: 1707058017
plugins {
id 'com.gtnewhorizons.gtnhconvention'
id 'idea'
id "dts.typescript-generator"
}
version = "1.11.1"
group= "kamkeel.customnpc-plus"
archivesBaseName = "CustomNPC-Plus"
def embedMixin = !project.hasProperty("nomixin");
if(!embedMixin){
version += "-nomixin"
}
// API Task
tasks.create('updateAPI', Exec) {
description 'Updates (and Inits) git submodules'
commandLine 'git', 'submodule', 'update', '--init', '--recursive'
group 'CustomNPC+'
}
// No Mixin Build Task
def gradleWrapper = System.getProperty('os.name').toLowerCase().contains('windows') ? 'gradlew.bat' : './gradlew'
tasks.create('buildNoMixin', Exec) {
description 'Builds mod without embed'
group 'CustomNPC+'
workingDir project.rootDir
commandLine gradleWrapper, 'build', '-Pnomixin'
}
// No Nashorn Run Tasks
tasks.create('runClientNoNashorn', Exec) {
description 'Runs the client without Nashorn'
group 'CustomNPC+'
workingDir project.rootDir
commandLine gradleWrapper, 'runClient', '-PnoNashorn'
}
tasks.create('runServerNoNashorn', Exec) {
description 'Runs the server without Nashorn'
group 'CustomNPC+'
workingDir project.rootDir
commandLine gradleWrapper, 'runServer', '-PnoNashorn'
}
sourceSets.main.java {
def apiDir = file('src/api/java')
if (!apiDir.exists()) {
throw new GradleException("Missing API sources: Run './gradlew updateAPI' or enable checkout submodules in CI.")
}
srcDirs += apiDir
}
// ============================================================================
// Scribe fixtures -- an offline generator for CustomNPC+ save data.
//
// Its own source set, so nothing here reaches the mod jar. It runs CustomNPC+'s
// own writeToNBT/writeNBT methods against a bootstrapped-but-unlaunched
// Minecraft, and writes the results into a world layout copied from each
// controller. See src/fixtures/README.md.
// ============================================================================
sourceSets {
fixtures {
java.srcDirs = ['src/fixtures/java']
compileClasspath += sourceSets.main.output + sourceSets.main.compileClasspath
runtimeClasspath += sourceSets.main.output + sourceSets.main.runtimeClasspath
}
}
tasks.register('scribeFixtures', JavaExec) {
group 'CustomNPC+'
description 'Generates CustomNPC+ save fixtures for Scribe. -Pout=<dir>, -Pworlds=<a,b>'
dependsOn 'fixturesClasses'
classpath = sourceSets.fixtures.runtimeClasspath
mainClass = 'kamkeel.npcs.fixtures.FixtureGenerator'
// Off the project dir, because CustomNpcs.getWorldSaveDirectory() resolves "." and
// a stray relative write would land in the repo root.
workingDir = project.buildDir
doFirst {
// Resolved against the project directory, not workingDir, so -Pout=build/x means what it
// looks like rather than build/build/x.
def out = project.hasProperty('out') ? project.file(project.property('out'))
: new File(project.buildDir, 'scribe-fixtures')
args = [out.absolutePath]
if (project.hasProperty('worlds')) {
args += ['--worlds', project.property('worlds')]
}
}
}
// ============================================================================
// TypeScript Definition Generation Task
// Generates .d.ts files from Java API sources for scripting IDE support
// ============================================================================
// TypeScript plugin is applied above in the main plugins block
tasks.named("generateTypeScriptDefinitions").configure {
sourceDirectories = ['src/api/java', 'src/main/java']
outputDirectory = "src/main/resources/assets/${project.property("modId")}/api"
apiPackages = ['noppes.npcs.api', 'net.minecraft'] as Set
cleanOutputFirst = true // Clean old generated files before regenerating
patchesDirectory = "dts-patches"
implementationPackages = [
'noppes.npcs.scripted',
'noppes.npcs.controllers.data',
'noppes.npcs.entity.data',
'noppes.npcs.quests',
'kamkeel.npcs.controllers.data'
] as Set
}
processResources.dependsOn generateTypeScriptDefinitions
sourcesJar.dependsOn generateTypeScriptDefinitions
// Javadoc configuration
javadoc {
options.encoding = 'UTF-8'
options.charSet = 'UTF-8'
options.docEncoding = 'UTF-8'
options.tags = [
'hookName:a:Hook Name:'
]
options.stylesheetFile = file('.github/javadoc/javadoc-theme.css')
options.header = file('.github/javadoc/javadoc-header.html').text.replaceAll('\\s+', ' ').trim()
options.addBooleanOption('-allow-script-in-comments', true)
options.footer = file('.github/javadoc/javadoc-footer.html').text.replaceAll('\\s+', ' ').trim()
// Only document the public API, not net.minecraft stubs
include 'noppes/npcs/api/**'
options.links(
'https://docs.oracle.com/en/java/javase/11/docs/api/'
)
javadocTool = javaToolchains.javadocToolFor {
languageVersion = JavaLanguageVersion.of(11)
}
}
// Modify the existing 'build' task to depend on 'updateAPI'
//tasks.apiClasses.dependsOn 'updateAPI'