Skip to content

Commit

Permalink
feat: Implement Manifold CLI argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Steveplays28 committed Oct 7, 2023
1 parent d049d12 commit 4c182ef
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
103 changes: 100 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>()

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
Expand All @@ -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'
Expand Down
8 changes: 0 additions & 8 deletions build.properties

This file was deleted.

20 changes: 12 additions & 8 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
Expand Down
5 changes: 5 additions & 0 deletions version_properties/1.19.2.properties
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions version_properties/1.20.1.properties
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4c182ef

Please sign in to comment.