diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 00000000..16156336 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,36 @@ +--- +name: Bug report +about: Create a report to help us improve Modular Machinery: Community Edition +labels: bug +--- + +## Describe the bug +A clear and concise description of the problem. + +## To reproduce +1. Go to '...' +2. Click on '...' +3. Run command '...' +4. See error + +## Expected behavior +Describe what you expected to happen. + +## Logs and crash reports +- Attach `logs/latest.log` and any crash report from `crash-reports/`. + +## Checklist +- [ ] I can reproduce this on the latest released version. +- [ ] I searched for existing issues. +- [ ] I included the exact source for any added or replacement mods. + +## Environment +- Modular Machinery Community Edition version: +- Minecraft: 1.12.2 +- Forge: +- Java: 8u__ +- OS: Windows/Linux/macOS (version) +- Modpack and relevant integration mods: + +## Additional context +Add any other relevant information, screenshots, or configuration excerpts. diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 00000000..c6b3a2da --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,5 @@ +blank_issues_enabled: false +contact_links: + - name: README + url: https://github.com/???/ModularMachinery-Community-Edition#readme + about: Check the README and bundled documentation before filing an issue. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 00000000..e8f28316 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for Modular Machinery: Community Edition +labels: enhancement +--- + +## Is your feature request related to a problem? +Describe the problem or limitation. + +## Describe the solution you'd like +Describe the behavior you would like to see. + +## Alternatives you've considered +Describe other solutions or workarounds. + +## Affected components or integrations +- + +## Additional context +Add mockups, configuration examples, or related links. diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 00000000..6e35bccf --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,38 @@ +# Summary +Explain the motivation and context for this change. + +## Type of change +- [ ] Bug fix (non-breaking change) +- [ ] New feature (non-breaking change) +- [ ] Breaking change +- [ ] Chore/refactor +- [ ] Documentation update only + +## Related issues +Closes # + +## What changed + +- + +## How to test +Provide steps and relevant commands. + +```cmd +rem From the repository root, using Java 21 for Gradle +gradle setupDecompWorkspace +gradle build +``` + +If this changes runtime behavior, include in-game verification steps. + +## Checklist +- [ ] I built the project locally with Gradle 8.14 and Java 21. +- [ ] I updated documentation when needed. +- [ ] I followed the existing code style. +- [ ] I did not include secrets or private data. +- [ ] If touching `mcmod.info`, it remains valid and accurate. +- [ ] I searched for existing PRs/issues that cover this change. + +## Additional context +Add anything reviewers should know. diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 85fa6816..919fdca6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,27 +1,88 @@ -name: Build mod +name: build -on: [ push, pull_request, workflow_dispatch ] +on: + push: + branches: + - '**' + tags: + - '**' + pull_request: + branches: + - '**' + workflow_dispatch: + +permissions: + contents: write jobs: build: - name: Build mod runs-on: ubuntu-latest - + env: + CURSEFORGE_TOKEN: ${{ secrets.CURSEFORGE_TOKEN }} steps: - - uses: actions/checkout@v4 - - name: Set up JDK 1.8 - uses: actions/setup-java@v4 - with: - distribution: 'adopt' - java-version: '8' - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - name: Setup Gradle - uses: gradle/actions/setup-gradle@v3 - - name: Build with Gradle - run: ./gradlew -Pnet.minecraftforge.gradle.disableUpdateChecker=true build - - name: Upload artifacts - uses: actions/upload-artifact@v4 - with: - name: ModularMachinery-CE - path: build/libs + - name: Checkout + uses: actions/checkout@v4 + + # Gradle 8.14/RFG 1.4.9 needs Java 21 + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + distribution: zulu + java-version: '21' + + - name: Cache Gradle and RFG + uses: actions/cache@v4 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + ~/.gradle/jdks + key: gradle-${{ runner.os }}-rfg-1_12_2-${{ hashFiles('**/*.gradle*', 'gradle/wrapper/gradle-wrapper.properties') }} + restore-keys: | + gradle-${{ runner.os }}-rfg-1_12_2- + + - name: Make gradlew executable + run: chmod +x gradlew + + - name: Build + run: | + ./gradlew --version + ./gradlew setupDecompWorkspace --info + ./gradlew build --info + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: modularmachinery-community-edition-jar + path: build/libs/*.jar + + - name: Publish GitHub Release (tags only) + if: ${{ startsWith(github.ref, 'refs/tags/') }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + TAG="${GITHUB_REF##*/}" + VERSION=$(./gradlew -q printVersion) + FULL_VERSION=$(./gradlew -q printFullVersion) + RELEASE_TYPE=$(./gradlew -q printReleaseType) + NOTES_FILE="/tmp/release_notes.md" + + if [[ -f CHANGELOG.md ]]; then + ./gradlew -q printChangelog > "$NOTES_FILE" + else + printf 'Release %s\n' "$FULL_VERSION" > "$NOTES_FILE" + fi + + gh release create "$TAG" build/libs/*.jar \ + --title "$FULL_VERSION" \ + --notes-file "$NOTES_FILE" \ + $(if [[ "$RELEASE_TYPE" != "release" ]]; then echo "--prerelease"; fi) + + - name: Publish to CurseForge (configured tags only) + if: ${{ env.CURSEFORGE_TOKEN != '' && vars.CURSEFORGE_PROJECT_ID != '' && startsWith(github.ref, 'refs/tags/') }} + run: | + RELEASE_TYPE=$(./gradlew -q printReleaseType) + ./gradlew curseforge --no-daemon \ + -Ppublish_to_curseforge=true \ + -Pcurseforge_project_id="${{ vars.CURSEFORGE_PROJECT_ID }}" \ + -Prelease_type="$RELEASE_TYPE" diff --git a/.gitignore b/.gitignore index 96a09920..aecadbe0 100644 --- a/.gitignore +++ b/.gitignore @@ -46,7 +46,11 @@ hs_err_pid* # For good measure... *.jks -gradle.properties + +.vscode /libs/* -.gradle \ No newline at end of file +.gradle +.kotlin +*.patch +*.zip diff --git a/build.gradle b/build.gradle new file mode 100644 index 00000000..aee777e8 --- /dev/null +++ b/build.gradle @@ -0,0 +1,369 @@ +import com.gtnewhorizons.retrofuturagradle.mcp.InjectTagsTask +import net.darkhax.curseforgegradle.TaskPublishCurseForge +import org.jetbrains.changelog.Changelog +import org.jetbrains.gradle.ext.Gradle +import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile + +plugins { + id 'java' + id 'java-library' + id 'maven-publish' + id 'org.jetbrains.kotlin.jvm' version '2.2.0' + id 'org.jetbrains.kotlin.plugin.serialization' version '2.2.0' + id 'org.jetbrains.gradle.plugin.idea-ext' version '1.4.1' + // Need 1.4.X for Kotlin / Gradle 8.14 (2.X.X needs Gradle 9) + id 'com.gtnewhorizons.retrofuturagradle' version '1.4.9' + // Need 1.1.X for Gradle 8.14 (1.2.X needs Gradle 9) + id 'net.darkhax.curseforgegradle' version '1.1.28' apply false + id 'com.modrinth.minotaur' version '2.+' apply false + id 'org.jetbrains.changelog' version '2.5.0' +} + +apply from: 'gradle/scripts/helpers.gradle' + +// Required project metadata. +assertProperty 'mod_version' +assertProperty 'root_package' +assertProperty 'mod_id' +assertProperty 'mod_name' + +assertSubProperties 'use_tags', 'tag_class_name' +assertSubProperties 'use_access_transformer', 'access_transformer_locations' +assertSubProperties 'use_mixins', 'mixin_booter_version', 'mixin_refmap' +assertSubProperties 'is_coremod', 'coremod_includes_mod', 'coremod_plugin_class_name' +assertSubProperties 'use_asset_mover', 'asset_mover_version' + +setDefaultProperty 'use_modern_java_syntax', false, false +setDefaultProperty 'generate_sources_jar', true, false +setDefaultProperty 'generate_javadocs_jar', true, false +setDefaultProperty 'mapping_channel', true, 'stable' +setDefaultProperty 'mapping_version', true, '39' +setDefaultProperty 'use_dependency_at_files', true, true +setDefaultProperty 'minecraft_username', true, 'Developer' +setDefaultProperty 'extra_jvm_args', false, '' +setDefaultProperty 'extra_tweak_classes', false, '' +setDefaultProperty 'change_minecraft_sources', false, false +setDefaultProperty 'publish_to_curseforge', true, false + +version = propertyString('mod_version') +group = propertyString('root_package') + +base { + archivesName.set(propertyString('mod_id')) +} + +tasks.named('decompressDecompiledSources').configure { + enabled = !propertyBool('change_minecraft_sources') || !layout.buildDirectory.dir('rfg/minecraft-src').get().asFile.exists() +} + +// Gradle/RFG run on Java 21, but the Java compiler stays on 17 so Jabel can lower mod bytecode to Java 8. +java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(17)) + vendor.set(JvmVendorSpec.AZUL) + } + if (propertyBool('generate_sources_jar')) { + withSourcesJar() + } + if (propertyBool('generate_javadocs_jar')) { + withJavadocJar() + } +} + +// Kotlin needs Java 8 game bytecode/runtime baseline. +kotlin { + jvmToolchain(8) + compilerOptions.jvmTarget.set(JvmTarget.JVM_1_8) +} + +tasks.withType(KotlinJvmCompile).configureEach { + compilerOptions.jvmTarget.set(JvmTarget.JVM_1_8) +} + +// Optional integrations need to compile and be present in development runs, but must not be +// published as runtime requirements of Modular Machinery. +configurations { + def runtimeOnlyNonPublishable = create('runtimeOnlyNonPublishable') { + description = 'Runtime-only dependencies that are not published alongside the jar' + canBeConsumed = false + canBeResolved = false + } + def devOnlyNonPublishable = create('devOnlyNonPublishable') { + description = 'Compile-time and development-runtime dependencies that are not published alongside the jar' + canBeConsumed = false + canBeResolved = false + } + + compileOnly.extendsFrom(devOnlyNonPublishable) + runtimeOnlyNonPublishable.extendsFrom(devOnlyNonPublishable) + runtimeClasspath.extendsFrom(runtimeOnlyNonPublishable) + testRuntimeClasspath.extendsFrom(runtimeOnlyNonPublishable) +} + +minecraft { + mcVersion.set('1.12.2') + + mcpMappingChannel.set(propertyString('mapping_channel')) + mcpMappingVersion.set(propertyString('mapping_version')) + useDependencyAccessTransformers.set(propertyBool('use_dependency_at_files')) + + username.set(propertyString('minecraft_username')) + extraTweakClasses.addAll(propertyStringList('extra_tweak_classes')) + + def args = ['-ea:' + group] + if (propertyBool('use_mixins')) { + args << '-Dmixin.checks.interfaces=true' + args << '-Dmixin.debug.export=true' + } + extraRunJvmArguments.addAll(args) + extraRunJvmArguments.addAll(propertyStringList('extra_jvm_args')) + + // These third-party libraries contain classes that must not be remapped into the release jar. + groupsToExcludeFromAutoReobfMapping.addAll('com.diffplug', 'com.diffplug.durian', 'net.industrial-craft') + + if (propertyBool('use_tags') && file('tags.properties').exists()) { + Properties props = new Properties().tap { it.load(file('tags.properties').newInputStream()); it } + if (!props.isEmpty()) { + injectedTags.set(props.collectEntries { k, v -> + def interpolated = interpolate(v) + if (interpolated == null || interpolated.isEmpty()) { + throw new GradleException("Empty tag value found for key: $k") + } + [(k): interpolated] + }) + } + } +} + +repositories { + maven { + name 'CleanroomMC Maven' + url 'https://maven.cleanroommc.com' + } +} + +dependencies { + if (propertyBool('use_modern_java_syntax')) { + annotationProcessor 'com.github.bsideup.jabel:jabel-javac-plugin:1.0.0' + // Work around Jabel issue #174. + annotationProcessor 'net.java.dev.jna:jna-platform:5.13.0' + compileOnly('com.github.bsideup.jabel:jabel-javac-plugin:1.0.0') { + transitive = false + } + // Allows jdk.unsupported classes such as sun.misc.Unsafe in the patched Minecraft runtime. + patchedMinecraft 'me.eigenraven.java8unsupported:java-8-unsupported-shim:1.0.0' + testAnnotationProcessor 'com.github.bsideup.jabel:jabel-javac-plugin:1.0.0' + testCompileOnly('com.github.bsideup.jabel:jabel-javac-plugin:1.0.0') { + transitive = false + } + testCompileOnly 'me.eigenraven.java8unsupported:java-8-unsupported-shim:1.0.0' + } + + if (propertyBool('use_asset_mover')) { + implementation "com.cleanroommc:assetmover:${propertyString('asset_mover_version')}" + } + + if (propertyBool('use_mixins')) { + String mixin = modUtils.enableMixins("zone.rong:mixinbooter:${propertyString('mixin_booter_version')}", propertyString('mixin_refmap')) + api(mixin) { + transitive = false + } + annotationProcessor 'org.ow2.asm:asm-debug-all:5.2' + annotationProcessor 'com.google.guava:guava:30.0-jre' + annotationProcessor 'com.google.code.gson:gson:2.8.9' + annotationProcessor(mixin) { + transitive = false + } + } + + if (propertyBool('enable_junit_testing')) { + testImplementation 'org.junit.jupiter:junit-jupiter:5.7.1' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' + } +} + +apply from: 'gradle/scripts/dependencies.gradle' + +if (propertyBool('use_access_transformer')) { + def atFiles = propertyStringList('access_transformer_locations').collect { location -> + def atFile = file("src/main/resources/${location}") + if (!atFile.exists()) { + throw new GradleException("Access Transformer file [$atFile] does not exist!") + } + atFile + } + tasks.named('applyJST').configure { + accessTransformerFiles.from(atFiles) + } +} + +processResources { + inputs.property 'mod_id', propertyString('mod_id') + inputs.property 'mod_name', propertyString('mod_name') + inputs.property 'mod_version', propertyString('mod_version') + inputs.property 'mcversion', minecraft.mcVersion.get() + inputs.property 'mod_description', propertyString('mod_description') + inputs.property 'mod_authors', propertyStringList('mod_authors', ',').join(', ') + inputs.property 'mod_credits', propertyString('mod_credits') + inputs.property 'mod_url', propertyString('mod_url') + inputs.property 'mod_update_json', propertyString('mod_update_json') + inputs.property 'mod_logo_path', propertyString('mod_logo_path') + inputs.property 'mixin_refmap', propertyString('mixin_refmap') + + // Retain the existing mcmod.info placeholders while exposing the template-style names too. + filesMatching(['mcmod.info', 'pack.mcmeta']) { + expand( + 'mod_id': propertyString('mod_id'), + 'mod_name': propertyString('mod_name'), + 'mod_version': propertyString('mod_version'), + 'version': propertyString('mod_version'), + 'mcversion': minecraft.mcVersion.get(), + 'mod_description': propertyString('mod_description'), + 'mod_authors': propertyStringList('mod_authors', ',').join(', '), + 'mod_credits': propertyString('mod_credits'), + 'mod_url': propertyString('mod_url'), + 'mod_update_json': propertyString('mod_update_json'), + 'mod_logo_path': propertyString('mod_logo_path'), + 'mixin_refmap': propertyString('mixin_refmap') + ) + } + + if (propertyBool('use_access_transformer')) { + rename '(.+_at.cfg)', 'META-INF/$1' + } +} + +jar { + manifest { + def attributeMap = [:] + if (propertyBool('is_coremod')) { + attributeMap['FMLCorePlugin'] = propertyString('coremod_plugin_class_name') + if (propertyBool('coremod_includes_mod')) { + attributeMap['FMLCorePluginContainsFMLMod'] = true + if (gradle.startParameter.taskNames.any { it in ['build', 'prepareObfModsFolder', 'runObfClient'] }) { + attributeMap['ForceLoadAsMod'] = true + } + } + } + if (propertyBool('use_access_transformer')) { + attributeMap['FMLAT'] = propertyString('access_transformer_locations') + } + + // Do not add MixinConfigs here: the early and late loaders select configs conditionally. + attributes(attributeMap) + } +} + +idea { + module { + inheritOutputDirs = true + } + project { + settings { + runConfigurations { + '1. Run Client'(Gradle) { + taskNames = ['runClient'] + } + '2. Run Server'(Gradle) { + taskNames = ['runServer'] + } + '3. Run Obfuscated Client'(Gradle) { + taskNames = ['runObfClient'] + } + '4. Run Obfuscated Server'(Gradle) { + taskNames = ['runObfServer'] + } + } + compiler.javac { + afterEvaluate { + javacAdditionalOptions = '-encoding utf8' + moduleJavacAdditionalOptions = [ + (project.name + '.main'): tasks.compileJava.options.compilerArgs.collect { '"' + it + '"' }.join(' ') + ] + } + } + } + } +} + +tasks.withType(JavaCompile).configureEach { + options.encoding = 'UTF-8' + if (propertyBool('use_modern_java_syntax')) { + if (name in ['compileMcLauncherJava', 'compilePatchedMcJava']) { + return + } + sourceCompatibility = '17' + targetCompatibility = '8' + options.release.set(8) + javaCompiler.set(javaToolchains.compilerFor { + languageVersion.set(JavaLanguageVersion.of(17)) + vendor.set(JvmVendorSpec.AZUL) + }) + } +} + +tasks.withType(Javadoc).configureEach { + if (propertyBool('use_modern_java_syntax')) { + sourceCompatibility = '17' + } +} + +tasks.named('injectTags', InjectTagsTask).configure { + onlyIf { + propertyBool('use_tags') && !tags.get().isEmpty() + } + outputClassName.set(propertyString('tag_class_name')) +} + +tasks.register('cleanroomAfterSync') { + group 'cleanroom helpers' + dependsOn 'injectTags' +} + +idea.project.settings { + taskTriggers { + afterSync 'cleanroomAfterSync' + } +} + +tasks.named('prepareObfModsFolder').configure { + finalizedBy 'prioritizeCoremods' +} + +tasks.register('prioritizeCoremods') { + dependsOn 'prepareObfModsFolder' + doLast { + fileTree('run/obfuscated').forEach { + if (it.isFile() && it.name =~ '(mixinbooter|configanytime)(-)([0-9])+\\.+([0-9])+(.jar)') { + it.renameTo(new File(it.parentFile, "!${it.name}")) + } + } + } +} + +String parserChangelog() { + if (!file('CHANGELOG.md').exists()) { + throw new GradleException('publish_with_changelog is true, but CHANGELOG.md does not exist in the workspace!') + } + String parsedChangelog = changelog.renderItem( + changelog.get(propertyString('mod_version')).withHeader(false).withEmptySections(false), + Changelog.OutputType.MARKDOWN) + if (parsedChangelog.isEmpty()) { + throw new GradleException('publish_with_changelog is true, but the changelog for the latest version is empty!') + } + parsedChangelog +} + +if (propertyBool('publish_to_curseforge')) { + assertProperty 'curseforge_project_id' + apply plugin: 'net.darkhax.curseforgegradle' + tasks.register('curseforge', TaskPublishCurseForge) { + disableVersionDetection() + group = 'publishing' + description = "Uploads CurseForge project ${propertyString('curseforge_project_id')}" + } +} + +apply from: 'gradle/scripts/publishing.gradle' +apply from: 'gradle/scripts/extra.gradle' diff --git a/build.gradle.kts b/build.gradle.kts deleted file mode 100644 index b5da34a4..00000000 --- a/build.gradle.kts +++ /dev/null @@ -1,346 +0,0 @@ -import org.jetbrains.gradle.ext.Gradle -import org.jetbrains.gradle.ext.RunConfigurationContainer -import java.util.* - -plugins { - kotlin("jvm") version "2.2.0" - kotlin("plugin.serialization") version "2.2.0" - id("java-library") - id("maven-publish") - id("org.jetbrains.gradle.plugin.idea-ext") version "1.1.7" - id("eclipse") - id("com.gtnewhorizons.retrofuturagradle") version "1.4.0" -} - -// Project properties -group = "hellfirepvp.modularmachinery" -version = "2.3.2" - -// Set the toolchain version to decouple the Java we run Gradle with from the Java used to compile and run the mod -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(17)) - // Azul covers the most platforms for Java 8 toolchains, crucially including MacOS arm64 - vendor.set(JvmVendorSpec.AZUL) - } - // Generate sources and javadocs jars when building and publishing - withSourcesJar() - withJavadocJar() -} - -kotlin { - jvmToolchain(8) -} - -// Most RFG configuration lives here, see the JavaDoc for com.gtnewhorizons.retrofuturagradle.MinecraftExtension -minecraft { - mcVersion.set("1.12.2") - - // Username for client run configurations - username.set("Kasumi_Nova") - - // Generate a field named VERSION with the mod version in the injected Tags class - injectedTags.put("VERSION", project.version) - - // If you need the old replaceIn mechanism, prefer the injectTags task because it doesn't inject a javac plugin. - // tagReplacementFiles.add("RfgExampleMod.java") - - // Enable assertions in the mod's package when running the client or server - val args = mutableListOf("-ea:${project.group}") - - // Mixin args - args.add("-Dfml.coreMods.load=github.kasuminova.mmce.mixin.MMCEEarlyMixinLoader") - args.add("-Dmixin.hotSwap=true") - args.add("-Dmixin.checks.interfaces=true") - args.add("-Dmixin.debug.export=true") - extraRunJvmArguments.addAll(args) - - // If needed, add extra tweaker classes like for mixins. - // extraTweakClasses.add("org.spongepowered.asm.launch.MixinTweaker") - - // Exclude some Maven dependency groups from being automatically included in the reobfuscated runs - groupsToExcludeFromAutoReobfMapping.addAll("com.diffplug", "com.diffplug.durian", "net.industrial-craft") -} - -// Generates a class named rfg.examplemod.Tags with the mod version in it, you can find it at -tasks.injectTags.configure { - outputClassName.set("${project.group}.Tags") -} - -// Put the version from gradle into mcmod.info -tasks.processResources.configure { - inputs.property("version", project.version) - inputs.property("mcversion", minecraft.mcVersion.get()) - - filesMatching("mcmod.info") { - expand(mapOf("version" to project.version, "mcversion" to minecraft.mcVersion.get())) - } -} - -tasks.compileJava.configure { - sourceCompatibility = "17" - options.release = 8 - options.encoding = "UTF-8" // Use the UTF-8 charset for Java compilation - - javaCompiler = javaToolchains.compilerFor { - languageVersion = JavaLanguageVersion.of(17) - } -} - -tasks.jar.configure { - manifest { - val attributes = manifest.attributes - attributes["FMLCorePlugin"] = "github.kasuminova.mmce.mixin.MMCEEarlyMixinLoader" - attributes["FMLCorePluginContainsFMLMod"] = true - } -} - -tasks.javadoc.configure { - // No need for JavaDoc. - actions = Collections.emptyList() -} - -// Create a new dependency type for runtime-only dependencies that don't get included in the maven publication -val runtimeOnlyNonPublishable: Configuration by configurations.creating { - description = "Runtime only dependencies that are not published alongside the jar" - isCanBeConsumed = false - isCanBeResolved = false -} -listOf(configurations.runtimeClasspath, configurations.testRuntimeClasspath).forEach { - it.configure { - extendsFrom( - runtimeOnlyNonPublishable - ) - } -} - -// Add an access tranformer -// tasks.deobfuscateMergedJarToSrg.configure {accessTransformerFiles.from("src/main/resources/META-INF/mymod_at.cfg")} - -// Dependencies -repositories { - flatDir { - dirs("libs") - } - maven { - url = uri("https://maven.aliyun.com/nexus/content/groups/public/") - } - maven { - url = uri("https://maven.aliyun.com/nexus/content/repositories/jcenter") - } - maven { - url = uri("https://maven.cleanroommc.com") - } - maven { - url = uri("https://cfa2.cursemaven.com") - } - maven { - url = uri("https://cursemaven.com") - } - maven { - url = uri("https://maven.blamejared.com/") - } - maven { - url = uri("https://repo.spongepowered.org/maven") - } - maven { - name = "OvermindDL1 Maven" - url = uri("https://gregtech.overminddl1.com/") - mavenContent { - excludeGroup("net.minecraftforge") // missing the `universal` artefact - } - } - maven { - name = "GeckoLib" - url = uri("https://dl.cloudsmith.io/public/geckolib3/geckolib/maven/") - } - maven { - name = "GTNH Maven" - url = uri("https://nexus.gtnewhorizons.com/repository/public/") - } -} - -dependencies { - annotationProcessor("com.github.bsideup.jabel:jabel-javac-plugin:0.4.2") - compileOnly("com.github.bsideup.jabel:jabel-javac-plugin:0.4.2") - // workaround for https://github.com/bsideup/jabel/issues/174 - annotationProcessor("net.java.dev.jna:jna-platform:5.13.0") - // Allow jdk.unsupported classes like sun.misc.Unsafe, workaround for JDK-8206937 and fixes Forge crashes in tests. - patchedMinecraft("me.eigenraven.java8unsupported:java-8-unsupported-shim:1.0.0") - // allow Jabel to work in tests - testAnnotationProcessor("com.github.bsideup.jabel:jabel-javac-plugin:1.0.0") - testCompileOnly("com.github.bsideup.jabel:jabel-javac-plugin:1.0.0") { - isTransitive = false // We only care about the 1 annotation class - } - testCompileOnly("me.eigenraven.java8unsupported:java-8-unsupported-shim:1.0.0") - - // Mixins - val mixin : String = modUtils.enableMixins("zone.rong:mixinbooter:8.9", "mixins.mmce.refmap.json").toString() - api (mixin) { - isTransitive = false - } - annotationProcessor("org.ow2.asm:asm-debug-all:5.2") - annotationProcessor("com.google.guava:guava:30.0-jre") - annotationProcessor("com.google.code.gson:gson:2.8.9") - annotationProcessor (mixin) { - isTransitive = false - } - - // Kotlin Support - runtimeOnly("io.github.chaosunity.forgelin:Forgelin-Continuous:2.2.0.0") { - isTransitive = false - } - compileOnly("org.jetbrains.kotlin:kotlin-stdlib:2.2.0") - compileOnly("org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.1") - - implementation("CraftTweaker2:CraftTweaker2-MC1120-Main:1.12-4.+") - implementation(rfg.deobf("curse.maven:had-enough-items-557549:4810661")) - implementation(rfg.deobf("curse.maven:zenutil-401178:5056679")) - implementation(rfg.deobf("curse.maven:RedstoneFlux-270789:2920436")) - implementation(rfg.deobf("curse.maven:CodeChickenLib-242818:2779848")) - implementation(rfg.deobf("curse.maven:brandonscore-231382:3051539")) - implementation(rfg.deobf("curse.maven:draconicevolution-223565:3051542")) - implementation(rfg.deobf("curse.maven:the-one-probe-245211:2667280")) - implementation(rfg.deobf("curse.maven:Mekanism-268560:2835175")) - compileOnly(rfg.deobf("curse.maven:industrialcraft-2-242638:3078604")) - compileOnly(rfg.deobf("curse.maven:nuclearcraft-overhauled-336895:3862197")) - compileOnly(rfg.deobf("curse.maven:flux-networks-248020:3178199")) - compileOnly(rfg.deobf("curse.maven:tinkers-construct-74072:2902483")) - compileOnly(rfg.deobf("curse.maven:mantle-74924:2713386")) - implementation(rfg.deobf("curse.maven:tx-loader-706505:4515357")) - implementation(rfg.deobf("curse.maven:cofh-core-69162:2920433")) - implementation(rfg.deobf("curse.maven:cofh-world-271384:2920434")) - implementation(rfg.deobf("curse.maven:thermal-foundation-222880:2926428")) - implementation(rfg.deobf("curse.maven:thermal-expansion-69163:2926431")) - - // AE2 Compat - // implementation(rfg.deobf("curse.maven:applied-energistics-2-223794:2747063")) - implementation(rfg.deobf("curse.maven:ae2-extended-life-570458:6302098")) - implementation(rfg.deobf("curse.maven:ae2-fluid-crafting-rework-623955:5504001")) - implementation(rfg.deobf("curse.maven:mekanism-energistics-1027681:5408319")) - implementation(rfg.deobf("curse.maven:nae2-884359:5380800")) - - // GeckoLib - implementation("software.bernie.geckolib:geckolib-forge-1.12.2:3.0.31") - // GTCEu / Bloom Effect Support - compileOnly(rfg.deobf("curse.maven:gregtech-ce-unofficial-557242:5322654")) - // Bloom Effect Support - implementation(rfg.deobf("kasuminova:lumenized:1.0.3:dev")) - - // Multiblocked - implementation(rfg.deobf("curse.maven:multiblocked-604054:4753960")) - - // Modular Magic compact - compileOnly(rfg.deobf("curse.maven:astral-sorcery-241721:3044416")) - implementation(rfg.deobf("curse.maven:blood-magic-224791:2822288")) - compileOnly(rfg.deobf("curse.maven:thaumcraft-223628:2629023")) - compileOnly(rfg.deobf("curse.maven:extrautils2-225561:2678374")) - compileOnly(rfg.deobf("curse.maven:naturesaura-306626:2882138")) - compileOnly(rfg.deobf("curse.maven:botania-225643:3330934")) - compileOnly(rfg.deobf("curse.maven:baubles-227083:2518667")) - implementation(rfg.deobf("curse.maven:guideapi-228832:2645992")) - compileOnly(rfg.deobf("curse.maven:patchouli-306770:3162874")) - compileOnly(rfg.deobf("curse.maven:thaumic-augmentation-319441:4486505")) - // Performance Test Tool - runtimeOnly(rfg.deobf("curse.maven:spark-361579:3542217")) - // Optimization - implementation(rfg.deobf("curse.maven:stellarcore-1064321:5560444")) - implementation(rfg.deobf("curse.maven:configanytime-870276:5212709")) -} - -// Publishing to a Maven repository -publishing { - publications { - create("maven") { - from(components["java"]) - } - } - repositories { -// // Example: publishing to the GTNH Maven repository -// maven { -// url = uri("http://jenkins.usrv.eu:8081/nexus/content/repositories/releases") -// isAllowInsecureProtocol = true -// credentials { -// username = System.getenv("MAVEN_USER") ?: "NONE" -// password = System.getenv("MAVEN_PASSWORD") ?: "NONE" -// } -// } - } -} - -// IDE Settings -//eclipse { -// classpath { -// isDownloadSources = true -// isDownloadJavadoc = true -// } -//} - -idea { - module { - isDownloadJavadoc = true - isDownloadSources = true - inheritOutputDirs = true // Fix resources in IJ-Native runs - } - project { - this.withGroovyBuilder { - "settings" { - "runConfigurations" { - val self = this.delegate as RunConfigurationContainer - self.add(Gradle("1. Run Client").apply { - setProperty("taskNames", listOf("runClient")) - }) - self.add(Gradle("2. Run Server").apply { - setProperty("taskNames", listOf("runServer")) - }) - self.add(Gradle("3. Run Obfuscated Client").apply { - setProperty("taskNames", listOf("runObfClient")) - }) - self.add(Gradle("4. Run Obfuscated Server").apply { - setProperty("taskNames", listOf("runObfServer")) - }) - /* - These require extra configuration in IntelliJ, so are not enabled by default - self.add(Application("Run Client (IJ Native, Deprecated)", project).apply { - mainClass = "GradleStart" - moduleName = project.name + ".ideVirtualMain" - afterEvaluate { - val runClient = tasks.runClient.get() - workingDirectory = runClient.workingDir.absolutePath - programParameters = runClient.calculateArgs(project).map { '"' + it + '"' }.joinToString(" ") - jvmArgs = runClient.calculateJvmArgs(project).map { '"' + it + '"' }.joinToString(" ") + - ' ' + runClient.systemProperties.map { "\"-D" + it.key + '=' + it.value.toString() + '"' } - .joinToString(" ") - } - }) - self.add(Application("Run Server (IJ Native, Deprecated)", project).apply { - mainClass = "GradleStartServer" - moduleName = project.name + ".ideVirtualMain" - afterEvaluate { - val runServer = tasks.runServer.get() - workingDirectory = runServer.workingDir.absolutePath - programParameters = runServer.calculateArgs(project).map { '"' + it + '"' }.joinToString(" ") - jvmArgs = runServer.calculateJvmArgs(project).map { '"' + it + '"' }.joinToString(" ") + - ' ' + runServer.systemProperties.map { "\"-D" + it.key + '=' + it.value.toString() + '"' } - .joinToString(" ") - } - }) - */ - } - "compiler" { - val self = this.delegate as org.jetbrains.gradle.ext.IdeaCompilerConfiguration - afterEvaluate { - self.javac.moduleJavacAdditionalOptions = mapOf( - (project.name + ".main") to - tasks.compileJava.get().options.compilerArgs.map { '"' + it + '"' }.joinToString(" ") - ) - } - } - } - } - } -} - -tasks.processIdeaSettings.configure { - dependsOn(tasks.injectTags) -} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 00000000..577a5fcd --- /dev/null +++ b/gradle.properties @@ -0,0 +1,84 @@ +# Gradle +org.gradle.jvmargs = -Xmx3G +org.gradle.parallel = true +org.gradle.caching = true + +# The Kotlin plugin otherwise adds kotlin-stdlib as an implementation dependency. The mod supplies it through Forgelin. +kotlin.stdlib.default.dependency = false + +# Source and test options +use_modern_java_syntax = true +generate_sources_jar = true +generate_javadocs_jar = false +enable_junit_testing = false +show_testing_output = false + +# Mod information +mod_version = 2.3.2 +root_package = hellfirepvp.modularmachinery +mod_id = modularmachinery +mod_name = Modular Machinery: Community Edition +mod_description = A modpack-maker toolset to create custom, massive, unique and complex machines and recipes from scratch with JSON. +mod_url = https://www.curseforge.com/minecraft/mc-mods/modularmachinery-community-edition +mod_update_json = +mod_authors = HellFirePvP, wiiv, KasumiNova, youyihj, ikexing +mod_credits = HellFirePvP code, wiiv ALL THE TEXTURES :3, and KasumiNova Improvements! And more community edition contributors! +mod_logo_path = assets/modularmachinery/textures/logo.png + +# Minecraft and run configurations +mapping_channel = stable +mapping_version = 39 +use_dependency_at_files = true +minecraft_username = Kasumi_Nova +extra_jvm_args = -Dfml.coreMods.load=github.kasuminova.mmce.mixin.MMCEEarlyMixinLoader -Dmixin.hotSwap=true +extra_tweak_classes = +change_minecraft_sources = false + +# Build-time tags +use_tags = true +tag_class_name = hellfirepvp.modularmachinery.Tags + +# Access transformers +use_access_transformer = false +access_transformer_locations = ${mod_id}_at.cfg + +# MixinBooter. Config loading remains in MMCEEarlyMixinLoader/MMCELateMixinLoader, so no manifest config list is used. +use_mixins = true +mixin_booter_version = 8.9 +generate_mixins_json = false +mixin_configs = +mixin_refmap = mixins.mmce.refmap.json + +# Coremod +is_coremod = true +coremod_includes_mod = true +coremod_plugin_class_name = github.kasuminova.mmce.mixin.MMCEEarlyMixinLoader + +# Optional AssetMover support +use_asset_mover = false +asset_mover_version = 2.5 + +# Maven publishing (provide MAVEN_USER and MAVEN_PASS) +publish_to_maven = false +publish_to_local_maven = false +maven_name = ${mod_name} +maven_url = + +# Release publishing +release_type = release +publish_with_changelog = ${{ it.file('CHANGELOG.md').exists() }} +client_side = true +server_side = true + +# CurseForge (provide CURSEFORGE_TOKEN) +publish_to_curseforge = false +curseforge_project_id = +curseforge_debug = false +curseforge_changelog = +curseforge_display_name = + +# Modrinth (provide MODRINTH_TOKEN) +publish_to_modrinth = false +modrinth_project_id = +modrinth_sync_readme = false +modrinth_debug = false diff --git a/gradle/scripts/dependencies.gradle b/gradle/scripts/dependencies.gradle new file mode 100644 index 00000000..16cb25af --- /dev/null +++ b/gradle/scripts/dependencies.gradle @@ -0,0 +1,110 @@ +apply from: 'gradle/scripts/helpers.gradle' + +repositories { + flatDir { + dirs 'libs' + } + maven { + name 'Aliyun Public' + url 'https://maven.aliyun.com/nexus/content/groups/public/' + } + maven { + name 'Aliyun JCenter' + url 'https://maven.aliyun.com/nexus/content/repositories/jcenter' + } + maven { + name 'CleanroomMC Maven' + url 'https://maven.cleanroommc.com' + } + // Keep both endpoints used by the legacy build: some historical files resolve through the CFA mirror. + maven { + name 'CFA2 CurseMaven' + url 'https://cfa2.cursemaven.com' + } + maven { + name 'CurseMaven' + url 'https://cursemaven.com' + } + maven { + name 'BlameJared Maven' + url 'https://maven.blamejared.com/' + } + maven { + name 'SpongePowered Maven' + url 'https://repo.spongepowered.org/maven' + } + maven { + name 'OvermindDL1 Maven' + url 'https://gregtech.overminddl1.com/' + mavenContent { + excludeGroup 'net.minecraftforge' // This repository lacks the Forge universal artifact. + } + } + maven { + name 'GeckoLib Maven' + url 'https://dl.cloudsmith.io/public/geckolib3/geckolib/maven/' + } + maven { + name 'GTNH Maven' + url 'https://nexus.gtnewhorizons.com/repository/public/' + } + mavenLocal() // Keep last so normal repository caches win. +} + +dependencies { + // Kotlin is supplied at runtime by Forgelin-Continuous. Its default Kotlin stdlib dependency is disabled in gradle.properties. + runtimeOnly('io.github.chaosunity.forgelin:Forgelin-Continuous:2.2.0.0') { + transitive = false + } + compileOnly 'org.jetbrains.kotlin:kotlin-stdlib:2.2.0' + compileOnly 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.1' + + devOnlyNonPublishable 'CraftTweaker2:CraftTweaker2-MC1120-Main:1.12-4.+' + devOnlyNonPublishable rfg.deobf('curse.maven:had-enough-items-557549:4810661') + devOnlyNonPublishable rfg.deobf('curse.maven:zenutil-401178:5056679') + devOnlyNonPublishable rfg.deobf('curse.maven:RedstoneFlux-270789:2920436') + devOnlyNonPublishable rfg.deobf('curse.maven:CodeChickenLib-242818:2779848') + devOnlyNonPublishable rfg.deobf('curse.maven:brandonscore-231382:3051539') + devOnlyNonPublishable rfg.deobf('curse.maven:draconicevolution-223565:3051542') + devOnlyNonPublishable rfg.deobf('curse.maven:the-one-probe-245211:2667280') + devOnlyNonPublishable rfg.deobf('curse.maven:Mekanism-268560:2835175') + compileOnly rfg.deobf('curse.maven:industrialcraft-2-242638:3078604') + compileOnly rfg.deobf('curse.maven:nuclearcraft-overhauled-336895:3862197') + compileOnly rfg.deobf('curse.maven:flux-networks-248020:3178199') + compileOnly rfg.deobf('curse.maven:tinkers-construct-74072:2902483') + compileOnly rfg.deobf('curse.maven:mantle-74924:2713386') + devOnlyNonPublishable rfg.deobf('curse.maven:tx-loader-706505:4515357') + devOnlyNonPublishable rfg.deobf('curse.maven:cofh-core-69162:2920433') + devOnlyNonPublishable rfg.deobf('curse.maven:cofh-world-271384:2920434') + devOnlyNonPublishable rfg.deobf('curse.maven:thermal-foundation-222880:2926428') + devOnlyNonPublishable rfg.deobf('curse.maven:thermal-expansion-69163:2926431') + + // AE2 compatibility + // devOnlyNonPublishable rfg.deobf('curse.maven:applied-energistics-2-223794:2747063') + devOnlyNonPublishable rfg.deobf('curse.maven:ae2-extended-life-570458:6302098') + devOnlyNonPublishable rfg.deobf('curse.maven:ae2-fluid-crafting-rework-623955:5504001') + devOnlyNonPublishable rfg.deobf('curse.maven:mekanism-energistics-1027681:5408319') + devOnlyNonPublishable rfg.deobf('curse.maven:nae2-884359:5380800') + + devOnlyNonPublishable 'software.bernie.geckolib:geckolib-forge-1.12.2:3.0.31' + compileOnly rfg.deobf('curse.maven:gregtech-ce-unofficial-557242:5322654') + devOnlyNonPublishable rfg.deobf('kasuminova:lumenized:1.0.3:dev') + devOnlyNonPublishable rfg.deobf('curse.maven:multiblocked-604054:4753960') + + // Modular Magic compatibility + compileOnly rfg.deobf('curse.maven:astral-sorcery-241721:3044416') + devOnlyNonPublishable rfg.deobf('curse.maven:blood-magic-224791:2822288') + compileOnly rfg.deobf('curse.maven:thaumcraft-223628:2629023') + compileOnly rfg.deobf('curse.maven:extrautils2-225561:2678374') + compileOnly rfg.deobf('curse.maven:naturesaura-306626:2882138') + compileOnly rfg.deobf('curse.maven:botania-225643:3330934') + compileOnly rfg.deobf('curse.maven:baubles-227083:2518667') + devOnlyNonPublishable rfg.deobf('curse.maven:guideapi-228832:2645992') + compileOnly rfg.deobf('curse.maven:patchouli-306770:3162874') + compileOnly rfg.deobf('curse.maven:thaumic-augmentation-319441:4486505') + + // Developer-only runtime tools and optimizations from the previous RFG build. + devOnlyNonPublishable rfg.deobf('curse.maven:spark-361579:3542217') + devOnlyNonPublishable rfg.deobf('curse.maven:stellarcore-1064321:5560444') + devOnlyNonPublishable rfg.deobf('curse.maven:configanytime-870276:5212709') +} diff --git a/gradle/scripts/extra.gradle b/gradle/scripts/extra.gradle new file mode 100644 index 00000000..9f3a595b --- /dev/null +++ b/gradle/scripts/extra.gradle @@ -0,0 +1,43 @@ +// CI helpers, modelled after AE2-PowerTools. They do not alter ordinary local builds. + +tasks.register('printChangelog') { + group 'publishing' + description 'Prints the changelog for the current mod_version to stdout' + doLast { + if (!file('CHANGELOG.md').exists()) { + throw new GradleException('CHANGELOG.md does not exist!') + } + println parserChangelog() + } +} + +tasks.register('printVersion') { + group 'publishing' + description 'Prints the mod_version to stdout' + doLast { + println propertyString('mod_version') + } +} + +tasks.register('printFullVersion') { + group 'publishing' + description 'Prints the full mod version to stdout' + doLast { + println "${propertyString('mod_name')} ${propertyString('mod_version')}" + } +} + +tasks.register('printReleaseType') { + group 'publishing' + description 'Infers release, beta, or alpha from mod_version' + doLast { + def version = propertyString('mod_version').toLowerCase() + def releaseType = 'release' + if (version.contains('alpha') || version =~ /^\\d+(\\.\\d+)*a\\d*$/) { + releaseType = 'alpha' + } else if (version.contains('beta') || version.contains('rc') || version.contains('pre') || version =~ /^\\d+(\\.\\d+)*b\\d*$/) { + releaseType = 'beta' + } + println releaseType + } +} diff --git a/gradle/scripts/helpers.gradle b/gradle/scripts/helpers.gradle new file mode 100644 index 00000000..0b3f2ee7 --- /dev/null +++ b/gradle/scripts/helpers.gradle @@ -0,0 +1,96 @@ +import groovy.text.SimpleTemplateEngine +import org.codehaus.groovy.runtime.MethodClosure + +ext.propertyString = this.&propertyString as MethodClosure +ext.propertyBool = this.&propertyBool as MethodClosure +ext.propertyStringList = this.&propertyStringList as MethodClosure +ext.interpolate = this.&interpolate as MethodClosure +ext.assertProperty = this.&assertProperty as MethodClosure +ext.assertSubProperties = this.&assertSubProperties as MethodClosure +ext.setDefaultProperty = this.&setDefaultProperty as MethodClosure +ext.assertEnvironmentVariable = this.&assertEnvironmentVariable as MethodClosure + +String propertyString(String key) { + return $property(key).toString() +} + +boolean propertyBool(String key) { + return propertyString(key).toBoolean() +} + +Collection propertyStringList(String key) { + return propertyStringList(key, ' ') +} + +Collection propertyStringList(String key, String delimit) { + return propertyString(key).split(delimit).findAll { !it.isEmpty() } +} + +private Object $property(String key) { + def value = project.findProperty(key) + if (value instanceof String) { + return interpolate(value) + } + return value +} + +String interpolate(String value) { + if (value.startsWith('${{') && value.endsWith('}}')) { + value = value.substring(3, value.length() - 2) + Binding newBinding = new Binding(this.binding.getVariables()) + newBinding.setProperty('it', this) + return new GroovyShell(this.getClass().getClassLoader(), newBinding).evaluate(value) + } + if (value.contains('${')) { + return new SimpleTemplateEngine().createTemplate(value).make(project.properties).toString() + } + return value +} + +void assertProperty(String propertyName) { + def property = property(propertyName) + if (property == null) { + throw new GradleException("Property ${propertyName} is not defined!") + } + if (property.isEmpty()) { + throw new GradleException("Property ${propertyName} is empty!") + } +} + +void assertSubProperties(String propertyName, String... subPropertyNames) { + assertProperty(propertyName) + if (propertyBool(propertyName)) { + for (String subPropertyName : subPropertyNames) { + assertProperty(subPropertyName) + } + } +} + +void setDefaultProperty(String propertyName, boolean warn, defaultValue) { + def property = property(propertyName) + def exists = true + if (property == null) { + exists = false + if (warn) { + project.logger.log(LogLevel.WARN, "Property ${propertyName} is not defined!") + } + } else if (property.isEmpty()) { + exists = false + if (warn) { + project.logger.log(LogLevel.WARN, "Property ${propertyName} is empty!") + } + } + if (!exists) { + project.setProperty(propertyName, defaultValue.toString()) + } +} + +void assertEnvironmentVariable(String propertyName) { + def property = System.getenv(propertyName) + if (property == null) { + throw new GradleException("System Environment Variable $propertyName is not defined!") + } + if (property.isEmpty()) { + throw new GradleException("Property $propertyName is empty!") + } +} diff --git a/gradle/scripts/publishing.gradle b/gradle/scripts/publishing.gradle new file mode 100644 index 00000000..ca7503ea --- /dev/null +++ b/gradle/scripts/publishing.gradle @@ -0,0 +1,105 @@ +apply from: 'gradle/scripts/helpers.gradle' + +setDefaultProperty('publish_to_maven', true, false) +setDefaultProperty('publish_to_curseforge', true, false) +setDefaultProperty('publish_to_modrinth', true, false) + +// CI may override these for release-candidate tags whose changelog header differs from mod_version. +setDefaultProperty('curseforge_changelog', false, '') +setDefaultProperty('curseforge_display_name', false, '') + +if (propertyBool('publish_to_maven')) { + assertProperty('maven_name') + assertProperty('maven_url') + publishing { + repositories { + maven { + name propertyString('maven_name').replaceAll('\\s', '') + url propertyString('maven_url') + credentials(PasswordCredentials) + } + } + publications { + mavenJava(MavenPublication) { + from components.java + setGroupId(propertyString('root_package')) + setArtifactId(propertyString('mod_id')) + } + } + } +} + +if (propertyBool('publish_to_curseforge')) { + assertProperty('curseforge_project_id') + assertProperty('release_type') + setDefaultProperty('curseforge_debug', false, false) + setDefaultProperty('client_side', false, true) + setDefaultProperty('server_side', false, true) + + if (!propertyBool('client_side') && !propertyBool('server_side')) { + throw new GradleException('At least one of client_side and server_side must be true!') + } + + tasks.named('curseforge') { + debugMode = propertyBool('curseforge_debug') + apiToken = System.getenv('CURSEFORGE_TOKEN') == null ? '' : System.getenv('CURSEFORGE_TOKEN') + dependsOn(tasks.reobfJar) + + def mainFile = upload(propertyString('curseforge_project_id'), tasks.reobfJar) + def changelogOverride = propertyString('curseforge_changelog') + def changelogRaw = !changelogOverride.isEmpty() ? changelogOverride : + (propertyBool('publish_with_changelog') ? parserChangelog() : '') + def displayNameOverride = propertyString('curseforge_display_name') + + mainFile.displayName = !displayNameOverride.isEmpty() ? displayNameOverride : + "${propertyString('mod_name')} ${propertyString('mod_version')}" + mainFile.releaseType = propertyString('release_type') + if (!changelogRaw.isEmpty()) { + mainFile.changelog = changelogRaw + mainFile.changelogType = 'markdown' + } + mainFile.addJavaVersion('Java 8') + mainFile.addModLoader('Forge') + mainFile.addGameVersion('1.12.2') + if (propertyBool('client_side')) mainFile.addEnvironment('Client') + if (propertyBool('server_side')) mainFile.addEnvironment('Server') + + if (propertyBool('use_mixins')) { + mainFile.addRelation('mixin-booter', 'requiredDependency') + } + if (propertyBool('use_asset_mover')) { + mainFile.addRelation('assetmover', 'requiredDependency') + } + } +} + +if (propertyBool('publish_to_modrinth')) { + apply plugin: 'com.modrinth.minotaur' + assertProperty('modrinth_project_id') + assertProperty('release_type') + setDefaultProperty('modrinth_debug', false, false) + + modrinth { + token = System.getenv('MODRINTH_TOKEN') == null ? '' : System.getenv('MODRINTH_TOKEN') + projectId = propertyString('modrinth_project_id') + versionNumber = propertyString('mod_version') + versionType = propertyString('release_type') + uploadFile = tasks.reobfJar + gameVersions = ['1.12.2'] + loaders = ['forge'] + debugMode = propertyBool('modrinth_debug') + if (propertyBool('use_mixins') || propertyBool('use_asset_mover')) { + dependencies { + if (propertyBool('use_mixins')) required.project 'mixinbooter' + if (propertyBool('use_asset_mover')) required.project 'assetmover' + } + } + if (propertyBool('publish_with_changelog')) { + changelog = parserChangelog() + } + if (propertyBool('modrinth_sync_readme')) { + syncBodyFrom = file('README.md').text + tasks.modrinth.dependsOn(tasks.modrinthSyncBody) + } + } +} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0817a5c9..48d593f4 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,7 @@ #Fri Mar 24 08:46:50 CST 2023 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists https.protocols=TLSv1.1,TLSv1.2,TLSv1.3 diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 00000000..0feb7f52 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,22 @@ +pluginManagement { + repositories { + maven { + name 'GTNH Maven' + url 'https://nexus.gtnewhorizons.com/repository/public/' + mavenContent { + includeGroup 'com.gtnewhorizons' + includeGroupByRegex 'com\\.gtnewhorizons\\..+' + } + } + gradlePluginPortal() + mavenCentral() + mavenLocal() + } +} + +plugins { + // Required for Java 8/17 toolchain provisioning when Gradle itself runs on another JDK. + id 'org.gradle.toolchains.foojay-resolver-convention' version '1.0.0' +} + +rootProject.name = 'ModularMachinery-CE' diff --git a/settings.gradle.kts b/settings.gradle.kts deleted file mode 100644 index 151603a0..00000000 --- a/settings.gradle.kts +++ /dev/null @@ -1,34 +0,0 @@ -//pluginManagement { -// repositories { -// maven { url = 'https://maven.minecraftforge.net/' } -// maven { -// name 'Garden of Fancy' -// url 'https://maven.gofancy.wtf/releases' -// } -// gradlePluginPortal() -// } -//} -pluginManagement { - repositories { - maven { - // RetroFuturaGradle - name = "GTNH Maven" - url = uri("https://nexus.gtnewhorizons.com/repository/public/") - isAllowInsecureProtocol = true - mavenContent { - includeGroupByRegex("com\\.gtnewhorizons\\..+") - includeGroup("com.gtnewhorizons") - } - } - gradlePluginPortal() - mavenCentral() - mavenLocal() - } -} - -plugins { - // Automatic toolchain provisioning - id("org.gradle.toolchains.foojay-resolver-convention") version "0.4.0" -} - -rootProject.name = "ModularMachinery-CE" diff --git a/src/main/java/github/kasuminova/mmce/client/gui/AEBaseGuiContainerDynamic.java b/src/main/java/github/kasuminova/mmce/client/gui/AEBaseGuiContainerDynamic.java index 1c1dcedd..cdb99abd 100644 --- a/src/main/java/github/kasuminova/mmce/client/gui/AEBaseGuiContainerDynamic.java +++ b/src/main/java/github/kasuminova/mmce/client/gui/AEBaseGuiContainerDynamic.java @@ -115,7 +115,7 @@ protected void updateHoveredSlot(final int mouseX, final int mouseY) { .orElse(null); } - protected boolean isMouseOverSlot(Slot slotIn, int mouseX, int mouseY) { + public boolean isMouseOverSlot(Slot slotIn, int mouseX, int mouseY) { return this.isPointInRegion(slotIn.xPos, slotIn.yPos, 16, 16, mouseX, mouseY); } diff --git a/src/main/java/github/kasuminova/mmce/client/gui/GuiContainerDynamic.java b/src/main/java/github/kasuminova/mmce/client/gui/GuiContainerDynamic.java index 9ba4808a..3da0c03c 100644 --- a/src/main/java/github/kasuminova/mmce/client/gui/GuiContainerDynamic.java +++ b/src/main/java/github/kasuminova/mmce/client/gui/GuiContainerDynamic.java @@ -139,7 +139,7 @@ protected void updateHoveredSlot(final int mouseX, final int mouseY) { .orElse(null); } - protected boolean isMouseOverSlot(Slot slotIn, int mouseX, int mouseY) { + public boolean isMouseOverSlot(Slot slotIn, int mouseX, int mouseY) { return this.isPointInRegion(slotIn.xPos, slotIn.yPos, 16, 16, mouseX, mouseY); } diff --git a/src/main/java/github/kasuminova/mmce/common/event/EventHandler.java b/src/main/java/github/kasuminova/mmce/common/event/EventHandler.java new file mode 100644 index 00000000..49130dc2 --- /dev/null +++ b/src/main/java/github/kasuminova/mmce/common/event/EventHandler.java @@ -0,0 +1,15 @@ +package github.kasuminova.mmce.common.event; + +/** + * Script callback for Modular Machinery events. + * + *

