diff --git a/.gitignore b/.gitignore index 5eea5e1..1751068 100644 --- a/.gitignore +++ b/.gitignore @@ -553,3 +553,6 @@ FodyWeavers.xsd # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* replay_pid* + +# Automatically generated build properties +**/build.properties diff --git a/build.gradle b/build.gradle index 0374557..930b63b 100644 --- a/build.gradle +++ b/build.gradle @@ -9,6 +9,103 @@ plugins { version = "${project.mod_version}+mc${project.supported_minecraft_version}" group = project.maven_group +def loadProperties() { + def versionPropertiesFolder = project.version_properties_folder + def defaultMinecraftVersion = project.default_minecraft_version + def minecraftVersions = fileTree(versionPropertiesFolder).files.name + def minecraftVersion = "" + + for (int i = 0; i < minecraftVersions.size(); i++) { + // Remove the ".properties" at the end of the filename to get the versions + minecraftVersions[i] = minecraftVersions[i].replaceAll("\\.properties", "") + } + + // Sort the version list so the list goes from oldest to newest + minecraftVersions.sort() + + int minecraftVersionIndex = -1 + println "Available Minecraft versions: ${minecraftVersions}" + + if (hasProperty("minecraft_version_properties")) { + minecraftVersion = minecraft_version_properties + minecraftVersionIndex = minecraftVersions.indexOf(minecraftVersion) + } + + if (minecraftVersionIndex == -1) { + println "minecraft_version_properties is unset or invalid! Defaulting to ${defaultMinecraftVersion}." + println "Tip: use -Pminecraft_version_properties=\"${defaultMinecraftVersion}\" as a command line argument to set minecraft_version_properties." + + minecraftVersion = defaultMinecraftVersion + minecraftVersionIndex = minecraftVersions.indexOf(defaultMinecraftVersion) + + assert minecraftVersionIndex != -1 + } + + println "Loading ${versionPropertiesFolder}/${minecraftVersion}.properties" + def props = new Properties() + props.load(new FileInputStream("${rootDir}/${versionPropertiesFolder}/${minecraftVersion}.properties")) + + props.each { prop -> gradle.ext.set(prop.key, prop.value) } + gradle.ext.minecraft_versions = minecraftVersions +} + +/** + * Creates the list of preprocessors to use. + * + * @param minecraftVersions Array of all Minecraft versions. + * @param minecraftVersionIndex Array index of the currently active Minecraft version. + */ +def writeManifoldPreprocessorDefinesToBuildProperties() { + def versionPropertiesFolder = project.version_properties_folder + def minecraftVersions = fileTree(versionPropertiesFolder).files.name + + for (int i = 0; i < minecraftVersions.size(); i++) { + // Remove the ".properties" at the end of the filename to get the versions + minecraftVersions[i] = minecraftVersions[i].replaceAll("\\.properties", "") + } + + // Sort the version list so the list goes from oldest to newest + minecraftVersions.sort() + + def minecraftVersion = minecraft_version_properties + def minecraftVersionIndex = minecraftVersions.indexOf(minecraftVersion) + def manifoldMinecraftVersionPreprocessorList = new ArrayList() + + for (int i = 0; i < minecraftVersions.size(); i++) { + String minecraftVersionManifold = minecraftVersions[i].replace(".", "_").replace("-", "_TO_MC_") + + if (minecraftVersionIndex == i) { + manifoldMinecraftVersionPreprocessorList.add("MC_" + minecraftVersionManifold) + } else { + manifoldMinecraftVersionPreprocessorList.add("# MC_" + minecraftVersionManifold) + } + } + + StringBuilder sb = new StringBuilder() + // Add a warning to the top of the build.properties file + // The whitespace at the end is intentional + sb.append("""# This file contains the Minecraft version Manifold uses. +# Please do not touch this file, as this is handled by the build script automatically. +# If you're updating the mod to a new Minecraft version, add a new version.properties file to the version_properties_folder + +# suppress inspection "WrongPropertyKeyValueDelimiter" for whole file +# suppress inspection "UnusedProperty" for whole file + +""") + + // Build the Minecraft version preprocessors list + for (String manifoldMinecraftVersionPreprocessor : manifoldMinecraftVersionPreprocessorList) { + sb.append(manifoldMinecraftVersionPreprocessor) + sb.append("=\n") + } + + // Write to build.properties + new File(projectDir, "build.properties").text = sb.toString() +} + +loadProperties() +writeManifoldPreprocessorDefinesToBuildProperties() + repositories { // Add repositories to retrieve artifacts from in here. // You should only use this when depending on other mods because @@ -33,9 +130,9 @@ repositories { dependencies { // To change the versions see the gradle.properties file - minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" + minecraft "com.mojang:minecraft:${gradle.ext.minecraft_version}" + mappings "net.fabricmc:yarn:${gradle.ext.yarn_mappings}:v2" + modImplementation "net.fabricmc:fabric-loader:${gradle.ext.loader_version}" // Manifold implementation 'systems.manifold:manifold-rt:2023.1.26' diff --git a/build.properties b/build.properties deleted file mode 100644 index f8e2d60..0000000 --- a/build.properties +++ /dev/null @@ -1,8 +0,0 @@ -# This file contains the Minecraft version Manifold uses. -# Please do not push an update to this file to Git unless you're updating the mod to a new Minecraft version. - -# suppress inspection "WrongPropertyKeyValueDelimiter" for whole file -# suppress inspection "UnusedProperty" for whole file - -#MC_1_19 -MC_1_20 diff --git a/gradle.properties b/gradle.properties index c08cf42..b416c23 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,14 +1,18 @@ -# Done to increase the memory available to gradle. +# Gradle settings +# Increase memory available to Gradle, enable parallelism, and enable caching org.gradle.jvmargs=-Xmx1G +org.gradle.parallel=true +org.gradle.caching=true -# Fabric Properties -# check these on https://modmuss50.me/fabric.html -minecraft_version=1.20.1 -yarn_mappings=1.20.1+build.10 -loader_version=0.14.12 - -# Mod Properties +# Mod properties mod_version=1.3.0 maven_group=io.github.steveplays28 archives_base_name=pathunderfencegates +version_properties_folder=version_properties +default_minecraft_version=1.20.1 supported_minecraft_version=1.19.x-1.20.x + +# Minecraft version to compile/run +# This loads the .properties file for this version, located in the version_properties_folder +# Override this using -Pminecraft_version_properties=\"${defaultMinecraftVersion}\" as a command line argument +minecraft_version_properties=1.20.1 diff --git a/src/main/java/io/github/steveplays28/pathunderfencegates/util/BlockStateUtil.java b/src/main/java/io/github/steveplays28/pathunderfencegates/util/BlockStateUtil.java index d479475..57d5dd7 100644 --- a/src/main/java/io/github/steveplays28/pathunderfencegates/util/BlockStateUtil.java +++ b/src/main/java/io/github/steveplays28/pathunderfencegates/util/BlockStateUtil.java @@ -4,7 +4,7 @@ import net.minecraft.block.enums.SlabType; import org.jetbrains.annotations.NotNull; -#if MC_1_19 +#if MC_1_19_2 import net.minecraft.tag.BlockTags; #else import net.minecraft.registry.tag.BlockTags; @@ -13,11 +13,11 @@ import static net.minecraft.block.SlabBlock.TYPE; public class BlockStateUtil { - @SuppressWarnings("deprecation") + #if MC_1_20_1 @SuppressWarnings("deprecation") #endif public static boolean BlockAllowedAboveDirtPathBlock(@NotNull BlockState blockState) { Block block = blockState.getBlock(); - return #if MC_1_19 !blockState.getMaterial().isSolid() #else !blockState.isSolid() #endif || blockState.isAir() || blockState.isIn( + return #if MC_1_19_2 !blockState.getMaterial().isSolid() #else !blockState.isSolid() #endif || blockState.isAir() || blockState.isIn( BlockTags.FENCE_GATES) || blockState.isIn( BlockTags.TRAPDOORS) || block instanceof BellBlock || block instanceof WallSignBlock || block instanceof PaneBlock || (block instanceof SlabBlock && blockState.get( TYPE).equals(SlabType.TOP)); diff --git a/version_properties/1.19.2.properties b/version_properties/1.19.2.properties new file mode 100644 index 0000000..45924be --- /dev/null +++ b/version_properties/1.19.2.properties @@ -0,0 +1,5 @@ +# Fabric properties +# Check these on https://modmuss50.me/fabric.html +minecraft_version=1.19.2 +yarn_mappings=1.19.2+build.28 +loader_version=0.14.12 diff --git a/version_properties/1.20.1.properties b/version_properties/1.20.1.properties new file mode 100644 index 0000000..aa45d7e --- /dev/null +++ b/version_properties/1.20.1.properties @@ -0,0 +1,5 @@ +# Fabric properties +# Check these on https://modmuss50.me/fabric.html +minecraft_version=1.20.1 +yarn_mappings=1.20.1+build.10 +loader_version=0.14.12