From 677843479bf37b5db6e191b4802ccb9fdc7e197f Mon Sep 17 00:00:00 2001 From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com> Date: Mon, 27 Nov 2023 19:38:03 +0100 Subject: [PATCH] Cleaned settings and finished V3 TODO list --- .../viafabricplus/ViaFabricPlus.java | 7 +-- .../fixes/ArmorHudEmulation1_8.java | 9 ++- .../fixes/minecraft/entity/MixinEntity.java | 3 +- .../minecraft/item/MixinHeldItemRenderer.java | 6 +- ...MixinExtensionProtocolMetadataStorage.java | 2 +- .../mixin/vialegacy/MixinViaLegacyConfig.java | 37 ++++++++++++ .../mixin/viaversion/MixinConfig.java | 42 +++++++++++++ .../protocolhack/ProtocolHack.java | 41 ++++++++++++- .../impl/ViaFabricPlusVLLoader.java | 4 +- .../impl/ViaFabricPlusVLViaConfig.java | 39 ++++++++++++ .../ViaFabricPlusViaVersionPlatformImpl.java | 41 +++++++++++++ .../ViaFabricPlusAlphaInventoryProvider.java | 41 +++++++++++-- .../protocolhack/util/ConfigPatcher.java | 60 +++++++++++++++++++ .../settings/impl/DebugSettings.java | 5 +- .../settings/impl/GeneralSettings.java | 2 + .../settings/impl/VisualSettings.java | 11 ++-- .../assets/viafabricplus/lang/en_us.json | 6 +- .../viafabricplus/viaversion-config.yml | 2 + src/main/resources/viafabricplus.mixins.json | 8 ++- 19 files changed, 336 insertions(+), 30 deletions(-) rename src/main/java/de/florianmichael/viafabricplus/injection/mixin/{fixes => }/vialegacy/MixinExtensionProtocolMetadataStorage.java (96%) create mode 100644 src/main/java/de/florianmichael/viafabricplus/injection/mixin/vialegacy/MixinViaLegacyConfig.java create mode 100644 src/main/java/de/florianmichael/viafabricplus/injection/mixin/viaversion/MixinConfig.java create mode 100644 src/main/java/de/florianmichael/viafabricplus/protocolhack/impl/ViaFabricPlusVLViaConfig.java create mode 100644 src/main/java/de/florianmichael/viafabricplus/protocolhack/impl/platform/ViaFabricPlusViaVersionPlatformImpl.java create mode 100644 src/main/java/de/florianmichael/viafabricplus/protocolhack/util/ConfigPatcher.java create mode 100644 src/main/resources/assets/viafabricplus/viaversion-config.yml diff --git a/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java b/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java index 1ad5a3b8..a1dff3a0 100644 --- a/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java +++ b/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java @@ -36,6 +36,7 @@ import java.util.concurrent.CompletableFuture; * TODO | General * - Make recipe fixes dynamic instead of a data dump in java classes * - Check if relevant for protocol translation: TakeItemEntityPacket isEmpty case (1.20 -> 1.20.1 change) + * - Check previous Donkey interaction fix (see git logs) * - Window interactions in <= 1.16.5 has changed and can be detected by the server * - Most CTS protocol features aren't supported (see https://github.com/ViaVersion/ViaFabricPlus/issues/181) * - Most CPE features aren't implemented correctly (see https://github.com/ViaVersion/ViaFabricPlus/issues/152) @@ -45,12 +46,6 @@ import java.util.concurrent.CompletableFuture; * - X/Z Face based jump movement in <= 1.13.2 is broken (https://github.com/ViaVersion/ViaFabricPlus/issues/189) * - Collision hit boxes has been changed (https://github.com/ViaVersion/ViaFabricPlus/issues/195) * - Blit-jump is not supported in <= 1.8.9 (https://github.com/ViaVersion/ViaFabricPlus/issues/225) - * - * TODO | Migration v3 - * - Use ViaProxy config patch for some clientside fixes options (Remove ViaFabricPlusVLViaConfig and MixinViaLegacyConfig) - * - Add setting for VFP AlphaInventoryProvider - * - Fix MixinAbstractDonkeyEntity - * - Check TO DO in MixinEntity */ public class ViaFabricPlus { private static final ViaFabricPlus instance = new ViaFabricPlus(); diff --git a/src/main/java/de/florianmichael/viafabricplus/fixes/ArmorHudEmulation1_8.java b/src/main/java/de/florianmichael/viafabricplus/fixes/ArmorHudEmulation1_8.java index fc1eb481..5123bead 100644 --- a/src/main/java/de/florianmichael/viafabricplus/fixes/ArmorHudEmulation1_8.java +++ b/src/main/java/de/florianmichael/viafabricplus/fixes/ArmorHudEmulation1_8.java @@ -26,7 +26,8 @@ import com.viaversion.viaversion.protocols.protocol1_9to1_8.ArmorType; import com.viaversion.viaversion.protocols.protocol1_9to1_8.ClientboundPackets1_9; import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8; import de.florianmichael.viafabricplus.ViaFabricPlus; -import de.florianmichael.viafabricplus.injection.access.IClientConnection; +import de.florianmichael.viafabricplus.protocolhack.ProtocolHack; +import de.florianmichael.viafabricplus.settings.impl.VisualSettings; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.minecraft.client.MinecraftClient; import net.minecraft.item.ItemStack; @@ -42,8 +43,12 @@ public class ArmorHudEmulation1_8 { public static void init() { ClientTickEvents.START_WORLD_TICK.register(world -> { + if (!VisualSettings.global().emulateArmorHud.isEnabled()) { + return; + } + if (MinecraftClient.getInstance().player != null) { - final UserConnection userConnection = ((IClientConnection) MinecraftClient.getInstance().getNetworkHandler().getConnection()).viaFabricPlus$getUserConnection(); + final UserConnection userConnection = ProtocolHack.getPlayNetworkUserConnection(); if (userConnection != null) { try { sendArmorUpdate(userConnection); diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinEntity.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinEntity.java index f26615d5..00d36443 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinEntity.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinEntity.java @@ -22,6 +22,7 @@ package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.entity; import de.florianmichael.viafabricplus.fixes.entity.EntityRidingOffsetsPre1_20_2; import de.florianmichael.viafabricplus.injection.access.IEntity; import de.florianmichael.viafabricplus.protocolhack.ProtocolHack; +import de.florianmichael.viafabricplus.settings.impl.DebugSettings; import it.unimi.dsi.fastutil.objects.Object2DoubleMap; import net.minecraft.block.BlockState; import net.minecraft.block.FenceGateBlock; @@ -217,7 +218,7 @@ public abstract class MixinEntity implements IEntity { @Override public boolean viaFabricPlus$isInLoadedChunkAndShouldTick() { - return this.viaFabricPlus$isInLoadedChunkAndShouldTick || !ProtocolHack.getTargetVersion().isBetweenInclusive(VersionEnum.r1_9, VersionEnum.r1_16_4tor1_16_5) /* || TODO: Add setting to force this*/; + return this.viaFabricPlus$isInLoadedChunkAndShouldTick || DebugSettings.global().alwaysTickClientPlayer.isEnabled(); } @Override diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinHeldItemRenderer.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinHeldItemRenderer.java index 2b953e1b..b80985ff 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinHeldItemRenderer.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinHeldItemRenderer.java @@ -47,10 +47,12 @@ public abstract class MixinHeldItemRenderer { slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;getUseAction()Lnet/minecraft/util/UseAction;")), at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/HeldItemRenderer;applyEquipOffset(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/util/Arm;F)V", ordinal = 2, shift = At.Shift.AFTER)) private void transformLegacyBlockAnimations(AbstractClientPlayerEntity player, float tickDelta, float pitch, Hand hand, float swingProgress, ItemStack item, float equipProgress, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) { - if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) { + final boolean blockHitAnimation = VisualSettings.global().enableBlockHitAnimation.isEnabled(); + + if (VisualSettings.global().enableSwordBlocking.isEnabled() || blockHitAnimation) { matrices.translate(-0.1F, 0.05F, 0.0F); - if (VisualSettings.global().blockHitAnimation.isEnabled()) { + if (blockHitAnimation) { final var arm = (hand == Hand.MAIN_HAND) ? player.getMainArm() : player.getMainArm().getOpposite(); applySwingOffset(matrices, arm, swingProgress); } diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/vialegacy/MixinExtensionProtocolMetadataStorage.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/vialegacy/MixinExtensionProtocolMetadataStorage.java similarity index 96% rename from src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/vialegacy/MixinExtensionProtocolMetadataStorage.java rename to src/main/java/de/florianmichael/viafabricplus/injection/mixin/vialegacy/MixinExtensionProtocolMetadataStorage.java index c0e4fcf7..59cf5af4 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/vialegacy/MixinExtensionProtocolMetadataStorage.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/vialegacy/MixinExtensionProtocolMetadataStorage.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package de.florianmichael.viafabricplus.injection.mixin.fixes.vialegacy; +package de.florianmichael.viafabricplus.injection.mixin.vialegacy; import de.florianmichael.viafabricplus.event.LoadClassicProtocolExtensionCallback; import de.florianmichael.viafabricplus.injection.access.IExtensionProtocolMetadataStorage; diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/vialegacy/MixinViaLegacyConfig.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/vialegacy/MixinViaLegacyConfig.java new file mode 100644 index 00000000..eb9c74c6 --- /dev/null +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/vialegacy/MixinViaLegacyConfig.java @@ -0,0 +1,37 @@ +/* + * This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus + * Copyright (C) 2021-2023 FlorianMichael/EnZaXD + * Copyright (C) 2023 RK_01/RaphiMC 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 . + */ + +package de.florianmichael.viafabricplus.injection.mixin.vialegacy; + +import de.florianmichael.viafabricplus.settings.impl.GeneralSettings; +import net.raphimc.vialegacy.ViaLegacyConfig; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(value = ViaLegacyConfig.class, remap = false) +public class MixinViaLegacyConfig { + + @Inject(method = { "isLegacySkullLoading", "isLegacySkinLoading" }, at = @At("HEAD"), cancellable = true) + public void replaceWithVFPSetting(CallbackInfoReturnable cir) { + cir.setReturnValue(GeneralSettings.global().loadSkinsAndSkullsInLegacyVersions.getValue()); + } + +} diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/viaversion/MixinConfig.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/viaversion/MixinConfig.java new file mode 100644 index 00000000..26ff8175 --- /dev/null +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/viaversion/MixinConfig.java @@ -0,0 +1,42 @@ +/* + * This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus + * Copyright (C) 2021-2023 FlorianMichael/EnZaXD + * Copyright (C) 2023 RK_01/RaphiMC 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 . + */ + +package de.florianmichael.viafabricplus.injection.mixin.viaversion; + +import com.viaversion.viaversion.util.Config; +import de.florianmichael.viafabricplus.protocolhack.util.ConfigPatcher; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import java.util.Map; + +@Mixin(value = Config.class, remap = false) +public abstract class MixinConfig { + + @Redirect(method = "loadConfig(Ljava/io/File;Ljava/net/URL;)Ljava/util/Map;", at = @At(value = "INVOKE", target = "Ljava/util/Map;containsKey(Ljava/lang/Object;)Z")) + private boolean allowConfigPatching(final Map map, final Object key) { + if (((Object) this) instanceof ConfigPatcher) { + return true; + } + + return map.containsKey(key); + } + +} \ No newline at end of file diff --git a/src/main/java/de/florianmichael/viafabricplus/protocolhack/ProtocolHack.java b/src/main/java/de/florianmichael/viafabricplus/protocolhack/ProtocolHack.java index 9284972e..38262040 100644 --- a/src/main/java/de/florianmichael/viafabricplus/protocolhack/ProtocolHack.java +++ b/src/main/java/de/florianmichael/viafabricplus/protocolhack/ProtocolHack.java @@ -37,7 +37,9 @@ import de.florianmichael.viafabricplus.protocolhack.command.ViaFabricPlusVLComma import de.florianmichael.viafabricplus.protocolhack.impl.ViaFabricPlusVLInjector; import de.florianmichael.viafabricplus.protocolhack.impl.ViaFabricPlusVLLoader; import de.florianmichael.viafabricplus.protocolhack.impl.platform.ViaFabricPlusViaLegacyPlatformImpl; +import de.florianmichael.viafabricplus.protocolhack.impl.platform.ViaFabricPlusViaVersionPlatformImpl; import de.florianmichael.viafabricplus.protocolhack.netty.ViaFabricPlusVLLegacyPipeline; +import de.florianmichael.viafabricplus.protocolhack.util.ConfigPatcher; import de.florianmichael.viafabricplus.protocolhack.util.NoPacketSendChannel; import io.netty.channel.Channel; import io.netty.util.AttributeKey; @@ -50,12 +52,13 @@ import net.raphimc.vialoader.ViaLoader; import net.raphimc.vialoader.impl.platform.ViaAprilFoolsPlatformImpl; import net.raphimc.vialoader.impl.platform.ViaBackwardsPlatformImpl; import net.raphimc.vialoader.impl.platform.ViaBedrockPlatformImpl; -import net.raphimc.vialoader.impl.platform.ViaVersionPlatformImpl; import net.raphimc.vialoader.util.VersionEnum; import org.cloudburstmc.netty.channel.raknet.config.RakChannelOption; import java.io.File; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ThreadLocalRandom; @@ -63,6 +66,7 @@ import java.util.concurrent.ThreadLocalRandom; * This class represents the whole Protocol Translator, here all important variables are stored */ public class ProtocolHack { + /** * These attribute keys are used to track the main connections of Minecraft and ViaVersion, so that they can be used later during the connection to send packets. */ @@ -174,7 +178,38 @@ public class ProtocolHack { throw new IllegalStateException("The player is not connected to a server"); } + /** + * Apply recommended config options to the ViaVersion config files + * + * @param directory The directory where the ViaVersion config files are located + */ + public static void patchConfigs(final File directory) { + final File configFolder = new File(directory, "ViaLoader"); + + final File viaVersionConfig = new File(configFolder, "viaversion.yml"); + final Map viaVersionPatches = new HashMap<>(); + viaVersionPatches.put("fix-infested-block-breaking", false); + viaVersionPatches.put("shield-blocking", false); + viaVersionPatches.put("no-delay-shield-blocking", true); + viaVersionPatches.put("chunk-border-fix", true); + new ConfigPatcher(viaVersionConfig, viaVersionPatches); + + final File viaLegacyConfig = new File(configFolder, "vialegacy.yml"); + final Map viaLegacyPatches = new HashMap<>(); + viaLegacyPatches.put("legacy-skull-loading", true); + viaLegacyPatches.put("legacy-skin-loading", true); + new ConfigPatcher(viaLegacyConfig, viaLegacyPatches); + } + + /** + * This method is used to initialize the whole Protocol Translator + * + * @param directory The directory where the ViaVersion config files are located + * @return A CompletableFuture that will be completed when the initialization is done + */ public static CompletableFuture init(final File directory) { + patchConfigs(directory); + // Register command callback for /viaversion and /viafabricplus ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> { final var commandHandler = (ViaFabricPlusVLCommandHandler) Via.getManager().getCommandHandler(); @@ -188,10 +223,11 @@ public class ProtocolHack { return CompletableFuture.runAsync(() -> { // Load ViaVersion and register all platforms and their components ViaLoader.init( - new ViaVersionPlatformImpl(directory), + new ViaFabricPlusViaVersionPlatformImpl(directory), new ViaFabricPlusVLLoader(), new ViaFabricPlusVLInjector(), new ViaFabricPlusVLCommandHandler(), + ViaBackwardsPlatformImpl::new, ViaFabricPlusViaLegacyPlatformImpl::new, ViaAprilFoolsPlatformImpl::new, @@ -200,4 +236,5 @@ public class ProtocolHack { PostViaVersionLoadCallback.EVENT.invoker().onPostViaVersionLoad(); }); } + } diff --git a/src/main/java/de/florianmichael/viafabricplus/protocolhack/impl/ViaFabricPlusVLLoader.java b/src/main/java/de/florianmichael/viafabricplus/protocolhack/impl/ViaFabricPlusVLLoader.java index 8304520c..94438b5f 100644 --- a/src/main/java/de/florianmichael/viafabricplus/protocolhack/impl/ViaFabricPlusVLLoader.java +++ b/src/main/java/de/florianmichael/viafabricplus/protocolhack/impl/ViaFabricPlusVLLoader.java @@ -36,6 +36,7 @@ import net.raphimc.viabedrock.protocol.providers.BlobCacheProvider; import net.raphimc.viabedrock.protocol.providers.NettyPipelineProvider; import net.raphimc.viabedrock.protocol.providers.TransferProvider; import net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.providers.AlphaInventoryProvider; +import net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.providers.TrackingAlphaInventoryProvider; 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; @@ -64,7 +65,8 @@ public class ViaFabricPlusVLLoader extends VLLoader { providers.use(EncryptionProvider.class, new ViaFabricPlusEncryptionProvider()); providers.use(GameProfileFetcher.class, new ViaFabricPlusGameProfileFetcher()); providers.use(ClassicMPPassProvider.class, new ViaFabricPlusClassicMPPassProvider()); - providers.use(AlphaInventoryProvider.class, new ViaFabricPlusAlphaInventoryProvider()); + + providers.use(AlphaInventoryProvider.class, new ViaFabricPlusAlphaInventoryProvider(providers.get(TrackingAlphaInventoryProvider.class))); providers.use(NettyPipelineProvider.class, new ViaFabricPlusNettyPipelineProvider()); providers.use(BlobCacheProvider.class, new ViaFabricPlusBlobCacheProvider()); diff --git a/src/main/java/de/florianmichael/viafabricplus/protocolhack/impl/ViaFabricPlusVLViaConfig.java b/src/main/java/de/florianmichael/viafabricplus/protocolhack/impl/ViaFabricPlusVLViaConfig.java new file mode 100644 index 00000000..2091d9b1 --- /dev/null +++ b/src/main/java/de/florianmichael/viafabricplus/protocolhack/impl/ViaFabricPlusVLViaConfig.java @@ -0,0 +1,39 @@ +/* + * This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus + * Copyright (C) 2021-2023 FlorianMichael/EnZaXD + * Copyright (C) 2023 RK_01/RaphiMC 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 . + */ + +package de.florianmichael.viafabricplus.protocolhack.impl; + +import net.raphimc.vialoader.impl.viaversion.VLViaConfig; + +import java.io.File; + +public class ViaFabricPlusVLViaConfig extends VLViaConfig { + + public ViaFabricPlusVLViaConfig(File configFile) { + super(configFile); + + UNSUPPORTED.add("simulate-pt"); + } + + @Override + public boolean isSimulatePlayerTick() { + return false; + } + +} diff --git a/src/main/java/de/florianmichael/viafabricplus/protocolhack/impl/platform/ViaFabricPlusViaVersionPlatformImpl.java b/src/main/java/de/florianmichael/viafabricplus/protocolhack/impl/platform/ViaFabricPlusViaVersionPlatformImpl.java new file mode 100644 index 00000000..218e67ed --- /dev/null +++ b/src/main/java/de/florianmichael/viafabricplus/protocolhack/impl/platform/ViaFabricPlusViaVersionPlatformImpl.java @@ -0,0 +1,41 @@ +/* + * This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus + * Copyright (C) 2021-2023 FlorianMichael/EnZaXD + * Copyright (C) 2023 RK_01/RaphiMC 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 . + */ + +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.reload(); + return config; + } + +} diff --git a/src/main/java/de/florianmichael/viafabricplus/protocolhack/provider/vialegacy/ViaFabricPlusAlphaInventoryProvider.java b/src/main/java/de/florianmichael/viafabricplus/protocolhack/provider/vialegacy/ViaFabricPlusAlphaInventoryProvider.java index 2ff19c8a..fd353a09 100644 --- a/src/main/java/de/florianmichael/viafabricplus/protocolhack/provider/vialegacy/ViaFabricPlusAlphaInventoryProvider.java +++ b/src/main/java/de/florianmichael/viafabricplus/protocolhack/provider/vialegacy/ViaFabricPlusAlphaInventoryProvider.java @@ -22,10 +22,13 @@ package de.florianmichael.viafabricplus.protocolhack.provider.vialegacy; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.item.Item; import de.florianmichael.viafabricplus.protocolhack.translator.ItemTranslator; +import de.florianmichael.viafabricplus.settings.impl.GeneralSettings; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.item.ItemStack; import net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.providers.AlphaInventoryProvider; +import net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.providers.TrackingAlphaInventoryProvider; +import net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.storage.AlphaInventoryTracker; import net.raphimc.vialoader.util.VersionEnum; import java.util.List; @@ -33,10 +36,15 @@ import java.util.List; import static net.raphimc.vialegacy.protocols.alpha.protocolb1_0_1_1_1toa1_2_3_5_1_2_6.Protocolb1_0_1_1_1toa1_2_3_5_1_2_6.copyItems; public class ViaFabricPlusAlphaInventoryProvider extends AlphaInventoryProvider { + private final TrackingAlphaInventoryProvider trackingAlphaInventoryProvider; + + public ViaFabricPlusAlphaInventoryProvider(final TrackingAlphaInventoryProvider trackingAlphaInventoryProvider) { + this.trackingAlphaInventoryProvider = trackingAlphaInventoryProvider; + } @Override public boolean usesInventoryTracker() { - return false; + return !GeneralSettings.global().emulateInventoryActionsInLegacyVersions.getValue(); } protected Item[] getMinecraftContainerItems(final List trackingItems) { @@ -53,38 +61,59 @@ public class ViaFabricPlusAlphaInventoryProvider extends AlphaInventoryProvider @Override public Item[] getMainInventoryItems(UserConnection user) { - if (getPlayer() == null) return new Item[37]; + if (usesInventoryTracker()) { + return trackingAlphaInventoryProvider.getMainInventoryItems(user); + } else if (getPlayer() == null) { + return new Item[37]; + } return getMinecraftContainerItems(getPlayer().getInventory().main); } @Override public Item[] getCraftingInventoryItems(UserConnection user) { - if (getPlayer() == null) return new Item[4]; + if (usesInventoryTracker()) { + return trackingAlphaInventoryProvider.getCraftingInventoryItems(user); + } else if (getPlayer() == null) { + return new Item[4]; + } return getMinecraftContainerItems(getPlayer().playerScreenHandler.getCraftingInput().getInputStacks()); } @Override public Item[] getArmorInventoryItems(UserConnection user) { - if (getPlayer() == null) return new Item[4]; + if (usesInventoryTracker()) { + return trackingAlphaInventoryProvider.getArmorInventoryItems(user); + } else if (getPlayer() == null) { + return new Item[4]; + } return getMinecraftContainerItems(getPlayer().getInventory().armor); } @Override public Item[] getContainerItems(UserConnection user) { - if (getPlayer() == null) return new Item[37]; + if (usesInventoryTracker()) { + return trackingAlphaInventoryProvider.getContainerItems(user); + } else if (getPlayer() == null) { + return new Item[37]; + } return getMinecraftContainerItems(getPlayer().currentScreenHandler.getStacks()); } @Override public void addToInventory(UserConnection user, Item item) { - getPlayer().getInventory().insertStack(ItemTranslator.viaB1_8toMc(item)); + if (usesInventoryTracker()) { + trackingAlphaInventoryProvider.addToInventory(user, item); + } else { + getPlayer().getInventory().insertStack(ItemTranslator.viaB1_8toMc(item)); + } } protected ClientPlayerEntity getPlayer() { return MinecraftClient.getInstance().player; } + } diff --git a/src/main/java/de/florianmichael/viafabricplus/protocolhack/util/ConfigPatcher.java b/src/main/java/de/florianmichael/viafabricplus/protocolhack/util/ConfigPatcher.java new file mode 100644 index 00000000..0a505b9a --- /dev/null +++ b/src/main/java/de/florianmichael/viafabricplus/protocolhack/util/ConfigPatcher.java @@ -0,0 +1,60 @@ +/* + * This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus + * Copyright (C) 2021-2023 FlorianMichael/EnZaXD + * Copyright (C) 2023 RK_01/RaphiMC 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 . + */ + +package de.florianmichael.viafabricplus.protocolhack.util; + +import com.viaversion.viaversion.util.Config; + +import java.io.File; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class ConfigPatcher extends Config { + + private final Map patches; + + public ConfigPatcher(final File configFile, final Map patches) { + super(configFile); + + this.patches = patches; + this.reload(); + } + + @Override + public URL getDefaultConfigURL() { + return ConfigPatcher.class.getClassLoader().getResource("assets/viafabricplus/viaversion-config.yml"); + } + + @Override + protected void handleConfig(Map config) { + for (final Map.Entry entry : this.patches.entrySet()) { + if (!config.containsKey(entry.getKey())) { + config.put(entry.getKey(), entry.getValue()); + } + } + } + + @Override + public List getUnsupportedOptions() { + return new ArrayList<>(); + } + +} \ No newline at end of file diff --git a/src/main/java/de/florianmichael/viafabricplus/settings/impl/DebugSettings.java b/src/main/java/de/florianmichael/viafabricplus/settings/impl/DebugSettings.java index 05a735bb..72f82555 100644 --- a/src/main/java/de/florianmichael/viafabricplus/settings/impl/DebugSettings.java +++ b/src/main/java/de/florianmichael/viafabricplus/settings/impl/DebugSettings.java @@ -31,6 +31,9 @@ public class DebugSettings extends SettingGroup { // 1.19 -> 1.18.2 public final VersionedBooleanSetting disableSequencing = new VersionedBooleanSetting(this, Text.translatable("debug_settings.viafabricplus.disable_sequencing"), VersionRange.andOlder(VersionEnum.r1_18_2)); + // 1.17 -> 1.16.5 + public final VersionedBooleanSetting alwaysTickClientPlayer = new VersionedBooleanSetting(this, Text.translatable("debug_settings.viafabricplus.always_tick_client_player"), VersionRange.of(VersionEnum.r1_9, VersionEnum.r1_16_4tor1_16_5)); + // 1.13 -> 1.12.2 public final VersionedBooleanSetting executeInputsInSync = new VersionedBooleanSetting(this, Text.translatable("debug_settings.viafabricplus.execute_inputs_in_sync"), VersionRange.andOlder(VersionEnum.r1_12_2)); public final VersionedBooleanSetting sneakInstant = new VersionedBooleanSetting(this, Text.translatable("debug_settings.viafabricplus.sneak_instant"), VersionRange.of(VersionEnum.r1_8, VersionEnum.r1_12_2)); @@ -49,7 +52,7 @@ public class DebugSettings extends SettingGroup { public final VersionedBooleanSetting replaceSneaking = new VersionedBooleanSetting(this, Text.translatable("debug_settings.viafabricplus.replace_sneaking"), VersionRange.andOlder(VersionEnum.r1_7_6tor1_7_10)); public final VersionedBooleanSetting longSneaking = new VersionedBooleanSetting(this, Text.translatable("debug_settings.viafabricplus.long_sneaking"), VersionRange.andOlder(VersionEnum.r1_7_6tor1_7_10)); - // r1_5tor1_5_1 -> r1_4_6tor1_4_7 + // 1.5/1.5.1 -> 1.4.6/1.4.7 public final VersionedBooleanSetting legacyMiningSpeeds = new VersionedBooleanSetting(this, Text.translatable("debug_settings.viafabricplus.legacy_mining_speeds"), VersionRange.andOlder(VersionEnum.r1_4_6tor1_4_7)); public DebugSettings() { diff --git a/src/main/java/de/florianmichael/viafabricplus/settings/impl/GeneralSettings.java b/src/main/java/de/florianmichael/viafabricplus/settings/impl/GeneralSettings.java index af2c1aa3..11a51fdb 100644 --- a/src/main/java/de/florianmichael/viafabricplus/settings/impl/GeneralSettings.java +++ b/src/main/java/de/florianmichael/viafabricplus/settings/impl/GeneralSettings.java @@ -55,6 +55,8 @@ public class GeneralSettings extends SettingGroup { Text.translatable("base.viafabricplus.cancel_and_notify"), Text.translatable("base.viafabricplus.cancel") ); + public final BooleanSetting loadSkinsAndSkullsInLegacyVersions = new BooleanSetting(this, Text.translatable("general_settings.viafabricplus.load_skins_and_skulls_in_legacy_versions"), true); + public final BooleanSetting emulateInventoryActionsInLegacyVersions = new BooleanSetting(this, Text.translatable("general_settings.viafabricplus.emulate_inventory_actions_in_legacy_versions"), true); public GeneralSettings() { super(Text.translatable("setting_group_name.viafabricplus.general")); diff --git a/src/main/java/de/florianmichael/viafabricplus/settings/impl/VisualSettings.java b/src/main/java/de/florianmichael/viafabricplus/settings/impl/VisualSettings.java index 35f4a0e0..96ce3b9b 100644 --- a/src/main/java/de/florianmichael/viafabricplus/settings/impl/VisualSettings.java +++ b/src/main/java/de/florianmichael/viafabricplus/settings/impl/VisualSettings.java @@ -46,16 +46,17 @@ public class VisualSettings extends SettingGroup { public final VersionedBooleanSetting removeNewerFeaturesFromCommandBlockScreen = new VersionedBooleanSetting(this, Text.translatable("visual_settings.viafabricplus.remove_newer_features_from_command_block_screen"), VersionRange.andOlder(VersionEnum.r1_8)); public final VersionedBooleanSetting showSuperSecretSettings = new VersionedBooleanSetting(this, Text.translatable("visual_settings.viafabricplus.show_super_secret_settings"), VersionRange.andOlder(VersionEnum.r1_8)); - // 1.8.x -> r1_7_6tor1_7_10 - public final VersionedBooleanSetting blockHitAnimation = new VersionedBooleanSetting(this, Text.translatable("visual_settings.viafabricplus.enable_block_hit_animation"), VersionRange.andOlder(VersionEnum.r1_7_6tor1_7_10)); + // 1.8.x -> 1.7.6 - 1.7.10 + public final VersionedBooleanSetting enableSwordBlocking = new VersionedBooleanSetting(this, Text.translatable("visual_settings.viafabricplus.enable_sword_blocking"), VersionRange.andOlder(VersionEnum.r1_7_6tor1_7_10)); + public final VersionedBooleanSetting enableBlockHitAnimation = new VersionedBooleanSetting(this, Text.translatable("visual_settings.viafabricplus.enable_block_hit_animation"), VersionRange.andOlder(VersionEnum.r1_7_6tor1_7_10)); - // r1_0_0tor1_0_1 -> b1_8tob1_8_1 + // 1.0.0-1.0.1 -> b1.8-b1.8.1 public final VersionedBooleanSetting replaceHurtSoundWithOOFSound = new VersionedBooleanSetting(this, Text.translatable("visual_settings.viafabricplus.replace_hurt_sound_with_oof_sound"), VersionRange.andOlder(VersionEnum.b1_8tob1_8_1)); - // b1_8tob1_8_1 -> b1_7tob1_7_3 + // b1.8/b1.8.1 -> b1_7/b1.7.3 public final VersionedBooleanSetting removeNewerHudElements = new VersionedBooleanSetting(this, Text.translatable("visual_settings.viafabricplus.remove_newer_hud_elements"), VersionRange.andOlder(VersionEnum.b1_7tob1_7_3)); - // a1_0_15 -> c0_28toc0_30 + // a1.0.15 -> c0_28/c0_30 public final VersionedBooleanSetting replaceCreativeInventory = new VersionedBooleanSetting(this, Text.translatable("visual_settings.viafabricplus.replace_creative_inventory_with_classic_inventory"), VersionRange.andOlder(VersionEnum.c0_28toc0_30)); public final VersionedBooleanSetting oldWalkingAnimation = new VersionedBooleanSetting(this, Text.translatable("visual_settings.viafabricplus.old_walking_animation"), VersionRange.andOlder(VersionEnum.c0_28toc0_30)); diff --git a/src/main/resources/assets/viafabricplus/lang/en_us.json b/src/main/resources/assets/viafabricplus/lang/en_us.json index 5daa905d..5cd255bb 100644 --- a/src/main/resources/assets/viafabricplus/lang/en_us.json +++ b/src/main/resources/assets/viafabricplus/lang/en_us.json @@ -41,6 +41,8 @@ "general_settings.viafabricplus.auto_detect_version": "Auto detect version", "general_settings.viafabricplus.show_advertised_server_version": "Show advertised/server version in Multiplayer", "general_settings.viafabricplus.ignore_packet_translation_errors": "Ignore packet translation errors", + "general_settings.viafabricplus.load_skins_and_skulls_in_legacy_versions": "Load skins and skulls in legacy versions", + "general_settings.viafabricplus.emulate_inventory_actions_in_legacy_versions": "Emulate inventory actions in legacy versions", "bedrock_settings.viafabricplus.confirm_transfer_server_prompt": "Open prompt GUI to confirm transferring to other servers", "bedrock_settings.viafabricplus.click_to_set_bedrock_account": "Click to set account for Bedrock edition", @@ -58,6 +60,7 @@ "debug_settings.viafabricplus.legacy_mining_speeds": "Legacy mining speeds", "debug_settings.viafabricplus.skip_containers_with_custom_display_names": "Skip containers with custom display names", "debug_settings.viafabricplus.prevent_entity_cramming": "Prevent entity cramming", + "debug_settings.viafabricplus.always_tick_client_player": "Always tick client player", "authentication_settings.viafabricplus.use_beta_craft_authentication": "Use BetaCraft authentication", "authentication_settings.viafabricplus.verify_session_for_online_mode": "Verify session for online mode servers", @@ -76,7 +79,8 @@ "visual_settings.viafabricplus.replace_creative_inventory_with_classic_inventory": "Replace creative inventory", "visual_settings.viafabricplus.old_walking_animation": "Old walking animation", "visual_settings.viafabricplus.change_font_renderer_behaviour": "Change Font renderer behaviour", - "visual_settings.viafabricplus.enable_block_hit_animation": "Enable 1.7 Block hit animation", + "visual_settings.viafabricplus.enable_sword_blocking": "Enable sword animation", + "visual_settings.viafabricplus.enable_block_hit_animation": "Enable block hit animation", "bedrock.viafabricplus.login": "Your browser should have opened.\nPlease enter the following Code: %s\nClosing this screen will cancel the process!", "bedrock.viafabricplus.confirm_transfer_server_prompt": "Do you want to transfer to the following server?\n%s\n\nThis will disconnect the current server and connect to the new one.", diff --git a/src/main/resources/assets/viafabricplus/viaversion-config.yml b/src/main/resources/assets/viafabricplus/viaversion-config.yml new file mode 100644 index 00000000..9fd9e267 --- /dev/null +++ b/src/main/resources/assets/viafabricplus/viaversion-config.yml @@ -0,0 +1,2 @@ +# Dummy file for the Config patcher features +nothing_to_see_here: true \ No newline at end of file diff --git a/src/main/resources/viafabricplus.mixins.json b/src/main/resources/viafabricplus.mixins.json index 2dc2041b..03f501cb 100644 --- a/src/main/resources/viafabricplus.mixins.json +++ b/src/main/resources/viafabricplus.mixins.json @@ -162,7 +162,7 @@ "fixes.minecraft.screen.screenhandler.MixinScreenHandler", "fixes.vialegacy.MixinClassicProtocolExtension", "fixes.vialegacy.MixinClientboundPacketsc0_30cpe", - "fixes.vialegacy.MixinExtensionProtocolMetadataStorage", + "vialegacy.MixinExtensionProtocolMetadataStorage", "fixes.vialegacy.MixinProtocol1_8to1_7_6_10", "fixes.vialegacy.MixinProtocolc0_30toc0_30cpe", "fixes.viaversion.MixinChatItemRewriter", @@ -199,5 +199,9 @@ ], "injectors": { "defaultRequire": 1 - } + }, + "mixins": [ + "vialegacy.MixinViaLegacyConfig", + "viaversion.MixinConfig" + ] }