Skip to content

Commit

Permalink
chore(ViaFabricPlus): bump dependency (#5167)
Browse files Browse the repository at this point in the history
Uses ViaFabricPlus 4.0.0 now.
  • Loading branch information
1zun4 authored Jan 2, 2025
1 parent 05c6337 commit 97bf05c
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 39 deletions.
8 changes: 7 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ dependencies {
modRuntimeOnly "com.terraformersmc:modmenu:${project.mod_menu_version}"
modImplementation "maven.modrinth:sodium:${project.sodium_version}"
modImplementation "maven.modrinth:lithium:${project.lithium_version}"
modImplementation "de.florianmichael:ViaFabricPlus:${project.viafabricplus_version}"

// ViaFabricPlus
modImplementation "com.viaversion:viafabricplus-api:${project.viafabricplus_version}"
modRuntimeOnly "com.viaversion:viafabricplus:${project.viafabricplus_version}"

// Minecraft Authlib
includeDependency ("com.github.CCBlueX:mc-authlib:${project.mc_authlib_version}") {
Expand Down Expand Up @@ -181,6 +184,9 @@ dependencies {
testImplementation "org.junit.jupiter:junit-jupiter:5.11.3"
testRuntimeOnly "org.junit.platform:junit-platform-launcher"

// Fix nullable annotations
compileOnly "com.google.code.findbugs:jsr305:3.0.2"

afterEvaluate {
configurations.includeDependency.incoming.resolutionResult.allDependencies.each {
dependencies.include(dependencies.implementation(dependencies.compileOnlyApi(it.requested.toString()) {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ mc_authlib_version=1.4.1
mod_menu_version=13.0.0-beta.1
sodium_version=mc1.21.4-0.6.5-fabric
lithium_version=mc1.21.4-0.14.3-fabric
viafabricplus_version=3.6.1
viafabricplus_version=4.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

import javax.annotation.Nullable;

import static net.ccbluex.liquidbounce.utils.client.ProtocolUtilKt.getHasProtocolTranslator;
import static net.ccbluex.liquidbounce.utils.client.ProtocolUtilKt.getUsesViaFabricPlus;

@Mixin(MinecraftClient.class)
public abstract class MixinMinecraftClient {
Expand Down Expand Up @@ -182,7 +182,7 @@ private void getClientTitle(CallbackInfoReturnable<String> callback) {
titleBuilder.append(" | ");

// ViaFabricPlus compatibility
if (getHasProtocolTranslator()) {
if (getUsesViaFabricPlus()) {
var protocolVersion = VfpCompatibility.INSTANCE.unsafeGetProtocolVersion();

if (protocolVersion != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@

package net.ccbluex.liquidbounce.utils.client.vfp;

import com.viaversion.viafabricplus.ViaFabricPlus;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.protocol.version.VersionType;
import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator;
import de.florianmichael.viafabricplus.screen.base.ProtocolSelectionScreen;
import net.ccbluex.liquidbounce.LiquidBounce;
import net.ccbluex.liquidbounce.utils.client.ClientProtocolVersion;
import net.minecraft.client.MinecraftClient;
Expand All @@ -42,7 +41,7 @@ public enum VfpCompatibility {

public ClientProtocolVersion unsafeGetProtocolVersion() {
try {
ProtocolVersion version = ProtocolTranslator.getTargetVersion();
ProtocolVersion version = ViaFabricPlus.getImpl().getTargetVersion();
return new ClientProtocolVersion(version.getName(), version.getVersion());
} catch (Throwable throwable) {
LiquidBounce.INSTANCE.getLogger().error("Failed to get protocol version", throwable);
Expand Down Expand Up @@ -73,7 +72,7 @@ public void unsafeOpenVfpProtocolSelection() {
currentScreen = new TitleScreen();
}

ProtocolSelectionScreen.INSTANCE.open(currentScreen);
ViaFabricPlus.getImpl().openProtocolSelectionScreen(currentScreen);
} catch (Throwable throwable) {
LiquidBounce.INSTANCE.getLogger().error("Failed to open ViaFabricPlus screen", throwable);
}
Expand All @@ -86,15 +85,15 @@ public void unsafeSelectProtocolVersion(int protocolId) {
}

ProtocolVersion version = ProtocolVersion.getProtocol(protocolId);
ProtocolTranslator.setTargetVersion(version);
ViaFabricPlus.getImpl().setTargetVersion(version);
} catch (Throwable throwable) {
LiquidBounce.INSTANCE.getLogger().error("Failed to select protocol version", throwable);
}
}

public boolean isEqual1_8() {
try {
var version = ProtocolTranslator.getTargetVersion();
var version = ViaFabricPlus.getImpl().getTargetVersion();

// Check if the version is equal to 1.8
return version.equalTo(ProtocolVersion.v1_8);
Expand All @@ -106,7 +105,7 @@ public boolean isEqual1_8() {

public boolean isOlderThanOrEqual1_8() {
try {
var version = ProtocolTranslator.getTargetVersion();
var version = ViaFabricPlus.getImpl().getTargetVersion();

// Check if the version is older or equal than 1.8
return version.olderThanOrEqualTo(ProtocolVersion.v1_8);
Expand All @@ -118,7 +117,7 @@ public boolean isOlderThanOrEqual1_8() {

public boolean isOlderThanOrEqual1_7_10() {
try {
var version = ProtocolTranslator.getTargetVersion();
var version = ViaFabricPlus.getImpl().getTargetVersion();

// Check if the version is older or equal than 1.7.10
return version.olderThanOrEqualTo(ProtocolVersion.v1_7_6);
Expand All @@ -130,7 +129,7 @@ public boolean isOlderThanOrEqual1_7_10() {

public boolean isNewerThanOrEqual1_16() {
try {
var version = ProtocolTranslator.getTargetVersion();
var version = ViaFabricPlus.getImpl().getTargetVersion();

// Check if the version is older or equal than 1.12.2
return version.newerThanOrEqualTo(ProtocolVersion.v1_16);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

package net.ccbluex.liquidbounce.utils.client.vfp;

import com.viaversion.viafabricplus.ViaFabricPlus;
import com.viaversion.viaversion.api.minecraft.BlockPosition;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
Expand All @@ -30,8 +31,6 @@

import java.util.function.Consumer;

import static de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator.getPlayNetworkUserConnection;

/**
* Compatibility layer for ViaFabricPlus on protocol 1.8
* <p>
Expand Down Expand Up @@ -61,7 +60,7 @@ private void writePacket(ServerboundPacketType packetType, Consumer<PacketWrappe
throw new IllegalStateException("Not on 1.8 protocol");
}

var packet = PacketWrapper.create(packetType, getPlayNetworkUserConnection());
var packet = PacketWrapper.create(packetType, ViaFabricPlus.getImpl().getPlayNetworkUserConnection());
writer.accept(packet);
packet.sendToServerRaw();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ object TranslationSignExploit : Choice("TranslationSign") {
val original = event.packet

if (original is UpdateSignC2SPacket) {
if (!hasProtocolTranslator) {
if (!usesViaFabricPlus) {
chat(markAsError(ModuleServerCrasher.message("signExploit.missingProtocolTranslator")))
return@handler
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ import net.ccbluex.liquidbounce.features.module.modules.player.invcleaner.Hotbar
import net.ccbluex.liquidbounce.features.module.modules.player.invcleaner.ItemSlot
import net.ccbluex.liquidbounce.features.module.modules.player.invcleaner.OffHandSlot
import net.ccbluex.liquidbounce.utils.client.Chronometer
import net.ccbluex.liquidbounce.utils.client.hasProtocolTranslator
import net.ccbluex.liquidbounce.utils.client.isNewerThanOrEquals1_16
import net.ccbluex.liquidbounce.utils.client.usesViaFabricPlus
import net.ccbluex.liquidbounce.utils.inventory.*
import net.ccbluex.liquidbounce.utils.item.findInventorySlot
import net.minecraft.component.DataComponentTypes
Expand Down Expand Up @@ -93,7 +93,7 @@ object ModuleOffhand : ClientModule("Offhand", Category.PLAYER, aliases = arrayO
tree(Gapple)
tree(Strength)

if (!hasProtocolTranslator) {
if (!usesViaFabricPlus) {
switchMode = enumChoice("SwitchMode", SwitchMode.SWITCH)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import com.google.gson.JsonObject
import io.netty.handler.codec.http.FullHttpResponse
import net.ccbluex.liquidbounce.LiquidBounce
import net.ccbluex.liquidbounce.api.services.client.ClientUpdate.update
import net.ccbluex.liquidbounce.utils.client.hasProtocolTranslator
import net.ccbluex.liquidbounce.utils.client.inGame
import net.ccbluex.liquidbounce.utils.client.mc
import net.ccbluex.liquidbounce.utils.client.usesViaFabricPlus
Expand All @@ -46,7 +45,7 @@ fun getClientInfo(requestObject: RequestObject) = httpOk(JsonObject().apply {
addProperty("gameDir", mc.runDirectory.path)
addProperty("inGame", inGame)
addProperty("viaFabricPlus", usesViaFabricPlus)
addProperty("hasProtocolHack", hasProtocolTranslator)
addProperty("hasProtocolHack", usesViaFabricPlus)
})

// GET /api/v1/client/update
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,24 @@
package net.ccbluex.liquidbounce.utils.client

import com.mojang.blaze3d.systems.RenderSystem
import com.viaversion.viafabricplus.ViaFabricPlus
import net.ccbluex.liquidbounce.utils.client.vfp.VfpCompatibility
import net.ccbluex.liquidbounce.utils.client.vfp.VfpCompatibility1_8
import net.minecraft.SharedConstants
import net.minecraft.util.math.BlockPos

// Only runs once
val usesViaFabricPlus = runCatching {
Class.forName("de.florianmichael.viafabricplus.ViaFabricPlus")
true
}.getOrDefault(false)
Class.forName("com.viaversion.viafabricplus.ViaFabricPlus")

// Register ViaFabricPlus protocol version change callback
ViaFabricPlus.getImpl().registerOnChangeProtocolVersionCallback { _, _ ->
// Update the window title
RenderSystem.recordRenderCall {
mc.updateWindowTitle()
}
}

val hasProtocolTranslator = runCatching {
Class.forName("de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator")
true
}.getOrDefault(false)

Expand All @@ -46,7 +51,7 @@ val defaultProtocolVersion = ClientProtocolVersion(SharedConstants.getGameVersio
val protocolVersion: ClientProtocolVersion
get() = runCatching {
// Check if the ViaFabricPlus mod is loaded - prevents from causing too many exceptions
if (hasProtocolTranslator) {
if (usesViaFabricPlus) {
return@runCatching VfpCompatibility.INSTANCE.unsafeGetProtocolVersion()
} else {
return@runCatching defaultProtocolVersion
Expand All @@ -58,7 +63,7 @@ val protocolVersion: ClientProtocolVersion
val protocolVersions: Array<ClientProtocolVersion>
get() = runCatching {
// Check if the ViaFabricPlus mod is loaded - prevents from causing too many exceptions
if (hasProtocolTranslator) {
if (usesViaFabricPlus) {
return@runCatching VfpCompatibility.INSTANCE.unsafeGetProtocolVersions()
} else {
return@runCatching arrayOf(defaultProtocolVersion)
Expand All @@ -72,44 +77,39 @@ data class ClientProtocolVersion(val name: String, val version: Int)
val isEqual1_8: Boolean
get() = runCatching {
// Check if the ViaFabricPlus mod is loaded - prevents from causing too many exceptions
hasProtocolTranslator && VfpCompatibility.INSTANCE.isEqual1_8
usesViaFabricPlus && VfpCompatibility.INSTANCE.isEqual1_8
}.onFailure {
logger.error("Failed to check if the server is using old combat", it)
}.getOrDefault(false)

val isOlderThanOrEqual1_8: Boolean
get() = runCatching {
// Check if the ViaFabricPlus mod is loaded - prevents from causing too many exceptions
hasProtocolTranslator && VfpCompatibility.INSTANCE.isOlderThanOrEqual1_8
usesViaFabricPlus && VfpCompatibility.INSTANCE.isOlderThanOrEqual1_8
}.onFailure {
logger.error("Failed to check if the server is using old combat", it)
}.getOrDefault(false)

val isOlderThanOrEquals1_7_10: Boolean
get() = runCatching {
// Check if the ViaFabricPlus mod is loaded - prevents from causing too many exceptions
hasProtocolTranslator && VfpCompatibility.INSTANCE.isOlderThanOrEqual1_7_10
usesViaFabricPlus && VfpCompatibility.INSTANCE.isOlderThanOrEqual1_7_10
}.onFailure {
logger.error("Failed to check if the server is using 1.7.10", it)
}.getOrDefault(false)

val isNewerThanOrEquals1_16: Boolean
get() = runCatching {
// Check if the ViaFabricPlus mod is loaded - prevents from causing too many exceptions
hasProtocolTranslator && VfpCompatibility.INSTANCE.isNewerThanOrEqual1_16
usesViaFabricPlus && VfpCompatibility.INSTANCE.isNewerThanOrEqual1_16
}.onFailure {
logger.error("Failed to check if the server is using 1.16+", it)
}.getOrDefault(false)

fun selectProtocolVersion(protocolId: Int) {
// Check if the ViaFabricPlus mod is loaded - prevents from causing too many exceptions
if (hasProtocolTranslator) {
if (usesViaFabricPlus) {
VfpCompatibility.INSTANCE.unsafeSelectProtocolVersion(protocolId)

// Update the window title
RenderSystem.recordRenderCall {
mc.updateWindowTitle()
}
} else {
error("ViaFabricPlus is not loaded")
}
Expand All @@ -126,7 +126,7 @@ fun openVfpProtocolSelection() {
}

fun sendSignUpdate(blockPos: BlockPos, lines: Array<String>) {
require(hasProtocolTranslator) { "ProtocolTranslator is missing" }
require(usesViaFabricPlus) { "ViaFabricPlus is missing" }
require(isEqual1_8) { "Not 1.8 protocol" }

VfpCompatibility1_8.INSTANCE.sendSignUpdate(blockPos, lines)
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,8 @@
"fabric": ">=${fabric_version}",
"viafabricplus": ">=${viafabricplus_version}"
},
"breaks": {
"viafabricplus": "<${viafabricplus_version}"
},
"accessWidener": "liquidbounce.accesswidener"
}

0 comments on commit 97bf05c

Please sign in to comment.