Skip to content

Commit

Permalink
Cleaned settings and finished V3 TODO list
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed Nov 27, 2023
1 parent c5191b5 commit 6778434
Show file tree
Hide file tree
Showing 19 changed files with 336 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
* 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)
Expand All @@ -45,12 +46,6 @@
* - 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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;
Expand Down Expand Up @@ -217,7 +218,7 @@ private void expandHitBox(CallbackInfoReturnable<Float> cir) {

@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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<Boolean> cir) {
cir.setReturnValue(GeneralSettings.global().loadSkinsAndSkullsInLegacyVersions.getValue());
}

}
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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<String, Object> map, final Object key) {
if (((Object) this) instanceof ConfigPatcher) {
return true;
}

return map.containsKey(key);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
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;
Expand All @@ -50,19 +52,21 @@
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;

/**
* 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.
*/
Expand Down Expand Up @@ -174,7 +178,38 @@ public static UserConnection getPlayNetworkUserConnection() {
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<String, Object> 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<String, Object> 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<Void> 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();
Expand All @@ -188,10 +223,11 @@ public static CompletableFuture<Void> init(final File directory) {
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,
Expand All @@ -200,4 +236,5 @@ public static CompletableFuture<Void> init(final File directory) {
PostViaVersionLoadCallback.EVENT.invoker().onPostViaVersionLoad();
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
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;
Expand Down Expand Up @@ -64,7 +65,8 @@ public void load() {
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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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;
}

}
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

package de.florianmichael.viafabricplus.protocolhack.impl.platform;

import com.viaversion.viaversion.configuration.AbstractViaConfig;
import de.florianmichael.viafabricplus.protocolhack.impl.ViaFabricPlusVLViaConfig;
import net.raphimc.vialoader.impl.platform.ViaVersionPlatformImpl;

import java.io.File;

public class ViaFabricPlusViaVersionPlatformImpl extends ViaVersionPlatformImpl {

public ViaFabricPlusViaVersionPlatformImpl(File rootFolder) {
super(rootFolder);
}

@Override
protected AbstractViaConfig createConfig() {
final AbstractViaConfig config = new ViaFabricPlusVLViaConfig(new File(this.getDataFolder(), "viaversion.yml"));
config.reload();
return config;
}

}
Loading

0 comments on commit 6778434

Please sign in to comment.