diff --git a/.gitignore b/.gitignore index 2c770e0..551e000 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ build # other eclipse run +runs \ No newline at end of file diff --git a/build.gradle b/build.gradle index d586d59..47b57d2 100644 --- a/build.gradle +++ b/build.gradle @@ -13,12 +13,9 @@ buildscript { } plugins { - id 'fabric-loom' version '1.2-SNAPSHOT' apply(false) - id 'net.minecraftforge.gradle' version '[6.0,6.2)' apply(false) - id 'org.spongepowered.gradle.vanilla' version '0.2.1-SNAPSHOT' apply(false) - id 'org.spongepowered.mixin' version '0.7-SNAPSHOT' apply(false) - id 'net.darkhax.curseforgegradle' version '1.1.16' apply(false) - id 'com.modrinth.minotaur' version '2.8.0' apply(false) + id 'net.darkhax.curseforgegradle' version '1.1.17' apply(false) + id 'com.modrinth.minotaur' version '2.8.5' apply(false) + id "org.jetbrains.gradle.plugin.idea-ext" version "1.1.7" } apply from: 'gradle/property_loader.gradle' @@ -101,6 +98,11 @@ task postDiscord() { downloadSources.add("<:fabric:916233929722314763> [Fabric](${project(':fabric').findProperty('curse_file_url')})") } + if (project(':neoforge').hasProperty('curse_file_url')) { + + downloadSources.add("<:neoforge:1173939148806176779> [NeoForge](${project(':neoforge').findProperty('curse_file_url')})") + } + // Add Curseforge DL link if available. def downloadString = downloadSources.toString() diff --git a/common/build.gradle b/common/build.gradle index 345ab57..8ad7bb1 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'org.spongepowered.gradle.vanilla' + id 'org.spongepowered.gradle.vanilla' version '0.2.1-SNAPSHOT' } apply from: '../gradle/property_helper.gradle' diff --git a/common/src/main/java/net/darkhax/attributefix/config/AttributeConfig.java b/common/src/main/java/net/darkhax/attributefix/config/AttributeConfig.java index b4348ad..5c45bd3 100644 --- a/common/src/main/java/net/darkhax/attributefix/config/AttributeConfig.java +++ b/common/src/main/java/net/darkhax/attributefix/config/AttributeConfig.java @@ -5,7 +5,7 @@ import com.google.gson.annotations.SerializedName; import net.darkhax.attributefix.Constants; import net.darkhax.attributefix.mixin.AccessorRangedAttribute; -import net.darkhax.attributefix.temp.RegistryHelper; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.ai.attributes.Attribute; import net.minecraft.world.entity.ai.attributes.Attributes; @@ -23,17 +23,16 @@ public class AttributeConfig { @Expose private Map attributes = new HashMap<>(); - public void applyChanges(RegistryHelper registry) { - + public void applyChanges() { Constants.LOG.info("Applying changes for {} attributes.", attributes.size()); for (Map.Entry configEntry : attributes.entrySet()) { final ResourceLocation attributeId = ResourceLocation.tryParse(configEntry.getKey()); - if (attributeId != null && registry.exists(attributeId)) { + if (attributeId != null && BuiltInRegistries.ATTRIBUTE.containsKey(attributeId)) { - final Attribute attribute = registry.get(attributeId); + final Attribute attribute = BuiltInRegistries.ATTRIBUTE.get(attributeId); if (attribute instanceof RangedAttribute ranged) { @@ -46,7 +45,7 @@ public void applyChanges(RegistryHelper registry) { continue; } - final AccessorRangedAttribute accessor = (AccessorRangedAttribute)(Object)attribute; + final AccessorRangedAttribute accessor = (AccessorRangedAttribute) (Object) attribute; if (minValue != ranged.getMinValue()) { @@ -64,16 +63,16 @@ public void applyChanges(RegistryHelper registry) { } } - public static AttributeConfig load(File configFile, RegistryHelper registry) { + public static AttributeConfig load(File configFile) { final AttributeConfig config = new AttributeConfig(); // Load/Generate the default values. - for (Attribute attribute : registry.getValues()) { + for (Attribute attribute : BuiltInRegistries.ATTRIBUTE) { if (attribute instanceof RangedAttribute ranged) { - final ResourceLocation id = registry.getId(attribute); + final ResourceLocation id = BuiltInRegistries.ATTRIBUTE.getKey(attribute); config.attributes.put(id.toString(), new Entry(id, ranged)); } } @@ -96,7 +95,7 @@ public static AttributeConfig load(File configFile, RegistryHelper re Constants.LOG.error("Attribute ID '{}' is not a valid. This entry will be ignored.", configEntry.getKey()); } - else if (!registry.exists(attributeId)) { + else if (!BuiltInRegistries.ATTRIBUTE.containsKey(attributeId)) { Constants.LOG.error("Attribute ID '{}' does not belong to a known attribute. This entry will be ignored.", configEntry.getKey()); } @@ -143,8 +142,8 @@ else if (!registry.exists(attributeId)) { } /** - * Map of Attributes to new default values.
- * Any attribute not in this map will retain the declared default value, but can still be changed via config. + * Map of Attributes to new default values.
Any attribute not in this map will retain the declared default + * value, but can still be changed via config. */ private static final Map NEW_DEFAULT_VALUES = ImmutableMap.of( Attributes.MAX_HEALTH, 1_000_000D, diff --git a/common/src/main/java/net/darkhax/attributefix/temp/RegistryHelper.java b/common/src/main/java/net/darkhax/attributefix/temp/RegistryHelper.java deleted file mode 100644 index f0c797c..0000000 --- a/common/src/main/java/net/darkhax/attributefix/temp/RegistryHelper.java +++ /dev/null @@ -1,18 +0,0 @@ -package net.darkhax.attributefix.temp; - -import net.minecraft.resources.ResourceLocation; - -import java.util.Collection; - -public interface RegistryHelper { - - T get(ResourceLocation id); - - ResourceLocation getId(T value); - - boolean isRegistered(T value); - - boolean exists(ResourceLocation id); - - Collection getValues(); -} \ No newline at end of file diff --git a/fabric/build.gradle b/fabric/build.gradle index e05c3db..95cd07c 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' + id 'fabric-loom' version '1.2-SNAPSHOT' id 'net.darkhax.curseforgegradle' id 'com.modrinth.minotaur' id 'idea' diff --git a/fabric/src/main/java/net/darkhax/attributefix/AttributeFixFabricClient.java b/fabric/src/main/java/net/darkhax/attributefix/AttributeFixFabricClient.java index 5ddb09e..9f51340 100644 --- a/fabric/src/main/java/net/darkhax/attributefix/AttributeFixFabricClient.java +++ b/fabric/src/main/java/net/darkhax/attributefix/AttributeFixFabricClient.java @@ -1,22 +1,15 @@ package net.darkhax.attributefix; import net.darkhax.attributefix.config.AttributeConfig; -import net.darkhax.attributefix.temp.RegistryHelper; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents; import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.world.entity.ai.attributes.Attribute; public class AttributeFixFabricClient implements ClientModInitializer { @Override public void onInitializeClient() { - - ClientLifecycleEvents.CLIENT_STARTED.register(mc -> { - - RegistryHelper registry = new AttributeRegistryHelper(); - AttributeConfig.load(FabricLoader.getInstance().getConfigDir().resolve(Constants.MOD_ID + ".json").toFile(), registry).applyChanges(registry); - }); + ClientLifecycleEvents.CLIENT_STARTED.register(mc -> AttributeConfig.load(FabricLoader.getInstance().getConfigDir().resolve(Constants.MOD_ID + ".json").toFile()).applyChanges()); } } diff --git a/fabric/src/main/java/net/darkhax/attributefix/AttributeFixFabricServer.java b/fabric/src/main/java/net/darkhax/attributefix/AttributeFixFabricServer.java deleted file mode 100644 index 9dace39..0000000 --- a/fabric/src/main/java/net/darkhax/attributefix/AttributeFixFabricServer.java +++ /dev/null @@ -1,24 +0,0 @@ -package net.darkhax.attributefix; - -import net.darkhax.attributefix.config.AttributeConfig; -import net.darkhax.attributefix.temp.RegistryHelper; -import net.fabricmc.api.DedicatedServerModInitializer; -import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; -import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.world.entity.ai.attributes.Attribute; - -public class AttributeFixFabricServer implements DedicatedServerModInitializer { - - @Override - public void onInitializeServer() { - - ServerLifecycleEvents.SERVER_STARTED.register(server -> { - - if (server.isDedicatedServer()) { - - RegistryHelper registry = new AttributeRegistryHelper(); - AttributeConfig.load(FabricLoader.getInstance().getConfigDir().resolve(Constants.MOD_ID + ".json").toFile(), registry).applyChanges(registry); - } - }); - } -} \ No newline at end of file diff --git a/fabric/src/main/java/net/darkhax/attributefix/AttributeRegistryHelper.java b/fabric/src/main/java/net/darkhax/attributefix/AttributeRegistryHelper.java deleted file mode 100644 index 3eafcd1..0000000 --- a/fabric/src/main/java/net/darkhax/attributefix/AttributeRegistryHelper.java +++ /dev/null @@ -1,42 +0,0 @@ -package net.darkhax.attributefix; - -import net.darkhax.attributefix.temp.RegistryHelper; -import net.minecraft.core.Registry; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.entity.ai.attributes.Attribute; - -import java.util.Collection; - -public class AttributeRegistryHelper implements RegistryHelper { - - @Override - public Attribute get(ResourceLocation id) { - - return BuiltInRegistries.ATTRIBUTE.get(id); - } - - @Override - public ResourceLocation getId(Attribute value) { - - return BuiltInRegistries.ATTRIBUTE.getKey(value); - } - - @Override - public boolean isRegistered(Attribute value) { - - return getId(value) != null; - } - - @Override - public boolean exists(ResourceLocation id) { - - return BuiltInRegistries.ATTRIBUTE.containsKey(id); - } - - @Override - public Collection getValues() { - - return BuiltInRegistries.ATTRIBUTE.stream().toList(); - } -} \ No newline at end of file diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 4a6a637..a8c1a57 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -31,9 +31,9 @@ "${mod_id}.mixins.json" ], "depends": { - "fabricloader": ">=0.14.21", + "fabricloader": ">=0.14.24", "fabric": "*", - "minecraft": "1.20.1", + "minecraft": "${minecraft_version}", "java": ">=17" }, "custom": { diff --git a/forge/build.gradle b/forge/build.gradle index 0f1b023..4ca6440 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -1,8 +1,8 @@ plugins { - id 'net.minecraftforge.gradle' + id 'net.minecraftforge.gradle' version '[6.0,6.2)' + id 'org.spongepowered.mixin' version '0.7-SNAPSHOT' id 'net.darkhax.curseforgegradle' id 'com.modrinth.minotaur' - id 'org.spongepowered.mixin' } apply from: '../gradle/patreon.gradle' diff --git a/forge/src/main/java/net/darkhax/attributefix/AttributeFixForge.java b/forge/src/main/java/net/darkhax/attributefix/AttributeFixForge.java index 87602d9..778bf21 100644 --- a/forge/src/main/java/net/darkhax/attributefix/AttributeFixForge.java +++ b/forge/src/main/java/net/darkhax/attributefix/AttributeFixForge.java @@ -1,8 +1,6 @@ package net.darkhax.attributefix; import net.darkhax.attributefix.config.AttributeConfig; -import net.darkhax.attributefix.temp.RegistryHelper; -import net.minecraft.world.entity.ai.attributes.Attribute; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent; @@ -15,7 +13,6 @@ public class AttributeFixForge { @SubscribeEvent public static void onLoadComplete(FMLLoadCompleteEvent event) { - RegistryHelper registry = new AttributeRegistryHelper(); - AttributeConfig.load(FMLPaths.CONFIGDIR.get().resolve(Constants.MOD_ID + ".json").toFile(), registry).applyChanges(registry); + AttributeConfig.load(FMLPaths.CONFIGDIR.get().resolve(Constants.MOD_ID + ".json").toFile()).applyChanges(); } } \ No newline at end of file diff --git a/forge/src/main/java/net/darkhax/attributefix/AttributeRegistryHelper.java b/forge/src/main/java/net/darkhax/attributefix/AttributeRegistryHelper.java deleted file mode 100644 index 3797ddb..0000000 --- a/forge/src/main/java/net/darkhax/attributefix/AttributeRegistryHelper.java +++ /dev/null @@ -1,42 +0,0 @@ -package net.darkhax.attributefix; - -import net.darkhax.attributefix.temp.RegistryHelper; -import net.minecraft.core.Registry; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.entity.ai.attributes.Attribute; -import net.minecraftforge.registries.ForgeRegistries; - -import java.util.Collection; - -public class AttributeRegistryHelper implements RegistryHelper { - - @Override - public Attribute get(ResourceLocation id) { - - return ForgeRegistries.ATTRIBUTES.getValue(id); - } - - @Override - public ResourceLocation getId(Attribute value) { - - return ForgeRegistries.ATTRIBUTES.getKey(value); - } - - @Override - public boolean isRegistered(Attribute value) { - - return ForgeRegistries.ATTRIBUTES.containsValue(value); - } - - @Override - public boolean exists(ResourceLocation id) { - - return ForgeRegistries.ATTRIBUTES.containsKey(id); - } - - @Override - public Collection getValues() { - - return ForgeRegistries.ATTRIBUTES.getValues(); - } -} \ No newline at end of file diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml index 01895da..7483593 100644 --- a/forge/src/main/resources/META-INF/mods.toml +++ b/forge/src/main/resources/META-INF/mods.toml @@ -1,5 +1,5 @@ modLoader="javafml" -loaderVersion="[47,)" +loaderVersion="[48,)" license="${mod_license}" issueTrackerURL="${mod_issues}" diff --git a/gradle.properties b/gradle.properties index a635ce0..e2c2ae3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,16 +1,20 @@ # Project -version=21.0 +version=22.0 group=net.darkhax.attributefix # Common -minecraft_version=1.20.1 +minecraft_version=1.20.2 # Forge -forge_version=47.1.44 +forge_version=48.0.37 + +# NeoForge +neoforge_version=20.2.47-beta +neoforge_version_range=20.2, # Fabric -fabric_version=0.87.0+1.20.1 -fabric_loader_version=0.14.22 +fabric_version=0.90.7+1.20.2 +fabric_loader_version=0.14.24 # Mod options mod_name=AttributeFix diff --git a/neoforge/build.gradle b/neoforge/build.gradle new file mode 100644 index 0000000..676c0f6 --- /dev/null +++ b/neoforge/build.gradle @@ -0,0 +1,172 @@ +plugins { + id 'net.neoforged.gradle.userdev' version '7.0.43' + id 'net.darkhax.curseforgegradle' + id 'com.modrinth.minotaur' +} + +apply from: '../gradle/patreon.gradle' + +base { + archivesName = "${mod_name}-NeoForge-${minecraft_version}" +} + +runs { + configureEach { + modSource project.sourceSets.main + } + client { + systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id + } + server { + systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id + programArgument '--nogui' + } + + gameTestServer { + systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id + } +} + +dependencies { + implementation "net.neoforged:neoforge:${neoforge_version}" + compileOnly project(':common') +} + +// NeoGradle compiles the game, but we don't want to add our common code to the game's code +TaskCollection.metaClass.excludingNeoTasks = { -> + delegate.matching { !it.name.startsWith("neo") } +} + +tasks.withType(JavaCompile).excludingNeoTasks().configureEach { + source(project(':common').sourceSets.main.allSource) +} + +tasks.withType(Javadoc).excludingNeoTasks().configureEach { + source(project(':common').sourceSets.main.allJava) +} + +tasks.named("sourcesJar", Jar) { + from(project(':common').sourceSets.main.allSource) +} + +tasks.withType(ProcessResources).excludingNeoTasks().configureEach { + from project(':common').sourceSets.main.resources +} + +processResources { + + from project(":common").sourceSets.main.resources + + def buildProps = project.properties.clone() + + // Replaces FML's magic file.jarVersion string with the correct version at + // build time. + buildProps.put('file', [jarVersion: project.version]) + + if (project.hasProperty('patreon')) { + + def supporters = new ArrayList() + + for (entry in project.ext.patreon.pledges) { + + def pledge = entry.value; + + if (pledge.isValid()) { + + supporters.add(pledge.getDisplayName()) + } + } + + buildProps.put('mod_supporters', supporters.join(', ')) + } + + filesMatching('*.mixins.json') { + filter(org.apache.tools.ant.filters.LineContains, negate: true, contains: ['refmap' ] ) + } + + filesMatching(['META-INF/mods.toml', 'pack.mcmeta', '*.mixins.json']) { + + expand buildProps + } +} + +// -- MAVEN PUBLISHING -- +project.publishing { + + publications { + + mavenJava(MavenPublication) { + + artifactId = base.archivesName.get() + from components.java + } + } + + repositories { + + maven { + + // Sets maven credentials if they are provided. This is generally + // only used for external/remote uploads. + if (project.hasProperty('mavenUsername') && project.hasProperty('mavenPassword')) { + + credentials { + + username findProperty('mavenUsername') + password findProperty('mavenPassword') + } + } + + url getDefaultString('mavenURL', 'undefined', true) + } + } +} + +// CurseForge Publishing +task publishCurseForge(type: net.darkhax.curseforgegradle.TaskPublishCurseForge) { + + apiToken = findProperty('curse_auth') + + def mainFile = upload(curse_project, jar) + mainFile.changelogType = 'markdown' + mainFile.changelog = project.ext.mod_changelog + mainFile.addJavaVersion('Java 17') + mainFile.releaseType = 'release' + mainFile.addGameVersion('Server', 'Client') + + // Append Patreon Supporters + def patreonInfo = project.findProperty('patreon') + + if (patreonInfo) { + mainFile.changelog += "\n\nThis project is made possible by [Patreon](${patreonInfo.campaignUrlTracked}) support from players like you. Thank you!\n\n${patreonInfo.pledgeLog}" + } + + doLast { + + if (project.hasProperty('mod_homepage')) { + + project.ext.curse_file_url = "${mod_homepage}/files/${mainFile.curseFileId}" + } + } +} + +// Modrinth +modrinth { + + def patreonInfo = project.findProperty('patreon') + def changelog = project.ext.mod_changelog + + if (patreonInfo) { + changelog += "\n\nThis project is made possible by [Patreon](${patreonInfo.campaignUrlTracked}) support from players like you. Thank you!\n\n${patreonInfo.pledgeLog}" + } + + token.set(project.findProperty('modrinth_auth')) + projectId.set(modrinth_project) + changelog = changelog + versionName.set("${mod_name}-NeoForge-${minecraft_version}-$version") + versionType.set('release') + uploadFile.set(tasks.jar) + + loaders = ["neoforge"] + gameVersions = ["${minecraft_version}"] +} \ No newline at end of file diff --git a/neoforge/src/main/java/net/darkhax/neoforge/AttributeFixNeoForge.java b/neoforge/src/main/java/net/darkhax/neoforge/AttributeFixNeoForge.java new file mode 100644 index 0000000..46d6c08 --- /dev/null +++ b/neoforge/src/main/java/net/darkhax/neoforge/AttributeFixNeoForge.java @@ -0,0 +1,19 @@ +package net.darkhax.neoforge; + +import net.darkhax.attributefix.Constants; +import net.darkhax.attributefix.config.AttributeConfig; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.Mod; +import net.neoforged.fml.event.lifecycle.FMLLoadCompleteEvent; +import net.neoforged.fml.loading.FMLPaths; + +@Mod(Constants.MOD_ID) +@Mod.EventBusSubscriber(modid = Constants.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) +public class AttributeFixNeoForge { + + @SubscribeEvent + public static void onLoadComplete(FMLLoadCompleteEvent event) { + + AttributeConfig.load(FMLPaths.CONFIGDIR.get().resolve(Constants.MOD_ID + ".json").toFile()).applyChanges(); + } +} \ No newline at end of file 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..3aee1c6 --- /dev/null +++ b/neoforge/src/main/resources/META-INF/mods.toml @@ -0,0 +1,33 @@ +modLoader = "javafml" +loaderVersion = "${neoforge_version_range}" +license = "${mod_license}" +issueTrackerURL="${mod_issues}" + +[[mods]] +modId = "${mod_id}" +version = "${version}" +displayName = "${mod_name}" +updateJSONURL = "https://updates.blamejared.com/get?n=${mod_id}&gv=${minecraft_version}&ml=neoforge" +displayURL = "${mod_homepage}" +credits = "This project is made possible with Patreon support from players like you. Thank you! ${mod_supporters}" +authors = "${mod_author}" +description = ''' +${mod_description} +''' + +[[mixins]] +config = "attributefix.mixins.json" + +[[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}" +ordering = "NONE" +side = "BOTH" \ No newline at end of file diff --git a/neoforge/src/main/resources/attributefix.mixins.json b/neoforge/src/main/resources/attributefix.mixins.json new file mode 100644 index 0000000..4a1666c --- /dev/null +++ b/neoforge/src/main/resources/attributefix.mixins.json @@ -0,0 +1,12 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "net.darkhax.attributefix.mixin", + "compatibilityLevel": "JAVA_17", + "mixins": [ + "AccessorRangedAttribute" + ], + "injectors": { + "defaultRequire": 1 + } +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index eb48565..f1ac2c6 100644 --- a/settings.gradle +++ b/settings.gradle @@ -5,6 +5,10 @@ pluginManagement { name = 'Forge' url = 'https://maven.minecraftforge.net/' } + maven { + name = 'NeoForge' + url = 'https://maven.neoforged.net/releases' + } maven { name = 'Fabric' url = 'https://maven.fabricmc.net/' @@ -23,4 +27,5 @@ plugins { rootProject.name = "AttributeFix" include('common') include('fabric') -include('forge') \ No newline at end of file +include('forge') +include('neoforge') \ No newline at end of file