Add 1.7->1.8 tablist behaviour and layout (#411)

* Implement legacy tablist functionality

* Address review comments (squashed)

* Minor changes following code review
This commit is contained in:
Pablo Herrera 2024-05-09 19:57:02 +02:00 committed by GitHub
parent 4a6d0b56a0
commit 60a26d2bb1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 208 additions and 1 deletions

View File

@ -77,6 +77,11 @@ public class ClientsideFixes {
*/
public static final String ATTRIBUTE_FIX_KEY = "VFP|AttributeFix";
/**
* This is an incremental index used for tablist entries to implement FIFO behavior <= 1.7
*/
public static int GLOBAL_TABLIST_INDEX = 0;
public static void init() {
// Register additional CPE features
CPEAdditions.modifyMappings();

View File

@ -0,0 +1,26 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2024 FlorianMichael/EnZaXD <florian.michael07@gmail.com> and RK_01/RaphiMC
* Copyright (C) 2023-2024 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.access;
public interface IPlayerListEntry {
int viaFabricPlus$getIndex();
}

View File

@ -0,0 +1,26 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2024 FlorianMichael/EnZaXD <florian.michael07@gmail.com> and RK_01/RaphiMC
* Copyright (C) 2023-2024 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.access;
public interface IPlayerListHud {
void viaFabricPlus$setMaxPlayers(int maxPlayers);
}

View File

@ -22,9 +22,11 @@ package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.network;
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
import com.llamalad7.mixinextras.sugar.Local;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viafabricplus.fixes.ClientsideFixes;
import de.florianmichael.viafabricplus.fixes.data.recipe.RecipeInfo;
import de.florianmichael.viafabricplus.fixes.data.recipe.Recipes1_11_2;
import de.florianmichael.viafabricplus.injection.access.IDownloadingTerrainScreen;
import de.florianmichael.viafabricplus.injection.access.IPlayerListHud;
import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator;
import de.florianmichael.viafabricplus.settings.impl.VisualSettings;
import net.minecraft.client.MinecraftClient;
@ -168,7 +170,7 @@ public abstract class MixinClientPlayNetworkHandler extends ClientCommonNetworkH
}
@Inject(method = "onGameJoin", at = @At("RETURN"))
private void sendRecipes(CallbackInfo ci) {
private void sendRecipes(GameJoinS2CPacket packet, CallbackInfo ci) {
if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_11_1)) {
final List<RecipeEntry<?>> recipes = new ArrayList<>();
final List<RecipeInfo> recipeInfos = Recipes1_11_2.getRecipes(ProtocolTranslator.getTargetVersion());
@ -177,6 +179,8 @@ public abstract class MixinClientPlayNetworkHandler extends ClientCommonNetworkH
}
this.onSynchronizeRecipes(new SynchronizeRecipesS2CPacket(recipes));
}
ClientsideFixes.GLOBAL_TABLIST_INDEX = 0;
((IPlayerListHud) MinecraftClient.getInstance().inGameHud.getPlayerListHud()).viaFabricPlus$setMaxPlayers(packet.maxPlayers());
}
}

View File

@ -0,0 +1,38 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2024 FlorianMichael/EnZaXD <florian.michael07@gmail.com> and RK_01/RaphiMC
* Copyright (C) 2023-2024 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.fixes.minecraft.network;
import de.florianmichael.viafabricplus.fixes.ClientsideFixes;
import de.florianmichael.viafabricplus.injection.access.IPlayerListEntry;
import net.minecraft.client.network.PlayerListEntry;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
@Mixin(PlayerListEntry.class)
public abstract class MixinPlayerListEntry implements IPlayerListEntry {
@Unique
private final int viaFabricPlus$index = ClientsideFixes.GLOBAL_TABLIST_INDEX++;
@Override
public int viaFabricPlus$getIndex() {
return viaFabricPlus$index;
}
}

View File

