Skip to content
This repository was archived by the owner on Jun 18, 2024. It is now read-only.

Commit 985c104

Browse files
committed
Remove mixin & update extension docs
1 parent 6366d93 commit 985c104

File tree

2 files changed

+8
-130
lines changed

2 files changed

+8
-130
lines changed

expansion/extensions.md

Lines changed: 8 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Summary:
66
* [How extensions are loaded](extensions.md#how-extensions-are-loaded)
77
* [Dependencies](extensions.md#dependencies)
88
* [Callback order](extensions.md#callback-order)
9+
* [Extension Isolation](extensions.md#extension-isolation)
910
* [Testing in a dev environment](extensions.md#testing-in-a-dev-environment)
10-
* [Dynamically unloading and (re)loading extensions](extensions.md#dynamically-unloading-and-re-loading-extensions)
1111

1212
## Writing your own extension for Minestom
1313

@@ -40,10 +40,6 @@ Then, create a `extension.json` at the root of the resources folder (`src/main/r
4040
"entrypoint": "testextension.TestExtension",
4141
"name": "TestExtension",
4242
"version": "1.0.0",
43-
"codeModifiers": [
44-
"testextension.TestModifier"
45-
],
46-
"mixinConfig": "mixins.testextension.json",
4743
"dependencies": [
4844
"DependentExtension",
4945
"Extension2"
@@ -62,8 +58,6 @@ Then, create a `extension.json` at the root of the resources folder (`src/main/r
6258
* `entrypoint`: Fully qualified name of your extension class
6359
* `name`: Name to use to represent the extension to users. Must match regex `[A-Za-z][_A-Za-z0-9]+`
6460
* `version`: Version of your extension
65-
* `codeModifiers (optional)`: List of code modifier fully qualified-named classes to modify Minestom classes at launch time
66-
* `mixinConfig (optional)`: Name of a JSON file for support of Mixin injection
6761
* `dependencies (optional)`: List of extension names required for this extension to work.
6862
* `externalDependencies (optional)`: List of external libraries used for this extension (see Dependencies)
6963

@@ -81,10 +75,6 @@ Discovery can also be forced when using `ExtensionManager#loadDynamicExtension(F
8175

8276
Then, Minestom ensures all required dependencies for the extension are found. For external dependencies, it will download them if necessary. For extension dependencies, it simply checks if they are already loaded, or about to be loaded (because discovered in the current load-cycle).
8377

84-
#### 3. Classloading and code modifiers setup
85-
86-
If the extension survived dependency solving, a new classloader is created for the extension to load its classes, and any potential code modifiers declared inside `extension.json` (including the Mixin config) are loaded.
87-
8878
#### 4. Instanciation and callbacks
8979

9080
The extension is then instanciated from the class provided inside `entrypoint`, and the `preInitialize`, `initialize` and `postInitialize` callbacks are called. (see [Callback order](extensions.md#callback-order) for more information)
@@ -126,102 +116,19 @@ To declare external dependencies, use the `externalDependencies` object inside `
126116

127117
Minestom will download and cache the libraries inside `extensions/.libs/`, so that it does not require to redownload them at each launch.
128118

129-
Different extensions can depend on the same library (with same coordinates) and will share the code.
130-
131119
## Callback order
132120

133121
During `MinecraftServer#start`, Minestom calls `preInitialize` on all extensions, then `initialize` on all extensions, and finally `postInitialize` on all extensions. Minestom does **NOT** guarantee the loading order of extensions, but it should be deterministic.
134122

135-
## Testing in a dev environment
136-
137-
The easiest option to ensure your extension is recognized, and that you can register code modifiers, is to wrap your main method inside a special launcher calling `Bootstrap#bootstrap`:
138-
139-
* First argument: `mainClass` fully qualified name of your main class
140-
* Second argument: `args` program arguments
141-
142-
`Bootstrap` will then setup extensions, modifiable classloader and mixin support, then call your `main(String[] args)` method.
143-
144-
Finally, when launching your wrapping launcher, add the following VM arguments:
145-
146-
* `-Dminestom.extension.indevfolder.classes=<folder to compiled classes of your extension>` Specifies the folder in which compiled classes of your extension are. With a default Gradle setup, `build/classes/java/main/` _should_ work.
147-
* `-Dminestom.extension.indevfolder.resources=<folder to resources of your extension>` Specifies the folder in which resources of your extension are. With a default Gradle setup, `build/resources/main/` _should_ work.
148-
149-
Launcher example:
150-
151-
```java
152-
package testextension;
153-
154-
import net.minestom.server.Bootstrap;
155-
import org.spongepowered.asm.launch.MixinBootstrap;
156-
import org.spongepowered.asm.mixin.Mixins;
157-
158-
// To launch with VM arguments:
159-
// -Dminestom.extension.indevfolder.classes=build/classes/java/main/ -Dminestom.extension.indevfolder.resources=build/resources/main/
160-
public class TestExtensionLauncher {
161-
162-
public static void main(String[] args) {
163-
Bootstrap.bootstrap("YOUR_MAIN_CLASS", args);
164-
}
165-
}
166-
```
167-
168-
## Dynamically unloading and (re)loading extensions
169-
170-
* [Unloading](extensions.md#unloading)
171-
* [Reloading](extensions.md#reloading-an-extension)
172-
* [Dynamic load](extensions.md#dynamic-load)
173-
* [Swapping extension jar at runtime](extensions.md#swapping-extension-jar-at-runtime)
174-
175-
### Unloading
123+
## Extension Isolation
176124

177-
Under the hood, Minestom registers each extension inside its own classloader. This allows extensions to be reloaded from disk without having to reboot the server.
125+
All extensions are completely isolated from each other by default, this means that you may not load a class from another dependency (without shading it, which has other concerns). If your extension depends on another, it must be specified in the `extension.json`, and then it will have access to the relevant classes.
178126

179-
This feature comes at a cost: because we want to fully reload an extension, all its classes must be reloaded. To do so, their classloader must be garbage-collected. This requires all references to the classloader and its classes to be garbage-collected.
127+
Currently, if two extensions depend on the same library they will not share the same instance.
180128

181-
This means that Minestom code _cannot_ have any reference to your extension when reloading/unloading. That includes event callbacks (for ANY type of event), custom biomes, custom blocks, commands, and so on.
182-
183-
To ensure your callbacks and code is unregistered from Minestom, override the `terminate` method of your extensions, and unregister everything there.
184-
185-
**If your extension is depended upon by other extensions, this will unload the dependent extensions too.**
186-
187-
Now that you are aware of the requirements, let's see how to unload an extension:
188-
189-
```java
190-
// get an ExtensionManager, for instance via MinecraftServer.getExtensionManager();
191-
extensionManager.unloadExtension("MyExtensionName"); // MyExtensionName must match the name given inside the extension.json file
192-
```
193-
194-
That's it, this line will unload the extension and all its dependents.
195-
196-
### Reloading an extension
197-
198-
_See Unloading for more information_
199-
200-
**If your extension is depended upon by other extensions, this will reload the dependent extensions too.**
201-
202-
This allows to reload an extension from the same jar file that it was loaded before.
203-
204-
```java
205-
// get an ExtensionManager, for instance via MinecraftServer.getExtensionManager();
206-
extensionManager.reload("MyExtensionName"); // MyExtensionName must match the name given inside the extension.json file
207-
```
208-
209-
### Dynamic load
210-
211-
Minestom allows dynamic loading of extensions. You do have to be aware that the extension will have its `preInitialize`, `initialize` and `postInitialize` callbacks called immediatly upon load.
212-
213-
This dynamic loading goes through the exact same phases as an extension loaded during server startup.
214-
215-
```java
216-
// get an ExtensionManager, for instance via MinecraftServer.getExtensionManager();
217-
File extensionJar = ...; // the location of the extension jar to dynamically load
218-
extensionManager.loadDynamicExtension(extensionJar);
219-
```
220-
221-
### Swapping extension jar at runtime
129+
## Testing in a dev environment
222130

223-
Now that you know how to dynamically unload and load an extension, the procedure is rather simple:
131+
You may set the following vm arguments to load an extension from the classes and resources on disk (eg in your build directory), as opposed to a packaged jar file.
224132

225-
1. Unload the extension via `ExtensionManager#unload(String)`
226-
2. Replace the jar
227-
3. (Re-)Load the extension via `ExtensionManager#loadDynamicExtension(File)`
133+
* `-Dminestom.extension.indevfolder.classes=<folder to compiled classes of your extension>` Specifies the folder in which compiled classes of your extension are. With a default Gradle setup, `build/classes/java/main/` should work.
134+
* `-Dminestom.extension.indevfolder.resources=<folder to resources of your extension>` Specifies the folder in which resources of your extension are. With a default Gradle setup, `build/resources/main/` should work.

expansion/mixin-support.md

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)