Make use of new @Pattern feature to centralize version-aware code
That is, most of the business code should not be aware that it is being compiled to multiple versions even when it heavily interacts with MC, preprocessor statements should be an escape hatch, not the norm. Similarly, code should not be forced to do `MCVer.getWindow(mc)` instead of the much more intuitive `mc.getWindow()`, and a new preprocessor (technically remap) feature makes this possible by defining "search and replace"-like patterns (but smarter in that they are type-aware) in one or more central places (the "Patterns.java" files) which then are applied all over the code base. In a way, this is another step in the automatic back-porting process where preprocessor statements are used when we cannot yet do something automatically. Previously we "merely" automatically converted between different mapping, this new feature now also allows us to automatically perform simple refactoring tasks like changing field access to a getter+setter (e.g. `mc.getWindow()`), or changing how a method is called (e.g. `BufferBuilder.begin`), or changing a method call chain (e.g. `dispatcher.camera.getYaw()`), or most other search-and-replace-like changes and any combination of those. The only major limitation is that the replacement itself is not smart, so arguments must be kept in same order (or be temporarily assigned to local variables which then can be used in any order).
This commit is contained in:
52
README.md
52
README.md
@@ -30,55 +30,9 @@ The `master` branch is solely to be used for the `version.json` file that contai
|
||||
used by the clients to check for updates of this mod.
|
||||
|
||||
### The Preprocessor
|
||||
To support multiple Minecraft versions with the ReplayMod, a [JCP](https://github.com/raydac/java-comment-preprocessor)-inspired preprocessor is used:
|
||||
```java
|
||||
//#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`.
|
||||
```java
|
||||
//#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.
|
||||
Common version dependent code (including the fml and forge event bus) are available as static methods/fields in the `MCVer` class.
|
||||
|
||||
The source code in `src/main` is generally for the most recent Minecraft version 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 change the version of the code in `src/main` if you wish to develop/debug with another version of Minecraft:
|
||||
```bash
|
||||
./gradle :1.9.4:setCoreVersion # switches all sources in src/main to 1.9.4
|
||||
```
|
||||
If you do so, you'll also have to refresh the project in your IDE.
|
||||
|
||||
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).
|
||||
|
||||
Some files may use the same preprocessor with different keywords.
|
||||
If required, more file extensions and keywords can be added in the `preprocess` block of the `versions/common.gradle` script.
|
||||
To support multiple Minecraft versions with the ReplayMod, a [JCP](https://github.com/raydac/java-comment-preprocessor)-inspired preprocessor is used.
|
||||
It has by now acquired a lot more sophisticated features to make it as noninvasive as possible.
|
||||
Please read the [preprocessor's README](https://github.com/ReplayMod/preprocessor/blob/master/README.md) to understand how it works.
|
||||
|
||||
### Versioning
|
||||
The ReplayMod uses the versioning scheme outlined [here](http://mcforge.readthedocs.io/en/latest/conventions/versioning/)
|
||||
|
||||
Reference in New Issue
Block a user