updated Developer API usage

This commit is contained in:
FlorianMichael 2023-05-28 20:04:38 +02:00
parent 9fe71ee548
commit a82475d4b8
7 changed files with 91 additions and 11 deletions

View File

@ -5,27 +5,26 @@ public class ViaFabricPlusExampleAddon implements ClientModInitializer {
@Override
public void onInitializeClient() {
ChangeProtocolVersionCallback.EVENT.register(protocolVersion -> {
System.out.println("Version changed to " + protocolVersion.getName());
ChangeProtocolVersionCallback.EVENT.register(versionEnum -> {
System.out.println("Version changed to " + versionEnum.getName());
});
}
}
```
#### ViaFabricPlus has 7 events at the moment:
#### ViaFabricPlus has 6 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. |
| FinishMinecraftLoadCallback | Called when Minecraft is finished with loading all its components |
| FinishViaLoadingBaseStartupCallback | Called when ViaLoadingBase and Via* is loaded and ready to use |
| FinishViaVersionStartupCallback | Called when ViaVersion is loaded and ready to use |
| InitializeSettingsCallback | 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**) |
| PreLoadCallback | Called before everything (Pre-pre load) |
| ViaLoadingBaseBuilderCallback | Called when Via* is initialized |
### General API
#### Get the release version of a material:
```java
final ProtocolRange range = ItemReleaseVersionDefinition.INSTANCE.getItemMap().get(Items.WRITABLE_BOOK); // If an item does not appear in the item map, it has always existed
final VersionRange range = ItemReleaseVersionDefinition.INSTANCE.getItemMap().get(Items.WRITABLE_BOOK); // If an item does not appear in the item map, it has always existed
// The Range class then contains all versions in which the item occurs.
// You can find out how the Range class works in the ViaLoadingBase README.

View File

@ -3,7 +3,7 @@
<h1>ViaFabricPlus</h1>
<a href="https://fabricmc.net"><img src="https://img.shields.io/badge/Mod%20Loader-Fabric-lightyellow?logo=data:image/png;base64,iVBORw0KGgoAAAANSUh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Enviroment-Client-purple">
<a href="https://discord.gg/BwWhCHUKDf"><img src="https://img.shields.io/discord/1033745845809586356?color=0098DB&label=Discord&logo=discord&logoColor=0098DB"></a> <br />
<a href="https://discord.gg/viaversion"><img src="https://img.shields.io/discord/1033745845809586356?color=0098DB&label=Discord&logo=discord&logoColor=0098DB"></a> <br />
<a href="https://modrinth.com/mod/viafabricplus"><img src="https://img.shields.io/badge/dynamic/json?color=158000&label=downloads&prefix=+%20&query=downloads&url=https://api.modrinth.com/v2/project/rIC2XJV4&logo=modrinth"></a>
<a href="https://curseforge.com/minecraft/mc-mods/viafabricplus"><img src="https://cf.way2muchnoise.eu/full_830604_downloads.svg"></a>
<a href="https://github.com/FlorianMichael/ViaFabricPlus/actions/workflows/build.yml"><img src="https://github.com/FlorianMichael/ViaFabricPlus/actions/workflows/build.yml/badge.svg?branch=main"></a>

View File

@ -29,6 +29,7 @@ import de.florianmichael.viafabricplus.base.event.FinishViaVersionStartupCallbac
import de.florianmichael.viafabricplus.protocolhack.command.ViaFabricPlusVLCommandHandler;
import de.florianmichael.viafabricplus.protocolhack.impl.ViaFabricPlusVLInjector;
import de.florianmichael.viafabricplus.protocolhack.impl.ViaFabricPlusVLLoader;
import de.florianmichael.viafabricplus.protocolhack.impl.platform.ViaFabricPlusViaVersionPlatformImpl;
import de.florianmichael.viafabricplus.protocolhack.netty.ViaFabricPlusVLLegacyPipeline;
import io.netty.channel.*;
import io.netty.util.AttributeKey;
@ -114,7 +115,7 @@ public class ProtocolHack {
}
public static void init() {
ViaLoader.init(null, new ViaFabricPlusVLLoader(), new ViaFabricPlusVLInjector(), new ViaFabricPlusVLCommandHandler(), ViaBackwardsPlatformImpl::new, ViaLegacyPlatformImpl::new, ViaAprilFoolsPlatformImpl::new, ViaBedrockPlatformImpl::new);
ViaLoader.init(new ViaFabricPlusViaVersionPlatformImpl(null), new ViaFabricPlusVLLoader(), new ViaFabricPlusVLInjector(), new ViaFabricPlusVLCommandHandler(), ViaBackwardsPlatformImpl::new, ViaLegacyPlatformImpl::new, ViaAprilFoolsPlatformImpl::new, ViaBedrockPlatformImpl::new);
initCommands();
FinishViaVersionStartupCallback.EVENT.invoker().onFinishViaVersionStartup();

View File

@ -0,0 +1,45 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viafabricplus.protocolhack.impl;
import de.florianmichael.viafabricplus.base.settings.groups.ExperimentalSettings;
import net.raphimc.vialoader.impl.viaversion.VLViaConfig;
import java.io.File;
public class ViaFabricPlusVLViaConfig extends VLViaConfig {
public ViaFabricPlusVLViaConfig(File configFile) {
super(configFile);
}
@Override
public boolean isLeftHandedHandling() {
return false;
}
@Override
public boolean isShieldBlocking() {
return false;
}
@Override
public boolean isChunkBorderFix() {
return ExperimentalSettings.INSTANCE.fixChunkBorders.getValue();
}
}

View File

@ -0,0 +1,38 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viafabricplus.protocolhack.impl.platform;
import com.viaversion.viaversion.configuration.AbstractViaConfig;
import de.florianmichael.viafabricplus.protocolhack.impl.ViaFabricPlusVLViaConfig;
import net.raphimc.vialoader.impl.platform.ViaVersionPlatformImpl;
import java.io.File;
public class ViaFabricPlusViaVersionPlatformImpl extends ViaVersionPlatformImpl {
public ViaFabricPlusViaVersionPlatformImpl(File rootFolder) {
super(rootFolder);
}
@Override
protected AbstractViaConfig createConfig() {
final AbstractViaConfig config = new ViaFabricPlusVLViaConfig(new File(this.getDataFolder(), "viaversion.yml"));
config.reloadConfig();
return config;
}
}

View File

@ -50,8 +50,6 @@ public class ViaFabricPlusVLLegacyPipeline extends VLLegacyPipeline {
ctx.pipeline().remove(VIABEDROCK_PACKET_ENCAPSULATION_HANDLER_NAME);
ctx.pipeline().remove(this.lengthSplitterName());
}
System.out.println(ctx.pipeline().names());
}
@Override

View File

@ -142,7 +142,6 @@ public class ViaFabricPlusBaseVersionProvider extends BaseVersionProvider {
});
}
}
System.out.println(ProtocolHack.getTargetVersion(connection.getChannel()).getName());
return ProtocolHack.getTargetVersion(connection.getChannel()).getVersion();
}
return super.getClosestServerProtocol(connection);