full recode

This commit is contained in:
FlorianMichael 2023-03-14 23:45:57 +01:00
parent 969025d3ce
commit 869225e159
79 changed files with 658 additions and 305 deletions

View File

@ -142,6 +142,38 @@ public class ExampleSettingGroup extends SettingGroup {
}
```
#### Implementing classic protocol commands:
```java
public class ExampleCommand implements ICommand {
@Override
public String name() {
return "example";
}
@Override
public String description() {
return null;
}
@Override
public void execute(String[] args) {
}
}
```
and then you register the command in your onLoad method:
```java
// addon main [...]
@Override
public void onLoad() {
ClassicProtocolCommands.commands.add(new ExampleCommand());
}
```
#### Implementing custom classic protocol extensions:
## Alternatives
- [ClientViaVersion](https://github.com/Gerrygames/ClientViaVersion): Discontinued 5zig plugin.
- [multiconnect](https://www.curseforge.com/minecraft/mc-mods/multiconnect): Fabric mod for connecting to older

View File

@ -56,6 +56,13 @@ dependencies {
modImplementation "com.terraformersmc:modmenu:${project.mod_menu_version}"
libs "com.github.FlorianMichael:ViaLoadingBase:${project.vialoadingbase_version}"
libs "com.github.FlorianMichael:DietrichEvents:${project.dietrichevents_version}"
libs("org.cloudburstmc.netty:netty-transport-raknet:${project.raknet_transport_version}") {
exclude group: "io.netty", module: "netty-common"
exclude group: "io.netty", module: "netty-buffer"
exclude group: "io.netty", module: "netty-codec"
exclude group: "io.netty", module: "netty-transport"
}
libs "com.viaversion:viaversion:${project.viaversion_version}"
libs "com.viaversion:viabackwards-common:${project.viabackwards_version}"
@ -67,12 +74,6 @@ dependencies {
libs "net.lenni0451.mcstructs:text:${project.mcstructs_text_version}"
libs "net.lenni0451:Reflect:${project.reflect_version}"
libs("org.cloudburstmc.netty:netty-transport-raknet:1.0.0.CR1-SNAPSHOT") {
exclude group: "io.netty", module: "netty-common"
exclude group: "io.netty", module: "netty-buffer"
exclude group: "io.netty", module: "netty-codec"
exclude group: "io.netty", module: "netty-transport"
}
}
processResources {

View File

@ -8,12 +8,14 @@ yarn_mappings=1.19.3+build.5
loader_version=0.14.14
# viafabricplus
mod_version=1.8.11
mod_version=1.9.0
maven_group=de.florianmichael
archives_base_name=viafabricplus
# base lib
vialoadingbase_version=6dad0a2561
dietrichevents_version=1.0.0
raknet_transport_version=1.0.0.CR1-SNAPSHOT
# viaversion (and required) libs
viaversion_version=4.6.0

View File

@ -17,154 +17,53 @@
*/
package de.florianmichael.viafabricplus;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
import de.florianmichael.dietrichevents.EventDispatcher;
import de.florianmichael.viafabricplus.definition.ChatLengthDefinition;
import de.florianmichael.viafabricplus.definition.ItemReleaseVersionDefinition;
import de.florianmichael.viafabricplus.definition.PackFormatsDefinition;
import de.florianmichael.viafabricplus.definition.c0_30.ClassicItemSelectionScreen;
import de.florianmichael.viafabricplus.definition.c0_30.CustomClassicProtocolExtensions;
import de.florianmichael.viafabricplus.definition.c0_30.command.ClassicProtocolCommands;
import de.florianmichael.viafabricplus.definition.v1_19_0.provider.CommandArgumentsProvider;
import de.florianmichael.viafabricplus.definition.v1_8_x.ArmorPointsDefinition;
import de.florianmichael.viafabricplus.platform.ViaAprilFoolsPlatformImpl;
import de.florianmichael.viafabricplus.platform.ViaBedrockPlatformImpl;
import de.florianmichael.viafabricplus.platform.ViaLegacyPlatformImpl;
import de.florianmichael.viafabricplus.provider.*;
import de.florianmichael.viafabricplus.settings.SettingGroup;
import de.florianmichael.viafabricplus.settings.groups.*;
import de.florianmichael.viafabricplus.util.SettingsSave;
import de.florianmichael.vialoadingbase.ViaLoadingBase;
import de.florianmichael.vialoadingbase.platform.SubPlatform;
import io.netty.util.AttributeKey;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.SharedConstants;
import net.minecraft.client.MinecraftClient;
import net.minecraft.network.ClientConnection;
import net.raphimc.viaaprilfools.api.AprilFoolsProtocolVersion;
import net.raphimc.viabedrock.api.BedrockProtocolVersion;
import net.raphimc.viabedrock.protocol.providers.NettyPipelineProvider;
import net.raphimc.vialegacy.api.LegacyProtocolVersion;
import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.providers.ClassicCustomCommandProvider;
import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.providers.ClassicMPPassProvider;
import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.providers.ClassicWorldHeightProvider;
import net.raphimc.vialegacy.protocols.release.protocol1_3_1_2to1_2_4_5.providers.OldAuthProvider;
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.providers.EncryptionProvider;
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.providers.GameProfileFetcher;
import de.florianmichael.viafabricplus.event.FinishMinecraftLoadListener;
import de.florianmichael.viafabricplus.event.LoadListener;
import de.florianmichael.viafabricplus.settings.SettingsSystem;
import de.florianmichael.viafabricplus.vialoadingbase.ViaLoadingBaseStartup;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class ViaFabricPlus {
public final static File RUN_DIRECTORY = new File("ViaFabricPlus");
public final static AttributeKey<UserConnection> LOCAL_VIA_CONNECTION = AttributeKey.newInstance("viafabricplus-via-connection");
public final static AttributeKey<ClientConnection> LOCAL_MINECRAFT_CONNECTION = AttributeKey.newInstance("viafabricplus-minecraft-connection");
public final static ViaFabricPlus INSTANCE = new ViaFabricPlus();
private final static ViaFabricPlus self = new ViaFabricPlus();
private final EventDispatcher eventDispatcher = new EventDispatcher();
private final SettingsSystem settingsSystem = new SettingsSystem();
private final List<SettingGroup> settingGroups = new ArrayList<>();
public void init() {
eventDispatcher.subscribe(FinishMinecraftLoadListener.class, () -> {
settingsSystem.init();
private final SubPlatform SUB_PLATFORM_VIA_LEGACY = new SubPlatform("ViaLegacy", () -> true, ViaLegacyPlatformImpl::new, protocolVersions -> {
final List<ProtocolVersion> legacyProtocols = new ArrayList<>(LegacyProtocolVersion.PROTOCOLS);
Collections.reverse(legacyProtocols);
// General definitions
PackFormatsDefinition.load();
ItemReleaseVersionDefinition.create();
ArmorPointsDefinition.load();
legacyProtocols.remove(LegacyProtocolVersion.c0_30cpe);
legacyProtocols.add(legacyProtocols.indexOf(LegacyProtocolVersion.c0_28toc0_30) + 1, LegacyProtocolVersion.c0_30cpe);
protocolVersions.addAll(legacyProtocols);
});
private final SubPlatform SUB_PLATFORM_VIA_APRIL_FOOLS = new SubPlatform("ViaAprilFools", () -> true, ViaAprilFoolsPlatformImpl::new, protocolVersions -> {
protocolVersions.add(protocolVersions.indexOf(ProtocolVersion.v1_14) + 1,AprilFoolsProtocolVersion.s3d_shareware);
protocolVersions.add(protocolVersions.indexOf(ProtocolVersion.v1_16) + 1, AprilFoolsProtocolVersion.s20w14infinite);
protocolVersions.add(protocolVersions.indexOf(ProtocolVersion.v1_16_2) + 1, AprilFoolsProtocolVersion.sCombatTest8c);
});
private final SubPlatform SUB_PLATFORM_VIA_BEDROCK = new SubPlatform("ViaBedrock", () -> true, ViaBedrockPlatformImpl::new, protocolVersions -> protocolVersions.add(BedrockProtocolVersion.bedrockLatest));
public void preLoad() {
CustomClassicProtocolExtensions.reflect();
ViaLoadingBase.ViaLoadingBaseBuilder builder = ViaLoadingBase.ViaLoadingBaseBuilder.create();
builder = builder.subPlatform(SUB_PLATFORM_VIA_BEDROCK, 0);
builder = builder.subPlatform(SUB_PLATFORM_VIA_LEGACY);
builder = builder.subPlatform(SUB_PLATFORM_VIA_APRIL_FOOLS);
builder = builder.runDirectory(RUN_DIRECTORY);
builder = builder.nativeVersion(SharedConstants.getProtocolVersion());
builder = builder.forceNativeVersionCondition(() -> {
if (MinecraftClient.getInstance() == null) return true;
return MinecraftClient.getInstance().isInSingleplayer();
// Classic Stuff
ChatLengthDefinition.create();
ClassicItemSelectionScreen.create();
ClassicProtocolCommands.load();
});
builder = builder.providers(providers -> {
providers.use(MovementTransmitterProvider.class, new ViaFabricPlusMovementTransmitterProvider());
providers.use(HandItemProvider.class, new ViaFabricPlusHandItemProvider());
eventDispatcher.post(new LoadListener.LoadEvent());
providers.use(CommandArgumentsProvider.class, new ViaFabricPlusCommandArgumentsProvider());
providers.use(OldAuthProvider.class, new ViaFabricPlusOldAuthProvider());
providers.use(ClassicWorldHeightProvider.class, new ViaFabricPlusClassicWorldHeightProvider());
providers.use(EncryptionProvider.class, new ViaFabricPlusEncryptionProvider());
providers.use(GameProfileFetcher.class, new ViaFabricPlusGameProfileFetcher());
providers.use(ClassicMPPassProvider.class, new ViaFabricPlusClassicMPPassProvider());
providers.use(ClassicCustomCommandProvider.class, new ViaFabricPlusClassicCustomCommandProvider());
providers.use(NettyPipelineProvider.class, new ViaFabricPlusNettyPipelineProvider());
});
builder = builder.onProtocolReload(protocolVersion -> {
FabricLoader.getInstance().getEntrypoints("viafabricplus", ViaFabricPlusAddon.class).forEach(viaFabricPlusAddon -> viaFabricPlusAddon.onChangeVersion(protocolVersion));
ItemReleaseVersionDefinition.reload(protocolVersion);
ChatLengthDefinition.reload(protocolVersion);
if (protocolVersion.isOlderThanOrEqualTo(LegacyProtocolVersion.c0_28toc0_30)) {
ClassicItemSelectionScreen.INSTANCE.reload(protocolVersion, false);
}
});
builder.build();
CustomClassicProtocolExtensions.create();
new ViaLoadingBaseStartup();
}
public void postLoad() throws Exception {
loadGroup(
GeneralSettings.getClassWrapper(),
BridgeSettings.getClassWrapper(),
MPPassSettings.getClassWrapper(),
VisualSettings.getClassWrapper(),
DebugSettings.getClassWrapper()
);
FabricLoader.getInstance().getEntrypoints("viafabricplus", ViaFabricPlusAddon.class).forEach(ViaFabricPlusAddon::onLoad);
SettingsSave.load(this);
PackFormatsDefinition.load();
ItemReleaseVersionDefinition.load();
ArmorPointsDefinition.load();
PackFormatsDefinition.checkOutdated(SharedConstants.getProtocolVersion());
ClassicProtocolCommands.load();
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
SettingsSave.save(this);
} catch (Exception e) {
throw new RuntimeException(e);
}
}));
public EventDispatcher getEventDispatcher() {
return eventDispatcher;
}
public void loadGroup(final SettingGroup... groups) {
this.settingGroups.addAll(Arrays.asList(groups));
}
public List<SettingGroup> getSettingGroups() {
return settingGroups;
}
public static ViaFabricPlus getClassWrapper() {
return ViaFabricPlus.self;
public SettingsSystem getSettingsSystem() {
return settingsSystem;
}
}

View File

@ -18,29 +18,37 @@
package de.florianmichael.viafabricplus.definition;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viafabricplus.ViaFabricPlus;
import de.florianmichael.viafabricplus.event.ChangeProtocolVersionListener;
import de.florianmichael.vialoadingbase.platform.ComparableProtocolVersion;
import net.minecraft.client.MinecraftClient;
import net.raphimc.vialegacy.api.LegacyProtocolVersion;
public class ChatLengthDefinition {
private static int maxLength = 256;
public static ChatLengthDefinition INSTANCE;
public static void reload(final ComparableProtocolVersion protocolVersion) {
maxLength = 256;
if (protocolVersion.isOlderThanOrEqualTo(ProtocolVersion.v1_10)) {
maxLength = 100;
public static void create() {
INSTANCE = new ChatLengthDefinition();
if (protocolVersion.isOlderThanOrEqualTo(LegacyProtocolVersion.c0_28toc0_30)) {
maxLength = 64 - MinecraftClient.getInstance().getSession().getUsername().length() - 2;
ViaFabricPlus.INSTANCE.getEventDispatcher().subscribe(ChangeProtocolVersionListener.class, protocolVersion -> {
INSTANCE.maxLength = 256;
if (protocolVersion.isOlderThanOrEqualTo(ProtocolVersion.v1_10)) {
INSTANCE.maxLength = 100;
if (protocolVersion.isOlderThanOrEqualTo(LegacyProtocolVersion.c0_28toc0_30)) {
INSTANCE.maxLength = 64 - MinecraftClient.getInstance().getSession().getUsername().length() - 2;
}
}
}
});
}
public static void expand() {
private int maxLength = 256;
public void expand() {
maxLength = Short.MAX_VALUE * 2;
}
public static int getMaxLength() {
public int getMaxLength() {
return maxLength;
}
}

View File

@ -18,6 +18,8 @@
package de.florianmichael.viafabricplus.definition;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viafabricplus.ViaFabricPlus;
import de.florianmichael.viafabricplus.event.ChangeProtocolVersionListener;
import de.florianmichael.vialoadingbase.platform.ComparableProtocolVersion;
import de.florianmichael.vialoadingbase.platform.ProtocolRange;
import net.minecraft.item.Item;
@ -33,21 +35,27 @@ import java.util.*;
* @copyright FlorianMichael as Jesse - 2020-2023
*/
public class ItemReleaseVersionDefinition {
private final static Map<Item, ProtocolRange[]> itemMap = new HashMap<>();
private final static List<Item> currentMap = new ArrayList<>();
public static ItemReleaseVersionDefinition INSTANCE;
public static void reload(final ComparableProtocolVersion protocolVersion) {
currentMap.clear();
currentMap.addAll(Registries.ITEM.stream().filter(item -> ItemReleaseVersionDefinition.contains(item, protocolVersion)).toList());
public static void create() {
INSTANCE = new ItemReleaseVersionDefinition();
ViaFabricPlus.INSTANCE.getEventDispatcher().subscribe(ChangeProtocolVersionListener.class, (protocolVersion -> {
INSTANCE.currentMap.clear();
INSTANCE.currentMap.addAll(Registries.ITEM.stream().filter(item -> INSTANCE.contains(item, protocolVersion)).toList());
}));
}
public static boolean contains(final Item item, final ComparableProtocolVersion protocolVersion) {
private final Map<Item, ProtocolRange[]> itemMap = new HashMap<>();
private final List<Item> currentMap = new ArrayList<>();
public boolean contains(final Item item, final ComparableProtocolVersion protocolVersion) {
if (!itemMap.containsKey(item)) return true;
return Arrays.stream(itemMap.get(item)).anyMatch(protocolRange -> protocolRange.contains(protocolVersion));
}
public static void load() {
public void load() {
register(Items.IRON_GOLEM_SPAWN_EGG, ProtocolRange.andNewer(ProtocolVersion.v1_19_3));
register(Items.SNOW_GOLEM_SPAWN_EGG, ProtocolRange.andNewer(ProtocolVersion.v1_19_3));
@ -1300,19 +1308,19 @@ public class ItemReleaseVersionDefinition {
register(Items.SPONGE, ProtocolRange.andNewer(LegacyProtocolVersion.c0_0_19a_06));
}
private static void register(final Item item, final ProtocolRange range) {
private void register(final Item item, final ProtocolRange range) {
itemMap.put(item, new ProtocolRange[]{range});
}
private static void register(final Item item, final ProtocolRange... ranges) {
private void register(final Item item, final ProtocolRange... ranges) {
itemMap.put(item, ranges);
}
public static Map<Item, ProtocolRange[]> getItemMap() {
public Map<Item, ProtocolRange[]> getItemMap() {
return itemMap;
}
public static List<Item> getCurrentMap() {
public List<Item> getCurrentMap() {
return currentMap;
}
}

View File

@ -68,6 +68,8 @@ public class PackFormatsDefinition {
registerVersion(ProtocolVersion.v1_8, 1, "1.8.9");
registerVersion(ProtocolVersion.v1_7_6, 1, "1.7.10");
registerVersion(ProtocolVersion.v1_7_1, 1, "1.7.5");
checkOutdated(SharedConstants.getProtocolVersion());
}
public static void checkOutdated(final int nativeVersion) {

View File

@ -17,6 +17,8 @@
*/
package de.florianmichael.viafabricplus.definition.c0_30;
import de.florianmichael.viafabricplus.ViaFabricPlus;
import de.florianmichael.viafabricplus.event.ChangeProtocolVersionListener;
import de.florianmichael.vialoadingbase.platform.ComparableProtocolVersion;
import de.florianmichael.vialoadingbase.platform.InternalProtocolList;
import net.minecraft.client.MinecraftClient;
@ -37,7 +39,17 @@ import java.util.List;
@SuppressWarnings("DataFlowIssue")
public class ClassicItemSelectionScreen extends Screen {
public static ClassicItemSelectionScreen INSTANCE = new ClassicItemSelectionScreen();
public static ClassicItemSelectionScreen INSTANCE;
public static void create() {
INSTANCE = new ClassicItemSelectionScreen();
ViaFabricPlus.INSTANCE.getEventDispatcher().subscribe(ChangeProtocolVersionListener.class, protocolVersion -> {
if (protocolVersion.isOlderThanOrEqualTo(LegacyProtocolVersion.c0_28toc0_30)) {
INSTANCE.reload(protocolVersion, false);
}
});
}
private final static int MAX_ROW_DIVIDER = 9;
private final static int ITEM_XY_BOX_DIMENSION_CLASSIC = 25;

View File

@ -19,6 +19,7 @@ package de.florianmichael.viafabricplus.definition.c0_30;
import com.viaversion.viaversion.api.connection.UserConnection;
import de.florianmichael.viafabricplus.ViaFabricPlus;
import de.florianmichael.viafabricplus.vialoadingbase.ViaLoadingBaseStartup;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.util.Window;
@ -29,7 +30,7 @@ public class ClassicProgressRenderer extends DrawableHelper {
public static void renderProgress(final MatrixStack matrices) {
if (MinecraftClient.getInstance().getNetworkHandler() == null) return;
final UserConnection connection = MinecraftClient.getInstance().getNetworkHandler().getConnection().channel.attr(ViaFabricPlus.LOCAL_VIA_CONNECTION).get();
final UserConnection connection = MinecraftClient.getInstance().getNetworkHandler().getConnection().channel.attr(ViaLoadingBaseStartup.LOCAL_VIA_CONNECTION).get();
if (connection == null) return;
final ClassicProgressStorage classicProgressStorage = connection.get(ClassicProgressStorage.class);
if (classicProgressStorage == null) return;

View File

@ -18,7 +18,11 @@
package de.florianmichael.viafabricplus.definition.c0_30;
import com.viaversion.viaversion.api.connection.UserConnection;
import de.florianmichael.dietrichevents.EventDispatcher;
import de.florianmichael.viafabricplus.ViaFabricPlus;
import de.florianmichael.viafabricplus.definition.ChatLengthDefinition;
import de.florianmichael.viafabricplus.event.LoadClassicProtocolExtensionListener;
import de.florianmichael.viafabricplus.event.LoadListener;
import de.florianmichael.vialoadingbase.ViaLoadingBase;
import io.netty.buffer.ByteBuf;
import net.lenni0451.reflect.Enums;
@ -32,24 +36,28 @@ import java.util.Map;
import java.util.function.BiConsumer;
public class CustomClassicProtocolExtensions {
public final static List<ClassicProtocolExtension> ALLOWED_EXTENSIONS = Arrays.asList(ClassicProtocolExtension.ENV_WEATHER_TYPE);
public static CustomClassicProtocolExtensions INSTANCE;
public final static Map<Integer, ClientboundPacketsc0_30cpe> CUSTOM_PACKETS = new HashMap<>();
public static ClientboundPacketsc0_30cpe EXT_WEATHER_TYPE;
public static void create() {
CustomClassicProtocolExtensions.INSTANCE = new CustomClassicProtocolExtensions();
public static void reflect() {
EXT_WEATHER_TYPE = createNewPacket(ClassicProtocolExtension.ENV_WEATHER_TYPE, 31, (user, buf) -> buf.readByte());
ViaFabricPlus.INSTANCE.getEventDispatcher().subscribe(LoadClassicProtocolExtensionListener.class, (classicProtocolExtension) -> {
if (classicProtocolExtension == ClassicProtocolExtension.LONGER_MESSAGES) ChatLengthDefinition.INSTANCE.expand();
if (classicProtocolExtension == ClassicProtocolExtension.CUSTOM_BLOCKS) ClassicItemSelectionScreen.INSTANCE.reload(ViaLoadingBase.getClassWrapper().getTargetVersion(), true);
});
}
public static void onAddServerExtension(final ClassicProtocolExtension extension) {
if (extension == ClassicProtocolExtension.LONGER_MESSAGES) ChatLengthDefinition.expand();
if (extension == ClassicProtocolExtension.CUSTOM_BLOCKS) ClassicItemSelectionScreen.INSTANCE.reload(ViaLoadingBase.getClassWrapper().getTargetVersion(), true);
}
public final List<ClassicProtocolExtension> ALLOWED_EXTENSIONS = Arrays.asList(ClassicProtocolExtension.ENV_WEATHER_TYPE);
public final Map<Integer, ClientboundPacketsc0_30cpe> CUSTOM_PACKETS = new HashMap<>();
public static ClientboundPacketsc0_30cpe EXT_WEATHER_TYPE;
public static ClientboundPacketsc0_30cpe createNewPacket(final ClassicProtocolExtension classicProtocolExtension, final int packetId, final BiConsumer<UserConnection, ByteBuf> packetSplitter) {
final ClientboundPacketsc0_30cpe packet = Enums.newInstance(ClientboundPacketsc0_30cpe.class, classicProtocolExtension.getName(), ClassicProtocolExtension.values().length, new Class[] { int.class, BiConsumer.class }, new Object[] { packetId, packetSplitter });
Enums.addEnumInstance(ClientboundPacketsc0_30cpe.class, packet);
CUSTOM_PACKETS.put(packetId, packet);
INSTANCE.CUSTOM_PACKETS.put(packetId, packet);
return packet;
}
}

View File

@ -21,6 +21,7 @@ import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import de.florianmichael.viafabricplus.ViaFabricPlus;
import de.florianmichael.viafabricplus.util.ScreenUtil;
import de.florianmichael.viafabricplus.vialoadingbase.ViaLoadingBaseStartup;
import net.minecraft.client.MinecraftClient;
import net.minecraft.util.Formatting;
import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.providers.ClassicCustomCommandProvider;
@ -44,7 +45,7 @@ public interface ICommand {
}
default UserConnection currentViaConnection() {
return MinecraftClient.getInstance().getNetworkHandler().getConnection().channel.attr(ViaFabricPlus.LOCAL_VIA_CONNECTION).get();
return MinecraftClient.getInstance().getNetworkHandler().getConnection().channel.attr(ViaLoadingBaseStartup.LOCAL_VIA_CONNECTION).get();
}
void execute(String[] args) throws Exception;

View File

@ -0,0 +1,46 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2023 FlorianMichael/MrLookAtMe (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.event;
import de.florianmichael.dietrichevents.AbstractEvent;
import de.florianmichael.dietrichevents.handle.EventExecutor;
import de.florianmichael.dietrichevents.handle.Listener;
import de.florianmichael.vialoadingbase.platform.ComparableProtocolVersion;
public interface ChangeProtocolVersionListener extends Listener {
void onChangeProtocolVersion(final ComparableProtocolVersion protocolVersion);
class ChangeProtocolVersionEvent extends AbstractEvent<ChangeProtocolVersionListener> {
private final EventExecutor<ChangeProtocolVersionListener> eventExecutor;
public ChangeProtocolVersionEvent(final ComparableProtocolVersion protocolVersion) {
this.eventExecutor = listener -> listener.onChangeProtocolVersion(protocolVersion);
}
@Override
public EventExecutor<ChangeProtocolVersionListener> getEventExecutor() {
return this.eventExecutor;
}
@Override
public Class<ChangeProtocolVersionListener> getListenerType() {
return ChangeProtocolVersionListener.class;
}
}
}

View File

@ -0,0 +1,41 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2023 FlorianMichael/MrLookAtMe (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.event;
import de.florianmichael.dietrichevents.AbstractEvent;
import de.florianmichael.dietrichevents.handle.EventExecutor;
import de.florianmichael.dietrichevents.handle.Listener;
public interface FinishMinecraftLoadListener extends Listener {
void onFinishMinecraftLoad();
class FinishMinecraftLoadEvent extends AbstractEvent<FinishMinecraftLoadListener> {
private final EventExecutor<FinishMinecraftLoadListener> eventExecutor = FinishMinecraftLoadListener::onFinishMinecraftLoad;
@Override
public EventExecutor<FinishMinecraftLoadListener> getEventExecutor() {
return eventExecutor;
}
@Override
public Class<FinishMinecraftLoadListener> getListenerType() {
return FinishMinecraftLoadListener.class;
}
}
}

View File

@ -0,0 +1,41 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2023 FlorianMichael/MrLookAtMe (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.event;
import de.florianmichael.dietrichevents.AbstractEvent;
import de.florianmichael.dietrichevents.handle.EventExecutor;
import de.florianmichael.dietrichevents.handle.Listener;
public interface FinishViaLoadingBaseStartupListener extends Listener {
void onFinishViaLoadingBaseStartup();
class FinishViaLoadingBaseStartupEvent extends AbstractEvent<FinishViaLoadingBaseStartupListener> {
private final EventExecutor<FinishViaLoadingBaseStartupListener> eventExecutor = FinishViaLoadingBaseStartupListener::onFinishViaLoadingBaseStartup;
@Override
public EventExecutor<FinishViaLoadingBaseStartupListener> getEventExecutor() {
return eventExecutor;
}
@Override
public Class<FinishViaLoadingBaseStartupListener> getListenerType() {
return FinishViaLoadingBaseStartupListener.class;
}
}
}

View File

@ -0,0 +1,41 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2023 FlorianMichael/MrLookAtMe (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.event;
import de.florianmichael.dietrichevents.AbstractEvent;
import de.florianmichael.dietrichevents.handle.EventExecutor;
import de.florianmichael.dietrichevents.handle.Listener;
public interface InitializeSettingsListener extends Listener {
void onInitializeSettings();
class InitializeSettingsEvent extends AbstractEvent<InitializeSettingsListener> {
private final EventExecutor<InitializeSettingsListener> eventExecutor = InitializeSettingsListener::onInitializeSettings;
@Override
public EventExecutor<InitializeSettingsListener> getEventExecutor() {
return eventExecutor;
}
@Override
public Class<InitializeSettingsListener> getListenerType() {
return InitializeSettingsListener.class;
}
}
}

View File

@ -0,0 +1,46 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2023 FlorianMichael/MrLookAtMe (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.event;
import de.florianmichael.dietrichevents.AbstractEvent;
import de.florianmichael.dietrichevents.handle.EventExecutor;
import de.florianmichael.dietrichevents.handle.Listener;
import net.raphimc.vialegacy.protocols.classic.protocolc0_28_30toc0_28_30cpe.data.ClassicProtocolExtension;
public interface LoadClassicProtocolExtensionListener extends Listener {
void onLoadClassicProtocolExtension(final ClassicProtocolExtension classicProtocolExtension);
class LoadClassicProtocolExtensionEvent extends AbstractEvent<LoadClassicProtocolExtensionListener> {
private final EventExecutor<LoadClassicProtocolExtensionListener> eventExecutor;
public LoadClassicProtocolExtensionEvent(final ClassicProtocolExtension classicProtocolExtension) {
this.eventExecutor = listener -> listener.onLoadClassicProtocolExtension(classicProtocolExtension);
}
@Override
public EventExecutor<LoadClassicProtocolExtensionListener> getEventExecutor() {
return this.eventExecutor;
}
@Override
public Class<LoadClassicProtocolExtensionListener> getListenerType() {
return LoadClassicProtocolExtensionListener.class;
}
}
}

View File

@ -15,18 +15,27 @@
* 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.definition.v1_8_x;
package de.florianmichael.viafabricplus.event;
public class IdlePacketExecutor {
private static Runnable skipIdlePacketExecute;
import de.florianmichael.dietrichevents.AbstractEvent;
import de.florianmichael.dietrichevents.handle.EventExecutor;
import de.florianmichael.dietrichevents.handle.Listener;
public static void skipIdlePacket() {
if (skipIdlePacketExecute != null) {
skipIdlePacketExecute.run();
public interface LoadListener extends Listener {
void onLoad();
class LoadEvent extends AbstractEvent<LoadListener> {
private final EventExecutor<LoadListener> eventExecutor = LoadListener::onLoad;
@Override
public EventExecutor<LoadListener> getEventExecutor() {
return this.eventExecutor;
}
@Override
public Class<LoadListener> getListenerType() {
return LoadListener.class;
}
}
public static void registerIdlePacketSkipExecute(final Runnable runnable) {
skipIdlePacketExecute = runnable;
}
}

View File

@ -15,13 +15,27 @@
* 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;
package de.florianmichael.viafabricplus.event;
import de.florianmichael.vialoadingbase.platform.ComparableProtocolVersion;
import de.florianmichael.dietrichevents.AbstractEvent;
import de.florianmichael.dietrichevents.handle.EventExecutor;
import de.florianmichael.dietrichevents.handle.Listener;
public interface ViaFabricPlusAddon {
public interface SkipIdlePacketListener extends Listener {
default void onLoad() {}
default void onChangeVersion(final ComparableProtocolVersion protocolVersion) {
void onSkipIdlePacket();
class SkipIdlePacketEvent extends AbstractEvent<SkipIdlePacketListener> {
private final EventExecutor<SkipIdlePacketListener> eventExecutor = SkipIdlePacketListener::onSkipIdlePacket;
@Override
public EventExecutor<SkipIdlePacketListener> getEventExecutor() {
return eventExecutor;
}
@Override
public Class<SkipIdlePacketListener> getListenerType() {
return SkipIdlePacketListener.class;
}
}
}

View File

@ -18,9 +18,9 @@
package de.florianmichael.viafabricplus.injection.mixin.base;
import de.florianmichael.viafabricplus.injection.access.IClientConnection;
import de.florianmichael.viafabricplus.platform.pre_netty.PreNettyConstants;
import de.florianmichael.viafabricplus.platform.raknet.BedrockRakNetConstants;
import de.florianmichael.viafabricplus.platform.raknet.RakNetPingSessions;
import de.florianmichael.viafabricplus.vialoadingbase.platform.pre_netty.PreNettyConstants;
import de.florianmichael.viafabricplus.vialoadingbase.platform.raknet.BedrockRakNetConstants;
import de.florianmichael.viafabricplus.vialoadingbase.platform.raknet.RakNetPingSessions;
import de.florianmichael.vialoadingbase.ViaLoadingBase;
import de.florianmichael.vialoadingbase.event.PipelineReorderEvent;
import io.netty.bootstrap.AbstractBootstrap;

View File

@ -17,19 +17,19 @@
*/
package de.florianmichael.viafabricplus.injection.mixin.base;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.connection.UserConnectionImpl;
import com.viaversion.viaversion.protocol.ProtocolPipelineImpl;
import de.florianmichael.viafabricplus.ViaFabricPlus;
import de.florianmichael.viafabricplus.injection.access.IClientConnection;
import de.florianmichael.viafabricplus.platform.pre_netty.PreNettyConstants;
import de.florianmichael.viafabricplus.platform.pre_netty.VFPPreNettyDecoder;
import de.florianmichael.viafabricplus.platform.pre_netty.VFPPreNettyEncoder;
import de.florianmichael.viafabricplus.platform.VFPVLBViaDecodeHandler;
import de.florianmichael.viafabricplus.platform.raknet.*;
import de.florianmichael.viafabricplus.platform.raknet.library_fix.FixedUnconnectedPingEncoder;
import de.florianmichael.viafabricplus.platform.raknet.library_fix.FixedUnconnectedPongDecoder;
import de.florianmichael.viafabricplus.vialoadingbase.ViaLoadingBaseStartup;
import de.florianmichael.viafabricplus.vialoadingbase.platform.pre_netty.PreNettyConstants;
import de.florianmichael.viafabricplus.vialoadingbase.platform.pre_netty.VFPPreNettyDecoder;
import de.florianmichael.viafabricplus.vialoadingbase.platform.pre_netty.VFPPreNettyEncoder;
import de.florianmichael.viafabricplus.vialoadingbase.platform.VFPVLBViaDecodeHandler;
import de.florianmichael.viafabricplus.vialoadingbase.platform.raknet.*;
import de.florianmichael.viafabricplus.vialoadingbase.platform.raknet.library_fix.FixedUnconnectedPingEncoder;
import de.florianmichael.viafabricplus.vialoadingbase.platform.raknet.library_fix.FixedUnconnectedPongDecoder;
import de.florianmichael.vialoadingbase.ViaLoadingBase;
import de.florianmichael.vialoadingbase.netty.VLBViaEncodeHandler;
import de.florianmichael.vialoadingbase.netty.NettyConstants;
@ -83,8 +83,8 @@ public class MixinClientConnection_1 {
if (channel instanceof SocketChannel || rakNet) {
final UserConnection user = new UserConnectionImpl(channel, true);
channel.attr(ViaFabricPlus.LOCAL_VIA_CONNECTION).set(user);
channel.attr(ViaFabricPlus.LOCAL_MINECRAFT_CONNECTION).set(field_11663);
channel.attr(ViaLoadingBaseStartup.LOCAL_VIA_CONNECTION).set(user);
channel.attr(ViaLoadingBaseStartup.LOCAL_MINECRAFT_CONNECTION).set(field_11663);
new ProtocolPipelineImpl(user);

View File

@ -18,6 +18,7 @@
package de.florianmichael.viafabricplus.injection.mixin.base;
import de.florianmichael.viafabricplus.ViaFabricPlus;
import de.florianmichael.viafabricplus.vialoadingbase.ViaLoadingBaseStartup;
import de.florianmichael.vialoadingbase.ViaLoadingBase;
import net.minecraft.client.network.ClientLoginNetworkHandler;
import net.minecraft.network.ClientConnection;
@ -40,7 +41,7 @@ public class MixinClientLoginNetworkHandler {
@Inject(method = "joinServerSession", at = @At("HEAD"), cancellable = true)
public void dontVerifySessionIfCracked(String serverId, CallbackInfoReturnable<Text> cir) {
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(LegacyProtocolVersion.r1_6_4)) {
if (!connection.channel.attr(ViaFabricPlus.LOCAL_VIA_CONNECTION).get().get(ProtocolMetadataStorage.class).authenticate) {
if (!connection.channel.attr(ViaLoadingBaseStartup.LOCAL_VIA_CONNECTION).get().get(ProtocolMetadataStorage.class).authenticate) {
cir.setReturnValue(null);
}
}

View File

@ -29,6 +29,6 @@ public class MixinMain {
@Inject(method = "main([Ljava/lang/String;Z)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/crash/CrashReport;initCrashReport()V"))
private static void preLoad(CallbackInfo ci) {
ViaFabricPlus.getClassWrapper().preLoad();
ViaFabricPlus.INSTANCE.init();
}
}

View File

@ -18,6 +18,7 @@
package de.florianmichael.viafabricplus.injection.mixin.base;
import de.florianmichael.viafabricplus.ViaFabricPlus;
import de.florianmichael.viafabricplus.event.FinishMinecraftLoadListener;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.RunArgs;
import org.spongepowered.asm.mixin.Mixin;
@ -30,8 +31,6 @@ public class MixinMinecraftClient {
@Inject(method = "<init>", at = @At("RETURN"))
public void postLoad(RunArgs args, CallbackInfo ci) {
try {
ViaFabricPlus.getClassWrapper().postLoad();
} catch (Exception ignored) {}
ViaFabricPlus.INSTANCE.getEventDispatcher().post(new FinishMinecraftLoadListener.FinishMinecraftLoadEvent());
}
}

View File

@ -17,7 +17,7 @@
*/
package de.florianmichael.viafabricplus.injection.mixin.base;
import de.florianmichael.viafabricplus.platform.raknet.RakNetPingSessions;
import de.florianmichael.viafabricplus.vialoadingbase.platform.raknet.RakNetPingSessions;
import de.florianmichael.vialoadingbase.ViaLoadingBase;
import net.minecraft.client.network.MultiplayerServerListPinger;
import net.raphimc.viabedrock.api.BedrockProtocolVersion;

View File

@ -22,6 +22,7 @@ import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viafabricplus.ViaFabricPlus;
import de.florianmichael.viafabricplus.settings.groups.BridgeSettings;
import de.florianmichael.viafabricplus.util.ScreenUtil;
import de.florianmichael.viafabricplus.vialoadingbase.ViaLoadingBaseStartup;
import de.florianmichael.vialoadingbase.ViaLoadingBase;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.hud.DebugHud;
@ -46,7 +47,7 @@ public class MixinDebugHud {
final List<String> information = new ArrayList<>();
if (MinecraftClient.getInstance().getNetworkHandler() != null) {
final UserConnection userConnection = MinecraftClient.getInstance().getNetworkHandler().getConnection().channel.attr(ViaFabricPlus.LOCAL_VIA_CONNECTION).get();
final UserConnection userConnection = MinecraftClient.getInstance().getNetworkHandler().getConnection().channel.attr(ViaLoadingBaseStartup.LOCAL_VIA_CONNECTION).get();
information.add("Pipeline count: " + userConnection.getProtocolInfo().getPipeline().pipes().size());
information.add("Target version: " + ViaLoadingBase.getClassWrapper().getTargetVersion().getName() + " (" + ViaLoadingBase.getClassWrapper().getTargetVersion().getVersion() + ")");

View File

@ -25,8 +25,9 @@ import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.Protocol1_17To1_
import de.florianmichael.viafabricplus.ViaFabricPlus;
import de.florianmichael.viafabricplus.injection.access.IClientPlayerEntity;
import de.florianmichael.viafabricplus.injection.access.IScreenHandler;
import de.florianmichael.viafabricplus.provider.ViaFabricPlusHandItemProvider;
import de.florianmichael.viafabricplus.translator.ItemTranslator;
import de.florianmichael.viafabricplus.vialoadingbase.ViaLoadingBaseStartup;
import de.florianmichael.viafabricplus.vialoadingbase.provider.ViaFabricPlusHandItemProvider;
import de.florianmichael.viafabricplus.util.ItemTranslator;
import de.florianmichael.vialoadingbase.ViaLoadingBase;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
@ -110,7 +111,7 @@ public abstract class MixinClientPlayerInteractionManager {
else
slotItemBeforeModification = viafabricplus_oldItems.get(clickSlot.getSlot());
final PacketWrapper clickSlotPacket = PacketWrapper.create(ServerboundPackets1_16_2.CLICK_WINDOW, networkHandler.getConnection().channel.attr(ViaFabricPlus.LOCAL_VIA_CONNECTION).get());
final PacketWrapper clickSlotPacket = PacketWrapper.create(ServerboundPackets1_16_2.CLICK_WINDOW, networkHandler.getConnection().channel.attr(ViaLoadingBaseStartup.LOCAL_VIA_CONNECTION).get());
clickSlotPacket.write(Type.UNSIGNED_BYTE, (short) clickSlot.getSyncId());
clickSlotPacket.write(Type.SHORT, (short) clickSlot.getSlot());

View File

@ -25,6 +25,7 @@ import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPac
import de.florianmichael.viafabricplus.ViaFabricPlus;
import de.florianmichael.viafabricplus.definition.v1_12_2.SyncInputExecutor;
import de.florianmichael.viafabricplus.settings.groups.DebugSettings;
import de.florianmichael.viafabricplus.vialoadingbase.ViaLoadingBaseStartup;
import de.florianmichael.vialoadingbase.ViaLoadingBase;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import net.minecraft.client.MinecraftClient;
@ -106,7 +107,7 @@ public abstract class MixinMinecraftClient {
@Inject(method = "handleInputEvents", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;hasRidingInventory()Z"))
private void onInventoryKeyPressed(CallbackInfo ci) throws Exception {
if (getNetworkHandler() != null && DebugSettings.getClassWrapper().sendOpenInventoryPacket.getValue()) {
final UserConnection viaConnection = MinecraftClient.getInstance().getNetworkHandler().getConnection().channel.attr(ViaFabricPlus.LOCAL_VIA_CONNECTION).get();
final UserConnection viaConnection = MinecraftClient.getInstance().getNetworkHandler().getConnection().channel.attr(ViaLoadingBaseStartup.LOCAL_VIA_CONNECTION).get();
if (viaConnection != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_11_1)) {
final PacketWrapper clientStatus = PacketWrapper.create(ServerboundPackets1_9_3.CLIENT_STATUS, viaConnection);

View File

@ -28,6 +28,6 @@ public class MixinStringHelper {
@ModifyConstant(method = "truncateChat", constant = @Constant(intValue = 256))
private static int expandChatLength(int constant) {
return ChatLengthDefinition.getMaxLength();
return ChatLengthDefinition.INSTANCE.getMaxLength();
}
}

View File

@ -19,8 +19,9 @@ package de.florianmichael.viafabricplus.injection.mixin.fixes.entity;
import com.mojang.authlib.GameProfile;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viafabricplus.ViaFabricPlus;
import de.florianmichael.viafabricplus.definition.v1_8_x.ArmorPointsDefinition;
import de.florianmichael.viafabricplus.definition.v1_8_x.IdlePacketExecutor;
import de.florianmichael.viafabricplus.event.SkipIdlePacketListener;
import de.florianmichael.viafabricplus.injection.access.IClientPlayerEntity;
import de.florianmichael.viafabricplus.settings.groups.DebugSettings;
import de.florianmichael.viafabricplus.settings.groups.VisualSettings;
@ -116,7 +117,7 @@ public abstract class MixinClientPlayerEntity extends AbstractClientPlayerEntity
} else if (this.lastOnGround != this.onGround || DebugSettings.getClassWrapper().sendIdlePacket.getValue()) {
this.networkHandler.sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(this.onGround));
} else {
IdlePacketExecutor.skipIdlePacket();
ViaFabricPlus.INSTANCE.getEventDispatcher().post(new SkipIdlePacketListener.SkipIdlePacketEvent());
}
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_8)) {
++this.ticksSinceLastPositionPacketSent;

View File

@ -20,6 +20,7 @@ package de.florianmichael.viafabricplus.injection.mixin.fixes.entity;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viafabricplus.ViaFabricPlus;
import de.florianmichael.viafabricplus.definition.v1_14_4.Meta18Storage;
import de.florianmichael.viafabricplus.vialoadingbase.ViaLoadingBaseStartup;
import de.florianmichael.vialoadingbase.ViaLoadingBase;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.passive.WolfEntity;
@ -35,7 +36,7 @@ public class MixinWolfEntity {
public float rewriteHealth(WolfEntity instance) {
float health = instance.getHealth();
if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_14_4)) {
return MinecraftClient.getInstance().getNetworkHandler().getConnection().channel.attr(ViaFabricPlus.LOCAL_VIA_CONNECTION).get().get(Meta18Storage.class).getHealthDataMap().getOrDefault(instance.getId(), health);
return MinecraftClient.getInstance().getNetworkHandler().getConnection().channel.attr(ViaLoadingBaseStartup.LOCAL_VIA_CONNECTION).get().get(Meta18Storage.class).getHealthDataMap().getOrDefault(instance.getId(), health);
}
return health;
}

View File

@ -32,7 +32,7 @@ public class MixinItemGroup_EntriesImpl {
@Redirect(method = "add", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;isEnabled(Lnet/minecraft/resource/featuretoggle/FeatureSet;)Z"))
public boolean removeUnknownItems(Item instance, FeatureSet featureSet) {
if (!GeneralSettings.getClassWrapper().removeNotAvailableItemsFromCreativeTab.getValue() || MinecraftClient.getInstance().isInSingleplayer()) return instance.isEnabled(featureSet);
if (ItemReleaseVersionDefinition.getCurrentMap().contains(instance)) return instance.isEnabled(featureSet);
if (ItemReleaseVersionDefinition.INSTANCE.getCurrentMap().contains(instance)) return instance.isEnabled(featureSet);
return false;
}

View File

@ -28,6 +28,6 @@ public class MixinChatMessageC2SPacket {
@ModifyConstant(method = "write", constant = @Constant(intValue = 256))
public int expandChatLength(int constant) {
return ChatLengthDefinition.getMaxLength();
return ChatLengthDefinition.INSTANCE.getMaxLength();
}
}

View File

@ -37,7 +37,7 @@ public class MixinChatScreen {
@Inject(method = "init", at = @At("RETURN"))
public void changeChatLength(CallbackInfo ci) {
this.chatField.setMaxLength(ChatLengthDefinition.getMaxLength());
this.chatField.setMaxLength(ChatLengthDefinition.INSTANCE.getMaxLength());
}
@Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/ChatHud;getIndicatorAt(DD)Lnet/minecraft/client/gui/hud/MessageIndicator;"))

View File

@ -24,6 +24,7 @@ import de.florianmichael.viafabricplus.ViaFabricPlus;
import de.florianmichael.viafabricplus.injection.access.IPublicKeyData;
import de.florianmichael.viafabricplus.definition.v1_19_0.storage.ChatSession1_19_0;
import de.florianmichael.viafabricplus.definition.v1_19_2.storage.ChatSession1_19_2;
import de.florianmichael.viafabricplus.vialoadingbase.ViaLoadingBaseStartup;
import de.florianmichael.vialoadingbase.ViaLoadingBase;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.ConnectScreen;
@ -76,7 +77,7 @@ public class MixinConnectScreen_1 {
final ClientConnection connection = field_2416.connection;
if (connection == null || connection.channel == null) return;
final UserConnection userConnection = connection.channel.attr(ViaFabricPlus.LOCAL_VIA_CONNECTION).get();
final UserConnection userConnection = connection.channel.attr(ViaLoadingBaseStartup.LOCAL_VIA_CONNECTION).get();
if (userConnection == null) {
ViaLoadingBase.LOGGER.log(Level.WARNING, "ViaVersion userConnection is null");

View File

@ -29,19 +29,19 @@ public class MixinClassicProtocolExtension {
@Inject(method = "supportsVersion", at = @At("HEAD"), cancellable = true)
public void allowExtensions_supportsVersion(int version, CallbackInfoReturnable<Boolean> cir) {
if (CustomClassicProtocolExtensions.ALLOWED_EXTENSIONS.contains((ClassicProtocolExtension) (Object) this))
if (CustomClassicProtocolExtensions.INSTANCE.ALLOWED_EXTENSIONS.contains((ClassicProtocolExtension) (Object) this))
cir.setReturnValue(true);
}
@Inject(method = "isSupported", at = @At("HEAD"), cancellable = true)
public void allowExtensions_isSupported(CallbackInfoReturnable<Boolean> cir) {
if (CustomClassicProtocolExtensions.ALLOWED_EXTENSIONS.contains((ClassicProtocolExtension) (Object) this))
if (CustomClassicProtocolExtensions.INSTANCE.ALLOWED_EXTENSIONS.contains((ClassicProtocolExtension) (Object) this))
cir.setReturnValue(true);
}
@Inject(method = "getHighestSupportedVersion", at = @At("HEAD"), cancellable = true)
public void allowExtensions_getHighestSupportedVersion(CallbackInfoReturnable<Integer> cir) {
if (CustomClassicProtocolExtensions.ALLOWED_EXTENSIONS.contains((ClassicProtocolExtension) (Object) this))
if (CustomClassicProtocolExtensions.INSTANCE.ALLOWED_EXTENSIONS.contains((ClassicProtocolExtension) (Object) this))
cir.setReturnValue(1);
}
}

View File

@ -29,8 +29,8 @@ public class MixinClientboundPacketsc0_30cpe {
@Inject(method = "getPacket", at = @At("HEAD"), cancellable = true)
private static void addCustomPackets(int id, CallbackInfoReturnable<ClientboundPacketsc0_30cpe> cir) {
if (CustomClassicProtocolExtensions.CUSTOM_PACKETS.containsKey(id)) {
cir.setReturnValue(CustomClassicProtocolExtensions.CUSTOM_PACKETS.get(id));
if (CustomClassicProtocolExtensions.INSTANCE.CUSTOM_PACKETS.containsKey(id)) {
cir.setReturnValue(CustomClassicProtocolExtensions.INSTANCE.CUSTOM_PACKETS.get(id));
}
}
}

View File

@ -17,9 +17,9 @@
*/
package de.florianmichael.viafabricplus.injection.mixin.fixes.vialegacy;
import de.florianmichael.viafabricplus.definition.ChatLengthDefinition;
import de.florianmichael.viafabricplus.definition.c0_30.CustomClassicProtocolExtensions;
import de.florianmichael.viafabricplus.ViaFabricPlus;
import de.florianmichael.viafabricplus.injection.access.IExtensionProtocolMetadataStorage;
import de.florianmichael.viafabricplus.event.LoadClassicProtocolExtensionListener;
import net.raphimc.vialegacy.protocols.classic.protocolc0_28_30toc0_28_30cpe.data.ClassicProtocolExtension;
import net.raphimc.vialegacy.protocols.classic.protocolc0_28_30toc0_28_30cpe.storage.ExtensionProtocolMetadataStorage;
import org.spongepowered.asm.mixin.Final;
@ -38,7 +38,7 @@ public class MixinExtensionProtocolMetadataStorage implements IExtensionProtocol
@Inject(method = "addServerExtension", at = @At("RETURN"))
public void updateChatLengthDefinition(ClassicProtocolExtension extension, int version, CallbackInfo ci) {
CustomClassicProtocolExtensions.onAddServerExtension(extension);
ViaFabricPlus.INSTANCE.getEventDispatcher().post(new LoadClassicProtocolExtensionListener.LoadClassicProtocolExtensionEvent(extension));
}
@Override

View File

@ -27,6 +27,6 @@ public class MixinProtocol1_11To1_10 {
@ModifyConstant(method = "lambda$register$0", constant = @Constant(intValue = 100))
private static int changeMaxChatLength(int constant) {
return ChatLengthDefinition.getMaxLength();
return ChatLengthDefinition.INSTANCE.getMaxLength();
}
}

View File

@ -22,11 +22,11 @@ import de.florianmichael.viafabricplus.screen.settings.settingrenderer.BooleanSe
import de.florianmichael.viafabricplus.screen.settings.settingrenderer.ModeSettingRenderer;
import de.florianmichael.viafabricplus.screen.settings.settingrenderer.ProtocolSyncBooleanSettingRenderer;
import de.florianmichael.viafabricplus.screen.settings.settingrenderer.meta.TitleRenderer;
import de.florianmichael.viafabricplus.settings.AbstractSetting;
import de.florianmichael.viafabricplus.settings.SettingGroup;
import de.florianmichael.viafabricplus.settings.impl.BooleanSetting;
import de.florianmichael.viafabricplus.settings.impl.ModeSetting;
import de.florianmichael.viafabricplus.settings.impl.ProtocolSyncBooleanSetting;
import de.florianmichael.viafabricplus.settings.base.AbstractSetting;
import de.florianmichael.viafabricplus.settings.base.SettingGroup;
import de.florianmichael.viafabricplus.settings.type_impl.BooleanSetting;
import de.florianmichael.viafabricplus.settings.type_impl.ModeSetting;
import de.florianmichael.viafabricplus.settings.type_impl.ProtocolSyncBooleanSetting;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.AlwaysSelectedEntryListWidget;
@ -90,7 +90,7 @@ public class SettingsScreen extends Screen {
public SlotList(MinecraftClient minecraftClient, int width, int height, int top, int bottom, int entryHeight) {
super(minecraftClient, width, height, top, bottom, entryHeight);
for (SettingGroup group : ViaFabricPlus.getClassWrapper().getSettingGroups()) {
for (SettingGroup group : ViaFabricPlus.INSTANCE.getSettingsSystem().getGroups()) {
this.addEntry(new TitleRenderer(group.getName()));
for (AbstractSetting<?> setting : group.getSettings()) {
try {

View File

@ -18,7 +18,7 @@
package de.florianmichael.viafabricplus.screen.settings.settingrenderer;
import de.florianmichael.viafabricplus.screen.settings.AbstractSettingRenderer;
import de.florianmichael.viafabricplus.settings.impl.BooleanSetting;
import de.florianmichael.viafabricplus.settings.type_impl.BooleanSetting;
import de.florianmichael.viafabricplus.util.ScreenUtil;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;

View File

@ -18,11 +18,7 @@
package de.florianmichael.viafabricplus.screen.settings.settingrenderer;
import de.florianmichael.viafabricplus.screen.settings.AbstractSettingRenderer;
import de.florianmichael.viafabricplus.settings.AbstractSetting;
import de.florianmichael.viafabricplus.settings.groups.GeneralSettings;
import de.florianmichael.viafabricplus.settings.impl.BooleanSetting;
import de.florianmichael.viafabricplus.settings.impl.ModeSetting;
import de.florianmichael.viafabricplus.settings.impl.ProtocolSyncBooleanSetting;
import de.florianmichael.viafabricplus.settings.type_impl.ModeSetting;
import de.florianmichael.viafabricplus.util.ScreenUtil;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
@ -31,7 +27,6 @@ import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import java.awt.*;
import java.util.Arrays;
public class ModeSettingRenderer extends AbstractSettingRenderer {

View File

@ -18,11 +18,8 @@
package de.florianmichael.viafabricplus.screen.settings.settingrenderer;
import de.florianmichael.viafabricplus.screen.settings.AbstractSettingRenderer;
import de.florianmichael.viafabricplus.settings.AbstractSetting;
import de.florianmichael.viafabricplus.settings.groups.GeneralSettings;
import de.florianmichael.viafabricplus.settings.impl.BooleanSetting;
import de.florianmichael.viafabricplus.settings.impl.ModeSetting;
import de.florianmichael.viafabricplus.settings.impl.ProtocolSyncBooleanSetting;
import de.florianmichael.viafabricplus.settings.type_impl.ProtocolSyncBooleanSetting;
import de.florianmichael.viafabricplus.util.ScreenUtil;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
@ -32,7 +29,6 @@ import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import java.awt.*;
import java.util.Arrays;
public class ProtocolSyncBooleanSettingRenderer extends AbstractSettingRenderer {
private final ProtocolSyncBooleanSetting value;

View File

@ -15,30 +15,61 @@
* 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.util;
package de.florianmichael.viafabricplus.settings;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import de.florianmichael.viafabricplus.ViaFabricPlus;
import de.florianmichael.viafabricplus.settings.AbstractSetting;
import de.florianmichael.viafabricplus.settings.SettingGroup;
import de.florianmichael.viafabricplus.event.InitializeSettingsListener;
import de.florianmichael.viafabricplus.settings.base.AbstractSetting;
import de.florianmichael.viafabricplus.settings.base.SettingGroup;
import de.florianmichael.viafabricplus.settings.groups.*;
import de.florianmichael.vialoadingbase.ViaLoadingBase;
import de.florianmichael.vialoadingbase.platform.InternalProtocolList;
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class SettingsSave {
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
public final static File CONFIG_FILE = new File(ViaFabricPlus.RUN_DIRECTORY, "settings.json");
public class SettingsSystem {
private final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
private final File CONFIG_FILE = new File(ViaFabricPlus.RUN_DIRECTORY, "settings.json");
public static void load(final ViaFabricPlus viaFabricPlus) throws Exception {
private final List<SettingGroup> groups = new ArrayList<>();
public void init() {
addGroup(
GeneralSettings.getClassWrapper(),
BridgeSettings.getClassWrapper(),
MPPassSettings.getClassWrapper(),
VisualSettings.getClassWrapper(),
DebugSettings.getClassWrapper()
);
ViaFabricPlus.INSTANCE.getEventDispatcher().post(new InitializeSettingsListener.InitializeSettingsEvent());
loadConfig();
Runtime.getRuntime().addShutdownHook(new Thread(this::save));
}
public void addGroup(final SettingGroup... groups) {
Collections.addAll(this.groups, groups);
}
public void loadConfig() {
if (CONFIG_FILE.exists()) {
final JsonObject parentNode = GSON.fromJson(new FileReader(CONFIG_FILE), JsonObject.class).getAsJsonObject();
final JsonObject parentNode;
try {
parentNode = GSON.fromJson(new FileReader(CONFIG_FILE), JsonObject.class).getAsJsonObject();
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
if (parentNode.has("protocol")) {
ViaLoadingBase.getClassWrapper().reload(InternalProtocolList.fromProtocolId(parentNode.get("protocol").getAsInt()));
}
for (SettingGroup group : viaFabricPlus.getSettingGroups()) {
for (SettingGroup group : groups) {
for (AbstractSetting<?> setting : group.getSettings()) {
setting.read(parentNode);
}
@ -46,20 +77,30 @@ public class SettingsSave {
}
}
public static void save(final ViaFabricPlus viaFabricPlus) throws IOException {
public void save() {
CONFIG_FILE.delete();
CONFIG_FILE.createNewFile();
try {
CONFIG_FILE.createNewFile();
} catch (IOException e) {
throw new RuntimeException(e);
}
try (final FileWriter fw = new FileWriter(CONFIG_FILE)) {
final JsonObject parentNode = new JsonObject();
parentNode.addProperty("protocol", ViaLoadingBase.getClassWrapper().getTargetVersion().getVersion());
for (SettingGroup group : viaFabricPlus.getSettingGroups()) {
for (SettingGroup group : groups) {
for (AbstractSetting<?> setting : group.getSettings()) {
setting.write(parentNode);
}
}
fw.write(GSON.toJson(parentNode));
fw.flush();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public List<SettingGroup> getGroups() {
return groups;
}
}

View File

@ -15,7 +15,7 @@
* 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.settings;
package de.florianmichael.viafabricplus.settings.base;
import com.google.gson.JsonObject;

View File

@ -15,7 +15,7 @@
* 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.settings;
package de.florianmichael.viafabricplus.settings.base;
import java.util.ArrayList;
import java.util.List;

View File

@ -17,8 +17,8 @@
*/
package de.florianmichael.viafabricplus.settings.groups;
import de.florianmichael.viafabricplus.settings.SettingGroup;
import de.florianmichael.viafabricplus.settings.impl.BooleanSetting;
import de.florianmichael.viafabricplus.settings.base.SettingGroup;
import de.florianmichael.viafabricplus.settings.type_impl.BooleanSetting;
public class BridgeSettings extends SettingGroup {
private final static BridgeSettings self = new BridgeSettings();

View File

@ -18,8 +18,8 @@
package de.florianmichael.viafabricplus.settings.groups;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viafabricplus.settings.SettingGroup;
import de.florianmichael.viafabricplus.settings.impl.ProtocolSyncBooleanSetting;
import de.florianmichael.viafabricplus.settings.base.SettingGroup;
import de.florianmichael.viafabricplus.settings.type_impl.ProtocolSyncBooleanSetting;
import de.florianmichael.vialoadingbase.platform.ProtocolRange;
import net.raphimc.vialegacy.api.LegacyProtocolVersion;

View File

@ -17,9 +17,9 @@
*/
package de.florianmichael.viafabricplus.settings.groups;
import de.florianmichael.viafabricplus.settings.SettingGroup;
import de.florianmichael.viafabricplus.settings.impl.BooleanSetting;
import de.florianmichael.viafabricplus.settings.impl.ModeSetting;
import de.florianmichael.viafabricplus.settings.base.SettingGroup;
import de.florianmichael.viafabricplus.settings.type_impl.BooleanSetting;
import de.florianmichael.viafabricplus.settings.type_impl.ModeSetting;
public class GeneralSettings extends SettingGroup {
private final static GeneralSettings self = new GeneralSettings();

View File

@ -17,8 +17,8 @@
*/
package de.florianmichael.viafabricplus.settings.groups;
import de.florianmichael.viafabricplus.settings.SettingGroup;
import de.florianmichael.viafabricplus.settings.impl.BooleanSetting;
import de.florianmichael.viafabricplus.settings.base.SettingGroup;
import de.florianmichael.viafabricplus.settings.type_impl.BooleanSetting;
public class MPPassSettings extends SettingGroup {
private final static MPPassSettings self = new MPPassSettings();

View File

@ -18,8 +18,8 @@
package de.florianmichael.viafabricplus.settings.groups;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viafabricplus.settings.SettingGroup;
import de.florianmichael.viafabricplus.settings.impl.ProtocolSyncBooleanSetting;
import de.florianmichael.viafabricplus.settings.base.SettingGroup;
import de.florianmichael.viafabricplus.settings.type_impl.ProtocolSyncBooleanSetting;
import de.florianmichael.vialoadingbase.platform.ProtocolRange;
import net.raphimc.vialegacy.api.LegacyProtocolVersion;

View File

@ -15,11 +15,11 @@
* 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.settings.impl;
package de.florianmichael.viafabricplus.settings.type_impl;
import com.google.gson.JsonObject;
import de.florianmichael.viafabricplus.settings.AbstractSetting;
import de.florianmichael.viafabricplus.settings.SettingGroup;
import de.florianmichael.viafabricplus.settings.base.AbstractSetting;
import de.florianmichael.viafabricplus.settings.base.SettingGroup;
public class BooleanSetting extends AbstractSetting<Boolean> {

View File

@ -15,11 +15,11 @@
* 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.settings.impl;
package de.florianmichael.viafabricplus.settings.type_impl;
import com.google.gson.JsonObject;
import de.florianmichael.viafabricplus.settings.AbstractSetting;
import de.florianmichael.viafabricplus.settings.SettingGroup;
import de.florianmichael.viafabricplus.settings.base.AbstractSetting;
import de.florianmichael.viafabricplus.settings.base.SettingGroup;
import java.util.Arrays;

View File

@ -15,10 +15,10 @@
* 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.settings.impl;
package de.florianmichael.viafabricplus.settings.type_impl;
import com.google.gson.JsonObject;
import de.florianmichael.viafabricplus.settings.SettingGroup;
import de.florianmichael.viafabricplus.settings.base.SettingGroup;
import de.florianmichael.viafabricplus.settings.groups.GeneralSettings;
import de.florianmichael.vialoadingbase.ViaLoadingBase;
import de.florianmichael.vialoadingbase.platform.ProtocolRange;

View File

@ -15,7 +15,7 @@
* 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.translator;
package de.florianmichael.viafabricplus.util;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;

View File

@ -0,0 +1,101 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2023 FlorianMichael/MrLookAtMe (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.vialoadingbase;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
import de.florianmichael.viafabricplus.ViaFabricPlus;
import de.florianmichael.viafabricplus.definition.v1_19_0.provider.CommandArgumentsProvider;
import de.florianmichael.viafabricplus.event.ChangeProtocolVersionListener;
import de.florianmichael.viafabricplus.event.FinishViaLoadingBaseStartupListener;
import de.florianmichael.viafabricplus.vialoadingbase.platform.ViaAprilFoolsPlatformImpl;
import de.florianmichael.viafabricplus.vialoadingbase.platform.ViaBedrockPlatformImpl;
import de.florianmichael.viafabricplus.vialoadingbase.platform.ViaLegacyPlatformImpl;
import de.florianmichael.viafabricplus.vialoadingbase.provider.*;
import de.florianmichael.vialoadingbase.ViaLoadingBase;
import de.florianmichael.vialoadingbase.platform.SubPlatform;
import io.netty.util.AttributeKey;
import net.minecraft.SharedConstants;
import net.minecraft.client.MinecraftClient;
import net.minecraft.network.ClientConnection;
import net.raphimc.viaaprilfools.api.AprilFoolsProtocolVersion;
import net.raphimc.viabedrock.api.BedrockProtocolVersion;
import net.raphimc.viabedrock.protocol.providers.NettyPipelineProvider;
import net.raphimc.vialegacy.api.LegacyProtocolVersion;
import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.providers.ClassicCustomCommandProvider;
import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.providers.ClassicMPPassProvider;
import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.providers.ClassicWorldHeightProvider;
import net.raphimc.vialegacy.protocols.release.protocol1_3_1_2to1_2_4_5.providers.OldAuthProvider;
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.providers.EncryptionProvider;
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.providers.GameProfileFetcher;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class ViaLoadingBaseStartup {
public final static AttributeKey<UserConnection> LOCAL_VIA_CONNECTION = AttributeKey.newInstance("viafabricplus-via-connection");
public final static AttributeKey<ClientConnection> LOCAL_MINECRAFT_CONNECTION = AttributeKey.newInstance("viafabricplus-minecraft-connection");
public ViaLoadingBaseStartup() {
ViaLoadingBase.ViaLoadingBaseBuilder builder = ViaLoadingBase.ViaLoadingBaseBuilder.create();
builder = builder.subPlatform(new SubPlatform("ViaBedrock", () -> true, ViaBedrockPlatformImpl::new, protocolVersions -> protocolVersions.add(BedrockProtocolVersion.bedrockLatest)), 0);
builder = builder.subPlatform(new SubPlatform("ViaLegacy", () -> true, ViaLegacyPlatformImpl::new, protocolVersions -> {
final List<ProtocolVersion> legacyProtocols = new ArrayList<>(LegacyProtocolVersion.PROTOCOLS);
Collections.reverse(legacyProtocols);
legacyProtocols.remove(LegacyProtocolVersion.c0_30cpe);
legacyProtocols.add(legacyProtocols.indexOf(LegacyProtocolVersion.c0_28toc0_30) + 1, LegacyProtocolVersion.c0_30cpe);
protocolVersions.addAll(legacyProtocols);
}));
builder = builder.subPlatform(new SubPlatform("ViaAprilFools", () -> true, ViaAprilFoolsPlatformImpl::new, protocolVersions -> {
protocolVersions.add(protocolVersions.indexOf(ProtocolVersion.v1_14) + 1, AprilFoolsProtocolVersion.s3d_shareware);
protocolVersions.add(protocolVersions.indexOf(ProtocolVersion.v1_16) + 1, AprilFoolsProtocolVersion.s20w14infinite);
protocolVersions.add(protocolVersions.indexOf(ProtocolVersion.v1_16_2) + 1, AprilFoolsProtocolVersion.sCombatTest8c);
}));
builder = builder.runDirectory(ViaFabricPlus.RUN_DIRECTORY);
builder = builder.nativeVersion(SharedConstants.getProtocolVersion());
builder = builder.forceNativeVersionCondition(() -> {
if (MinecraftClient.getInstance() == null) return true;
return MinecraftClient.getInstance().isInSingleplayer();
});
builder = builder.providers(providers -> {
providers.use(MovementTransmitterProvider.class, new ViaFabricPlusMovementTransmitterProvider());
providers.use(HandItemProvider.class, new ViaFabricPlusHandItemProvider());
providers.use(CommandArgumentsProvider.class, new ViaFabricPlusCommandArgumentsProvider());
providers.use(OldAuthProvider.class, new ViaFabricPlusOldAuthProvider());
providers.use(ClassicWorldHeightProvider.class, new ViaFabricPlusClassicWorldHeightProvider());
providers.use(EncryptionProvider.class, new ViaFabricPlusEncryptionProvider());
providers.use(GameProfileFetcher.class, new ViaFabricPlusGameProfileFetcher());
providers.use(ClassicMPPassProvider.class, new ViaFabricPlusClassicMPPassProvider());
providers.use(ClassicCustomCommandProvider.class, new ViaFabricPlusClassicCustomCommandProvider());
providers.use(NettyPipelineProvider.class, new ViaFabricPlusNettyPipelineProvider());
});
builder = builder.onProtocolReload(protocolVersion -> ViaFabricPlus.INSTANCE.getEventDispatcher().post(new ChangeProtocolVersionListener.ChangeProtocolVersionEvent(protocolVersion)));
builder.build();
ViaFabricPlus.INSTANCE.getEventDispatcher().post(new FinishViaLoadingBaseStartupListener.FinishViaLoadingBaseStartupEvent());
}
}

View File

@ -15,7 +15,7 @@
* 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.platform;
package de.florianmichael.viafabricplus.vialoadingbase.platform;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;

View File

@ -15,7 +15,7 @@
* 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.platform;
package de.florianmichael.viafabricplus.vialoadingbase.platform;
import com.viaversion.viaversion.api.Via;
import de.florianmichael.vialoadingbase.util.JLoggerToLog4j;

View File

@ -15,7 +15,7 @@
* 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.platform;
package de.florianmichael.viafabricplus.vialoadingbase.platform;
import com.viaversion.viaversion.api.Via;
import de.florianmichael.vialoadingbase.util.JLoggerToLog4j;

View File

@ -15,7 +15,7 @@
* 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.platform;
package de.florianmichael.viafabricplus.vialoadingbase.platform;
import com.viaversion.viaversion.api.Via;
import de.florianmichael.vialoadingbase.util.JLoggerToLog4j;

View File

@ -15,7 +15,7 @@
* 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.platform.pre_netty;
package de.florianmichael.viafabricplus.vialoadingbase.platform.pre_netty;
public class PreNettyConstants {

View File

@ -15,7 +15,7 @@
* 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.platform.pre_netty;
package de.florianmichael.viafabricplus.vialoadingbase.platform.pre_netty;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;

View File

@ -15,7 +15,7 @@
* 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.platform.pre_netty;
package de.florianmichael.viafabricplus.vialoadingbase.platform.pre_netty;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;

View File

@ -15,7 +15,7 @@
* 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.platform.raknet;
package de.florianmichael.viafabricplus.vialoadingbase.platform.raknet;
public class BedrockRakNetConstants {

View File

@ -15,7 +15,7 @@
* 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.platform.raknet;
package de.florianmichael.viafabricplus.vialoadingbase.platform.raknet;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOutboundHandlerAdapter;

View File

@ -15,7 +15,7 @@
* 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.platform.raknet;
package de.florianmichael.viafabricplus.vialoadingbase.platform.raknet;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;

View File

@ -15,7 +15,7 @@
* 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.platform.raknet;
package de.florianmichael.viafabricplus.vialoadingbase.platform.raknet;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.CompositeByteBuf;

View File

@ -15,7 +15,7 @@
* 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.platform.raknet;
package de.florianmichael.viafabricplus.vialoadingbase.platform.raknet;
import java.net.InetAddress;
import java.util.ArrayList;

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viafabricplus.platform.raknet.library_fix;
package de.florianmichael.viafabricplus.vialoadingbase.platform.raknet.library_fix;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viafabricplus.platform.raknet.library_fix;
package de.florianmichael.viafabricplus.vialoadingbase.platform.raknet.library_fix;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;

View File

@ -15,7 +15,7 @@
* 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.provider;
package de.florianmichael.viafabricplus.vialoadingbase.provider;
import com.viaversion.viaversion.api.connection.UserConnection;
import de.florianmichael.viafabricplus.definition.c0_30.command.ClassicProtocolCommands;

View File

@ -15,13 +15,12 @@
* 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.provider;
package de.florianmichael.viafabricplus.vialoadingbase.provider;
import com.google.common.hash.Hashing;
import com.google.common.io.Resources;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import de.florianmichael.viafabricplus.settings.groups.GeneralSettings;
import de.florianmichael.viafabricplus.settings.groups.MPPassSettings;
import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.providers.ClassicMPPassProvider;
import net.raphimc.vialegacy.protocols.release.protocol1_3_1_2to1_2_4_5.providers.OldAuthProvider;

View File

@ -15,7 +15,7 @@
* 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.provider;
package de.florianmichael.viafabricplus.vialoadingbase.provider;
import com.viaversion.viaversion.api.connection.UserConnection;
import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.providers.ClassicWorldHeightProvider;

View File

@ -15,7 +15,7 @@
* 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.provider;
package de.florianmichael.viafabricplus.vialoadingbase.provider;
import com.viaversion.viaversion.util.Pair;
import de.florianmichael.viafabricplus.definition.v1_19_0.provider.CommandArgumentsProvider;

View File

@ -15,11 +15,12 @@
* 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.provider;
package de.florianmichael.viafabricplus.vialoadingbase.provider;
import com.viaversion.viaversion.api.connection.UserConnection;
import de.florianmichael.viafabricplus.ViaFabricPlus;
import de.florianmichael.viafabricplus.injection.access.IClientConnection;
import de.florianmichael.viafabricplus.vialoadingbase.ViaLoadingBaseStartup;
import net.minecraft.network.ClientConnection;
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.providers.EncryptionProvider;
@ -27,7 +28,7 @@ public class ViaFabricPlusEncryptionProvider extends EncryptionProvider {
@Override
public void enableDecryption(UserConnection user) {
final ClientConnection clientConnection = user.getChannel().attr(ViaFabricPlus.LOCAL_MINECRAFT_CONNECTION).get();
final ClientConnection clientConnection = user.getChannel().attr(ViaLoadingBaseStartup.LOCAL_MINECRAFT_CONNECTION).get();
if (clientConnection != null) {
((IClientConnection) clientConnection).viafabricplus_setupPreNettyEncryption();
}

View File

@ -15,7 +15,7 @@
* 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.provider;
package de.florianmichael.viafabricplus.vialoadingbase.provider;
import com.mojang.authlib.Agent;
import com.mojang.authlib.GameProfileRepository;

View File

@ -15,13 +15,13 @@
* 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.provider;
package de.florianmichael.viafabricplus.vialoadingbase.provider;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider;
import de.florianmichael.viafabricplus.translator.ItemTranslator;
import de.florianmichael.viafabricplus.util.ItemTranslator;
import net.minecraft.item.ItemStack;
public class ViaFabricPlusHandItemProvider extends HandItemProvider {

View File

@ -15,7 +15,7 @@
* 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.provider;
package de.florianmichael.viafabricplus.vialoadingbase.provider;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;

View File

@ -15,11 +15,12 @@
* 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.provider;
package de.florianmichael.viafabricplus.vialoadingbase.provider;
import com.viaversion.viaversion.api.connection.UserConnection;
import de.florianmichael.viafabricplus.ViaFabricPlus;
import de.florianmichael.viafabricplus.injection.access.IClientConnection;
import de.florianmichael.viafabricplus.vialoadingbase.ViaLoadingBaseStartup;
import net.raphimc.viabedrock.protocol.providers.NettyPipelineProvider;
import javax.crypto.NoSuchPaddingException;
@ -32,7 +33,7 @@ public class ViaFabricPlusNettyPipelineProvider extends NettyPipelineProvider {
@Override
public void enableCompression(UserConnection user, int threshold, int algorithm) {
final IClientConnection currentConnection = (IClientConnection) user.getChannel().attr(ViaFabricPlus.LOCAL_MINECRAFT_CONNECTION).get();
final IClientConnection currentConnection = (IClientConnection) user.getChannel().attr(ViaLoadingBaseStartup.LOCAL_MINECRAFT_CONNECTION).get();
try {
switch (algorithm) {
@ -48,7 +49,7 @@ public class ViaFabricPlusNettyPipelineProvider extends NettyPipelineProvider {
@Override
public void enableEncryption(UserConnection user, SecretKey key) {
final IClientConnection currentConnection = (IClientConnection) user.getChannel().attr(ViaFabricPlus.LOCAL_MINECRAFT_CONNECTION).get();
final IClientConnection currentConnection = (IClientConnection) user.getChannel().attr(ViaLoadingBaseStartup.LOCAL_MINECRAFT_CONNECTION).get();
try {
currentConnection.viafabricplus_enableAesGcmEncryption(key);

View File

@ -15,12 +15,13 @@
* 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.provider;
package de.florianmichael.viafabricplus.vialoadingbase.provider;
import com.viaversion.viaversion.api.connection.UserConnection;
import de.florianmichael.viafabricplus.ViaFabricPlus;
import de.florianmichael.viafabricplus.settings.groups.MPPassSettings;
import de.florianmichael.viafabricplus.util.ScreenUtil;
import de.florianmichael.viafabricplus.vialoadingbase.ViaLoadingBaseStartup;
import net.minecraft.client.MinecraftClient;
import net.minecraft.text.Text;
import net.raphimc.vialegacy.protocols.release.protocol1_3_1_2to1_2_4_5.providers.OldAuthProvider;
@ -37,7 +38,7 @@ public class ViaFabricPlusOldAuthProvider extends OldAuthProvider {
mc.getSessionService().joinServer(mc.getSession().getProfile(), mc.getSession().getAccessToken(), serverId);
} catch (Exception e) {
if (MPPassSettings.getClassWrapper().disconnectIfJoinServerCallFails.getValue()) {
user.getChannel().attr(ViaFabricPlus.LOCAL_MINECRAFT_CONNECTION).get().disconnect(Text.literal(ScreenUtil.prefixedMessage("ViaLegacy fails to verify your session! Please log in into an Account or disable the BetaCraft authentication in the ViaFabricPlus Settings")));
user.getChannel().attr(ViaLoadingBaseStartup.LOCAL_MINECRAFT_CONNECTION).get().disconnect(Text.literal(ScreenUtil.prefixedMessage("ViaLegacy fails to verify your session! Please log in into an Account or disable the BetaCraft authentication in the ViaFabricPlus Settings")));
} else {
e.printStackTrace();
}