@ -0,0 +1,104 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2024 FlorianMichael/EnZaXD <florian.michael07@gmail.com> and RK_01/RaphiMC
* Copyright (C) 2023-2024 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.fixes.minecraft.screen.hud;
import de.florianmichael.viafabricplus.injection.access.IPlayerListEntry;
import de.florianmichael.viafabricplus.injection.access.IPlayerListHud;
import de.florianmichael.viafabricplus.settings.impl.VisualSettings;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.hud.PlayerListHud;
import net.minecraft.client.network.PlayerListEntry;
import net.minecraft.network.ClientConnection;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
@Mixin(PlayerListHud.class)
public abstract class MixinPlayerListHud implements IPlayerListHud {
@Unique
private static final Comparator<PlayerListEntry> viaFabricPlus$FIFO_COMPARATOR
= Comparator.comparingInt(ple -> ((IPlayerListEntry) ple).viaFabricPlus$getIndex());
@Shadow
@Final
private MinecraftClient client;
@Unique
private int viaFabricPlus$maxSlots;
@Unique
private boolean viaFabricPlus$hideSkins = true;
@Inject(method = "collectPlayerEntries", at = @At("HEAD"), cancellable = true)
private void collectPlayerEntries(CallbackInfoReturnable<List<PlayerListEntry>> result) {
if (VisualSettings.global().enableLegacyTablist.isEnabled()) {
result.setReturnValue(this.client.player.networkHandler.getListedPlayerListEntries().stream()
.sorted(viaFabricPlus$FIFO_COMPARATOR)
.limit(viaFabricPlus$maxSlots)
.collect(Collectors.collectingAndThen(Collectors.toList(), this::viaFabricPlus$transpose)));
} else {
viaFabricPlus$hideSkins = false;
}
}
@Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/ClientConnection;isEncrypted()Z"))
private boolean hideSkins(ClientConnection instance) {
return !viaFabricPlus$hideSkins && instance.isEncrypted();
}
@Unique
private List<PlayerListEntry> viaFabricPlus$transpose(final List<PlayerListEntry> list) {
// Only bother transposing if we know the list is full
if (list.size() != viaFabricPlus$maxSlots) {
viaFabricPlus$hideSkins = list.stream().noneMatch(e -> e.getProfile().getProperties().containsKey("textures"));
return list;
}
final List<PlayerListEntry> result = new ArrayList<>(list.size());
final int columns = viaFabricPlus$maxSlots / PlayerListHud.MAX_ROWS;
boolean anyHasSkinData = false;
for (int i = 0; i < viaFabricPlus$maxSlots; i++) {
final int row = i % PlayerListHud.MAX_ROWS;
final int col = i / PlayerListHud.MAX_ROWS;
final PlayerListEntry current = list.get(row * columns + col);
result.add(current);
anyHasSkinData = anyHasSkinData || current.getProfile().getProperties().containsKey("textures");
}
viaFabricPlus$hideSkins = !anyHasSkinData;
return result;
}
@Override
public void viaFabricPlus$setMaxPlayers(final int maxPlayers) {
this.viaFabricPlus$maxSlots = Math.min(200, Math.max(20,
((maxPlayers + PlayerListHud.MAX_ROWS - 1) / PlayerListHud.MAX_ROWS) * PlayerListHud.MAX_ROWS));
}
}

View File

@ -53,6 +53,7 @@ public class VisualSettings extends SettingGroup {
// 1.8.x -> 1.7.6 - 1.7.10
public final VersionedBooleanSetting enableBlockHitAnimation = new VersionedBooleanSetting(this, Text.translatable("visual_settings.viafabricplus.enable_block_hit_animation"), VersionRange.andOlder(ProtocolVersion.v1_7_6));
public final VersionedBooleanSetting enableLegacyTablist = new VersionedBooleanSetting(this, Text.translatable("visual_settings.viafabricplus.enable_legacy_tablist"), VersionRange.andOlder(ProtocolVersion.v1_7_6));
// 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(LegacyProtocolVersion.b1_8tob1_8_1));

View File

@ -83,6 +83,7 @@
"visual_settings.viafabricplus.enable_block_hit_animation": "Enable block hit animation",
"visual_settings.viafabricplus.disable_server_pinging": "Disable server pinging",
"visual_settings.viafabricplus.sideways_backwards_walking": "Sideways backwards walking",
"visual_settings.viafabricplus.enable_legacy_tablist": "Enable legacy tablist",
"bedrock.viafabricplus.login": "Your browser should have opened.\nClosing this screen will cancel the process!",
"authentication.viafabricplus.failed_to_verify_session": "ViaFabricPlus couldn't verify your session! Please log in to an account or disable the BetaCraft authentication in the ViaFabricPlus Settings",

View File

@ -135,6 +135,7 @@
"fixes.minecraft.network.MixinClientPlayerInteractionManager",
"fixes.minecraft.network.MixinClientPlayNetworkHandler",
"fixes.minecraft.network.MixinMultiplayerServerListPinger",
"fixes.minecraft.network.MixinPlayerListEntry",
"fixes.minecraft.network.MixinUpdatePlayerAbilitiesC2SPacket",
"fixes.minecraft.screen.MixinAbstractCommandBlockScreen",
"fixes.minecraft.screen.MixinAbstractSignEditScreen",
@ -152,6 +153,7 @@
"fixes.minecraft.screen.MixinStructureBlockScreen_1",
"fixes.minecraft.screen.hud.MixinChatHud",
"fixes.minecraft.screen.hud.MixinInGameHud",
"fixes.minecraft.screen.hud.MixinPlayerListHud",
"fixes.minecraft.screen.screenhandler.MixinAbstractFurnaceScreenHandler",
"fixes.minecraft.screen.screenhandler.MixinBrewingStandScreenHandler_FuelSlot",
"fixes.minecraft.screen.screenhandler.MixinCraftingScreenHandler",