updated docs/ folder

This commit is contained in:
FlorianMichael 2023-11-28 15:07:51 +01:00
parent 5057809c30
commit 9f80ee41e1
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
3 changed files with 36 additions and 12 deletions

View File

@ -4,20 +4,44 @@ ViaFabricPlus provides various events and APIs for developers to use. This page
## Events
ViaFabricPlus events are using the [Fabric Event API](https://fabricmc.net/wiki/tutorial:events). You can register to them like this:
```java
ChangeProtocolVersionCallback.EVENT.register(versionEnum -> {
System.out.println("Version changed to " + versionEnum.getName());
ChangeProtocolVersionCallback.EVENT.register((oldVersion, newVersion) -> {
System.out.println("Version changed to " + newVersion.getName());
});
```
### ViaFabricPlus has 7 events at the moment
### ViaFabricPlus has 8 events at the moment
| Callback class name | Description |
|--------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ChangeProtocolVersionCallback | Called when the user changes the target version in the screen, or if you connect to a server for which a specific version has been selected, you disconnect, the event for the actual version is also called. |
| DisconnectCallback | Called when the user disconnects from a server. |
| DisconnectCallback | Called when the user disconnects from a server |
| LoadCallback | Called at the earliest point ViaFabricPlus is injecting too |
| LoadClassicProtocolExtensionCallback | Called when the classic server sends the protocol extensions (only in **c0.30 CPE**) |
| PostGameLoadCallback | Called when Minecraft is finished with loading all its components |
| PostViaVersionLoadCallback | Called when ViaVersion is loaded and ready to use |
| RegisterSettingsCallback | Called after the default setting groups are loaded and before the setting config is loaded |
| LoadClassicProtocolExtensionCallback | Called when the classic server sends the protocol extensions (only in **c0.30 CPE**) |
| LoadCallback | Called at the earliest point ViaFabricPlus is injecting too |
| LoadSaveFiles | Called before and after the save files are loaded |
## Get and set the current protocol version
```java
final VersionEnum version = ProtocolHack.getTargetVersion();
if (version == VersionEnum.r1_8) {
ProtocolHack.setTargetVersion(VersionEnum.r1_9);
}
```
## Get a Minecraft ClientConnection by channel
```java
final ClientConnection connection = channel.attr(ProtocolHack.CLIENT_CONNECTION_ATTRIBUTE_KEY).get();
```
## Interact with UserConnection objects
```java
// If ViaVersion is translating, this field will return the user connection of the client
final UserConnection userConnection = ProtocolHack.getPlayNetworkUserConnection();
// If you need a dummy user connection for testing, you can use this method
final UserConnection cursedDummy = ProtocolHack.createDummyUserConnection(ProtocolHack.NATIVE_VERSION, VersionEnum.r1_18_2);
// The cursedDummy field now contains all protocols from the native version to 1.18.2
```
## ViaVersion internals
### Add CustomPayload channels for versions below 1.13

View File

@ -26,10 +26,10 @@ import net.fabricmc.fabric.api.event.EventFactory;
/**
* This event is fired when ViaFabricPlus has loaded its save files, and before it starts reading the values from the save files.
*/
public interface SaveFilesCallback {
public interface LoadSaveFilesCallback {
Event<SaveFilesCallback> EVENT = EventFactory.createArrayBacked(SaveFilesCallback.class, listeners -> (saveManager, state) -> {
for (SaveFilesCallback listener : listeners) {
Event<LoadSaveFilesCallback> EVENT = EventFactory.createArrayBacked(LoadSaveFilesCallback.class, listeners -> (saveManager, state) -> {
for (LoadSaveFilesCallback listener : listeners) {
listener.onLoadSaveFiles(saveManager, state);
}
});

View File

@ -19,7 +19,7 @@
package de.florianmichael.viafabricplus.save;
import de.florianmichael.viafabricplus.event.SaveFilesCallback;
import de.florianmichael.viafabricplus.event.LoadSaveFilesCallback;
import de.florianmichael.viafabricplus.save.impl.AccountsSave;
import de.florianmichael.viafabricplus.save.impl.SettingsSave;
import de.florianmichael.viafabricplus.settings.SettingsManager;
@ -35,7 +35,7 @@ public class SaveManager {
private final AccountsSave accountsSave;
public SaveManager(final SettingsManager settingsManager) {
SaveFilesCallback.EVENT.invoker().onLoadSaveFiles(this, SaveFilesCallback.State.PRE);
LoadSaveFilesCallback.EVENT.invoker().onLoadSaveFiles(this, LoadSaveFilesCallback.State.PRE);
// Register saves
add(
@ -55,7 +55,7 @@ public class SaveManager {
}
}));
SaveFilesCallback.EVENT.invoker().onLoadSaveFiles(this, SaveFilesCallback.State.POST);
LoadSaveFilesCallback.EVENT.invoker().onLoadSaveFiles(this, LoadSaveFilesCallback.State.POST);
}
public void add(final AbstractSave... saves) {