From fdaf6a88c41a6cd559a78625e0b28a61f4cda063 Mon Sep 17 00:00:00 2001 From: cech12 Date: Wed, 3 Jan 2024 22:05:33 +0100 Subject: [PATCH] Update to Forge 48.1.0 & Neoforge 20.2.86 - Move to Multiloader mod template to support Forge and Neoforge --- .github/ISSUE_TEMPLATE/bug.yml | 15 +- .github/workflows/cicd-workflow.yml | 48 +++- .gitignore | 1 + CHANGELOG.md | 4 + build.gradle | 230 ++++++------------ common/build.gradle | 34 +++ .../de/cech12/ceramicbucket/CommonLoader.java | 19 ++ .../de/cech12/ceramicbucket/Constants.java | 20 ++ .../ceramicbucket/platform/Services.java | 40 +++ .../platform/services/IConfigHelper.java | 51 ++++ .../platform/services/IPlatformHelper.java | 38 +++ .../assets/ceramicbucket/lang/de_de.json | 0 .../assets/ceramicbucket/lang/en_us.json | 0 .../assets/ceramicbucket/lang/es_es.json | 0 .../assets/ceramicbucket/lang/ko_kr.json | 0 .../assets/ceramicbucket/lang/pt_br.json | 0 .../assets/ceramicbucket/lang/pt_pt.json | 0 .../assets/ceramicbucket/lang/ru_ru.json | 0 .../assets/ceramicbucket/lang/uk_ua.json | 0 .../models/item/ceramic_bucket.json | 0 .../models/item/unfired_clay_bucket.json | 0 .../textures/item/ceramic_bucket.png | Bin .../textures/item/ceramic_bucket_cracked.png | Bin .../item/ceramic_bucket_cracked_lower.png | Bin .../textures/item/ceramic_bucket_lower.png | Bin .../textures/item/unfired_clay_bucket.png | Bin .../recipes/misc/ceramic_bucket.json | 0 .../recipes/misc/unfired_clay_bucket.json | 0 .../ceramicbucket/recipes/ceramic_bucket.json | 0 .../recipes/unfired_clay_bucket.json | 0 .../tags/fluids/ceramic_cracking.json | 0 {src => common/src}/main/resources/logo.png | Bin .../src}/main/resources/pack.mcmeta | 0 forge/build.gradle | 107 ++++++++ .../ceramicbucket/CeramicBucketMod.java | 29 +-- .../cech12/ceramicbucket/init/ModTags.java | 4 +- .../platform/ForgeConfigHelper.java | 98 ++++++++ .../platform/ForgePlatformHelper.java | 27 ++ forge/src/main/resources/META-INF/mods.toml | 31 +++ ...amicbucket.platform.services.IConfigHelper | 1 + ...icbucket.platform.services.IPlatformHelper | 1 + .../cech12/ceramicbucket/BucketTestUtils.java | 2 +- .../ceramicbucket/IntegrationTestUtils.java | 2 +- .../integration/CauldronTests.java | 2 +- .../integration/DispenserTests.java | 2 +- .../integration/EntityTests.java | 2 +- .../ceramicbucket/integration/WorldTests.java | 2 +- .../ceramicbucket/unit/ConfigTests.java | 2 +- .../ceramicbucket/unit/ItemFiltersTests.java | 2 +- .../structures/cauldron/cauldron_empty.nbt | Bin .../cauldron/cauldron_water_full.nbt | Bin .../cauldron/cauldron_water_one_third.nbt | Bin .../cauldron/cauldron_water_two_thirds.nbt | Bin .../structures/dispenser/empty_dispenser.nbt | Bin .../structures/entity/entity_pit.nbt | Bin .../structures/world/fluid_pit.nbt | Bin gradle.properties | 50 ++-- neoforge/build.gradle | 71 ++++++ .../ceramicbucket/CeramicBucketMod.java | 58 +++++ .../de/cech12/ceramicbucket/init/ModTags.java | 23 ++ .../platform/NeoForgeConfigHelper.java | 98 ++++++++ .../platform/NeoForgePlatformHelper.java | 27 ++ .../src/main/resources/META-INF/mods.toml | 31 +++ ...amicbucket.platform.services.IConfigHelper | 1 + ...icbucket.platform.services.IPlatformHelper | 1 + settings.gradle | 25 +- .../ceramicbucket/config/ServerConfig.java | 52 ---- src/main/resources/META-INF/mods.toml | 31 --- 68 files changed, 991 insertions(+), 291 deletions(-) create mode 100644 common/build.gradle create mode 100644 common/src/main/java/de/cech12/ceramicbucket/CommonLoader.java create mode 100644 common/src/main/java/de/cech12/ceramicbucket/Constants.java create mode 100644 common/src/main/java/de/cech12/ceramicbucket/platform/Services.java create mode 100644 common/src/main/java/de/cech12/ceramicbucket/platform/services/IConfigHelper.java create mode 100644 common/src/main/java/de/cech12/ceramicbucket/platform/services/IPlatformHelper.java rename {src => common/src}/main/resources/assets/ceramicbucket/lang/de_de.json (100%) rename {src => common/src}/main/resources/assets/ceramicbucket/lang/en_us.json (100%) rename {src => common/src}/main/resources/assets/ceramicbucket/lang/es_es.json (100%) rename {src => common/src}/main/resources/assets/ceramicbucket/lang/ko_kr.json (100%) rename {src => common/src}/main/resources/assets/ceramicbucket/lang/pt_br.json (100%) rename {src => common/src}/main/resources/assets/ceramicbucket/lang/pt_pt.json (100%) rename {src => common/src}/main/resources/assets/ceramicbucket/lang/ru_ru.json (100%) rename {src => common/src}/main/resources/assets/ceramicbucket/lang/uk_ua.json (100%) rename {src => common/src}/main/resources/assets/ceramicbucket/models/item/ceramic_bucket.json (100%) rename {src => common/src}/main/resources/assets/ceramicbucket/models/item/unfired_clay_bucket.json (100%) rename {src => common/src}/main/resources/assets/ceramicbucket/textures/item/ceramic_bucket.png (100%) rename {src => common/src}/main/resources/assets/ceramicbucket/textures/item/ceramic_bucket_cracked.png (100%) rename {src => common/src}/main/resources/assets/ceramicbucket/textures/item/ceramic_bucket_cracked_lower.png (100%) rename {src => common/src}/main/resources/assets/ceramicbucket/textures/item/ceramic_bucket_lower.png (100%) rename {src => common/src}/main/resources/assets/ceramicbucket/textures/item/unfired_clay_bucket.png (100%) rename {src => common/src}/main/resources/data/ceramicbucket/advancements/recipes/misc/ceramic_bucket.json (100%) rename {src => common/src}/main/resources/data/ceramicbucket/advancements/recipes/misc/unfired_clay_bucket.json (100%) rename {src => common/src}/main/resources/data/ceramicbucket/recipes/ceramic_bucket.json (100%) rename {src => common/src}/main/resources/data/ceramicbucket/recipes/unfired_clay_bucket.json (100%) rename {src => common/src}/main/resources/data/ceramicbucket/tags/fluids/ceramic_cracking.json (100%) rename {src => common/src}/main/resources/logo.png (100%) rename {src => common/src}/main/resources/pack.mcmeta (100%) create mode 100644 forge/build.gradle rename {src/main/java => forge/src/main/java/de}/cech12/ceramicbucket/CeramicBucketMod.java (72%) rename {src/main/java => forge/src/main/java/de}/cech12/ceramicbucket/init/ModTags.java (86%) create mode 100644 forge/src/main/java/de/cech12/ceramicbucket/platform/ForgeConfigHelper.java create mode 100644 forge/src/main/java/de/cech12/ceramicbucket/platform/ForgePlatformHelper.java create mode 100644 forge/src/main/resources/META-INF/mods.toml create mode 100644 forge/src/main/resources/META-INF/services/de.cech12.ceramicbucket.platform.services.IConfigHelper create mode 100644 forge/src/main/resources/META-INF/services/de.cech12.ceramicbucket.platform.services.IPlatformHelper rename {src/test/java => forge/src/test/java/de}/cech12/ceramicbucket/BucketTestUtils.java (99%) rename {src/test/java => forge/src/test/java/de}/cech12/ceramicbucket/IntegrationTestUtils.java (99%) rename {src/test/java => forge/src/test/java/de}/cech12/ceramicbucket/integration/CauldronTests.java (99%) rename {src/test/java => forge/src/test/java/de}/cech12/ceramicbucket/integration/DispenserTests.java (99%) rename {src/test/java => forge/src/test/java/de}/cech12/ceramicbucket/integration/EntityTests.java (99%) rename {src/test/java => forge/src/test/java/de}/cech12/ceramicbucket/integration/WorldTests.java (98%) rename {src/test/java => forge/src/test/java/de}/cech12/ceramicbucket/unit/ConfigTests.java (99%) rename {src/test/java => forge/src/test/java/de}/cech12/ceramicbucket/unit/ItemFiltersTests.java (99%) rename {src => forge/src}/test/resources/data/ceramicbucket/structures/cauldron/cauldron_empty.nbt (100%) rename {src => forge/src}/test/resources/data/ceramicbucket/structures/cauldron/cauldron_water_full.nbt (100%) rename {src => forge/src}/test/resources/data/ceramicbucket/structures/cauldron/cauldron_water_one_third.nbt (100%) rename {src => forge/src}/test/resources/data/ceramicbucket/structures/cauldron/cauldron_water_two_thirds.nbt (100%) rename {src => forge/src}/test/resources/data/ceramicbucket/structures/dispenser/empty_dispenser.nbt (100%) rename {src => forge/src}/test/resources/data/ceramicbucket/structures/entity/entity_pit.nbt (100%) rename {src => forge/src}/test/resources/data/ceramicbucket/structures/world/fluid_pit.nbt (100%) create mode 100644 neoforge/build.gradle create mode 100644 neoforge/src/main/java/de/cech12/ceramicbucket/CeramicBucketMod.java create mode 100644 neoforge/src/main/java/de/cech12/ceramicbucket/init/ModTags.java create mode 100644 neoforge/src/main/java/de/cech12/ceramicbucket/platform/NeoForgeConfigHelper.java create mode 100644 neoforge/src/main/java/de/cech12/ceramicbucket/platform/NeoForgePlatformHelper.java create mode 100644 neoforge/src/main/resources/META-INF/mods.toml create mode 100644 neoforge/src/main/resources/META-INF/services/de.cech12.ceramicbucket.platform.services.IConfigHelper create mode 100644 neoforge/src/main/resources/META-INF/services/de.cech12.ceramicbucket.platform.services.IPlatformHelper delete mode 100644 src/main/java/cech12/ceramicbucket/config/ServerConfig.java delete mode 100644 src/main/resources/META-INF/mods.toml diff --git a/.github/ISSUE_TEMPLATE/bug.yml b/.github/ISSUE_TEMPLATE/bug.yml index eb9d071..e9fb17a 100644 --- a/.github/ISSUE_TEMPLATE/bug.yml +++ b/.github/ISSUE_TEMPLATE/bug.yml @@ -14,11 +14,22 @@ body: description: What version of Minecraft were you running? validations: required: true + - type: dropdown + id: modLoader + attributes: + label: Mod Loader + description: What mod loader were you using? + options: + - Fabric + - Forge + - NeoForge + validations: + required: true - type: input id: modLoaderVersion attributes: - label: Forge Version - description: What version of Forge were you using? + label: Mod Loader Version + description: What mod loader version were you using? validations: required: true - type: input diff --git a/.github/workflows/cicd-workflow.yml b/.github/workflows/cicd-workflow.yml index 10841af..2cc0795 100644 --- a/.github/workflows/cicd-workflow.yml +++ b/.github/workflows/cicd-workflow.yml @@ -33,13 +33,15 @@ jobs: mod-id: ceramicbucket secrets: github-token: ${{ secrets.GITHUB_TOKEN }} - publish-curseforge: + publish-forge-on-curseforge: needs: publish-github if: startsWith(github.ref, 'refs/tags/') - name: Publish Curseforge + name: Publish Forge on Curseforge uses: cech12/MinecraftModActions/.github/workflows/publish-curseforge.yml@main with: java-version: 17 + subproject: forge + title-prefix: forge- curseforge-id: 363799 game-versions: | 1.20.2 @@ -49,13 +51,51 @@ jobs: secrets: github-token: ${{ secrets.GITHUB_TOKEN }} curseforge-token: ${{ secrets.CURSEFORGE_API_KEY }} - publish-modrinth: + publish-forge-on-modrinth: needs: publish-github if: startsWith(github.ref, 'refs/tags/') - name: Publish Modrinth + name: Publish Forge on Modrinth uses: cech12/MinecraftModActions/.github/workflows/publish-modrinth.yml@main with: java-version: 17 + subproject: forge + title-prefix: forge- + modrinth-id: M9G5zpf1 + game-versions: | + 1.20.2 + release-type: release + loaders: | + forge + secrets: + github-token: ${{ secrets.GITHUB_TOKEN }} + modrinth-token: ${{ secrets.MODRINTH_API_KEY }} + publish-neoforge-on-curseforge: + needs: publish-github + if: startsWith(github.ref, 'refs/tags/') + name: Publish NeoForge on Curseforge + uses: cech12/MinecraftModActions/.github/workflows/publish-curseforge.yml@main + with: + java-version: 17 + subproject: neoforge + title-prefix: neoforge- + curseforge-id: 363799 + game-versions: | + 1.20.2 + release-type: release + loaders: | + neoforge + secrets: + github-token: ${{ secrets.GITHUB_TOKEN }} + curseforge-token: ${{ secrets.CURSEFORGE_API_KEY }} + publish-neoforge-on-modrinth: + needs: publish-github + if: startsWith(github.ref, 'refs/tags/') + name: Publish NeoForge on Modrinth + uses: cech12/MinecraftModActions/.github/workflows/publish-modrinth.yml@main + with: + java-version: 17 + subproject: neoforge + title-prefix: neoforge- modrinth-id: M9G5zpf1 game-versions: | 1.20.2 diff --git a/.gitignore b/.gitignore index 5d3192c..33ba68d 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ build # other eclipse run +runs run-data # Files from Forge MDK diff --git a/CHANGELOG.md b/CHANGELOG.md index 874010c..000e660 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Forge Recommended Versioning](https://mcforge.readthedocs.io/en/latest/conventions/versioning/). +## [1.20.2-5.0.0.0] - 2024-01-03 +- Update to Forge 48.1.0 & Neoforge 20.2.86 +- Move to Multiloader mod template to support Forge and Neoforge + ## [1.20.2-4.2.0.0] - 2023-10-16 ### Changed - update and move back to Forge 1.20.2-48.0.23 (from NeoForge) until it is stable diff --git a/build.gradle b/build.gradle index 61bd249..1f67105 100644 --- a/build.gradle +++ b/build.gradle @@ -1,169 +1,91 @@ plugins { - id 'eclipse' - id 'idea' - id 'maven-publish' - id 'net.minecraftforge.gradle' version '[6.0,6.2)' + // Required for NeoGradle + id "org.jetbrains.gradle.plugin.idea-ext" version "1.1.7" } -version = "${minecraft_version}-${mod_version}" -group = mod_group_id -base { - archivesName = mod_id -} - -// Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. -java.toolchain.languageVersion = JavaLanguageVersion.of(17) - -println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" -minecraft { - mappings channel: 'official', version: minecraft_version - - // When true, this property will have all Eclipse/IntelliJ IDEA run configurations run the "prepareX" task for the given run configuration before launching the game. - // In most cases, it is not necessary to enable. - // enableEclipsePrepareRuns = true - // enableIdeaPrepareRuns = true - - // This property allows configuring Gradle's ProcessResources task(s) to run on IDE output locations before launching the game. - // It is REQUIRED to be set to true for this template to function. - // See https://docs.gradle.org/current/dsl/org.gradle.language.jvm.tasks.ProcessResources.html - copyIdeResources = true - - // When true, this property will add the folder name of all declared run configurations to generated IDE run configurations. - // The folder name can be set on a run configuration using the "folderName" property. - // By default, the folder name of a run configuration is the name of the Gradle project containing it. - // generateRunFolders = true - - // See https://docs.minecraftforge.net/en/latest/advanced/accesstransformers/ for more information. - // accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') - - // Default run configurations. - runs { - // applies to all the run configs below - configureEach { - workingDirectory project.file('run') - - // Recommended logging data for a userdev environment - // The markers can be added/remove as needed separated by commas. - // "SCAN": For mods scan. - // "REGISTRIES": For firing of registry events. - // "REGISTRYDUMP": For getting the contents of all registries. - property 'forge.logging.markers', 'REGISTRIES' - - // Recommended logging level for the console - // You can set various levels here. - // Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels - property 'forge.logging.console.level', 'debug' - - //for bucketlib - property 'mixin.env.remapRefMap', 'true' - property 'mixin.env.refMapRemappingFile', "${buildDir}/createSrgToMcp/output.srg" - - mods { - "${mod_id}" { - source sourceSets.main - } - } - } - - client { - // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. - property 'forge.enabledGameTestNamespaces', mod_id +subprojects { + apply plugin: 'java' + + version "$project.minecraft_version-$project.mod_version" + + java.toolchain.languageVersion = JavaLanguageVersion.of(17) + //java.withSourcesJar() + //java.withJavadocJar() + + jar { + from(rootProject.file("LICENSE")) + manifest { + attributes([ + 'Specification-Title' : mod_id, + 'Specification-Vendor' : mod_author, + 'Specification-Version' : project.jar.archiveVersion, + 'Implementation-Title' : project.name, + 'Implementation-Version' : project.jar.archiveVersion, + 'Implementation-Vendor' : mod_author, + 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), + 'Timestamp' : System.currentTimeMillis(), + 'Built-On-Java' : "${System.getProperty('java.vm.version')} (${System.getProperty('java.vm.vendor')})", + 'Built-On-Minecraft' : minecraft_version + ]) } + } - server { - property 'forge.enabledGameTestNamespaces', mod_id - args '--nogui' - } + //sourcesJar { + // from(rootProject.file("LICENSE")) + //} - gameTestServer { - property 'forge.enabledGameTestNamespaces', mod_id + repositories { + mavenCentral() + maven { + name = 'Sponge / Mixin' + url = 'https://repo.spongepowered.org/repository/maven-public/' } - - data { - // example of overriding the workingDirectory set in configureEach above - workingDirectory project.file('run-data') - - // Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources. - args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') + maven { + name = 'BlameJared Maven (JEI / CraftTweaker / Bookshelf)' + url = 'https://maven.blamejared.com' } } -} - -// Include resources generated by data generators. -sourceSets.main.resources { srcDir 'src/generated/resources' } - -repositories { - maven { - name 'Jitpack' - url 'https://jitpack.io' - } - maven { - url 'https://repo.maven.apache.org/maven2' - name 'Maven Central' - } -} - -dependencies { - minecraft "net.minecraftforge:forge:${project.minecraft_version}-${project.forge_version}" - - // compile against the BucketLib API but do not include it at runtime - compileOnly fg.deobf("com.github.cech12:BucketLib:${project.bucketlib_version}:api") - // at runtime, use the full BucketLib jar - runtimeOnly fg.deobf("com.github.cech12:BucketLib:${project.bucketlib_version}") -} - -tasks.named('processResources', ProcessResources).configure { - var replaceProperties = [ - minecraft_version: minecraft_version, minecraft_version_range: minecraft_version_range, - forge_version: forge_version, forge_version_range: forge_version_range, - loader_version_range: loader_version_range, - mod_id: mod_id, mod_name: mod_name, mod_license: mod_license, mod_version: mod_version, - mod_authors: mod_authors, mod_description: mod_description, mod_issue_tracker: mod_issue_tracker, - mod_url: mod_url, - bucketlib_version_range: bucketlib_version_range - ] - inputs.properties replaceProperties - - filesMatching(['META-INF/mods.toml', 'pack.mcmeta']) { - expand replaceProperties + [project: project] - } -} -tasks.named('jar', Jar).configure { - manifest { - attributes([ - 'Specification-Title' : mod_id, - 'Specification-Vendor' : mod_authors, - 'Specification-Version' : project.jar.archiveVersion, - 'Implementation-Title' : project.name, - 'Implementation-Version' : project.jar.archiveVersion, - 'Implementation-Vendor' : mod_authors, - 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") - ]) + tasks.withType(JavaCompile).configureEach { + it.options.encoding = 'UTF-8' + it.options.getRelease().set(17) } - // This is the preferred method to reobfuscate your jar file - finalizedBy 'reobfJar' -} - -// However if you are in a multi-project build, dev time needs unobfed jar files, so you can delay the obfuscation until publishing by doing: -// tasks.named('publish').configure { -// dependsOn 'reobfJar' -// } - -publishing { - publications { - register('mavenJava', MavenPublication) { - artifact jar + processResources { + def expandProps = [ + "version": version, + "group": project.group, //Else we target the task's group. + "minecraft_version": minecraft_version, + "minecraft_version_range": minecraft_version_range, + "forge_version": forge_version, + "forge_version_range": forge_version_range, + "forge_loader_version_range": forge_loader_version_range, + //"fabric_version": fabric_version, + //"fabric_loader_version": fabric_loader_version, + "neoforge_version": neoforge_version, + "neoforge_version_range": neoforge_version_range, + "neoforge_loader_version_range": neoforge_loader_version_range, + "mod_id": mod_id, + "mod_name": mod_name, + "mod_author": mod_author, + "mod_license": mod_license, + "mod_url": mod_url, + "mod_issue_tracker": mod_issue_tracker, + "mod_description": project.description, + "bucketlib_version": bucketlib_version, + "bucketlib_version_range": bucketlib_version_range + ] + + filesMatching(['pack.mcmeta', 'fabric.mod.json', 'META-INF/mods.toml', '*.mixins.json']) { + expand expandProps } + inputs.properties(expandProps) } - repositories { - maven { - url "file://${project.projectDir}/mcmodsrepo" - } - } -} -tasks.withType(JavaCompile).configureEach { - options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation -} + // Disables Gradle's custom module metadata from being published to maven. The + // metadata includes mapped dependencies which are not reasonably consumable by + // other mod developers. + tasks.withType(GenerateModuleMetadata).configureEach { + enabled = false + } +} \ No newline at end of file diff --git a/common/build.gradle b/common/build.gradle new file mode 100644 index 0000000..19f6c17 --- /dev/null +++ b/common/build.gradle @@ -0,0 +1,34 @@ +plugins { + id 'idea' + id 'java' + id 'maven-publish' + id 'org.spongepowered.gradle.vanilla' version '0.2.1-SNAPSHOT' +} +base { + archivesName = "${mod_id}-common" +} +minecraft { + version(minecraft_version) + if(file("src/main/resources/${mod_id}.accesswidener").exists()){ + accessWideners(file("src/main/resources/${mod_id}.accesswidener")) + } +} + +dependencies { + compileOnly group:'org.spongepowered', name:'mixin', version:'0.8.5' + implementation group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.1' +} + +publishing { + publications { + mavenJava(MavenPublication) { + artifactId base.archivesName.get() + from components.java + } + } + repositories { + maven { + url "file://" + System.getenv("local_maven") + } + } +} \ No newline at end of file diff --git a/common/src/main/java/de/cech12/ceramicbucket/CommonLoader.java b/common/src/main/java/de/cech12/ceramicbucket/CommonLoader.java new file mode 100644 index 0000000..486021f --- /dev/null +++ b/common/src/main/java/de/cech12/ceramicbucket/CommonLoader.java @@ -0,0 +1,19 @@ +package de.cech12.ceramicbucket; + +import de.cech12.ceramicbucket.platform.Services; + +/** + * A static class for all loaders which initializes everything which is used by all loaders. + */ +public class CommonLoader { + + /** + * Initialize method that should be called by every loader mod in the constructor. + */ + public static void init() { + Services.CONFIG.init(); + } + + private CommonLoader() {} + +} diff --git a/common/src/main/java/de/cech12/ceramicbucket/Constants.java b/common/src/main/java/de/cech12/ceramicbucket/Constants.java new file mode 100644 index 0000000..6e6d19f --- /dev/null +++ b/common/src/main/java/de/cech12/ceramicbucket/Constants.java @@ -0,0 +1,20 @@ +package de.cech12.ceramicbucket; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Class that contains all common constants. + */ +public class Constants { + + /** mod id */ + public static final String MOD_ID = "ceramicbucket"; + /** mod name*/ + public static final String MOD_NAME = "Ceramic Bucket"; + /** Logger instance */ + public static final Logger LOG = LoggerFactory.getLogger(MOD_NAME); + + private Constants() {} + +} \ No newline at end of file diff --git a/common/src/main/java/de/cech12/ceramicbucket/platform/Services.java b/common/src/main/java/de/cech12/ceramicbucket/platform/Services.java new file mode 100644 index 0000000..8e72fc2 --- /dev/null +++ b/common/src/main/java/de/cech12/ceramicbucket/platform/Services.java @@ -0,0 +1,40 @@ +package de.cech12.ceramicbucket.platform; + +import de.cech12.ceramicbucket.Constants; +import de.cech12.ceramicbucket.platform.services.IConfigHelper; +import de.cech12.ceramicbucket.platform.services.IPlatformHelper; + +import java.util.ServiceLoader; + +/** + * Service loaders are a built-in Java feature that allow us to locate implementations of an interface that vary from one + * environment to another. In the context of MultiLoader we use this feature to access a mock API in the common code that + * is swapped out for the platform specific implementation at runtime. + */ +public class Services { + + /** Platform instance */ + public static final IPlatformHelper PLATFORM = load(IPlatformHelper.class); + /** Config instance */ + public static final IConfigHelper CONFIG = load(IConfigHelper.class); + + /** + * This code is used to load a service for the current environment. Your implementation of the service must be defined + * manually by including a text file in META-INF/services named with the fully qualified class name of the service. + * Inside the file you should write the fully qualified class name of the implementation to load for the platform. For + * example our file on Forge points to ForgePlatformHelper while Fabric points to FabricPlatformHelper. + * @param clazz Service class, which should be loaded. + * @return service instance + * @param Type of service class + */ + public static T load(Class clazz) { + final T loadedService = ServiceLoader.load(clazz) + .findFirst() + .orElseThrow(() -> new NullPointerException("Failed to load service for " + clazz.getName())); + Constants.LOG.debug("Loaded {} for service {}", loadedService, clazz); + return loadedService; + } + + private Services() {} + +} \ No newline at end of file diff --git a/common/src/main/java/de/cech12/ceramicbucket/platform/services/IConfigHelper.java b/common/src/main/java/de/cech12/ceramicbucket/platform/services/IConfigHelper.java new file mode 100644 index 0000000..903ef94 --- /dev/null +++ b/common/src/main/java/de/cech12/ceramicbucket/platform/services/IConfigHelper.java @@ -0,0 +1,51 @@ +package de.cech12.ceramicbucket.platform.services; + +/** + * Common configuration helper service interface. + */ +public interface IConfigHelper { + + /** Default value of break temperature */ + int BREAK_TEMPERATURE_DEFAULT = 1000; + /** Default value of durability */ + int DURABILITY_DEFAULT = 0; + /** Default value of fish obtaining option */ + boolean FISH_OBTAINING_ENABLED_DEFAULT = true; + /** Default value of milking option */ + boolean MILKING_ENABLED_DEFAULT = true; + + + /** + * Initialization method for the Service implementations. + */ + void init(); + + /** + * Gets the configured break temperature value. + * + * @return configured break temperature value + */ + int getBreakTemperature(); + + /** + * Gets the configured durability value. + * + * @return configured durability value + */ + int getDurability(); + + /** + * Gets the fish obtaining enabled value. + * + * @return configured fish obtaining enabled value + */ + boolean isFishObtainingEnabled(); + + /** + * Gets the configured milking enabled value. + * + * @return configured milking enabled value + */ + boolean isMilkingEnabled(); + +} \ No newline at end of file diff --git a/common/src/main/java/de/cech12/ceramicbucket/platform/services/IPlatformHelper.java b/common/src/main/java/de/cech12/ceramicbucket/platform/services/IPlatformHelper.java new file mode 100644 index 0000000..f0a5b1e --- /dev/null +++ b/common/src/main/java/de/cech12/ceramicbucket/platform/services/IPlatformHelper.java @@ -0,0 +1,38 @@ +package de.cech12.ceramicbucket.platform.services; + +/** + * Common platform helper service interface. + */ +public interface IPlatformHelper { + + /** + * Gets the name of the current platform + * + * @return The name of the current platform. + */ + String getPlatformName(); + + /** + * Checks if a mod with the given id is loaded. + * + * @param modId The mod to check if it is loaded. + * @return True if the mod is loaded, false otherwise. + */ + boolean isModLoaded(String modId); + + /** + * Check if the game is currently in a development environment. + * + * @return True if in a development environment, false otherwise. + */ + boolean isDevelopmentEnvironment(); + + /** + * Gets the name of the environment type as a string. + * + * @return The name of the environment type. + */ + default String getEnvironmentName() { + return isDevelopmentEnvironment() ? "development" : "production"; + } +} \ No newline at end of file diff --git a/src/main/resources/assets/ceramicbucket/lang/de_de.json b/common/src/main/resources/assets/ceramicbucket/lang/de_de.json similarity index 100% rename from src/main/resources/assets/ceramicbucket/lang/de_de.json rename to common/src/main/resources/assets/ceramicbucket/lang/de_de.json diff --git a/src/main/resources/assets/ceramicbucket/lang/en_us.json b/common/src/main/resources/assets/ceramicbucket/lang/en_us.json similarity index 100% rename from src/main/resources/assets/ceramicbucket/lang/en_us.json rename to common/src/main/resources/assets/ceramicbucket/lang/en_us.json diff --git a/src/main/resources/assets/ceramicbucket/lang/es_es.json b/common/src/main/resources/assets/ceramicbucket/lang/es_es.json similarity index 100% rename from src/main/resources/assets/ceramicbucket/lang/es_es.json rename to common/src/main/resources/assets/ceramicbucket/lang/es_es.json diff --git a/src/main/resources/assets/ceramicbucket/lang/ko_kr.json b/common/src/main/resources/assets/ceramicbucket/lang/ko_kr.json similarity index 100% rename from src/main/resources/assets/ceramicbucket/lang/ko_kr.json rename to common/src/main/resources/assets/ceramicbucket/lang/ko_kr.json diff --git a/src/main/resources/assets/ceramicbucket/lang/pt_br.json b/common/src/main/resources/assets/ceramicbucket/lang/pt_br.json similarity index 100% rename from src/main/resources/assets/ceramicbucket/lang/pt_br.json rename to common/src/main/resources/assets/ceramicbucket/lang/pt_br.json diff --git a/src/main/resources/assets/ceramicbucket/lang/pt_pt.json b/common/src/main/resources/assets/ceramicbucket/lang/pt_pt.json similarity index 100% rename from src/main/resources/assets/ceramicbucket/lang/pt_pt.json rename to common/src/main/resources/assets/ceramicbucket/lang/pt_pt.json diff --git a/src/main/resources/assets/ceramicbucket/lang/ru_ru.json b/common/src/main/resources/assets/ceramicbucket/lang/ru_ru.json similarity index 100% rename from src/main/resources/assets/ceramicbucket/lang/ru_ru.json rename to common/src/main/resources/assets/ceramicbucket/lang/ru_ru.json diff --git a/src/main/resources/assets/ceramicbucket/lang/uk_ua.json b/common/src/main/resources/assets/ceramicbucket/lang/uk_ua.json similarity index 100% rename from src/main/resources/assets/ceramicbucket/lang/uk_ua.json rename to common/src/main/resources/assets/ceramicbucket/lang/uk_ua.json diff --git a/src/main/resources/assets/ceramicbucket/models/item/ceramic_bucket.json b/common/src/main/resources/assets/ceramicbucket/models/item/ceramic_bucket.json similarity index 100% rename from src/main/resources/assets/ceramicbucket/models/item/ceramic_bucket.json rename to common/src/main/resources/assets/ceramicbucket/models/item/ceramic_bucket.json diff --git a/src/main/resources/assets/ceramicbucket/models/item/unfired_clay_bucket.json b/common/src/main/resources/assets/ceramicbucket/models/item/unfired_clay_bucket.json similarity index 100% rename from src/main/resources/assets/ceramicbucket/models/item/unfired_clay_bucket.json rename to common/src/main/resources/assets/ceramicbucket/models/item/unfired_clay_bucket.json diff --git a/src/main/resources/assets/ceramicbucket/textures/item/ceramic_bucket.png b/common/src/main/resources/assets/ceramicbucket/textures/item/ceramic_bucket.png similarity index 100% rename from src/main/resources/assets/ceramicbucket/textures/item/ceramic_bucket.png rename to common/src/main/resources/assets/ceramicbucket/textures/item/ceramic_bucket.png diff --git a/src/main/resources/assets/ceramicbucket/textures/item/ceramic_bucket_cracked.png b/common/src/main/resources/assets/ceramicbucket/textures/item/ceramic_bucket_cracked.png similarity index 100% rename from src/main/resources/assets/ceramicbucket/textures/item/ceramic_bucket_cracked.png rename to common/src/main/resources/assets/ceramicbucket/textures/item/ceramic_bucket_cracked.png diff --git a/src/main/resources/assets/ceramicbucket/textures/item/ceramic_bucket_cracked_lower.png b/common/src/main/resources/assets/ceramicbucket/textures/item/ceramic_bucket_cracked_lower.png similarity index 100% rename from src/main/resources/assets/ceramicbucket/textures/item/ceramic_bucket_cracked_lower.png rename to common/src/main/resources/assets/ceramicbucket/textures/item/ceramic_bucket_cracked_lower.png diff --git a/src/main/resources/assets/ceramicbucket/textures/item/ceramic_bucket_lower.png b/common/src/main/resources/assets/ceramicbucket/textures/item/ceramic_bucket_lower.png similarity index 100% rename from src/main/resources/assets/ceramicbucket/textures/item/ceramic_bucket_lower.png rename to common/src/main/resources/assets/ceramicbucket/textures/item/ceramic_bucket_lower.png diff --git a/src/main/resources/assets/ceramicbucket/textures/item/unfired_clay_bucket.png b/common/src/main/resources/assets/ceramicbucket/textures/item/unfired_clay_bucket.png similarity index 100% rename from src/main/resources/assets/ceramicbucket/textures/item/unfired_clay_bucket.png rename to common/src/main/resources/assets/ceramicbucket/textures/item/unfired_clay_bucket.png diff --git a/src/main/resources/data/ceramicbucket/advancements/recipes/misc/ceramic_bucket.json b/common/src/main/resources/data/ceramicbucket/advancements/recipes/misc/ceramic_bucket.json similarity index 100% rename from src/main/resources/data/ceramicbucket/advancements/recipes/misc/ceramic_bucket.json rename to common/src/main/resources/data/ceramicbucket/advancements/recipes/misc/ceramic_bucket.json diff --git a/src/main/resources/data/ceramicbucket/advancements/recipes/misc/unfired_clay_bucket.json b/common/src/main/resources/data/ceramicbucket/advancements/recipes/misc/unfired_clay_bucket.json similarity index 100% rename from src/main/resources/data/ceramicbucket/advancements/recipes/misc/unfired_clay_bucket.json rename to common/src/main/resources/data/ceramicbucket/advancements/recipes/misc/unfired_clay_bucket.json diff --git a/src/main/resources/data/ceramicbucket/recipes/ceramic_bucket.json b/common/src/main/resources/data/ceramicbucket/recipes/ceramic_bucket.json similarity index 100% rename from src/main/resources/data/ceramicbucket/recipes/ceramic_bucket.json rename to common/src/main/resources/data/ceramicbucket/recipes/ceramic_bucket.json diff --git a/src/main/resources/data/ceramicbucket/recipes/unfired_clay_bucket.json b/common/src/main/resources/data/ceramicbucket/recipes/unfired_clay_bucket.json similarity index 100% rename from src/main/resources/data/ceramicbucket/recipes/unfired_clay_bucket.json rename to common/src/main/resources/data/ceramicbucket/recipes/unfired_clay_bucket.json diff --git a/src/main/resources/data/ceramicbucket/tags/fluids/ceramic_cracking.json b/common/src/main/resources/data/ceramicbucket/tags/fluids/ceramic_cracking.json similarity index 100% rename from src/main/resources/data/ceramicbucket/tags/fluids/ceramic_cracking.json rename to common/src/main/resources/data/ceramicbucket/tags/fluids/ceramic_cracking.json diff --git a/src/main/resources/logo.png b/common/src/main/resources/logo.png similarity index 100% rename from src/main/resources/logo.png rename to common/src/main/resources/logo.png diff --git a/src/main/resources/pack.mcmeta b/common/src/main/resources/pack.mcmeta similarity index 100% rename from src/main/resources/pack.mcmeta rename to common/src/main/resources/pack.mcmeta diff --git a/forge/build.gradle b/forge/build.gradle new file mode 100644 index 0000000..3024b74 --- /dev/null +++ b/forge/build.gradle @@ -0,0 +1,107 @@ +plugins { + id 'idea' + id 'maven-publish' + id 'net.minecraftforge.gradle' version '[6.0.16,6.2)' + id 'org.spongepowered.mixin' version '0.7-SNAPSHOT' +} +base { + archivesName = "${mod_id}-forge" +} +//mixin { +// add(sourceSets.main, "${mod_id}.refmap.json") +// config("${mod_id}.mixins.json") +// config("${mod_id}.forge.mixins.json") +//} + +minecraft { + mappings channel: 'official', version: minecraft_version + + copyIdeResources = true //Calls processResources when in dev + + // Automatically enable forge AccessTransformers if the file exists + // This location is hardcoded in Forge and can not be changed. + // https://github.com/MinecraftForge/MinecraftForge/blob/be1698bb1554f9c8fa2f58e32b9ab70bc4385e60/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModFile.java#L123 + if (file('src/main/resources/META-INF/accesstransformer.cfg').exists()) { + accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') + } + + runs { + configureEach { + workingDirectory project.file('run') + ideaModule "${rootProject.name}.${project.name}.main" + property 'forge.logging.markers', 'REGISTRIES' + property 'forge.logging.console.level', 'debug' + property 'mixin.env.remapRefMap', 'true' + property 'mixin.env.refMapRemappingFile', "${projectDir}/build/createSrgToMcp/output.srg" + mods { + "${mod_id}" { + source sourceSets.main + source project(":common").sourceSets.main + //source sourceSets.test + } + } + } + client { + property 'forge.enabledGameTestNamespaces', mod_id + } + server { + property 'forge.enabledGameTestNamespaces', mod_id + args '--nogui' + } + gameTestServer { + property 'forge.enabledGameTestNamespaces', mod_id + } + data { + workingDirectory project.file('run-data') + args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') + } + } +} + +sourceSets.main.resources.srcDir 'src/generated/resources' + +repositories { + maven { + name = 'Jitpack' + url = 'https://jitpack.io' + } +} + +dependencies { + minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" + compileOnly project(":common") + //annotationProcessor("org.spongepowered:mixin:0.8.5-SNAPSHOT:processor") + + implementation fg.deobf("com.github.cech12.BucketLib:forge:${bucketlib_version}") +} + +tasks.withType(JavaCompile).configureEach { + source(project(":common").sourceSets.main.allSource) +} +//tasks.withType(Javadoc).configureEach { +// source(project(":common").sourceSets.main.allJava) +//} +//tasks.named("sourcesJar", Jar) { +// from(project(":common").sourceSets.main.allSource) +//} + +processResources { + from project(":common").sourceSets.main.resources +} + +jar.finalizedBy('reobfJar') + +publishing { + publications { + mavenJava(MavenPublication) { + artifactId base.archivesName.get() + from components.java + fg.component(it) + } + } + repositories { + maven { + url "file://" + System.getenv("local_maven") + } + } +} \ No newline at end of file diff --git a/src/main/java/cech12/ceramicbucket/CeramicBucketMod.java b/forge/src/main/java/de/cech12/ceramicbucket/CeramicBucketMod.java similarity index 72% rename from src/main/java/cech12/ceramicbucket/CeramicBucketMod.java rename to forge/src/main/java/de/cech12/ceramicbucket/CeramicBucketMod.java index c9dc165..d16da03 100644 --- a/src/main/java/cech12/ceramicbucket/CeramicBucketMod.java +++ b/forge/src/main/java/de/cech12/ceramicbucket/CeramicBucketMod.java @@ -1,22 +1,18 @@ -package cech12.ceramicbucket; +package de.cech12.ceramicbucket; -import cech12.bucketlib.api.BucketLibApi; -import cech12.bucketlib.api.item.UniversalBucketItem; -import cech12.ceramicbucket.config.ServerConfig; -import cech12.ceramicbucket.init.ModTags; +import de.cech12.bucketlib.api.BucketLibApi; +import de.cech12.bucketlib.api.item.UniversalBucketItem; +import de.cech12.ceramicbucket.init.ModTags; +import de.cech12.ceramicbucket.platform.Services; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.CreativeModeTabs; import net.minecraft.world.item.Item; import net.minecraftforge.event.BuildCreativeModeTabContentsEvent; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.config.ModConfig; import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; -import net.minecraftforge.fml.loading.FMLConfig; -import net.minecraftforge.fml.loading.FMLPaths; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.MissingMappingsEvent; @@ -25,7 +21,7 @@ import java.util.Arrays; import java.util.List; -import static cech12.ceramicbucket.CeramicBucketMod.MOD_ID; +import static de.cech12.ceramicbucket.CeramicBucketMod.MOD_ID; @Mod(MOD_ID) @Mod.EventBusSubscriber(modid = MOD_ID) @@ -38,12 +34,12 @@ public class CeramicBucketMod { public static final RegistryObject UNFIRED_CLAY_BUCKET = ITEMS.register("unfired_clay_bucket", () -> new Item(new Item.Properties())); public static final RegistryObject CERAMIC_BUCKET = ITEMS.register("ceramic_bucket", () -> new UniversalBucketItem( new UniversalBucketItem.Properties() - .upperCrackingTemperature(ServerConfig.CERAMIC_BUCKET_BREAK_TEMPERATURE) + .upperCrackingTemperature(Services.CONFIG::getBreakTemperature) .crackingFluids(ModTags.Fluids.CERAMIC_CRACKING) - .milking(ServerConfig.MILKING_ENABLED) - .entityObtaining(ServerConfig.FISH_OBTAINING_ENABLED) + .milking(Services.CONFIG::isMilkingEnabled) + .entityObtaining(Services.CONFIG::isFishObtainingEnabled) .dyeable(14975336) - .durability(ServerConfig.CERAMIC_BUCKET_DURABILITY) + .durability(Services.CONFIG::getDurability) )); private static final List oldResourceLocations = Arrays.stream(new String[]{ @@ -62,10 +58,9 @@ public CeramicBucketMod() { //listeners modEventBus.addListener(this::addItemsToTabs); //Config - ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, ServerConfig.SERVER_CONFIG); - ServerConfig.loadConfig(ServerConfig.SERVER_CONFIG, FMLPaths.GAMEDIR.get().resolve(FMLConfig.defaultConfigPath()).resolve(MOD_ID + "-server.toml")); + CommonLoader.init(); //register for IMC event - FMLJavaModLoadingContext.get().getModEventBus().addListener(this::sendImc); + modEventBus.addListener(this::sendImc); } private void sendImc(InterModEnqueueEvent evt) { diff --git a/src/main/java/cech12/ceramicbucket/init/ModTags.java b/forge/src/main/java/de/cech12/ceramicbucket/init/ModTags.java similarity index 86% rename from src/main/java/cech12/ceramicbucket/init/ModTags.java rename to forge/src/main/java/de/cech12/ceramicbucket/init/ModTags.java index ce0b64c..ad11563 100644 --- a/src/main/java/cech12/ceramicbucket/init/ModTags.java +++ b/forge/src/main/java/de/cech12/ceramicbucket/init/ModTags.java @@ -1,6 +1,6 @@ -package cech12.ceramicbucket.init; +package de.cech12.ceramicbucket.init; -import cech12.ceramicbucket.CeramicBucketMod; +import de.cech12.ceramicbucket.CeramicBucketMod; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.TagKey; import net.minecraft.world.level.material.Fluid; diff --git a/forge/src/main/java/de/cech12/ceramicbucket/platform/ForgeConfigHelper.java b/forge/src/main/java/de/cech12/ceramicbucket/platform/ForgeConfigHelper.java new file mode 100644 index 0000000..af42a84 --- /dev/null +++ b/forge/src/main/java/de/cech12/ceramicbucket/platform/ForgeConfigHelper.java @@ -0,0 +1,98 @@ +package de.cech12.ceramicbucket.platform; + +import com.electronwill.nightconfig.core.file.CommentedFileConfig; +import com.electronwill.nightconfig.core.io.WritingMode; +import de.cech12.ceramicbucket.Constants; +import de.cech12.ceramicbucket.platform.services.IConfigHelper; +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.fml.ModLoadingContext; +import net.minecraftforge.fml.config.ModConfig; +import net.minecraftforge.fml.loading.FMLConfig; +import net.minecraftforge.fml.loading.FMLPaths; + +import java.nio.file.Path; + +/** + * The config service implementation for Forge. + */ +public class ForgeConfigHelper implements IConfigHelper { + + private static ForgeConfigSpec SERVER_CONFIG; + + private static final ForgeConfigSpec.IntValue BREAK_TEMPERATURE; + private static final ForgeConfigSpec.IntValue DURABILITY; + private static final ForgeConfigSpec.BooleanValue FISH_OBTAINING_ENABLED; + private static final ForgeConfigSpec.BooleanValue MILKING_ENABLED; + + static { + final ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder(); + + builder.push("Balance Options"); + + BREAK_TEMPERATURE = builder + .comment("Minimum temperature of fluid at which the Ceramic Bucket breaks when emptied. (-1 means that bucket never breaks caused by high fluid temperature)") + .defineInRange("ceramicBucketBreakTemperature", BREAK_TEMPERATURE_DEFAULT, -1, 10000); + + DURABILITY = builder + .comment("Defines the maximum durability of a Ceramic Bucket. (0 deactivates the durability)") + .defineInRange("durability", DURABILITY_DEFAULT, 0, 10000); + + FISH_OBTAINING_ENABLED = builder + .comment("Whether or not obtaining fish with a Ceramic Bucket should be enabled.") + .define("fishObtainingEnabled", FISH_OBTAINING_ENABLED_DEFAULT); + + MILKING_ENABLED = builder + .comment("Whether or not milking entities with a Ceramic Bucket should be enabled.") + .define("milkingEnabled", MILKING_ENABLED_DEFAULT); + + builder.pop(); + + SERVER_CONFIG = builder.build(); + } + + @Override + public void init() { + ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, SERVER_CONFIG); + Path path = FMLPaths.GAMEDIR.get().resolve(FMLConfig.defaultConfigPath()).resolve(Constants.MOD_ID + "-server.toml"); + final CommentedFileConfig configData = CommentedFileConfig.builder(path).sync().autosave().writingMode(WritingMode.REPLACE).build(); + configData.load(); + SERVER_CONFIG.setConfig(configData); + } + + @Override + public int getBreakTemperature() { + try { + return BREAK_TEMPERATURE.get(); + } catch (IllegalStateException ex) { + return BREAK_TEMPERATURE_DEFAULT; + } + } + + @Override + public int getDurability() { + try { + return DURABILITY.get(); + } catch (IllegalStateException ex) { + return DURABILITY_DEFAULT; + } + } + + @Override + public boolean isFishObtainingEnabled() { + try { + return FISH_OBTAINING_ENABLED.get(); + } catch (IllegalStateException ex) { + return FISH_OBTAINING_ENABLED_DEFAULT; + } + } + + @Override + public boolean isMilkingEnabled() { + try { + return MILKING_ENABLED.get(); + } catch (IllegalStateException ex) { + return MILKING_ENABLED_DEFAULT; + } + } + +} diff --git a/forge/src/main/java/de/cech12/ceramicbucket/platform/ForgePlatformHelper.java b/forge/src/main/java/de/cech12/ceramicbucket/platform/ForgePlatformHelper.java new file mode 100644 index 0000000..e9e9798 --- /dev/null +++ b/forge/src/main/java/de/cech12/ceramicbucket/platform/ForgePlatformHelper.java @@ -0,0 +1,27 @@ +package de.cech12.ceramicbucket.platform; + +import de.cech12.ceramicbucket.platform.services.IPlatformHelper; +import net.minecraftforge.fml.ModList; +import net.minecraftforge.fml.loading.FMLLoader; + +/** + * The platform service implementation for Forge. + */ +public class ForgePlatformHelper implements IPlatformHelper { + + @Override + public String getPlatformName() { + return "Forge"; + } + + @Override + public boolean isModLoaded(String modId) { + return ModList.get().isLoaded(modId); + } + + @Override + public boolean isDevelopmentEnvironment() { + return !FMLLoader.isProduction(); + } + +} diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml new file mode 100644 index 0000000..5a8b4af --- /dev/null +++ b/forge/src/main/resources/META-INF/mods.toml @@ -0,0 +1,31 @@ +modLoader="javafml" +loaderVersion="${forge_loader_version_range}" +issueTrackerURL="${mod_issue_tracker}" +license="${mod_license}" +[[mods]] +modId="${mod_id}" +version="${version}" +displayName="${mod_name}" +displayURL="${mod_url}" +logoFile="logo.png" +authors="${mod_author}" +description='''${mod_description}''' +[[dependencies.${mod_id}]] +modId="forge" +mandatory=true +versionRange="${forge_version_range}" +ordering="NONE" +side="BOTH" +[[dependencies.${mod_id}]] +modId="minecraft" +mandatory=true +versionRange="${minecraft_version_range}" +ordering="NONE" +side="BOTH" +[[dependencies.${mod_id}]] +modId="bucketlib" +mandatory=true +versionRange="${bucketlib_version_range}" +referralUrl="https://github.com/cech12/BucketLib" +ordering="NONE" +side="BOTH" \ No newline at end of file diff --git a/forge/src/main/resources/META-INF/services/de.cech12.ceramicbucket.platform.services.IConfigHelper b/forge/src/main/resources/META-INF/services/de.cech12.ceramicbucket.platform.services.IConfigHelper new file mode 100644 index 0000000..61a25a9 --- /dev/null +++ b/forge/src/main/resources/META-INF/services/de.cech12.ceramicbucket.platform.services.IConfigHelper @@ -0,0 +1 @@ +de.cech12.ceramicbucket.platform.ForgeConfigHelper \ No newline at end of file diff --git a/forge/src/main/resources/META-INF/services/de.cech12.ceramicbucket.platform.services.IPlatformHelper b/forge/src/main/resources/META-INF/services/de.cech12.ceramicbucket.platform.services.IPlatformHelper new file mode 100644 index 0000000..c9ae68e --- /dev/null +++ b/forge/src/main/resources/META-INF/services/de.cech12.ceramicbucket.platform.services.IPlatformHelper @@ -0,0 +1 @@ +de.cech12.ceramicbucket.platform.ForgePlatformHelper \ No newline at end of file diff --git a/src/test/java/cech12/ceramicbucket/BucketTestUtils.java b/forge/src/test/java/de/cech12/ceramicbucket/BucketTestUtils.java similarity index 99% rename from src/test/java/cech12/ceramicbucket/BucketTestUtils.java rename to forge/src/test/java/de/cech12/ceramicbucket/BucketTestUtils.java index 084d2d3..7d0d591 100644 --- a/src/test/java/cech12/ceramicbucket/BucketTestUtils.java +++ b/forge/src/test/java/de/cech12/ceramicbucket/BucketTestUtils.java @@ -1,4 +1,4 @@ -package cech12.ceramicbucket; +package de.cech12.ceramicbucket; /* import cech12.ceramicbucket.api.item.CeramicBucketItems; diff --git a/src/test/java/cech12/ceramicbucket/IntegrationTestUtils.java b/forge/src/test/java/de/cech12/ceramicbucket/IntegrationTestUtils.java similarity index 99% rename from src/test/java/cech12/ceramicbucket/IntegrationTestUtils.java rename to forge/src/test/java/de/cech12/ceramicbucket/IntegrationTestUtils.java index 8701193..55d5616 100644 --- a/src/test/java/cech12/ceramicbucket/IntegrationTestUtils.java +++ b/forge/src/test/java/de/cech12/ceramicbucket/IntegrationTestUtils.java @@ -1,4 +1,4 @@ -package cech12.ceramicbucket; +package de.cech12.ceramicbucket; /* import com.alcatrazescapee.mcjunitlib.framework.IntegrationTestHelper; diff --git a/src/test/java/cech12/ceramicbucket/integration/CauldronTests.java b/forge/src/test/java/de/cech12/ceramicbucket/integration/CauldronTests.java similarity index 99% rename from src/test/java/cech12/ceramicbucket/integration/CauldronTests.java rename to forge/src/test/java/de/cech12/ceramicbucket/integration/CauldronTests.java index 9642392..0b36960 100644 --- a/src/test/java/cech12/ceramicbucket/integration/CauldronTests.java +++ b/forge/src/test/java/de/cech12/ceramicbucket/integration/CauldronTests.java @@ -1,4 +1,4 @@ -package cech12.ceramicbucket.integration; +package de.cech12.ceramicbucket.integration; /* import cech12.ceramicbucket.BucketTestUtils; diff --git a/src/test/java/cech12/ceramicbucket/integration/DispenserTests.java b/forge/src/test/java/de/cech12/ceramicbucket/integration/DispenserTests.java similarity index 99% rename from src/test/java/cech12/ceramicbucket/integration/DispenserTests.java rename to forge/src/test/java/de/cech12/ceramicbucket/integration/DispenserTests.java index 3f0b549..cb062d1 100644 --- a/src/test/java/cech12/ceramicbucket/integration/DispenserTests.java +++ b/forge/src/test/java/de/cech12/ceramicbucket/integration/DispenserTests.java @@ -1,4 +1,4 @@ -package cech12.ceramicbucket.integration; +package de.cech12.ceramicbucket.integration; /* import cech12.ceramicbucket.BucketTestUtils; diff --git a/src/test/java/cech12/ceramicbucket/integration/EntityTests.java b/forge/src/test/java/de/cech12/ceramicbucket/integration/EntityTests.java similarity index 99% rename from src/test/java/cech12/ceramicbucket/integration/EntityTests.java rename to forge/src/test/java/de/cech12/ceramicbucket/integration/EntityTests.java index c3cfbfd..8120748 100644 --- a/src/test/java/cech12/ceramicbucket/integration/EntityTests.java +++ b/forge/src/test/java/de/cech12/ceramicbucket/integration/EntityTests.java @@ -1,4 +1,4 @@ -package cech12.ceramicbucket.integration; +package de.cech12.ceramicbucket.integration; /* import cech12.ceramicbucket.BucketTestUtils; diff --git a/src/test/java/cech12/ceramicbucket/integration/WorldTests.java b/forge/src/test/java/de/cech12/ceramicbucket/integration/WorldTests.java similarity index 98% rename from src/test/java/cech12/ceramicbucket/integration/WorldTests.java rename to forge/src/test/java/de/cech12/ceramicbucket/integration/WorldTests.java index 3a9eff4..2f4a736 100644 --- a/src/test/java/cech12/ceramicbucket/integration/WorldTests.java +++ b/forge/src/test/java/de/cech12/ceramicbucket/integration/WorldTests.java @@ -1,4 +1,4 @@ -package cech12.ceramicbucket.integration; +package de.cech12.ceramicbucket.integration; /* import cech12.ceramicbucket.BucketTestUtils; diff --git a/src/test/java/cech12/ceramicbucket/unit/ConfigTests.java b/forge/src/test/java/de/cech12/ceramicbucket/unit/ConfigTests.java similarity index 99% rename from src/test/java/cech12/ceramicbucket/unit/ConfigTests.java rename to forge/src/test/java/de/cech12/ceramicbucket/unit/ConfigTests.java index f651f14..25aa423 100644 --- a/src/test/java/cech12/ceramicbucket/unit/ConfigTests.java +++ b/forge/src/test/java/de/cech12/ceramicbucket/unit/ConfigTests.java @@ -1,4 +1,4 @@ -package cech12.ceramicbucket.unit; +package de.cech12.ceramicbucket.unit; /* import cech12.ceramicbucket.BucketTestUtils; diff --git a/src/test/java/cech12/ceramicbucket/unit/ItemFiltersTests.java b/forge/src/test/java/de/cech12/ceramicbucket/unit/ItemFiltersTests.java similarity index 99% rename from src/test/java/cech12/ceramicbucket/unit/ItemFiltersTests.java rename to forge/src/test/java/de/cech12/ceramicbucket/unit/ItemFiltersTests.java index 0b9af7e..ae30a88 100644 --- a/src/test/java/cech12/ceramicbucket/unit/ItemFiltersTests.java +++ b/forge/src/test/java/de/cech12/ceramicbucket/unit/ItemFiltersTests.java @@ -1,4 +1,4 @@ -package cech12.ceramicbucket.unit; +package de.cech12.ceramicbucket.unit; /* import cech12.ceramicbucket.api.item.CeramicBucketItems; diff --git a/src/test/resources/data/ceramicbucket/structures/cauldron/cauldron_empty.nbt b/forge/src/test/resources/data/ceramicbucket/structures/cauldron/cauldron_empty.nbt similarity index 100% rename from src/test/resources/data/ceramicbucket/structures/cauldron/cauldron_empty.nbt rename to forge/src/test/resources/data/ceramicbucket/structures/cauldron/cauldron_empty.nbt diff --git a/src/test/resources/data/ceramicbucket/structures/cauldron/cauldron_water_full.nbt b/forge/src/test/resources/data/ceramicbucket/structures/cauldron/cauldron_water_full.nbt similarity index 100% rename from src/test/resources/data/ceramicbucket/structures/cauldron/cauldron_water_full.nbt rename to forge/src/test/resources/data/ceramicbucket/structures/cauldron/cauldron_water_full.nbt diff --git a/src/test/resources/data/ceramicbucket/structures/cauldron/cauldron_water_one_third.nbt b/forge/src/test/resources/data/ceramicbucket/structures/cauldron/cauldron_water_one_third.nbt similarity index 100% rename from src/test/resources/data/ceramicbucket/structures/cauldron/cauldron_water_one_third.nbt rename to forge/src/test/resources/data/ceramicbucket/structures/cauldron/cauldron_water_one_third.nbt diff --git a/src/test/resources/data/ceramicbucket/structures/cauldron/cauldron_water_two_thirds.nbt b/forge/src/test/resources/data/ceramicbucket/structures/cauldron/cauldron_water_two_thirds.nbt similarity index 100% rename from src/test/resources/data/ceramicbucket/structures/cauldron/cauldron_water_two_thirds.nbt rename to forge/src/test/resources/data/ceramicbucket/structures/cauldron/cauldron_water_two_thirds.nbt diff --git a/src/test/resources/data/ceramicbucket/structures/dispenser/empty_dispenser.nbt b/forge/src/test/resources/data/ceramicbucket/structures/dispenser/empty_dispenser.nbt similarity index 100% rename from src/test/resources/data/ceramicbucket/structures/dispenser/empty_dispenser.nbt rename to forge/src/test/resources/data/ceramicbucket/structures/dispenser/empty_dispenser.nbt diff --git a/src/test/resources/data/ceramicbucket/structures/entity/entity_pit.nbt b/forge/src/test/resources/data/ceramicbucket/structures/entity/entity_pit.nbt similarity index 100% rename from src/test/resources/data/ceramicbucket/structures/entity/entity_pit.nbt rename to forge/src/test/resources/data/ceramicbucket/structures/entity/entity_pit.nbt diff --git a/src/test/resources/data/ceramicbucket/structures/world/fluid_pit.nbt b/forge/src/test/resources/data/ceramicbucket/structures/world/fluid_pit.nbt similarity index 100% rename from src/test/resources/data/ceramicbucket/structures/world/fluid_pit.nbt rename to forge/src/test/resources/data/ceramicbucket/structures/world/fluid_pit.nbt diff --git a/gradle.properties b/gradle.properties index c148328..8910741 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,26 +1,40 @@ -# Sets default memory used for gradle commands. Can be overridden by user or command line properties. -# This is required to provide enough memory for the Minecraft decompilation process. -org.gradle.jvmargs=-Xmx3G -org.gradle.daemon=false - -## Environment Properties -minecraft_version=1.20.2 -minecraft_version_range=[1.20.2,1.21) -forge_version=48.0.23 -forge_version_range=[48.0.23,) -loader_version_range=[48,) +# Important Notes: +# fabric.mod.json's modid field cannot be expanded, you must change it manually. +# Every field you add must be added to the root build.gradle expandProps map. -## Mod Properties +# Project +group=de.cech12.ceramicbucket +mod_version=5.0.0.0 mod_id=ceramicbucket -mod_version=4.2.0.0 -mod_group_id=cech12.ceramicbucket mod_name=Ceramic Bucket -mod_authors=Cech12 +mod_author=Cech12 mod_license=The MIT License (MIT) mod_url=https://github.com/cech12/CeramicBucket mod_issue_tracker=https://github.com/cech12/CeramicBucket/issues -mod_description=A mod which adds a Ceramic Bucket. +description=A mod which adds a Ceramic Bucket. + +# Common +minecraft_version=1.20.2 +minecraft_version_range=[1.20.2, 1.21) + +# Fabric +#fabric_version=0.91.0+1.20.2 +#fabric_loader_version=0.15.0 + +# Forge +forge_version=48.1.0 +forge_version_range=[48.1.0,) +forge_loader_version_range=[48,) + +# NeoForge +neoforge_version=20.2.86 +neoforge_version_range=[20.2.86,) +neoforge_loader_version_range=[1,) #Bucket Lib -bucketlib_version=1.20.2-2.4.0.0 -bucketlib_version_range=[1.20.2-2.4.0.0,) +bucketlib_version=1.20.2-3.0.0.4 +bucketlib_version_range=[1.20.2-3.0.0.4,) + +# Gradle +org.gradle.jvmargs=-Xmx3G +org.gradle.daemon=false \ No newline at end of file diff --git a/neoforge/build.gradle b/neoforge/build.gradle new file mode 100644 index 0000000..bca2036 --- /dev/null +++ b/neoforge/build.gradle @@ -0,0 +1,71 @@ +plugins { + id 'idea' + id 'net.neoforged.gradle.userdev' version '7.0.41' + id 'java-library' +} +base { + archivesName = "${mod_id}-neoforge" +} + +// Automatically enable neoforge AccessTransformers if the file exists +// This location is hardcoded in FML and can not be changed. +// https://github.com/neoforged/FancyModLoader/blob/a952595eaaddd571fbc53f43847680b00894e0c1/loader/src/main/java/net/neoforged/fml/loading/moddiscovery/ModFile.java#L118 +if (file('src/main/resources/META-INF/accesstransformer.cfg').exists()) { + minecraft.accessTransformers.file file('src/main/resources/META-INF/accesstransformer.cfg') +} +runs { + configureEach { + modSource project.sourceSets.main + modSource project.sourceSets.test + } + client { + systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id + } + server { + systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id + programArgument '--nogui' + } + gameTestServer { + systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id + } + data { + programArguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath() + } +} + +sourceSets.main.resources { srcDir 'src/generated/resources' } + +repositories { + maven { + name = 'Jitpack' + url = 'https://jitpack.io' + } +} + +dependencies { + implementation "net.neoforged:neoforge:${neoforge_version}" + compileOnly project(":common") + testCompileOnly project(":common") + + implementation "com.github.cech12.BucketLib:neoforge:${bucketlib_version}" +} + +// NeoGradle compiles the game, but we don't want to add our common code to the game's code +Spec notNeoTask = { Task it -> !it.name.startsWith("neo") } as Spec + +tasks.withType(JavaCompile).matching(notNeoTask).configureEach { + source(project(":common").sourceSets.main.allSource) +} + +//tasks.withType(Javadoc).matching(notNeoTask).configureEach { +// options.tags = [ "reason" ] +// source(project(":common").sourceSets.main.allJava) +//} + +//tasks.named("sourcesJar", Jar) { +// from(project(":common").sourceSets.main.allSource) +//} + +tasks.withType(ProcessResources).matching(notNeoTask).configureEach { + from project(":common").sourceSets.main.resources +} \ No newline at end of file diff --git a/neoforge/src/main/java/de/cech12/ceramicbucket/CeramicBucketMod.java b/neoforge/src/main/java/de/cech12/ceramicbucket/CeramicBucketMod.java new file mode 100644 index 0000000..5d99ae5 --- /dev/null +++ b/neoforge/src/main/java/de/cech12/ceramicbucket/CeramicBucketMod.java @@ -0,0 +1,58 @@ +package de.cech12.ceramicbucket; + +import de.cech12.bucketlib.api.BucketLibApi; +import de.cech12.bucketlib.api.item.UniversalBucketItem; +import de.cech12.ceramicbucket.init.ModTags; +import de.cech12.ceramicbucket.platform.Services; +import net.minecraft.world.item.CreativeModeTabs; +import net.minecraft.world.item.Item; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.fml.common.Mod; +import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent; +import net.neoforged.fml.event.lifecycle.InterModEnqueueEvent; +import net.neoforged.neoforge.registries.DeferredItem; +import net.neoforged.neoforge.registries.DeferredRegister; + +import static de.cech12.ceramicbucket.CeramicBucketMod.MOD_ID; + +@Mod(MOD_ID) +public class CeramicBucketMod { + + public static final String MOD_ID = "ceramicbucket"; + + public static final DeferredRegister.Items ITEMS = DeferredRegister.createItems(MOD_ID); + + public static final DeferredItem UNFIRED_CLAY_BUCKET = ITEMS.register("unfired_clay_bucket", () -> new Item(new Item.Properties())); + + public static final DeferredItem CERAMIC_BUCKET = ITEMS.register("ceramic_bucket", () -> new UniversalBucketItem( + new UniversalBucketItem.Properties() + .upperCrackingTemperature(Services.CONFIG::getBreakTemperature) + .crackingFluids(ModTags.Fluids.CERAMIC_CRACKING) + .milking(Services.CONFIG::isMilkingEnabled) + .entityObtaining(Services.CONFIG::isFishObtainingEnabled) + .dyeable(14975336) + .durability(Services.CONFIG::getDurability) + )); + + public CeramicBucketMod(IEventBus modEventBus) { + ITEMS.register(modEventBus); + //listeners + modEventBus.addListener(this::addItemsToTabs); + //Config + CommonLoader.init(); + //register for IMC event + modEventBus.addListener(this::sendImc); + } + + private void sendImc(InterModEnqueueEvent evt) { + BucketLibApi.registerBucket(CERAMIC_BUCKET.getId()); + } + + private void addItemsToTabs(BuildCreativeModeTabContentsEvent event) { + //CERAMIC_BUCKET is added by BucketLib + if (event.getTabKey() == CreativeModeTabs.INGREDIENTS) { + event.accept(UNFIRED_CLAY_BUCKET); + } + } + +} diff --git a/neoforge/src/main/java/de/cech12/ceramicbucket/init/ModTags.java b/neoforge/src/main/java/de/cech12/ceramicbucket/init/ModTags.java new file mode 100644 index 0000000..d633ab3 --- /dev/null +++ b/neoforge/src/main/java/de/cech12/ceramicbucket/init/ModTags.java @@ -0,0 +1,23 @@ +package de.cech12.ceramicbucket.init; + +import de.cech12.ceramicbucket.CeramicBucketMod; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.TagKey; +import net.minecraft.world.level.material.Fluid; + +import javax.annotation.Nonnull; + +public class ModTags { + + public static class Fluids { + + public static final TagKey CERAMIC_CRACKING = tag("ceramic_cracking"); + + private static TagKey tag(@Nonnull String name) { + return TagKey.create(Registries.FLUID, new ResourceLocation(CeramicBucketMod.MOD_ID, name)); + } + + } + +} diff --git a/neoforge/src/main/java/de/cech12/ceramicbucket/platform/NeoForgeConfigHelper.java b/neoforge/src/main/java/de/cech12/ceramicbucket/platform/NeoForgeConfigHelper.java new file mode 100644 index 0000000..9e398d5 --- /dev/null +++ b/neoforge/src/main/java/de/cech12/ceramicbucket/platform/NeoForgeConfigHelper.java @@ -0,0 +1,98 @@ +package de.cech12.ceramicbucket.platform; + +import com.electronwill.nightconfig.core.file.CommentedFileConfig; +import com.electronwill.nightconfig.core.io.WritingMode; +import de.cech12.ceramicbucket.Constants; +import de.cech12.ceramicbucket.platform.services.IConfigHelper; +import net.neoforged.fml.ModLoadingContext; +import net.neoforged.fml.config.ModConfig; +import net.neoforged.fml.loading.FMLConfig; +import net.neoforged.fml.loading.FMLPaths; +import net.neoforged.neoforge.common.ModConfigSpec; + +import java.nio.file.Path; + +/** + * The config service implementation for Forge. + */ +public class NeoForgeConfigHelper implements IConfigHelper { + + private static ModConfigSpec SERVER_CONFIG; + + private static final ModConfigSpec.IntValue BREAK_TEMPERATURE; + private static final ModConfigSpec.IntValue DURABILITY; + private static final ModConfigSpec.BooleanValue FISH_OBTAINING_ENABLED; + private static final ModConfigSpec.BooleanValue MILKING_ENABLED; + + static { + final ModConfigSpec.Builder builder = new ModConfigSpec.Builder(); + + builder.push("Balance Options"); + + BREAK_TEMPERATURE = builder + .comment("Minimum temperature of fluid at which the Ceramic Bucket breaks when emptied. (-1 means that bucket never breaks caused by high fluid temperature)") + .defineInRange("ceramicBucketBreakTemperature", BREAK_TEMPERATURE_DEFAULT, -1, 10000); + + DURABILITY = builder + .comment("Defines the maximum durability of a Ceramic Bucket. (0 deactivates the durability)") + .defineInRange("durability", DURABILITY_DEFAULT, 0, 10000); + + FISH_OBTAINING_ENABLED = builder + .comment("Whether or not obtaining fish with a Ceramic Bucket should be enabled.") + .define("fishObtainingEnabled", FISH_OBTAINING_ENABLED_DEFAULT); + + MILKING_ENABLED = builder + .comment("Whether or not milking entities with a Ceramic Bucket should be enabled.") + .define("milkingEnabled", MILKING_ENABLED_DEFAULT); + + builder.pop(); + + SERVER_CONFIG = builder.build(); + } + + @Override + public void init() { + ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, SERVER_CONFIG); + Path path = FMLPaths.GAMEDIR.get().resolve(FMLConfig.defaultConfigPath()).resolve(Constants.MOD_ID + "-server.toml"); + final CommentedFileConfig configData = CommentedFileConfig.builder(path).sync().autosave().writingMode(WritingMode.REPLACE).build(); + configData.load(); + SERVER_CONFIG.setConfig(configData); + } + + @Override + public int getBreakTemperature() { + try { + return BREAK_TEMPERATURE.get(); + } catch (IllegalStateException ex) { + return BREAK_TEMPERATURE_DEFAULT; + } + } + + @Override + public int getDurability() { + try { + return DURABILITY.get(); + } catch (IllegalStateException ex) { + return DURABILITY_DEFAULT; + } + } + + @Override + public boolean isFishObtainingEnabled() { + try { + return FISH_OBTAINING_ENABLED.get(); + } catch (IllegalStateException ex) { + return FISH_OBTAINING_ENABLED_DEFAULT; + } + } + + @Override + public boolean isMilkingEnabled() { + try { + return MILKING_ENABLED.get(); + } catch (IllegalStateException ex) { + return MILKING_ENABLED_DEFAULT; + } + } + +} diff --git a/neoforge/src/main/java/de/cech12/ceramicbucket/platform/NeoForgePlatformHelper.java b/neoforge/src/main/java/de/cech12/ceramicbucket/platform/NeoForgePlatformHelper.java new file mode 100644 index 0000000..39c66ba --- /dev/null +++ b/neoforge/src/main/java/de/cech12/ceramicbucket/platform/NeoForgePlatformHelper.java @@ -0,0 +1,27 @@ +package de.cech12.ceramicbucket.platform; + +import de.cech12.ceramicbucket.platform.services.IPlatformHelper; +import net.neoforged.fml.ModList; +import net.neoforged.fml.loading.FMLLoader; + +/** + * The platform service implementation for Forge. + */ +public class NeoForgePlatformHelper implements IPlatformHelper { + + @Override + public String getPlatformName() { + return "NeoForge"; + } + + @Override + public boolean isModLoaded(String modId) { + return ModList.get().isLoaded(modId); + } + + @Override + public boolean isDevelopmentEnvironment() { + return !FMLLoader.isProduction(); + } + +} diff --git a/neoforge/src/main/resources/META-INF/mods.toml b/neoforge/src/main/resources/META-INF/mods.toml new file mode 100644 index 0000000..23eb9bc --- /dev/null +++ b/neoforge/src/main/resources/META-INF/mods.toml @@ -0,0 +1,31 @@ +modLoader="javafml" +loaderVersion="${neoforge_loader_version_range}" +issueTrackerURL="${mod_issue_tracker}" +license="${mod_license}" +[[mods]] +modId="${mod_id}" +version="${version}" +displayName="${mod_name}" +displayURL="${mod_url}" +logoFile="logo.png" +authors="${mod_author}" +description='''${mod_description}''' +[[dependencies.${mod_id}]] +modId="neoforge" +mandatory=true +versionRange="${neoforge_version_range}" +ordering="NONE" +side="BOTH" +[[dependencies.${mod_id}]] +modId="minecraft" +mandatory=true +versionRange="${minecraft_version_range}" +ordering="NONE" +side="BOTH" +[[dependencies.${mod_id}]] +modId="bucketlib" +mandatory=true +versionRange="${bucketlib_version_range}" +referralUrl="https://github.com/cech12/BucketLib" +ordering="NONE" +side="BOTH" \ No newline at end of file diff --git a/neoforge/src/main/resources/META-INF/services/de.cech12.ceramicbucket.platform.services.IConfigHelper b/neoforge/src/main/resources/META-INF/services/de.cech12.ceramicbucket.platform.services.IConfigHelper new file mode 100644 index 0000000..1591e74 --- /dev/null +++ b/neoforge/src/main/resources/META-INF/services/de.cech12.ceramicbucket.platform.services.IConfigHelper @@ -0,0 +1 @@ +de.cech12.ceramicbucket.platform.NeoForgeConfigHelper \ No newline at end of file diff --git a/neoforge/src/main/resources/META-INF/services/de.cech12.ceramicbucket.platform.services.IPlatformHelper b/neoforge/src/main/resources/META-INF/services/de.cech12.ceramicbucket.platform.services.IPlatformHelper new file mode 100644 index 0000000..1d6744e --- /dev/null +++ b/neoforge/src/main/resources/META-INF/services/de.cech12.ceramicbucket.platform.services.IPlatformHelper @@ -0,0 +1 @@ +de.cech12.ceramicbucket.platform.NeoForgePlatformHelper \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 291d399..dfd3917 100644 --- a/settings.gradle +++ b/settings.gradle @@ -2,12 +2,31 @@ pluginManagement { repositories { gradlePluginPortal() maven { - name = 'MinecraftForge' + name = 'Fabric' + url = 'https://maven.fabricmc.net/' + } + maven { + name = 'NeoForge' + url = 'https://maven.neoforged.net/releases/' + } + maven { + name = 'Forge' url = 'https://maven.minecraftforge.net/' } + maven { + name = 'Sponge Snapshots' + url = 'https://repo.spongepowered.org/repository/maven-public/' + } } } plugins { - id 'org.gradle.toolchains.foojay-resolver-convention' version '0.5.0' -} \ No newline at end of file + id 'org.gradle.toolchains.foojay-resolver-convention' version '0.7.0' +} + +// This should match the folder name of the project, or else IDEA may complain (see https://youtrack.jetbrains.com/issue/IDEA-317606) +rootProject.name = 'CeramicBucket' +include("common") +//include("fabric") +include("forge") +include("neoforge") \ No newline at end of file diff --git a/src/main/java/cech12/ceramicbucket/config/ServerConfig.java b/src/main/java/cech12/ceramicbucket/config/ServerConfig.java deleted file mode 100644 index ab6eb53..0000000 --- a/src/main/java/cech12/ceramicbucket/config/ServerConfig.java +++ /dev/null @@ -1,52 +0,0 @@ -package cech12.ceramicbucket.config; - -import com.electronwill.nightconfig.core.file.CommentedFileConfig; -import com.electronwill.nightconfig.core.io.WritingMode; -import net.minecraftforge.common.ForgeConfigSpec; - -import java.nio.file.Path; - -public class ServerConfig { - - public static final int DEFAULT_CERAMIC_BUCKET_BREAK_TEMPERATURE = 1000; - - public static ForgeConfigSpec SERVER_CONFIG; - - public static final ForgeConfigSpec.IntValue CERAMIC_BUCKET_BREAK_TEMPERATURE; - public static final ForgeConfigSpec.BooleanValue MILKING_ENABLED; - public static final ForgeConfigSpec.BooleanValue FISH_OBTAINING_ENABLED; - public static final ForgeConfigSpec.IntValue CERAMIC_BUCKET_DURABILITY; - - static { - final ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder(); - - builder.push("Balance Options"); - - CERAMIC_BUCKET_BREAK_TEMPERATURE = builder - .comment("Minimum temperature of fluid at which the Ceramic Bucket breaks when emptied. (-1 means that bucket never breaks caused by high fluid temperature)") - .defineInRange("ceramicBucketBreakTemperature", DEFAULT_CERAMIC_BUCKET_BREAK_TEMPERATURE, -1, 10000); - - MILKING_ENABLED = builder - .comment("Whether or not milking entities with a Ceramic Bucket should be enabled.") - .define("milkingEnabled", true); - - FISH_OBTAINING_ENABLED = builder - .comment("Whether or not obtaining fish with a Ceramic Bucket should be enabled.") - .define("fishObtainingEnabled", true); - - CERAMIC_BUCKET_DURABILITY = builder - .comment("Defines the maximum durability of a Ceramic Bucket. (0 deactivates the durability)") - .defineInRange("durability", 0, 0, 10000); - - builder.pop(); - - SERVER_CONFIG = builder.build(); - } - - public static void loadConfig(ForgeConfigSpec spec, Path path) { - final CommentedFileConfig configData = CommentedFileConfig.builder(path).sync().autosave().writingMode(WritingMode.REPLACE).build(); - configData.load(); - spec.setConfig(configData); - } - -} diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml deleted file mode 100644 index 13cae8a..0000000 --- a/src/main/resources/META-INF/mods.toml +++ /dev/null @@ -1,31 +0,0 @@ -modLoader="javafml" -loaderVersion="${loader_version_range}" -issueTrackerURL="${mod_issue_tracker}" -license="${mod_license}" -[[mods]] - modId="${mod_id}" - version="${minecraft_version}-${mod_version}" - displayName="${mod_name}" - displayURL="${mod_url}" - logoFile="logo.png" - authors="${mod_authors}" - description='''${mod_description}''' -[[dependencies.${mod_id}]] - modId="forge" - mandatory=true - versionRange="${forge_version_range}" - ordering="NONE" - side="BOTH" -[[dependencies.${mod_id}]] - modId="minecraft" - mandatory=true - versionRange="${minecraft_version_range}" - ordering="NONE" - side="BOTH" -[[dependencies.${mod_id}]] - modId="bucketlib" - mandatory=true - versionRange="${bucketlib_version_range}" - referralUrl="https://github.com/cech12/BucketLib" - ordering="NONE" - side="BOTH" \ No newline at end of file