Skip to content

Commit

Permalink
Wait for ViaVersion fixes
Browse files Browse the repository at this point in the history
Latest via build has many bugs
  • Loading branch information
Aspw-w committed Apr 6, 2024
1 parent 7ee8d5d commit 22778f4
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 30 deletions.
7 changes: 6 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def viaLibs = [
"com.viaversion:viaversion:${project.viaversion_version}",
"com.viaversion:viabackwards:${project.viabackwards_version}",
"com.viaversion:viarewind-universal:${project.viarewind_version}",
"net.raphimc:ViaLoader:${project.vialoader_version}"
"net.raphimc:ViaLoader:${project.vialoader_version}",
"net.raphimc:ViaAprilFools:${project.viaaprilfools_version}"
]

dependencies {
Expand All @@ -71,6 +72,10 @@ dependencies {
include(via)
}

include ("net.raphimc:ViaLegacy:${project.vialegacy_version}") {
exclude group: "com.google.code.gson", module: "gson"
}

include('com.github.half-cambodian-hacker-man:Koffee:d8cee73') {
exclude module: 'asm-commons'
exclude module: 'asm-tree'
Expand Down
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ mixingradle_version = ae2a80e
viaversion_version=4.10.0-24w09a-SNAPSHOT
viabackwards_version=4.10.0-24w09a-SNAPSHOT
viarewind_version=3.0.7-24w09a-SNAPSHOT
vialoader_version=2.2.13-SNAPSHOT
vialoader_version=2.2.13-SNAPSHOT
vialegacy_version=2.2.22-SNAPSHOT
viaaprilfools_version=2.0.11-SNAPSHOT
21 changes: 2 additions & 19 deletions src/main/java/net/aspw/client/Launch.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.aspw.client

import com.viaversion.viaversion.api.protocol.version.ProtocolVersion
import net.aspw.client.config.FileManager
import net.aspw.client.event.ClientShutdownEvent
import net.aspw.client.event.EventManager
Expand All @@ -25,16 +24,15 @@ import net.aspw.client.utils.ClassUtils.hasForge
import net.aspw.client.utils.misc.sound.TipSoundManager
import net.aspw.client.visual.client.clickgui.dropdown.ClickGui
import net.aspw.client.visual.font.semi.Fonts
import net.raphimc.vialoader.util.ProtocolVersionList

object Launch {

// Client information
const val CLIENT_BEST = "NightX"
const val CLIENT_FOLDER = "NightX-Client"
const val CLIENT_VERSION = "B105"
const val CLIENT_VERSION = "B106"
const val CLIENT_CHAT = "§c$CLIENT_BEST: §r"
const val CLIENT_PROTOCOL_RANGE = "1.8 to 1.20.4"
const val CLIENT_PROTOCOL_RANGE = "1.7.2 to 1.20.4"

var isStarting = false

Expand All @@ -57,9 +55,6 @@ object Launch {
// Discord RPC
lateinit var discordRPC: DiscordRPC

// ViaVersion
var versions = mutableListOf<ProtocolVersion>()

/**
* Execute if client will be started
*/
Expand All @@ -72,18 +67,6 @@ object Launch {

ProtocolBase.init(ProtocolMod.PLATFORM)

versions.addAll(ProtocolVersionList.getProtocolsNewToOld())

try {
for (i in versions) {
if (i == ProtocolVersion.unknown || i == ProtocolVersion.v1_20_5) {
versions.remove(i)
ClientUtils.getLogger().info("Removed Unknown Protocols ($i)")
}
}
} catch (_: Exception) {
}

// Check update
APIConnecter.checkStaffList()
APIConnecter.checkStatus()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package net.aspw.client.injection.forge.mixins.client;

import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import net.aspw.client.Launch;
import net.aspw.client.event.*;
import net.aspw.client.features.module.impl.other.FastPlace;
import net.aspw.client.injection.forge.mixins.accessors.MinecraftForgeClientAccessor;
import net.aspw.client.protocol.ProtocolBase;
import net.aspw.client.protocol.api.ProtocolFixes;
import net.aspw.client.utils.CPSCounter;
import net.aspw.client.utils.MinecraftInstance;
Expand Down Expand Up @@ -268,7 +270,7 @@ private void sendClickBlockToController(boolean leftClick) {
if (leftClick && this.objectMouseOver != null && this.objectMouseOver.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
BlockPos blockPos = this.objectMouseOver.getBlockPos();

if (this.thePlayer.isUsingItem())
if (this.thePlayer.isUsingItem() && ProtocolBase.getManager().getTargetVersion().newerThanOrEqualTo(ProtocolVersion.v1_8))
return;

if (this.leftClickCounter == 0)
Expand Down
31 changes: 27 additions & 4 deletions src/main/java/net/aspw/client/protocol/ProtocolBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@
import net.aspw.client.protocol.api.*;
import net.aspw.client.utils.ClientUtils;
import net.raphimc.vialoader.ViaLoader;
import net.raphimc.vialoader.impl.platform.ViaBackwardsPlatformImpl;
import net.raphimc.vialoader.impl.platform.ViaRewindPlatformImpl;
import net.raphimc.vialoader.impl.platform.ViaVersionPlatformImpl;
import net.raphimc.vialoader.impl.platform.*;
import net.raphimc.vialoader.netty.CompressionReorderEvent;
import net.raphimc.vialoader.util.ProtocolVersionList;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ProtocolBase {

private ProtocolVersion targetVersion = ProtocolVersion.v1_8;
public static final AttributeKey<UserConnection> LOCAL_VIA_USER = AttributeKey.valueOf("local_via_user");
public static final AttributeKey<VFNetworkManager> VF_NETWORK_MANAGER = AttributeKey.valueOf("encryption_setup");
private static ProtocolBase manager;
public static List<ProtocolVersion> versions = new ArrayList<>();

public ProtocolBase() {
}
Expand All @@ -30,9 +34,28 @@ public static void init(final VFPlatform platform) {
return;
}

final ProtocolVersion version = ProtocolVersion.getProtocol(platform.getGameVersion());

if (version == ProtocolVersion.unknown)
throw new IllegalArgumentException("Unknown Protocol Found (" + platform.getGameVersion() + ")");

manager = new ProtocolBase();

ViaLoader.init(new ViaVersionPlatformImpl(null), new ProtocolVLLoader(platform), new ProtocolVLInjector(), null, ViaBackwardsPlatformImpl::new, ViaRewindPlatformImpl::new, null, null);
ViaLoader.init(new ViaVersionPlatformImpl(null), new ProtocolVLLoader(platform), new ProtocolVLInjector(), null, ViaBackwardsPlatformImpl::new, ViaRewindPlatformImpl::new, ViaLegacyPlatformImpl::new, ViaAprilFoolsPlatformImpl::new);

versions.addAll(ProtocolVersionList.getProtocolsNewToOld());

try {
Iterator<ProtocolVersion> iterator = versions.iterator();
while (iterator.hasNext()) {
ProtocolVersion i = iterator.next();
if (i == ProtocolVersion.unknown || i.olderThan(ProtocolVersion.v1_7_2) || i == ProtocolVersion.v1_20_5) {
iterator.remove();
ClientUtils.getLogger().info("Removed Protocol (" + i + ")");
}
}
} catch (Exception ignored) {
}

ClientUtils.getLogger().info("ViaVersion Injected");
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/net/aspw/client/protocol/ProtocolMod.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package net.aspw.client.protocol;

import net.aspw.client.protocol.api.VFPlatform;
import net.minecraft.realms.RealmsSharedConstants;
import net.minecraftforge.fml.common.Mod;

@Mod(modid = "NightX", version = "Release")
public class ProtocolMod implements VFPlatform {

public static final ProtocolMod PLATFORM = new ProtocolMod();

@Override
public int getGameVersion() {
return RealmsSharedConstants.NETWORK_PROTOCOL_VERSION;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.mojang.realmsclient.gui.ChatFormatting;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import net.aspw.client.Launch;
import net.aspw.client.protocol.ProtocolBase;
import net.aspw.client.visual.font.smooth.FontLoaders;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -75,12 +74,12 @@ public SlotList(Minecraft client, int width, int height, int top, int bottom, in

@Override
protected int getSize() {
return Launch.INSTANCE.getVersions().size() - 2;
return ProtocolBase.versions.size();
}

@Override
protected void elementClicked(int index, boolean b, int i1, int i2) {
finishedCallback.finished(Launch.INSTANCE.getVersions().get(index), parent);
finishedCallback.finished(ProtocolBase.versions.get(index), parent);
}

@Override
Expand All @@ -96,7 +95,7 @@ protected void drawBackground() {
@Override
protected void drawSlot(int index, int x, int y, int slotHeight, int mouseX, int mouseY) {
final ProtocolVersion targetVersion = ProtocolBase.getManager().getTargetVersion();
final ProtocolVersion version = Launch.INSTANCE.getVersions().get(index);
final ProtocolVersion version = ProtocolBase.versions.get(index);

String color;
if (targetVersion == version) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/aspw/client/protocol/api/VFPlatform.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package net.aspw.client.protocol.api;

public interface VFPlatform {

int getGameVersion();
}

0 comments on commit 22778f4

Please sign in to comment.