Skip to content

VersionBlocks

Scribble edited this page Mar 18, 2025 · 1 revision

Version Blocks

A key component of Discombobulator is the ability to declare code blocks that should be commented in on version and commented out in another:

	//# 1.14.4
	System.out.println("Only enabled in 1.14.4 and above");
	//# end

The versions and order that are supported have to be added to the build.gradle in the root project.

A version block is defined by comment characters, either // or # in e.g. accesswidener files, followed by a # then a version string (1.14.4).

The spaces between the components are not important, you can in theory add //#1.14.4 or // #1.14.4,
but the //# 1.14.4 format is used here.

A version block is always terminated by either the beginning of another version block or an //# end block. If that is not the case, the console will print an error, when running Discombobulator related tasks.

You can translate the version block above into the following fake java code:

	if(version >= "1.14.4") {
		System.out.println("Only enabled in 1.14.4 and above");
	}

Multiple version blocks

	//# 1.15.2
//$$	System.out.println("Only enabled in 1.15.2 and above");
	//# 1.14.4
	System.out.println("Only enabled in 1.14.4 and above");
	//# end

This would translate into the following java code:

	if(version >= "1.15.2"){
		System.out.println("Only enabled in 1.15.2 and above");
	} else if(version >= "1.14.4" && version < "1.15.2") {
		System.out.println("Only enabled in 1.14.4 and above");
	}

If the code part is commented out, $$ characters at the beginning of the comment will be added to show that the line was commented out by the preprocessor.

Clone this wiki locally