JosephMillsAtWork / preprocessor

The source file preprocessor used in the RM to support multiple MC versions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The Preprocessor

To support multiple Minecraft versions with the ReplayMod, a JCP-inspired preprocessor is used:

        //#if MC>=11200
        // This is the block for MC >= 1.12.0
        category.addDetail(name, callable::call);
        //#else
        //$$ // This is the block for MC < 1.12.0
        //$$ category.setDetail(name, callable::call);
        //#endif

Any comments starting with //$$ will automatically be introduced / removed based on the surrounding condition(s). Normal comments are left untouched. The //#else branch is optional.

Conditions can be nested arbitrarily but their indention shall always be equal to the indention of the code at the //#if line. The //$$ shall be aligned with the inner-most //#if.

    //#if MC>=10904
    public CPacketResourcePackStatus makeStatusPacket(String hash, Action action) {
        //#if MC>=11002
        return new CPacketResourcePackStatus(action);
        //#else
        //$$ return new CPacketResourcePackStatus(hash, action);
        //#endif
    }
    //#else
    //$$ public C19PacketResourcePackStatus makeStatusPacket(String hash, Action action) {
    //$$     return new C19PacketResourcePackStatus(hash, action);
    //$$ }
    //#endif

Code for the more recent MC version shall be placed in the first branch of the if-else-construct. Version-dependent import statements shall be placed separately from and after all other imports but before the static and java.* imports.

The source code resides in src/main (gradle project determined by versions/mainVersion e.g. with 11404 it'll be :1.14.4) and is automatically passed through the preprocessor when any of the other versions are built (gradle projects :1.8, :1.8.9, etc.). Do NOT edit any of the code in versions/$MCVERSION/build/ as it is automatically generated and will be overwritten without warning.

You can pass the original source code through the preprocessor if you wish to develop/debug with another version of Minecraft:

./gradle :1.9.4:setCoreVersion # switches all sources in src/main to 1.9.4

Make sure to switch back to the most recent branch before committing! Care should also be taken that switching to a different branch and back doesn't introduce any uncommitted changes (e.g. due to different indention, especially in case of nested conditions).

The replaymod_at.cfg file uses the same preprocessor but with different keywords (see already existent examples in that file). If required, more file extensions and keywords can be added to the implementation.

License

The Preprocessor is provided under the terms of the GNU General Public License Version 3 or (at your option) any later version. See LICENSE.md for the full license text.

About

The source file preprocessor used in the RM to support multiple MC versions

License:GNU General Public License v3.0


Languages

Language:Kotlin 100.0%