diff --git a/docusaurus.config.js b/docusaurus.config.js index 1196920f..befefbf4 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -47,6 +47,9 @@ const config = { includeCurrentVersion: true, versions: { current: { + label: "1.21.4", + }, + "1.21.3": { label: "1.21.2 - 1.21.3", }, "1.21.1": { diff --git a/versioned_docs/version-1.21.3/advanced/_category_.json b/versioned_docs/version-1.21.3/advanced/_category_.json new file mode 100644 index 00000000..2161114e --- /dev/null +++ b/versioned_docs/version-1.21.3/advanced/_category_.json @@ -0,0 +1,4 @@ +{ + "label": "Advanced Topics", + "position": 12 +} \ No newline at end of file diff --git a/versioned_docs/version-1.21.3/advanced/accesstransformers.md b/versioned_docs/version-1.21.3/advanced/accesstransformers.md new file mode 100644 index 00000000..838b759d --- /dev/null +++ b/versioned_docs/version-1.21.3/advanced/accesstransformers.md @@ -0,0 +1,147 @@ +# Access Transformers + +Access Transformers (ATs for short) allow for widening the visibility and modifying the `final` flags of classes, methods, and fields. They allow modders to access and modify otherwise inaccessible members in classes outside their control. + +The [specification document][specs] can be viewed on the NeoForged GitHub. + +## Adding ATs + +Adding an Access Transformer to your mod project is as simple as adding a single line into your `build.gradle`: + +Access Transformers need to be declared in `build.gradle`. AT files can be specified anywhere as long as they are copied to the `resources` output directory on compilation. + +```groovy +// In build.gradle: +// This block is where your mappings version is also specified +minecraft { + accessTransformers { + file('src/main/resources/META-INF/accesstransformer.cfg') + } +} +``` + +By default, NeoForge will search for `META-INF/accesstransformer.cfg`. If the `build.gradle` specifies access transformers in any other location, then their location needs to be defined within `neoforge.mods.toml`: + +```toml +# In neoforge.mods.toml: +[[accessTransformers]] +## The file is relative to the output directory of the resources, or the root path inside the jar when compiled +## The 'resources' directory represents the root output directory of the resources +file="META-INF/accesstransformer.cfg" +``` + +Additionally, multiple AT files can be specified and will be applied in order. This can be useful for larger mods with multiple packages. + +```groovy +// In build.gradle: +minecraft { + accessTransformers { + file('src/main/resources/accesstransformer_main.cfg') + file('src/additions/resources/accesstransformer_additions.cfg') + } +} +``` + +```toml +# In neoforge.mods.toml +[[accessTransformers]] +file="accesstransformer_main.cfg" + +[[accessTransformers]] +file="accesstransformer_additions.cfg" +``` + +After adding or modifying any Access Transformer, the Gradle project must be refreshed for the transformations to take effect. + +## The Access Transformer Specification + +### Comments + +All text after a `#` until the end of the line will be treated as a comment and will not be parsed. + +### Access Modifiers + +Access modifiers specify to what new member visibility the given target will be transformed to. In decreasing order of visibility: + +- `public` - visible to all classes inside and outside its package +- `protected` - visible only to classes inside the package and subclasses +- `default` - visible only to classes inside the package +- `private` - visible only to inside the class + +A special modifier `+f` and `-f` can be appended to the aforementioned modifiers to either add or remove respectively the `final` modifier, which prevents subclassing, method overriding, or field modification when applied. + +:::danger +Directives only modify the method they directly reference; any overriding methods will not be access-transformed. It is advised to ensure transformed methods do not have non-transformed overrides that restrict the visibility, which will result in the JVM throwing an error. + +Examples of methods that can be safely transformed are `private` methods, `final` methods (or methods in `final` classes), and `static` methods. +::: + +### Targets and Directives + +#### Classes + +To target classes: + +``` + +``` + +Inner classes are denoted by combining the fully qualified name of the outer class and the name of the inner class with a `$` as separator. + +#### Fields + +To target fields: + +``` + +``` + +#### Methods + +Targeting methods require a special syntax to denote the method parameters and return type: + +``` + () +``` + +##### Specifying Types + +Also called "descriptors": see the [Java Virtual Machine Specification, SE 21, sections 4.3.2 and 4.3.3][jvmdescriptors] for more technical details. + +- `B` - `byte`, a signed byte +- `C` - `char`, a Unicode character code point in UTF-16 +- `D` - `double`, a double-precision floating-point value +- `F` - `float`, a single-precision floating-point value +- `I` - `integer`, a 32-bit integer +- `J` - `long`, a 64-bit integer +- `S` - `short`, a signed short +- `Z` - `boolean`, a `true` or `false` value +- `[` - references one dimension of an array + - Example: `[[S` refers to `short[][]` +- `L;` - references a reference type + - Example: `Ljava/lang/String;` refers to `java.lang.String` reference type _(note the use of slashes instead of periods)_ +- `(` - references a method descriptor, parameters should be supplied here or nothing if no parameters are present + - Example: `(I)Z` refers to a method that requires an integer argument and returns a boolean +- `V` - indicates a method returns no value, can only be used at the end of a method descriptor + - Example: `()V` refers to a method that has no arguments and returns nothing + +### Examples + +``` +# Makes public the ByteArrayToKeyFunction interface in Crypt +public net.minecraft.util.Crypt$ByteArrayToKeyFunction + +# Makes protected and removes the final modifier from 'random' in MinecraftServer +protected-f net.minecraft.server.MinecraftServer random + +# Makes public the 'makeExecutor' method in Util, +# accepting a String and returns a TracingExecutor +public net.minecraft.Util makeExecutor(Ljava/lang/String;)Lnet/minecraft/TracingExecutor; + +# Makes public the 'leastMostToIntArray' method in UUIDUtil, +# accepting two longs and returning an int[] +public net.minecraft.core.UUIDUtil leastMostToIntArray(JJ)[I +``` + +[specs]: https://github.com/NeoForged/AccessTransformers/blob/main/FMLAT.md +[jvmdescriptors]: https://docs.oracle.com/javase/specs/jvms/se21/html/jvms-4.html#jvms-4.3.2 diff --git a/versioned_docs/version-1.21.3/advanced/extensibleenums.md b/versioned_docs/version-1.21.3/advanced/extensibleenums.md new file mode 100644 index 00000000..d3532304 --- /dev/null +++ b/versioned_docs/version-1.21.3/advanced/extensibleenums.md @@ -0,0 +1,148 @@ +# Extensible Enums + +Extensible Enums are an enhancement of specific Vanilla enums to allow new entries to be added. This is done by modifying the compiled bytecode of the enum at runtime to add the elements. + +## `IExtensibleEnum` + +All enums that can have new entries implement the `IExtensibleEnum` interface. This interface acts as a marker to allow the `RuntimeEnumExtender` launch plugin service to know what enums should be transformed. + +:::warning +You should **not** be implementing this interface on your own enums. Use maps or registries instead depending on your usecase. +Enums which are not patched to implement the interface cannot have the interface added to them via mixins or coremods due to the order the transformers run in. +::: + +### Creating an Enum Entry + +To create new enum entries, a JSON file needs to be created and referenced in the `neoforge.mods.toml` with the `enumExtensions` entry of a `[[mods]]` block. The specified path must be relative to the `resources` directory: +```toml +# In neoforge.mods.toml: +[[mods]] +## The file is relative to the output directory of the resources, or the root path inside the jar when compiled +## The 'resources' directory represents the root output directory of the resources +enumExtensions="META-INF/enumextensions.json" +``` + +The definition of the entry consists of the target enum's class name, the new field's name (must be prefixed with the mod ID), the descriptor of the constructor to use for constructing the entry and the parameters to be passed to said constructor. + +```json5 +{ + "entries": [ + { + // The enum class the entry should be added to + "enum": "net/minecraft/world/item/ItemDisplayContext", + // The field name of the new entry, must be prefixed with the mod ID + "name": "EXAMPLEMOD_STANDING", + // The constructor to be used + "constructor": "(ILjava/lang/String;Ljava/lang/String;)V", + // Constant parameters provided directly. + "parameters": [ -1, "examplemod:standing", null ] + }, + { + "enum": "net/minecraft/world/item/Rarity", + "name": "EXAMPLEMOD_CUSTOM", + "constructor": "(ILjava/lang/String;Ljava/util/function/UnaryOperator;)V", + // The parameters to be used, provided as a reference to an EnumProxy field in the given class + "parameters": { + "class": "example/examplemod/MyEnumParams", + "field": "CUSTOM_RARITY_ENUM_PROXY" + } + }, + { + "enum": "net/minecraft/world/damagesource/DamageEffects", + "name": "EXAMPLEMOD_TEST", + "constructor": "(Ljava/lang/String;Ljava/util/function/Supplier;)V", + // The parameters to be used, provided as a reference to a method in the given class + "parameters": { + "class": "example/examplemod/MyEnumParams", + "method": "getTestDamageEffectsParameter" + } + } + ] +} +``` + +```java +public class MyEnumParams { + public static final EnumProxy CUSTOM_RARITY_ENUM_PROXY = new EnumProxy<>( + Rarity.class, -1, "examplemod:custom", (UnaryOperator