Updated Via API usage

This commit is contained in:
FlorianMichael 2023-12-27 21:54:28 +01:00
parent 5c2e9c3349
commit b58a74acd7
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
6 changed files with 1 additions and 126 deletions

View File

@ -1,61 +0,0 @@
/*
* 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.fixes.minecraft.entity;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import de.florianmichael.viafabricplus.settings.impl.DebugSettings;
import net.minecraft.block.entity.LockableContainerBlockEntity;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.raphimc.vialoader.util.VersionEnum;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
@Mixin(LockableContainerBlockEntity.class)
public abstract class MixinLockableContainerBlockEntity {
/*
Workaround for https://github.com/ViaVersion/ViaFabricPlus/issues/223
TODO | The problem:
ViaVersion rewrites components in all protocols not really well, which also leads to some other issues
(see to-do list and https://github.com/ViaVersion/ViaVersion/issues/3413), some servers send custom names as json
which the old 1.12.2 client could read, but modern versions can't anymore, we have to implement the component rewriting in ViaVersion completely for all
protocols so that this issue can be fixed properly, but since nobody will probably do that in the near future,
this fix, so that you can at least see / join the world.
*/
@WrapOperation(method = "readNbt", at = @At(value = "INVOKE", target = "Lnet/minecraft/text/Text$Serialization;fromJson(Ljava/lang/String;)Lnet/minecraft/text/MutableText;"))
private MutableText allowInvalidJson(String json, Operation<MutableText> operation) {
if (DebugSettings.global().skipContainersWithCustomDisplayNames.isEnabled()) {
try {
return operation.call(json);
} catch (Exception e) { // In case the json is invalid for the modern client, we just return the raw json
return Text.literal(json);
}
}
return operation.call(json);
}
}

View File

@ -20,8 +20,8 @@
package de.florianmichael.viafabricplus.injection.mixin.fixes.viaversion;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.libs.mcstructs.snbt.SNbtSerializer;
import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.ChatItemRewriter;
import net.lenni0451.mcstructs.snbt.SNbtSerializer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

View File

@ -1,60 +0,0 @@
/*
* 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.fixes.viaversion;
import com.viaversion.viaversion.libs.gson.JsonElement;
import com.viaversion.viaversion.libs.gson.JsonNull;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.util.ComponentConverter;
import net.lenni0451.mcstructs.text.ATextComponent;
import net.lenni0451.mcstructs.text.serializer.TextComponentCodec;
import net.lenni0451.mcstructs.text.serializer.TextComponentSerializer;
import net.raphimc.vialegacy.api.util.converter.JsonConverter;
import net.raphimc.vialegacy.api.util.converter.NbtConverter;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
@Mixin(value = ComponentConverter.class, remap = false)
public abstract class MixinComponentConverter {
/**
* @author RK_01
* @reason Replace code with a proper conversion
*/
@Overwrite
public static JsonElement tagComponentToJson(final Tag tag) {
final ATextComponent textComponent = TextComponentCodec.V1_20_3.deserializeNbtTree(NbtConverter.viaToMcStructs(tag));
if (textComponent == null) return JsonNull.INSTANCE;
return JsonConverter.gsonToVia(TextComponentSerializer.V1_19_4.serializeJson(textComponent));
}
/**
* @author RK_01
* @reason Replace code with a proper conversion
*/
@Overwrite
public static Tag jsonComponentToTag(final JsonElement component) {
final ATextComponent textComponent = TextComponentSerializer.V1_19_4.deserialize(JsonConverter.viaToGson(component));
if (textComponent == null) return null;
return NbtConverter.mcStructsToVia(TextComponentCodec.V1_20_3.serializeNbt(textComponent));
}
}

View File

@ -40,7 +40,6 @@ public class DebugSettings extends SettingGroup {
// 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));
public final VersionedBooleanSetting skipContainersWithCustomDisplayNames = new VersionedBooleanSetting(this, Text.translatable("debug_settings.viafabricplus.skip_containers_with_custom_display_names"), VersionRange.andOlder(VersionEnum.r1_12_2));
// 1.12 -> 1.11.1-1.11.2
public final VersionedBooleanSetting sendOpenInventoryPacket = new VersionedBooleanSetting(this, Text.translatable("debug_settings.viafabricplus.send_open_inventory_packet"), VersionRange.andOlder(VersionEnum.r1_11_1to1_11_2));

View File

@ -59,7 +59,6 @@
"debug_settings.viafabricplus.replace_sneaking": "Replace sneaking",
"debug_settings.viafabricplus.long_sneaking": "Long sneaking",
"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",

View File

@ -102,7 +102,6 @@
"fixes.minecraft.entity.MixinEntityRenderDispatcher",
"fixes.minecraft.entity.MixinItemEntity",
"fixes.minecraft.entity.MixinLivingEntity",
"fixes.minecraft.entity.MixinLockableContainerBlockEntity",
"fixes.minecraft.entity.MixinOtherClientPlayerEntity",
"fixes.minecraft.entity.MixinPlayerEntity",
"fixes.minecraft.entity.MixinPlayerEntityRenderer",
@ -171,7 +170,6 @@
"fixes.viaversion.MixinChatItemRewriter",
"fixes.viaversion.MixinCommandBlockProvider",
"fixes.viaversion.MixinCommonBoss",
"fixes.viaversion.MixinComponentConverter",
"fixes.viaversion.MixinEntityIdRewriter",
"fixes.viaversion.MixinEntityPackets1_17",
"fixes.viaversion.MixinEntityPackets1_19_4",