-
Notifications
You must be signed in to change notification settings - Fork 4
Conditional Compilation
Haxe's conditional compilation feature utilizes compiler flags (or "defines") to allow for chunks of code (from entire files to individual expressions) to be included or excluded depending on the circumstances. This is an incredibly core part of what makes PickHaxe functional, and powerful.
PickHaxe provides a wide variety of defines, which allow you to create large mods with support across multiple versions, in a manner which would be impossible with Java. You can look these up at any time with the command haxe -lib pickhaxe --help-user-defines
.
The most commonly utilized define in PickHaxe is the Minecraft version defines. Since the formatting of snapshot versions breaks standard comparison, a full range of defines is automatically created during each build.
#if minecraft_eq_1_19_4
LOGGER.info('This is Minecraft 1.19.4!');
#end
#if (minecraft_gteq_1_19 && minecraft_lteq_1_19_4)
LOGGER.info('This is one of the Minecraft 1.19 versions!');
#end
#if minecraft_lt_1_20
LOGGER.info('This is a version before 1.20!');
#end
#if (minecraft_gteq_1_19_4 && minecraft_lt_1_20)
LOGGER.info('This is one of the Minecraft snapshots between 1.19 and 1.20!');
#end
#if minecraft_eq_23w13a_or_b
LOGGER.info('This is the Voting April Fools Snapshot!');
#end
#if minecraft_eq_23w45a
LOGGER.info('This is the Trial Chambers snapshot!');
#end
PickHaxe adds defines to distinguish between Minecraft mod loaders.
#if fabric
LOGGER.info('Hello Fabric World! Welcome to Minecraft!');
#end
#if !fabric
LOGGER.info('This is NOT Fabric!');
#end
#if forge
LOGGER.info('Hello Forge World! Welcome to Minecraft!');
#end
Many of the metadata parameters are available through defines as well.
pickhaxe.mod.id
pickhaxe.mod.version
pickhaxe.mod.description