+ * Script integrations adapt their own function types to this interface on + * their side, so machine and recipe state never depends on a particular + * scripting mod. + */ +@FunctionalInterface +public interface EventHandler { + + void handle(E event); +} diff --git a/src/main/java/github/kasuminova/mmce/common/event/machine/MachineEvent.java b/src/main/java/github/kasuminova/mmce/common/event/machine/MachineEvent.java index 44207a74..1e3af5f4 100644 --- a/src/main/java/github/kasuminova/mmce/common/event/machine/MachineEvent.java +++ b/src/main/java/github/kasuminova/mmce/common/event/machine/MachineEvent.java @@ -1,7 +1,7 @@ package github.kasuminova.mmce.common.event.machine; import crafttweaker.annotations.ZenRegister; -import crafttweaker.util.IEventHandler; +import github.kasuminova.mmce.common.event.EventHandler; import github.kasuminova.mmce.common.handler.UpgradeMachineEventHandler; import github.kasuminova.mmce.common.helper.IMachineController; import hellfirepvp.modularmachinery.ModularMachinery; @@ -67,12 +67,12 @@ public void postCrTEvent() { if (foundMachine == null) { return; } - List> handlers = foundMachine.getMachineEventHandlers(getClass()); + List> handlers = foundMachine.getMachineEventHandlers(getClass()); if (handlers == null) { return; } - for (IEventHandler handler : handlers) { + for (EventHandler handler : handlers) { handler.handle(this); if (isCanceled()) { break; diff --git a/src/main/java/github/kasuminova/mmce/common/event/machine/SmartInterfaceUpdateEvent.java b/src/main/java/github/kasuminova/mmce/common/event/machine/SmartInterfaceUpdateEvent.java index 3619ba8d..ebfe76eb 100644 --- a/src/main/java/github/kasuminova/mmce/common/event/machine/SmartInterfaceUpdateEvent.java +++ b/src/main/java/github/kasuminova/mmce/common/event/machine/SmartInterfaceUpdateEvent.java @@ -6,23 +6,29 @@ import hellfirepvp.modularmachinery.common.tiles.base.TileMultiblockMachineController; import hellfirepvp.modularmachinery.common.util.SmartInterfaceData; import net.minecraft.util.math.BlockPos; +import net.minecraftforge.fml.common.Optional; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenGetter; @ZenRegister @ZenClass("mods.modularmachinery.SmartInterfaceUpdateEvent") public class SmartInterfaceUpdateEvent extends MachineEvent { - private final IBlockPos interfacePos; + private final BlockPos interfacePos; private final SmartInterfaceData newData; public SmartInterfaceUpdateEvent(TileMultiblockMachineController controller, BlockPos interfacePos, SmartInterfaceData newData) { super(controller); - this.interfacePos = CraftTweakerMC.getIBlockPos(interfacePos); + this.interfacePos = interfacePos; this.newData = newData; } @ZenGetter("interfacePos") + @Optional.Method(modid = "crafttweaker") public IBlockPos getInterfacePos() { + return CraftTweakerMC.getIBlockPos(interfacePos); + } + + public BlockPos getInterfaceBlockPos() { return interfacePos; } diff --git a/src/main/java/github/kasuminova/mmce/common/event/recipe/RecipeEvent.java b/src/main/java/github/kasuminova/mmce/common/event/recipe/RecipeEvent.java index 7ed5b6a9..516b5232 100644 --- a/src/main/java/github/kasuminova/mmce/common/event/recipe/RecipeEvent.java +++ b/src/main/java/github/kasuminova/mmce/common/event/recipe/RecipeEvent.java @@ -1,7 +1,7 @@ package github.kasuminova.mmce.common.event.recipe; import crafttweaker.annotations.ZenRegister; -import crafttweaker.util.IEventHandler; +import github.kasuminova.mmce.common.event.EventHandler; import github.kasuminova.mmce.common.event.machine.MachineEvent; import hellfirepvp.modularmachinery.common.crafting.ActiveMachineRecipe; import hellfirepvp.modularmachinery.common.crafting.helper.RecipeCraftingContext; @@ -49,11 +49,11 @@ public void postCrTEvent() { if (isCanceled()) { return; } - List> handlers = activeRecipe.getRecipe().getRecipeEventHandlers().get(getClass()); + List> handlers = activeRecipe.getRecipe().getRecipeEventHandlers().get(getClass()); if (handlers == null) { return; } - for (IEventHandler handler : handlers) { + for (EventHandler handler : handlers) { handler.handle(this); if (isCanceled()) { break; diff --git a/src/main/java/github/kasuminova/mmce/common/handler/UpgradeMachineEventHandler.java b/src/main/java/github/kasuminova/mmce/common/handler/UpgradeMachineEventHandler.java index 2835b397..faea7a3f 100644 --- a/src/main/java/github/kasuminova/mmce/common/handler/UpgradeMachineEventHandler.java +++ b/src/main/java/github/kasuminova/mmce/common/handler/UpgradeMachineEventHandler.java @@ -2,9 +2,9 @@ import github.kasuminova.mmce.common.event.machine.MachineEvent; import github.kasuminova.mmce.common.upgrade.DynamicMachineUpgrade; +import github.kasuminova.mmce.common.upgrade.UpgradeEventHandler; import github.kasuminova.mmce.common.upgrade.MachineUpgrade; import hellfirepvp.modularmachinery.ModularMachinery; -import hellfirepvp.modularmachinery.common.integration.crafttweaker.helper.UpgradeEventHandlerCT; import hellfirepvp.modularmachinery.common.tiles.TileUpgradeBus; import hellfirepvp.modularmachinery.common.tiles.base.TileMultiblockMachineController; import hellfirepvp.modularmachinery.common.util.MiscUtils; @@ -24,7 +24,7 @@ public static void onMachineEvent(MachineEvent event) { } } - List processors = upgrade.getEventHandlers(event.getClass()); + List processors = upgrade.getEventHandlers(event.getClass()); if (processors.isEmpty()) { continue; } @@ -39,7 +39,7 @@ public static void onMachineEvent(MachineEvent event) { upgrade.readNBT(provider.getUpgradeCustomData(upgrade)); synchronized (parentBus) { - for (final UpgradeEventHandlerCT handler : processors) { + for (final UpgradeEventHandler handler : processors) { handler.handle(event, upgrade); if (event.isCanceled()) { break; diff --git a/src/main/java/github/kasuminova/mmce/common/helper/IBlockStatePredicate.java b/src/main/java/github/kasuminova/mmce/common/helper/IBlockStatePredicate.java index 3e60d04e..a1de1997 100644 --- a/src/main/java/github/kasuminova/mmce/common/helper/IBlockStatePredicate.java +++ b/src/main/java/github/kasuminova/mmce/common/helper/IBlockStatePredicate.java @@ -3,6 +3,7 @@ import crafttweaker.annotations.ZenRegister; import crafttweaker.api.block.IBlockState; +import net.minecraftforge.fml.common.Optional; import stanhebben.zenscript.annotations.ZenClass; import java.util.function.Predicate; @@ -13,6 +14,7 @@ public interface IBlockStatePredicate extends Predicate { @Override + @Optional.Method(modid = "crafttweaker") boolean test(IBlockState t); } diff --git a/src/main/java/github/kasuminova/mmce/common/helper/IMachineController.java b/src/main/java/github/kasuminova/mmce/common/helper/IMachineController.java index 340098b7..aeda4b31 100644 --- a/src/main/java/github/kasuminova/mmce/common/helper/IMachineController.java +++ b/src/main/java/github/kasuminova/mmce/common/helper/IMachineController.java @@ -16,6 +16,7 @@ import hellfirepvp.modularmachinery.common.modifier.RecipeModifier; import hellfirepvp.modularmachinery.common.tiles.base.TileMultiblockMachineController; import hellfirepvp.modularmachinery.common.util.SmartInterfaceData; +import net.minecraftforge.fml.common.Optional; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenGetter; import stanhebben.zenscript.annotations.ZenMethod; @@ -33,6 +34,7 @@ public interface IMachineController { * @return 世界 */ @ZenGetter("world") + @Optional.Method(modid = "crafttweaker") IWorld getIWorld(); /** @@ -41,6 +43,7 @@ public interface IMachineController { * @return IBlockState */ @ZenGetter("blockState") + @Optional.Method(modid = "crafttweaker") IBlockState getIBlockState(); /** @@ -49,6 +52,7 @@ public interface IMachineController { * @return IFacing */ @ZenGetter("facing") + @Optional.Method(modid = "crafttweaker") IFacing getFacing(); /** @@ -57,6 +61,7 @@ public interface IMachineController { * @return 坐标 */ @ZenGetter("pos") + @Optional.Method(modid = "crafttweaker") IBlockPos getIPos(); /** @@ -66,6 +71,7 @@ public interface IMachineController { * @return 旋转后的坐标 */ @ZenMethod + @Optional.Method(modid = "crafttweaker") IBlockPos rotateWithControllerFacing(final IBlockPos pos); /** @@ -138,6 +144,7 @@ public interface IMachineController { * @return IData */ @ZenGetter("customData") + @Optional.Method(modid = "crafttweaker") IData getCustomData(); /** @@ -146,6 +153,7 @@ public interface IMachineController { * @param data IData */ @ZenSetter("customData") + @Optional.Method(modid = "crafttweaker") void setCustomData(IData data); /** @@ -273,6 +281,7 @@ public interface IMachineController { * @return 存在数量。 */ @ZenMethod + @Optional.Method(modid = "crafttweaker") int getBlocksInPattern(final IItemStack blockStack); /** @@ -284,6 +293,7 @@ public interface IMachineController { * @return 存在数量。 */ @ZenMethod + @Optional.Method(modid = "crafttweaker") int getBlocksInPattern(final IBlockStateMatcher blockStateMatcher); /** @@ -306,6 +316,7 @@ public interface IMachineController { * @return 存在数量。 */ @ZenMethod + @Optional.Method(modid = "crafttweaker") int getBlocksInPattern(final IBlockStatePredicate predicate); /** @@ -317,6 +328,7 @@ public interface IMachineController { * @return 所有位置。 */ @ZenMethod + @Optional.Method(modid = "crafttweaker") IBlockPos[] getBlockPosInPattern(final IItemStack blockStack); /** @@ -328,6 +340,7 @@ public interface IMachineController { * @return 所有位置。 */ @ZenMethod + @Optional.Method(modid = "crafttweaker") IBlockPos[] getBlockPosInPattern(final IBlockStateMatcher blockStateMatcher); /** @@ -339,6 +352,7 @@ public interface IMachineController { * @return 所有位置。 */ @ZenMethod + @Optional.Method(modid = "crafttweaker") IBlockPos[] getBlockPosInPattern(final String blockName); /** @@ -350,6 +364,7 @@ public interface IMachineController { * @return 所有位置。 */ @ZenMethod + @Optional.Method(modid = "crafttweaker") IBlockPos[] getBlockPosInPattern(final IBlockStatePredicate predicate); /** @@ -359,6 +374,7 @@ public interface IMachineController { */ @Nullable @ZenGetter("ownerPlayer") + @Optional.Method(modid = "crafttweaker") IPlayer getOwnerIPlayer(); /** diff --git a/src/main/java/github/kasuminova/mmce/common/helper/MachineController.java b/src/main/java/github/kasuminova/mmce/common/helper/MachineController.java index a9cb5a50..10cde9e3 100644 --- a/src/main/java/github/kasuminova/mmce/common/helper/MachineController.java +++ b/src/main/java/github/kasuminova/mmce/common/helper/MachineController.java @@ -7,6 +7,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import net.minecraftforge.fml.common.Optional; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; @@ -22,6 +23,7 @@ public class MachineController { * @return 如果无控制器则返回 null,否则返回 IMachineController 实例。 */ @ZenMethod + @Optional.Method(modid = "crafttweaker") public static IMachineController getControllerAt(IWorld worldCT, IBlockPos posCT) { World world = CraftTweakerMC.getWorld(worldCT); BlockPos pos = CraftTweakerMC.getBlockPos(posCT); @@ -40,6 +42,7 @@ public static IMachineController getControllerAt(IWorld worldCT, IBlockPos posCT * @return 如果无控制器则返回 null,否则返回 IMachineController 实例。 */ @ZenMethod + @Optional.Method(modid = "crafttweaker") public static IMachineController getControllerAt(IWorld worldCT, int x, int y, int z) { World world = CraftTweakerMC.getWorld(worldCT); BlockPos pos = new BlockPos(x, y, z); diff --git a/src/main/java/github/kasuminova/mmce/common/upgrade/MachineUpgrade.java b/src/main/java/github/kasuminova/mmce/common/upgrade/MachineUpgrade.java index a04df9ad..dc1e74b4 100644 --- a/src/main/java/github/kasuminova/mmce/common/upgrade/MachineUpgrade.java +++ b/src/main/java/github/kasuminova/mmce/common/upgrade/MachineUpgrade.java @@ -1,7 +1,6 @@ package github.kasuminova.mmce.common.upgrade; import crafttweaker.annotations.ZenRegister; -import hellfirepvp.modularmachinery.common.integration.crafttweaker.helper.UpgradeEventHandlerCT; import hellfirepvp.modularmachinery.common.tiles.TileUpgradeBus; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -21,7 +20,7 @@ public abstract class MachineUpgrade { protected final UpgradeType type; - protected final Map, List> eventProcessor = new HashMap<>(); + protected final Map, List> eventProcessor = new HashMap<>(); protected TileUpgradeBus parentBus = null; @@ -46,11 +45,11 @@ public NBTTagCompound writeNBT() { public abstract List getBusGUIDescriptions(); - public void addEventHandler(Class eventClass, UpgradeEventHandlerCT handler) { + public void addEventHandler(Class eventClass, UpgradeEventHandler handler) { eventProcessor.computeIfAbsent(eventClass, v -> new ArrayList<>()).add(handler); } - public List getEventHandlers(Class eventClass) { + public List getEventHandlers(Class eventClass) { return eventProcessor.getOrDefault(eventClass, Collections.emptyList()); } diff --git a/src/main/java/github/kasuminova/mmce/common/upgrade/SimpleDynamicMachineUpgrade.java b/src/main/java/github/kasuminova/mmce/common/upgrade/SimpleDynamicMachineUpgrade.java index d465aa87..261ba43a 100644 --- a/src/main/java/github/kasuminova/mmce/common/upgrade/SimpleDynamicMachineUpgrade.java +++ b/src/main/java/github/kasuminova/mmce/common/upgrade/SimpleDynamicMachineUpgrade.java @@ -4,9 +4,9 @@ import crafttweaker.api.data.IData; import crafttweaker.api.item.IItemStack; import crafttweaker.api.minecraft.CraftTweakerMC; -import hellfirepvp.modularmachinery.common.integration.crafttweaker.helper.IFunction; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.fml.common.Optional; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenGetter; import stanhebben.zenscript.annotations.ZenMethod; @@ -15,12 +15,13 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.function.Function; @ZenRegister @ZenClass("mods.modularmachinery.SimpleDynamicMachineUpgrade") public class SimpleDynamicMachineUpgrade extends DynamicMachineUpgrade { - private IFunction descriptionHandler = null; - private IFunction busGuiDescriptionHandler = null; + private Function descriptionHandler = null; + private Function busGuiDescriptionHandler = null; private NBTTagCompound itemData = new NBTTagCompound(); private NBTTagCompound customData = new NBTTagCompound(); @@ -37,6 +38,7 @@ public SimpleDynamicMachineUpgrade(final UpgradeType type) { * @return IData,永不为空。 */ @ZenGetter("itemData") + @Optional.Method(modid = "crafttweaker") public IData getItemData() { return CraftTweakerMC.getIDataModifyable(itemData); } @@ -49,6 +51,7 @@ public IData getItemData() { * @param itemData IData,不能为空。 */ @ZenSetter("itemData") + @Optional.Method(modid = "crafttweaker") public void setItemData(final IData itemData) { this.itemData = CraftTweakerMC.getNBTCompound(itemData); } @@ -61,6 +64,7 @@ public void setItemData(final IData itemData) { * @return IData,永不为空。 */ @ZenGetter("customData") + @Optional.Method(modid = "crafttweaker") public IData getCustomData() { return CraftTweakerMC.getIDataModifyable(customData); } @@ -73,11 +77,13 @@ public IData getCustomData() { * @param customData IData,不能为空。 */ @ZenSetter("customData") + @Optional.Method(modid = "crafttweaker") public void setCustomData(final IData customData) { this.customData = CraftTweakerMC.getNBTCompound(customData); } @ZenGetter("parentStack") + @Optional.Method(modid = "crafttweaker") public IItemStack getParentStackCT() { return CraftTweakerMC.getIItemStack(parentStack); } @@ -98,11 +104,11 @@ public void decrementItemDurability(final int durability) { } } - public void setDescriptionHandler(final IFunction handler) { + public void setDescriptionHandler(final Function handler) { this.descriptionHandler = handler; } - public void setBusGUIDescriptionHandler(final IFunction handler) { + public void setBusGUIDescriptionHandler(final Function handler) { this.busGuiDescriptionHandler = handler; } diff --git a/src/main/java/github/kasuminova/mmce/common/upgrade/SimpleMachineUpgrade.java b/src/main/java/github/kasuminova/mmce/common/upgrade/SimpleMachineUpgrade.java index 0f2966e1..6c6e2418 100644 --- a/src/main/java/github/kasuminova/mmce/common/upgrade/SimpleMachineUpgrade.java +++ b/src/main/java/github/kasuminova/mmce/common/upgrade/SimpleMachineUpgrade.java @@ -3,9 +3,9 @@ import crafttweaker.annotations.ZenRegister; import crafttweaker.api.data.IData; import crafttweaker.api.minecraft.CraftTweakerMC; -import hellfirepvp.modularmachinery.common.integration.crafttweaker.helper.IFunction; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.fml.common.Optional; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenGetter; import stanhebben.zenscript.annotations.ZenSetter; @@ -14,13 +14,14 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.function.Function; @ZenRegister @ZenClass("mods.modularmachinery.SimpleMachineUpgrade") public class SimpleMachineUpgrade extends MachineUpgrade { - private final List descriptions = new ArrayList<>(); - private IFunction busGuiDescriptionHandler = null; - private NBTTagCompound customData = new NBTTagCompound(); + private final List descriptions = new ArrayList<>(); + private Function busGuiDescriptionHandler = null; + private NBTTagCompound customData = new NBTTagCompound(); public SimpleMachineUpgrade(final UpgradeType type) { super(type); @@ -39,7 +40,7 @@ public void addDescription(String desc) { descriptions.add(desc); } - public void setBusGUIDescriptionHandler(final IFunction handler) { + public void setBusGUIDescriptionHandler(final Function handler) { this.busGuiDescriptionHandler = handler; } @@ -51,6 +52,7 @@ public void setBusGUIDescriptionHandler(final IFunction BlockArrayCache.buildCache(MachineRegistry.getLoadedMachines())); } diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/ActiveMachineRecipe.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/ActiveMachineRecipe.java index b655c000..80cb30b9 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/ActiveMachineRecipe.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/ActiveMachineRecipe.java @@ -21,6 +21,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; import net.minecraftforge.common.util.Constants; +import net.minecraftforge.fml.common.Optional; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenGetter; import stanhebben.zenscript.annotations.ZenSetter; @@ -210,11 +211,13 @@ public String getRegistryName() { } @ZenGetter("data") + @Optional.Method(modid = "crafttweaker") public IData getData() { return CraftTweakerMC.getIDataModifyable(data); } @ZenSetter("data") + @Optional.Method(modid = "crafttweaker") public void setData(IData data) { this.data = CraftTweakerMC.getNBTCompound(data); } diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/MachineRecipe.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/MachineRecipe.java index 4e572729..6adc49f6 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/MachineRecipe.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/MachineRecipe.java @@ -16,7 +16,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; -import crafttweaker.util.IEventHandler; +import github.kasuminova.mmce.common.event.EventHandler; import github.kasuminova.mmce.common.event.recipe.RecipeEvent; import hellfirepvp.modularmachinery.ModularMachinery; import hellfirepvp.modularmachinery.common.crafting.command.RecipeCommandContainer; @@ -26,7 +26,7 @@ import hellfirepvp.modularmachinery.common.crafting.requirement.RequirementEnergy; import hellfirepvp.modularmachinery.common.crafting.requirement.type.RequirementType; import hellfirepvp.modularmachinery.common.data.Config; -import hellfirepvp.modularmachinery.common.integration.crafttweaker.RecipeAdapterBuilder; +import hellfirepvp.modularmachinery.common.crafting.adapter.RecipeAdapterDefinition; import hellfirepvp.modularmachinery.common.lib.RegistriesMM; import hellfirepvp.modularmachinery.common.lib.RequirementTypesMM; import hellfirepvp.modularmachinery.common.machine.DynamicMachine; @@ -61,16 +61,16 @@ public class MachineRecipe implements Comparable { protected static int counter = 0; - protected final int sortId; - protected final String recipeFilePath; - protected final ResourceLocation owningMachine, registryName; - protected final int tickTime; - protected final List> recipeRequirements = Lists.newArrayList(); - protected final RecipeCommandContainer commandContainer = new RecipeCommandContainer(); - protected final int configuredPriority; - protected final boolean voidPerTickFailure; - protected final Map, List>> recipeEventHandlers; - protected final List tooltipList; + protected final int sortId; + protected final String recipeFilePath; + protected final ResourceLocation owningMachine, registryName; + protected final int tickTime; + protected final List> recipeRequirements = Lists.newArrayList(); + protected final RecipeCommandContainer commandContainer = new RecipeCommandContainer(); + protected final int configuredPriority; + protected final boolean voidPerTickFailure; + protected final Map, List>> recipeEventHandlers; + protected final List tooltipList; protected boolean parallelized; protected String threadName; @@ -97,7 +97,7 @@ public MachineRecipe(String path, ResourceLocation registryName, ResourceLocatio public MachineRecipe(String path, ResourceLocation registryName, ResourceLocation owningMachine, int tickTime, int configuredPriority, boolean voidPerTickFailure, boolean parallelized, - Map, List>> recipeEventHandlers, List tooltipList, + Map, List>> recipeEventHandlers, List tooltipList, String threadName, int maxThreads, boolean loadJEI) { this.sortId = counter; counter++; @@ -132,7 +132,7 @@ public MachineRecipe(PreparedRecipe preparedRecipe) { this.loadJEI = preparedRecipe.getLoadJEI(); } - public void mergeAdapter(final RecipeAdapterBuilder adapterBuilder) { + public void mergeAdapter(final RecipeAdapterDefinition adapterBuilder) { this.parallelized = adapterBuilder.isParallelized(); this.tooltipList.addAll(adapterBuilder.getTooltipList()); this.loadJEI = adapterBuilder.getLoadJEI(); @@ -163,9 +163,9 @@ public List getFormattedTooltip() { .collect(Collectors.toList()); } - public void addRecipeEventHandler(Class hClass, IEventHandler handler) { + public void addRecipeEventHandler(Class hClass, EventHandler handler) { recipeEventHandlers.putIfAbsent(hClass, new ArrayList<>()); - recipeEventHandlers.get(hClass).add((IEventHandler) handler); + recipeEventHandlers.get(hClass).add((EventHandler) handler); } public boolean isParallelized() { @@ -173,11 +173,11 @@ public boolean isParallelized() { } @Nullable - public List> getRecipeEventHandlers(Class handlerClass) { + public List> getRecipeEventHandlers(Class handlerClass) { return recipeEventHandlers.get(handlerClass); } - public Map, List>> getRecipeEventHandlers() { + public Map, List>> getRecipeEventHandlers() { return recipeEventHandlers; } diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/PreparedRecipe.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/PreparedRecipe.java index 2373eaa5..360d1a11 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/PreparedRecipe.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/PreparedRecipe.java @@ -8,7 +8,7 @@ package hellfirepvp.modularmachinery.common.crafting; -import crafttweaker.util.IEventHandler; +import github.kasuminova.mmce.common.event.EventHandler; import github.kasuminova.mmce.common.event.recipe.RecipeEvent; import hellfirepvp.modularmachinery.common.crafting.helper.ComponentRequirement; import net.minecraft.util.ResourceLocation; @@ -43,7 +43,7 @@ default boolean voidPerTickFailure() { List> getComponents(); - Map, List>> getRecipeEventHandlers(); + Map, List>> getRecipeEventHandlers(); List getTooltipList(); diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/RecipeLoader.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/RecipeLoader.java index eae28fa2..e302fb0b 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/RecipeLoader.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/RecipeLoader.java @@ -15,7 +15,7 @@ import hellfirepvp.modularmachinery.common.crafting.adapter.RecipeAdapterAccessor; import hellfirepvp.modularmachinery.common.crafting.command.RecipeRunnableCommand; import hellfirepvp.modularmachinery.common.crafting.helper.ComponentRequirement; -import hellfirepvp.modularmachinery.common.integration.crafttweaker.RecipeAdapterBuilder; +import hellfirepvp.modularmachinery.common.crafting.adapter.RecipeAdapterDefinition; import hellfirepvp.modularmachinery.common.modifier.RecipeModifier; import net.minecraft.util.JsonUtils; @@ -103,7 +103,7 @@ public static Collection loadRecipes(List recipeCandidates, return loadedRecipes; } - public static List loadAdapterRecipes(List adapterCandidates, List adapterBuilders) { + public static List loadAdapterRecipes(List adapterCandidates, List adapterBuilders) { List loadedRecipes = new LinkedList<>(); for (File f : adapterCandidates) { try (InputStreamReader isr = new InputStreamReader(Files.newInputStream(f.toPath()), StandardCharsets.UTF_8)) { @@ -119,7 +119,7 @@ public static List loadAdapterRecipes(List adapterCandidate failedAttempts.put(f.getPath(), exc); } } - for (RecipeAdapterBuilder builder : adapterBuilders) { + for (RecipeAdapterDefinition builder : adapterBuilders) { RecipeAdapterAccessor accessor = new RecipeAdapterAccessor(builder); Collection recipes = accessor.loadRecipesForAdapter(); if (recipes.isEmpty()) { diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/RecipeRegistry.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/RecipeRegistry.java index 42a93f44..53066d5a 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/RecipeRegistry.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/RecipeRegistry.java @@ -14,7 +14,7 @@ import hellfirepvp.modularmachinery.common.CommonProxy; import hellfirepvp.modularmachinery.common.crafting.adapter.RecipeAdapterAccessor; import hellfirepvp.modularmachinery.common.data.DataLoadProfiler; -import hellfirepvp.modularmachinery.common.integration.crafttweaker.RecipeAdapterBuilder; +import hellfirepvp.modularmachinery.common.crafting.adapter.RecipeAdapterDefinition; import hellfirepvp.modularmachinery.common.machine.DynamicMachine; import net.minecraft.command.ICommandSender; import net.minecraft.util.ResourceLocation; @@ -47,8 +47,8 @@ public class RecipeRegistry { private static final Map>> REGISTRY_RECIPE_BY_MACHINE = new HashMap<>(); private static final Map RECIPE_REGISTRY = new HashMap<>(); - private final List earlyRecipes = new LinkedList<>(); - private final List earlyRecipeAdapters = new LinkedList<>(); + private final List earlyRecipes = new LinkedList<>(); + private final List earlyRecipeAdapters = new LinkedList<>(); private RecipeRegistry() { } @@ -73,7 +73,7 @@ public static MachineRecipe getRecipe(ResourceLocation key) { private static Map> loadAdapters(@Nullable ICommandSender sender, Map sharedLoadRegistry, - List earlyRecipeAdapters) { + List earlyRecipeAdapters) { ProgressManager.ProgressBar barRecipes = ProgressManager.push("RecipeRegistry - Adapters", 3); barRecipes.step("Discovering Adapter-Files"); DataLoadProfiler profiler = new DataLoadProfiler(); @@ -241,7 +241,7 @@ public void registerRecipeEarly(PreparedRecipe recipe) { this.earlyRecipes.add(recipe); } - public void registerRecipeAdapterEarly(RecipeAdapterBuilder recipeAdapter) { + public void registerRecipeAdapterEarly(RecipeAdapterDefinition recipeAdapter) { this.earlyRecipeAdapters.add(recipeAdapter); } diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/AdapterMinecraftFurnace.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/AdapterMinecraftFurnace.java index 52d82dc7..9f80766c 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/AdapterMinecraftFurnace.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/AdapterMinecraftFurnace.java @@ -8,7 +8,7 @@ package hellfirepvp.modularmachinery.common.crafting.adapter; -import crafttweaker.util.IEventHandler; +import github.kasuminova.mmce.common.event.EventHandler; import github.kasuminova.mmce.common.event.Phase; import github.kasuminova.mmce.common.event.recipe.RecipeCheckEvent; import github.kasuminova.mmce.common.event.recipe.RecipeEvent; @@ -48,7 +48,7 @@ public AdapterMinecraftFurnace() { public Collection createRecipesFor(ResourceLocation owningMachineName, List modifiers, List> additionalRequirements, - Map, List>> eventHandlers, + Map, List>> eventHandlers, List recipeTooltips) { FurnaceRecipes furnaceRecipes = FurnaceRecipes.instance(); Map inputOutputMap = furnaceRecipes.getSmeltingList(); @@ -64,7 +64,7 @@ public Collection createRecipesFor(ResourceLocation owningMachine new ResourceLocation("minecraft", "smelting_" + incId + "_" + input + "_" + output), owningMachineName, tickTime, 0, false); - recipe.addRecipeEventHandler(RecipeCheckEvent.class, (IEventHandler) event -> { + recipe.addRecipeEventHandler(RecipeCheckEvent.class, (EventHandler) event -> { if (event.phase == Phase.START) { event.getActiveRecipe().getDataCompound().setFloat("experience", experience); } diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/DynamicMachineRecipeAdapter.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/DynamicMachineRecipeAdapter.java index 135d25ed..4d5719ec 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/DynamicMachineRecipeAdapter.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/DynamicMachineRecipeAdapter.java @@ -8,7 +8,7 @@ package hellfirepvp.modularmachinery.common.crafting.adapter; -import crafttweaker.util.IEventHandler; +import github.kasuminova.mmce.common.event.EventHandler; import github.kasuminova.mmce.common.event.recipe.RecipeEvent; import hellfirepvp.modularmachinery.ModularMachinery; import hellfirepvp.modularmachinery.common.crafting.MachineRecipe; @@ -44,7 +44,7 @@ public DynamicMachineRecipeAdapter(@Nonnull ResourceLocation registryName, Dynam public Collection createRecipesFor(ResourceLocation owningMachineName, List modifiers, List> additionalRequirements, - Map, List>> eventHandlers, + Map, List>> eventHandlers, List recipeTooltips) { String newIdentifier = owningMachineName.getNamespace() + "." + owningMachineName.getPath(); diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/RecipeAdapter.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/RecipeAdapter.java index 8a9d8976..168ef260 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/RecipeAdapter.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/RecipeAdapter.java @@ -8,7 +8,7 @@ package hellfirepvp.modularmachinery.common.crafting.adapter; -import crafttweaker.util.IEventHandler; +import github.kasuminova.mmce.common.event.EventHandler; import github.kasuminova.mmce.common.event.recipe.RecipeEvent; import hellfirepvp.modularmachinery.common.crafting.MachineRecipe; import hellfirepvp.modularmachinery.common.crafting.helper.ComponentRequirement; @@ -41,7 +41,7 @@ public RecipeAdapter(@Nonnull ResourceLocation registryName) { @Deprecated public static void addAdditionalRequirements(MachineRecipe recipe, List> additionalRequirements, - Map, List>> eventHandlers, + Map, List>> eventHandlers, List recipeTooltips) { } @@ -65,7 +65,7 @@ public Class getRegistryType() { public abstract Collection createRecipesFor(ResourceLocation owningMachineName, List modifiers, List> additionalRequirements, - Map, List>> eventHandlers, + Map, List>> eventHandlers, List recipeTooltips); @Nonnull diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/RecipeAdapterAccessor.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/RecipeAdapterAccessor.java index e7c6b3c5..8818664e 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/RecipeAdapterAccessor.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/RecipeAdapterAccessor.java @@ -15,12 +15,11 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; -import crafttweaker.util.IEventHandler; +import github.kasuminova.mmce.common.event.EventHandler; import github.kasuminova.mmce.common.event.recipe.RecipeEvent; import hellfirepvp.modularmachinery.ModularMachinery; import hellfirepvp.modularmachinery.common.crafting.MachineRecipe; import hellfirepvp.modularmachinery.common.crafting.helper.ComponentRequirement; -import hellfirepvp.modularmachinery.common.integration.crafttweaker.RecipeAdapterBuilder; import hellfirepvp.modularmachinery.common.modifier.RecipeModifier; import net.minecraft.util.ResourceLocation; @@ -42,10 +41,10 @@ public class RecipeAdapterAccessor { private final ResourceLocation owningMachine, adapterKey; - private final List modifiers; - private final List> additionalRecipeRequirements; - private final Map, List>> recipeEventHandlers; - private final List tooltipList; + private final List modifiers; + private final List> additionalRecipeRequirements; + private final Map, List>> recipeEventHandlers; + private final List tooltipList; private final List cacheLoaded = new LinkedList<>(); @@ -58,7 +57,7 @@ public RecipeAdapterAccessor(ResourceLocation owningMachine, ResourceLocation ad this.tooltipList = new ArrayList<>(); } - public RecipeAdapterAccessor(RecipeAdapterBuilder builder) { + public RecipeAdapterAccessor(RecipeAdapterDefinition builder) { this.owningMachine = builder.getAssociatedMachineName(); this.adapterKey = builder.getAdapterParentMachineName(); this.modifiers = builder.getModifiers(); @@ -84,9 +83,9 @@ public void addRequirement(ComponentRequirement requirement) { } @SuppressWarnings("unchecked") - public void addRecipeEventHandler(Class hClass, IEventHandler handler) { + public void addRecipeEventHandler(Class hClass, EventHandler handler) { recipeEventHandlers.putIfAbsent(hClass, new ArrayList<>()); - recipeEventHandlers.get(hClass).add((IEventHandler) handler); + recipeEventHandlers.get(hClass).add((EventHandler) handler); } public void addTooltip(String tooltip) { diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/RecipeAdapterDefinition.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/RecipeAdapterDefinition.java new file mode 100644 index 00000000..bb39993e --- /dev/null +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/RecipeAdapterDefinition.java @@ -0,0 +1,21 @@ +package hellfirepvp.modularmachinery.common.crafting.adapter; + +import hellfirepvp.modularmachinery.common.crafting.PreparedRecipe; +import hellfirepvp.modularmachinery.common.modifier.RecipeModifier; +import net.minecraft.util.ResourceLocation; + +import java.util.List; + +/** + * The description of a recipe adapter. + * + *

+ * CraftTweaker and other script engines may provide implementations, while + * the recipe loader only relies on this contract. + */ +public interface RecipeAdapterDefinition extends PreparedRecipe { + + List getModifiers(); + + ResourceLocation getAdapterParentMachineName(); +} diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/RecipeAdapterRegistry.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/RecipeAdapterRegistry.java index 80684c12..c858ef29 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/RecipeAdapterRegistry.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/RecipeAdapterRegistry.java @@ -8,7 +8,7 @@ package hellfirepvp.modularmachinery.common.crafting.adapter; -import crafttweaker.util.IEventHandler; +import github.kasuminova.mmce.common.event.EventHandler; import github.kasuminova.mmce.common.event.recipe.RecipeEvent; import hellfirepvp.modularmachinery.common.crafting.MachineRecipe; import hellfirepvp.modularmachinery.common.crafting.helper.ComponentRequirement; @@ -37,7 +37,7 @@ public static Collection createRecipesFor(ResourceLocation owning ResourceLocation adapterKey, List modifiers, List> additionalRequirements, - Map, List>> eventHandlers, + Map, List>> eventHandlers, List recipeTooltips) { RecipeAdapter adapter = RegistriesMM.ADAPTER_REGISTRY.getValue(adapterKey); if (adapter == null) { diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/ic2/AdapterIC2Compressor.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/ic2/AdapterIC2Compressor.java index 6c6c30f5..603bd0e1 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/ic2/AdapterIC2Compressor.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/ic2/AdapterIC2Compressor.java @@ -1,6 +1,6 @@ package hellfirepvp.modularmachinery.common.crafting.adapter.ic2; -import crafttweaker.util.IEventHandler; +import github.kasuminova.mmce.common.event.EventHandler; import github.kasuminova.mmce.common.event.recipe.RecipeEvent; import hellfirepvp.modularmachinery.common.crafting.MachineRecipe; import hellfirepvp.modularmachinery.common.crafting.helper.ComponentRequirement; @@ -28,7 +28,7 @@ public AdapterIC2Compressor() { public Collection createRecipesFor(ResourceLocation owningMachineName, List modifiers, List> additionalRequirements, - Map, List>> eventHandlers, + Map, List>> eventHandlers, List recipeTooltips) { Iterable>> machineRecipes = Recipes.compressor.getRecipes(); diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/ic2/AdapterIC2Macerator.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/ic2/AdapterIC2Macerator.java index c057e528..b0716976 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/ic2/AdapterIC2Macerator.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/ic2/AdapterIC2Macerator.java @@ -1,6 +1,6 @@ package hellfirepvp.modularmachinery.common.crafting.adapter.ic2; -import crafttweaker.util.IEventHandler; +import github.kasuminova.mmce.common.event.EventHandler; import github.kasuminova.mmce.common.event.recipe.RecipeEvent; import hellfirepvp.modularmachinery.common.crafting.MachineRecipe; import hellfirepvp.modularmachinery.common.crafting.helper.ComponentRequirement; @@ -28,7 +28,7 @@ public AdapterIC2Macerator() { public Collection createRecipesFor(ResourceLocation owningMachineName, List modifiers, List> additionalRequirements, - Map, List>> eventHandlers, + Map, List>> eventHandlers, List recipeTooltips) { Iterable>> machineRecipes = Recipes.macerator.getRecipes(); diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/nco/AdapterNCOAlloyFurnace.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/nco/AdapterNCOAlloyFurnace.java index bc9aa364..0f0e0f08 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/nco/AdapterNCOAlloyFurnace.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/nco/AdapterNCOAlloyFurnace.java @@ -1,6 +1,6 @@ package hellfirepvp.modularmachinery.common.crafting.adapter.nco; -import crafttweaker.util.IEventHandler; +import github.kasuminova.mmce.common.event.EventHandler; import github.kasuminova.mmce.common.event.recipe.RecipeEvent; import github.kasuminova.mmce.common.itemtype.ChancedIngredientStack; import hellfirepvp.modularmachinery.common.crafting.MachineRecipe; @@ -39,7 +39,7 @@ public AdapterNCOAlloyFurnace() { public Collection createRecipesFor(ResourceLocation owningMachineName, List modifiers, List> additionalRequirements, - Map, List>> eventHandlers, + Map, List>> eventHandlers, List recipeTooltips) { List recipeList = NCRecipes.alloy_furnace.getRecipeList(); List machineRecipeList = new ArrayList<>(recipeList.size()); diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/nco/AdapterNCOChemicalReactor.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/nco/AdapterNCOChemicalReactor.java index 6cb26066..60ff849d 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/nco/AdapterNCOChemicalReactor.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/nco/AdapterNCOChemicalReactor.java @@ -1,6 +1,6 @@ package hellfirepvp.modularmachinery.common.crafting.adapter.nco; -import crafttweaker.util.IEventHandler; +import github.kasuminova.mmce.common.event.EventHandler; import github.kasuminova.mmce.common.event.recipe.RecipeEvent; import hellfirepvp.modularmachinery.common.crafting.MachineRecipe; import hellfirepvp.modularmachinery.common.crafting.helper.ComponentRequirement; @@ -31,7 +31,7 @@ public AdapterNCOChemicalReactor() { @Nonnull @Override - public Collection createRecipesFor(ResourceLocation owningMachineName, List modifiers, List> additionalRequirements, Map, List>> eventHandlers, List recipeTooltips) { + public Collection createRecipesFor(ResourceLocation owningMachineName, List modifiers, List> additionalRequirements, Map, List>> eventHandlers, List recipeTooltips) { List recipeList = NCRecipes.chemical_reactor.getRecipeList(); List machineRecipeList = new ArrayList<>(recipeList.size()); diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/nco/AdapterNCOInfuser.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/nco/AdapterNCOInfuser.java index 751e1562..61fc34ac 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/nco/AdapterNCOInfuser.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/nco/AdapterNCOInfuser.java @@ -1,6 +1,6 @@ package hellfirepvp.modularmachinery.common.crafting.adapter.nco; -import crafttweaker.util.IEventHandler; +import github.kasuminova.mmce.common.event.EventHandler; import github.kasuminova.mmce.common.event.recipe.RecipeEvent; import github.kasuminova.mmce.common.itemtype.ChancedIngredientStack; import hellfirepvp.modularmachinery.common.crafting.MachineRecipe; @@ -43,7 +43,7 @@ public AdapterNCOInfuser() { public Collection createRecipesFor(ResourceLocation owningMachineName, List modifiers, List> additionalRequirements, - Map, List>> eventHandlers, List recipeTooltips) { + Map, List>> eventHandlers, List recipeTooltips) { InfuserRecipes infuserRecipes = NCRecipes.infuser; List recipeList = infuserRecipes.getRecipeList(); diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/nco/AdapterNCOMelter.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/nco/AdapterNCOMelter.java index fa5964d8..d247b102 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/nco/AdapterNCOMelter.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/nco/AdapterNCOMelter.java @@ -1,6 +1,6 @@ package hellfirepvp.modularmachinery.common.crafting.adapter.nco; -import crafttweaker.util.IEventHandler; +import github.kasuminova.mmce.common.event.EventHandler; import github.kasuminova.mmce.common.event.recipe.RecipeEvent; import github.kasuminova.mmce.common.itemtype.ChancedIngredientStack; import hellfirepvp.modularmachinery.common.crafting.MachineRecipe; @@ -40,7 +40,7 @@ public AdapterNCOMelter() { @Nonnull @Override - public Collection createRecipesFor(ResourceLocation owningMachineName, List modifiers, List> additionalRequirements, Map, List>> eventHandlers, List recipeTooltips) { + public Collection createRecipesFor(ResourceLocation owningMachineName, List modifiers, List> additionalRequirements, Map, List>> eventHandlers, List recipeTooltips) { MelterRecipes melterRecipes = NCRecipes.melter; List recipeList = melterRecipes.getRecipeList(); diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/tc6/AdapterTC6InfusionMatrix.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/tc6/AdapterTC6InfusionMatrix.java index 273c1b4f..e9121857 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/tc6/AdapterTC6InfusionMatrix.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/tc6/AdapterTC6InfusionMatrix.java @@ -1,6 +1,6 @@ package hellfirepvp.modularmachinery.common.crafting.adapter.tc6; -import crafttweaker.util.IEventHandler; +import github.kasuminova.mmce.common.event.EventHandler; import github.kasuminova.mmce.common.event.recipe.RecipeEvent; import github.kasuminova.mmce.common.itemtype.ChancedIngredientStack; import hellfirepvp.modularmachinery.common.crafting.MachineRecipe; @@ -36,7 +36,7 @@ public AdapterTC6InfusionMatrix() { @Nonnull @Override - public Collection createRecipesFor(ResourceLocation owningMachineName, List modifiers, List> additionalRequirements, Map, List>> eventHandlers, List recipeTooltips) { + public Collection createRecipesFor(ResourceLocation owningMachineName, List modifiers, List> additionalRequirements, Map, List>> eventHandlers, List recipeTooltips) { List machineRecipeList = new ArrayList<>(); ThaumcraftApi.getCraftingRecipes().forEach((recipeName, tcRecipe) -> { diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/tconstruct/AdapterSmelteryAlloyRecipe.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/tconstruct/AdapterSmelteryAlloyRecipe.java index 4ab9b06d..eb8f8d55 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/tconstruct/AdapterSmelteryAlloyRecipe.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/tconstruct/AdapterSmelteryAlloyRecipe.java @@ -1,6 +1,6 @@ package hellfirepvp.modularmachinery.common.crafting.adapter.tconstruct; -import crafttweaker.util.IEventHandler; +import github.kasuminova.mmce.common.event.EventHandler; import github.kasuminova.mmce.common.event.recipe.RecipeEvent; import hellfirepvp.modularmachinery.common.crafting.MachineRecipe; import hellfirepvp.modularmachinery.common.crafting.adapter.RecipeAdapter; @@ -29,7 +29,7 @@ public AdapterSmelteryAlloyRecipe() { @Nonnull @Override - public Collection createRecipesFor(ResourceLocation owningMachineName, List modifiers, List> additionalRequirements, Map, List>> eventHandlers, List recipeTooltips) { + public Collection createRecipesFor(ResourceLocation owningMachineName, List modifiers, List> additionalRequirements, Map, List>> eventHandlers, List recipeTooltips) { List alloyRecipes = TinkerRegistry.getAlloys(); List machineRecipeList = new ArrayList<>(alloyRecipes.size()); diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/tconstruct/AdapterSmelteryMeltingRecipe.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/tconstruct/AdapterSmelteryMeltingRecipe.java index a766c51c..b76d8057 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/tconstruct/AdapterSmelteryMeltingRecipe.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/tconstruct/AdapterSmelteryMeltingRecipe.java @@ -1,6 +1,6 @@ package hellfirepvp.modularmachinery.common.crafting.adapter.tconstruct; -import crafttweaker.util.IEventHandler; +import github.kasuminova.mmce.common.event.EventHandler; import github.kasuminova.mmce.common.event.Phase; import github.kasuminova.mmce.common.event.recipe.RecipeCheckEvent; import github.kasuminova.mmce.common.event.recipe.RecipeEvent; @@ -34,7 +34,7 @@ public AdapterSmelteryMeltingRecipe() { @Nonnull @Override - public Collection createRecipesFor(ResourceLocation owningMachineName, List modifiers, List> additionalRequirements, Map, List>> eventHandlers, List recipeTooltips) { + public Collection createRecipesFor(ResourceLocation owningMachineName, List modifiers, List> additionalRequirements, Map, List>> eventHandlers, List recipeTooltips) { List meltingRecipes = TinkerRegistry.getAllMeltingRecipies(); List machineRecipeList = new ArrayList<>(meltingRecipes.size()); @@ -44,7 +44,7 @@ public Collection createRecipesFor(ResourceLocation owningMachine modifiers, RequirementTypesMM.REQUIREMENT_DURATION, IOType.INPUT, (float) meltingRecipe.temperature / 10, false)), 1), incId, false ); - recipe.addRecipeEventHandler(RecipeCheckEvent.class, (IEventHandler) event -> { + recipe.addRecipeEventHandler(RecipeCheckEvent.class, (EventHandler) event -> { if (event.phase == Phase.START) { event.getActiveRecipe().getDataCompound().setFloat("temperatureRequired", meltingRecipe.temperature); } diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/te5/InsolatorRecipeAdapter.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/te5/InsolatorRecipeAdapter.java index 0c3ac222..5d2870d2 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/te5/InsolatorRecipeAdapter.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/adapter/te5/InsolatorRecipeAdapter.java @@ -1,7 +1,7 @@ package hellfirepvp.modularmachinery.common.crafting.adapter.te5; import cofh.thermalexpansion.util.managers.machine.InsolatorManager; -import crafttweaker.util.IEventHandler; +import github.kasuminova.mmce.common.event.EventHandler; import github.kasuminova.mmce.common.event.recipe.RecipeEvent; import github.kasuminova.mmce.common.util.HashedItemStack; import hellfirepvp.modularmachinery.common.crafting.MachineRecipe; @@ -49,7 +49,7 @@ private static boolean isFertilizer(final ItemStack primaryInput) { public Collection createRecipesFor(final ResourceLocation owningMachineName, final List modifiers, final List> additionalRequirements, - final Map, List>> eventHandlers, + final Map, List>> eventHandlers, final List recipeTooltips) { List recipes = new ArrayList<>(); InsolatorManager.InsolatorRecipe[] insolatorRecipes = InsolatorManager.getRecipeList(); diff --git a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/MachineBuilder.java b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/MachineBuilder.java index 4f69913d..dac37178 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/MachineBuilder.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/MachineBuilder.java @@ -348,7 +348,7 @@ public MachineBuilder addSmartInterfaceType(SmartInterfaceType type) { */ @ZenMethod public MachineBuilder addStructureFormedHandler(IEventHandler function) { - machine.addMachineEventHandler(MachineStructureFormedEvent.class, function); + machine.addMachineEventHandler(MachineStructureFormedEvent.class, function::handle); return this; } @@ -357,7 +357,7 @@ public MachineBuilder addStructureFormedHandler(IEventHandler function) { - machine.addMachineEventHandler(MachineStructureUpdateEvent.class, function); + machine.addMachineEventHandler(MachineStructureUpdateEvent.class, function::handle); return this; } @@ -366,7 +366,7 @@ public MachineBuilder addStructureUpdateHandler(IEventHandler function) { - machine.addMachineEventHandler(MachineTickEvent.class, function); + machine.addMachineEventHandler(MachineTickEvent.class, function::handle); return this; } @@ -378,7 +378,7 @@ public MachineBuilder addGUIRenderHandler(IEventHandler function) { - machine.addMachineEventHandler(SmartInterfaceUpdateEvent.class, function); + machine.addMachineEventHandler(SmartInterfaceUpdateEvent.class, function::handle); return this; } diff --git a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/RecipeAdapterBuilder.java b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/RecipeAdapterBuilder.java index 3d6aff5d..bc5f5901 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/RecipeAdapterBuilder.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/RecipeAdapterBuilder.java @@ -4,6 +4,7 @@ import crafttweaker.annotations.ZenRegister; import hellfirepvp.modularmachinery.ModularMachinery; import hellfirepvp.modularmachinery.common.crafting.RecipeRegistry; +import hellfirepvp.modularmachinery.common.crafting.adapter.RecipeAdapterDefinition; import hellfirepvp.modularmachinery.common.modifier.RecipeModifier; import net.minecraft.util.ResourceLocation; import stanhebben.zenscript.annotations.ZenClass; @@ -14,7 +15,7 @@ @ZenRegister @ZenClass("mods.modularmachinery.RecipeAdapterBuilder") -public class RecipeAdapterBuilder extends RecipePrimer { +public class RecipeAdapterBuilder extends RecipePrimer implements RecipeAdapterDefinition { protected final List modifiers = new LinkedList<>(); protected final ResourceLocation parentMachineName; diff --git a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/RecipePrimer.java b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/RecipePrimer.java index daf4d6e0..0f49ab90 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/RecipePrimer.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/RecipePrimer.java @@ -18,6 +18,7 @@ import crafttweaker.api.minecraft.CraftTweakerMC; import crafttweaker.api.oredict.IOreDictEntry; import crafttweaker.util.IEventHandler; +import github.kasuminova.mmce.common.event.EventHandler; import github.kasuminova.mmce.common.event.Phase; import github.kasuminova.mmce.common.event.recipe.FactoryRecipeFailureEvent; import github.kasuminova.mmce.common.event.recipe.FactoryRecipeFinishEvent; @@ -85,10 +86,10 @@ public class RecipePrimer implements PreparedRecipe { private final int tickTime, priority; private final boolean doesVoidPerTick; - private final List> components = new LinkedList<>(); - private final List needAfterInitActions = new LinkedList<>(); - private final List toolTipList = new ArrayList<>(); - private final Map, List>> recipeEventHandlers = new HashMap<>(); + private final List> components = new LinkedList<>(); + private final List needAfterInitActions = new LinkedList<>(); + private final List toolTipList = new ArrayList<>(); + private final Map, List>> recipeEventHandlers = new HashMap<>(); private boolean parallelized = Config.recipeParallelizeEnabledByDefault; private boolean loadJEI = true; @@ -405,7 +406,7 @@ public RecipePrimer addFactoryFinishHandler(IEventHandler void addRecipeEventHandler(Class hClass, IEventHandler handler) { recipeEventHandlers.putIfAbsent(hClass, new ArrayList<>()); - recipeEventHandlers.get(hClass).add((IEventHandler) handler); + recipeEventHandlers.get(hClass).add(event -> handler.handle((H) event)); } //---------------------------------------------------------------------------------------------- @@ -934,7 +935,7 @@ public boolean voidPerTickFailure() { } @Override - public Map, List>> getRecipeEventHandlers() { + public Map, List>> getRecipeEventHandlers() { return recipeEventHandlers; } diff --git a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/event/MMEvents.java b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/event/MMEvents.java index dbf5b450..a00c6766 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/event/MMEvents.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/event/MMEvents.java @@ -44,7 +44,7 @@ public static void onStructureFormed(String machineRegistryName, IEventHandler { DynamicMachine machine = MachineRegistry.getRegistry().getMachine(new ResourceLocation(ModularMachinery.MODID, machineRegistryName)); if (machine != null) { - machine.addMachineEventHandler(MachineStructureFormedEvent.class, function); + machine.addMachineEventHandler(MachineStructureFormedEvent.class, function::handle); } else { CraftTweakerAPI.logError("Could not find machine `" + machineRegistryName + "`!"); } @@ -56,7 +56,7 @@ public static void onStructureUpdate(String machineRegistryName, IEventHandler { DynamicMachine machine = MachineRegistry.getRegistry().getMachine(new ResourceLocation(ModularMachinery.MODID, machineRegistryName)); if (machine != null) { - machine.addMachineEventHandler(MachineStructureUpdateEvent.class, function); + machine.addMachineEventHandler(MachineStructureUpdateEvent.class, function::handle); } else { CraftTweakerAPI.logError("Could not find machine `" + machineRegistryName + "`!"); } @@ -112,7 +112,7 @@ public static void onControllerGUIRender(String machineRegistryName, IEventHandl WAIT_FOR_MODIFY.add(() -> { DynamicMachine machine = MachineRegistry.getRegistry().getMachine(new ResourceLocation(ModularMachinery.MODID, machineRegistryName)); if (machine != null) { - machine.addMachineEventHandler(ControllerGUIRenderEvent.class, function); + machine.addMachineEventHandler(ControllerGUIRenderEvent.class, function::handle); } else { CraftTweakerAPI.logError("Could not find machine `" + machineRegistryName + "`!"); } @@ -128,7 +128,7 @@ public static void onControllerModelAnimation(String machineRegistryName, IEvent WAIT_FOR_MODIFY.add(() -> { DynamicMachine machine = MachineRegistry.getRegistry().getMachine(new ResourceLocation(ModularMachinery.MODID, machineRegistryName)); if (machine != null) { - machine.addMachineEventHandler(ControllerModelAnimationEvent.class, function); + machine.addMachineEventHandler(ControllerModelAnimationEvent.class, function::handle); } else { CraftTweakerAPI.logError("Could not find machine `" + machineRegistryName + "`!"); } @@ -144,7 +144,7 @@ public static void onControllerModelGet(String machineRegistryName, IEventHandle WAIT_FOR_MODIFY.add(() -> { DynamicMachine machine = MachineRegistry.getRegistry().getMachine(new ResourceLocation(ModularMachinery.MODID, machineRegistryName)); if (machine != null) { - machine.addMachineEventHandler(ControllerModelGetEvent.class, function); + machine.addMachineEventHandler(ControllerModelGetEvent.class, function::handle); } else { CraftTweakerAPI.logError("Could not find machine `" + machineRegistryName + "`!"); } @@ -156,7 +156,7 @@ public static void onSmartInterfaceUpdate(String machineRegistryName, IEventHand WAIT_FOR_MODIFY.add(() -> { DynamicMachine machine = MachineRegistry.getRegistry().getMachine(new ResourceLocation(ModularMachinery.MODID, machineRegistryName)); if (machine != null) { - machine.addMachineEventHandler(SmartInterfaceUpdateEvent.class, function); + machine.addMachineEventHandler(SmartInterfaceUpdateEvent.class, function::handle); } else { CraftTweakerAPI.logError("Could not find machine `" + machineRegistryName + "`!"); } diff --git a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/helper/IFunction.java b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/helper/IFunction.java index 5b1b2edf..7335ca14 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/helper/IFunction.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/helper/IFunction.java @@ -3,9 +3,13 @@ import crafttweaker.annotations.ZenRegister; import stanhebben.zenscript.annotations.ZenClass; +import java.util.function.Function; + @ZenRegister @FunctionalInterface @ZenClass("mods.modularmachinery.IFunction") -public interface IFunction { +public interface IFunction extends Function { + + @Override R apply(T param); } diff --git a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/upgrade/DynamicMachineUpgradeBuilder.java b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/upgrade/DynamicMachineUpgradeBuilder.java index 3d2b5a58..230f7a05 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/upgrade/DynamicMachineUpgradeBuilder.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/upgrade/DynamicMachineUpgradeBuilder.java @@ -291,6 +291,6 @@ public void buildAndRegister() { } private void addEventHandler(Class eventClass, UpgradeEventHandlerCT handler) { - machineUpgrade.addEventHandler(eventClass, handler); + machineUpgrade.addEventHandler(eventClass, handler::handle); } } diff --git a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/upgrade/MachineUpgradeBuilder.java b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/upgrade/MachineUpgradeBuilder.java index 86eddbab..043cd7c5 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/upgrade/MachineUpgradeBuilder.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/integration/crafttweaker/upgrade/MachineUpgradeBuilder.java @@ -328,6 +328,6 @@ public void buildAndRegister() { } private void addEventHandler(Class eventClass, UpgradeEventHandlerCT handler) { - machineUpgrade.addEventHandler(eventClass, handler); + machineUpgrade.addEventHandler(eventClass, handler::handle); } } diff --git a/src/main/java/hellfirepvp/modularmachinery/common/machine/DynamicMachine.java b/src/main/java/hellfirepvp/modularmachinery/common/machine/DynamicMachine.java index fa047b26..81d297c3 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/machine/DynamicMachine.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/machine/DynamicMachine.java @@ -15,7 +15,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; -import crafttweaker.util.IEventHandler; +import github.kasuminova.mmce.common.event.EventHandler; import github.kasuminova.mmce.common.concurrent.RecipeCraftingContextPool; import github.kasuminova.mmce.common.event.machine.MachineEvent; import github.kasuminova.mmce.common.util.BlockPos2ValueMap; @@ -66,7 +66,7 @@ public class DynamicMachine extends AbstractMachine { private final Map> modifiers = new BlockPos2ValueMap<>(); private final List multiBlockModifiers = new ArrayList<>(); - private final Map, List>> machineEventHandlers = new HashMap<>(); + private final Map, List>> machineEventHandlers = new HashMap<>(); private final TaggedPositionBlockArray pattern = new TaggedPositionBlockArray(); private final Map dynamicPatterns = new HashMap<>(); @@ -139,17 +139,17 @@ public Map getFilteredType(Collection ignore return filtered; } - public void addMachineEventHandler(Class hClass, IEventHandler handler) { + public void addMachineEventHandler(Class hClass, EventHandler handler) { machineEventHandlers.putIfAbsent(hClass, new ArrayList<>()); - machineEventHandlers.get(hClass).add((IEventHandler) handler); + machineEventHandlers.get(hClass).add((EventHandler) handler); } @Nullable - public List> getMachineEventHandlers(Class handlerClass) { + public List> getMachineEventHandlers(Class handlerClass) { return machineEventHandlers.get(handlerClass); } - public Map, List>> getMachineEventHandlers() { + public Map, List>> getMachineEventHandlers() { return machineEventHandlers; } diff --git a/src/main/java/hellfirepvp/modularmachinery/common/machine/factory/FactoryRecipeThread.java b/src/main/java/hellfirepvp/modularmachinery/common/machine/factory/FactoryRecipeThread.java index 5c80b303..ec6c87b5 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/machine/factory/FactoryRecipeThread.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/machine/factory/FactoryRecipeThread.java @@ -1,6 +1,5 @@ package hellfirepvp.modularmachinery.common.machine.factory; -import crafttweaker.CraftTweakerAPI; import crafttweaker.annotations.ZenRegister; import github.kasuminova.mmce.common.concurrent.FactoryRecipeSearchTask; import github.kasuminova.mmce.common.util.concurrent.Action; @@ -253,7 +252,7 @@ public FactoryRecipeThread addRecipe(String recipeName) { if (recipe != null) { addRecipe(recipe); } else { - CraftTweakerAPI.logError("[ModularMachinery] Cloud not found recipe by name " + recipeName + "!"); + ModularMachinery.log.error("[ModularMachinery] Could not find recipe by name {}!", recipeName); } } else { WAIT_FOR_ADD.add(() -> { @@ -261,7 +260,7 @@ public FactoryRecipeThread addRecipe(String recipeName) { if (recipe != null) { addRecipe(recipe); } else { - CraftTweakerAPI.logError("[ModularMachinery] Cloud not found recipe by name " + recipeName + "!"); + ModularMachinery.log.error("[ModularMachinery] Could not find recipe by name {}!", recipeName); } }); } diff --git a/src/main/java/hellfirepvp/modularmachinery/common/modifier/RecipeModifier.java b/src/main/java/hellfirepvp/modularmachinery/common/modifier/RecipeModifier.java index 5687c6a8..ced1bfa9 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/modifier/RecipeModifier.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/modifier/RecipeModifier.java @@ -19,7 +19,6 @@ import hellfirepvp.modularmachinery.common.crafting.helper.ComponentRequirement; import hellfirepvp.modularmachinery.common.crafting.helper.RecipeCraftingContext; import hellfirepvp.modularmachinery.common.crafting.requirement.type.RequirementType; -import hellfirepvp.modularmachinery.common.integration.crafttweaker.RecipeModifierBuilder; import hellfirepvp.modularmachinery.common.lib.RegistriesMM; import hellfirepvp.modularmachinery.common.machine.IOType; import net.minecraft.nbt.NBTTagCompound; @@ -84,13 +83,19 @@ public static void applyValueToApplier(final ModifierApplier applier, final Reci public static RecipeModifier deserialize(NBTTagCompound compound) { if (compound.hasKey("target") && compound.hasKey("ioTarget") && compound.hasKey("operation") && compound.hasKey("value") && compound.hasKey("chance")) { - return RecipeModifierBuilder.newBuilder() - .setRequirementType(compound.getString("target")) - .setIOType(compound.getByte("ioTarget") == 0 ? IO_INPUT : IO_OUTPUT) - .setOperation(compound.getByte("operation")) - .setValue(compound.getFloat("value")) - .isAffectChance(compound.getBoolean("chance")) - .build(); + String targetName = compound.getString("target"); + int operation = compound.getByte("operation"); + if (targetName.isEmpty() || operation < OPERATION_ADD || operation > OPERATION_MULTIPLY) { + return null; + } + + RequirementType target = RegistriesMM.REQUIREMENT_TYPE_REGISTRY.getValue(new ResourceLocation(targetName)); + if (target == null) { + return null; + } + + IOType ioType = compound.getByte("ioTarget") == 0 ? IOType.INPUT : IOType.OUTPUT; + return new RecipeModifier(target, ioType, compound.getFloat("value"), operation, compound.getBoolean("chance")); } return null; } diff --git a/src/main/java/hellfirepvp/modularmachinery/common/registry/RegistryBlocks.java b/src/main/java/hellfirepvp/modularmachinery/common/registry/RegistryBlocks.java index 24a99b40..408751d4 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/registry/RegistryBlocks.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/registry/RegistryBlocks.java @@ -103,6 +103,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.common.registry.GameRegistry; +import net.minecraftforge.fml.common.Optional; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import org.apache.commons.io.FileUtils; @@ -400,10 +401,9 @@ private static void registerCustomControllers() { } List waitForLoadMachines = MachineRegistry.getWaitForLoadMachines(); - for (MachineBuilder builder : MachineBuilder.PRE_LOAD_MACHINES.values()) { - waitForLoadMachines.add(builder.getMachine()); + if (Mods.CRAFTTWEAKER.isPresent()) { + addCraftTweakerPreloadMachines(waitForLoadMachines); } - MachineBuilder.PRE_LOAD_MACHINES.clear(); if (Config.mocCompatibleMode) { for (DynamicMachine machine : waitForLoadMachines) { @@ -440,6 +440,14 @@ private static void registerCustomControllers() { } } + @Optional.Method(modid = "crafttweaker") + private static void addCraftTweakerPreloadMachines(List machines) { + for (MachineBuilder builder : MachineBuilder.PRE_LOAD_MACHINES.values()) { + machines.add(builder.getMachine()); + } + MachineBuilder.PRE_LOAD_MACHINES.clear(); + } + private static void registerBlockModels() { for (Block block : blockModelRegister) { ModularMachinery.proxy.registerBlockModel(block); diff --git a/src/main/java/hellfirepvp/modularmachinery/common/tiles/base/TileMultiblockMachineController.java b/src/main/java/hellfirepvp/modularmachinery/common/tiles/base/TileMultiblockMachineController.java index bc4e7019..58299d0a 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/tiles/base/TileMultiblockMachineController.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/tiles/base/TileMultiblockMachineController.java @@ -937,24 +937,29 @@ public void checkAndAddSmartInterface(MachineComponent component, BlockPos re } } + @Method(modid = "crafttweaker") public IWorld getIWorld() { return CraftTweakerMC.getIWorld(getWorld()); } + @Method(modid = "crafttweaker") public crafttweaker.api.block.IBlockState getIBlockState() { return CraftTweakerMC.getBlockState(getWorld().getBlockState(getPos())); } @Override + @Method(modid = "crafttweaker") public IFacing getFacing() { return CraftTweakerMC.getIFacing(controllerRotation); } + @Method(modid = "crafttweaker") public IBlockPos getIPos() { return CraftTweakerMC.getIBlockPos(getPos()); } @Override + @Method(modid = "crafttweaker") public IBlockPos rotateWithControllerFacing(final IBlockPos posCT) { BlockPos pos = CraftTweakerMC.getBlockPos(posCT); return CraftTweakerMC.getIBlockPos(MiscUtils.rotateYCCWNorthUntil(pos, controllerRotation == null ? EnumFacing.NORTH : controllerRotation)); @@ -964,10 +969,12 @@ public String getFormedMachineName() { return isStructureFormed() ? foundMachine.getRegistryName().toString() : null; } + @Method(modid = "crafttweaker") public IData getCustomData() { return CraftTweakerMC.getIDataModifyable(customData); } + @Method(modid = "crafttweaker") public void setCustomData(IData data) { customData = CraftTweakerMC.getNBTCompound(data); markNoUpdateSync(); @@ -1179,6 +1186,7 @@ public IDynamicPatternInfo getDynamicPattern(final String patternName) { } @Override + @Method(modid = "crafttweaker") public int getBlocksInPattern(final IItemStack blockStack) { if (foundPattern == null || blockStack == null) { return 0; @@ -1192,6 +1200,7 @@ public int getBlocksInPattern(final IItemStack blockStack) { } @Override + @Method(modid = "crafttweaker") public int getBlocksInPattern(final IBlockStateMatcher blockStateMatcher) { if (foundPattern == null) { return 0; @@ -1209,6 +1218,7 @@ public int getBlocksInPattern(final String blockName) { } @Override + @Method(modid = "crafttweaker") public int getBlocksInPattern(final IBlockStatePredicate predicate) { if (foundPattern == null) { return 0; @@ -1217,6 +1227,7 @@ public int getBlocksInPattern(final IBlockStatePredicate predicate) { } @Override + @Method(modid = "crafttweaker") public IBlockPos[] getBlockPosInPattern(IItemStack blockStack) { if (foundPattern == null || blockStack == null) { return new IBlockPos[0]; @@ -1230,6 +1241,7 @@ public IBlockPos[] getBlockPosInPattern(IItemStack blockStack) { } @Override + @Method(modid = "crafttweaker") public IBlockPos[] getBlockPosInPattern(IBlockStateMatcher blockStateMatcher) { if (foundPattern == null) { return new IBlockPos[0]; @@ -1238,6 +1250,7 @@ public IBlockPos[] getBlockPosInPattern(IBlockStateMatcher blockStateMatcher) { } @Override + @Method(modid = "crafttweaker") public IBlockPos[] getBlockPosInPattern(String blockName) { if (foundPattern == null) { return new IBlockPos[0]; @@ -1247,6 +1260,7 @@ public IBlockPos[] getBlockPosInPattern(String blockName) { } @Override + @Method(modid = "crafttweaker") public IBlockPos[] getBlockPosInPattern(IBlockStatePredicate predicate) { if (foundPattern == null) { return new IBlockPos[0]; @@ -1272,6 +1286,7 @@ public int getBlocksInPatternInternal(final Predicate predicate) { return count; } + @Method(modid = "crafttweaker") public IBlockPos[] getBlockPossInPatternInternal(final Predicate predicate) { if (foundPattern == null) { return new IBlockPos[0]; @@ -1292,6 +1307,7 @@ public IBlockPos[] getBlockPossInPatternInternal(final Predicate pr @Nullable @Override + @Method(modid = "crafttweaker") @SuppressWarnings("ConstantValue") public IPlayer getOwnerIPlayer() { if (owner == null) { diff --git a/src/main/java/hellfirepvp/modularmachinery/common/util/SmartInterfaceData.java b/src/main/java/hellfirepvp/modularmachinery/common/util/SmartInterfaceData.java index 227ea718..ad29f889 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/util/SmartInterfaceData.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/util/SmartInterfaceData.java @@ -6,6 +6,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; +import net.minecraftforge.fml.common.Optional; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenGetter; import stanhebben.zenscript.annotations.ZenSetter; @@ -47,6 +48,7 @@ public BlockPos getPos() { * 返回此数据对应控制器所在的位置。 */ @ZenGetter("pos") + @Optional.Method(modid = "crafttweaker") public IBlockPos getIPos() { return CraftTweakerMC.getIBlockPos(pos); } diff --git a/tags.properties b/tags.properties new file mode 100644 index 00000000..3dd2c3c7 --- /dev/null +++ b/tags.properties @@ -0,0 +1 @@ +VERSION = ${mod_version} \ No newline at end of file