Merge branch 'refs/heads/dev'

This commit is contained in:
FlorianMichael 2024-06-16 18:21:48 +02:00
commit 127e7ed9e2
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
116 changed files with 2279 additions and 198 deletions

View File

@ -25,7 +25,6 @@ body:
description: |
If you encounter warnings/errors in your console, **paste them with https://mclo.gs/ and put the paste link here**.
If the error is small/less than 10 lines, you may put it directly into this field.
Please use Not Enough Crashes if possible, making the stacktrace easier to understand.
value: |
```
Put the mclo.gs link or text here.
@ -72,9 +71,9 @@ body:
attributes:
label: Additional Server Info
description: |
Does the server use a proxy (eg. BungeeCord)? What software are used and what plugins/mods (Check with F3 debug menu)? Are you using client-side mode?
Does the server use a proxy (eg. Velocity)? What software are used and what plugins/mods (Check with F3 debug menu)? Are you using client-side mode?
placeholder: |
Example: "I also use BungeeCord with the following plugins: x, y, z"
Example: "I also use Velocity with the following plugins: x, y, z"
validations:
required: false

View File

@ -10,7 +10,7 @@
Allows the connection to/from different Minecraft versions on your Minecraft client/server (LAN worlds too)
This mod can be installed on 1.8.9, 1.12.2, 1.14.4, 1.15.2, 1.16.5, 1.17.1, 1.18.2, 1.19.4, 1.20.1, 1.20.4, 1.20.6 with Fabric Loader.
This mod can be installed on 1.8.9, 1.12.2, 1.14.4, 1.15.2, 1.16.5, 1.17.1, 1.18.2, 1.19.4, 1.20.1, 1.20.4, 1.20.6, 1.21 with Fabric Loader.
## Dependencies
@ -40,6 +40,8 @@ registry synchronization (fabric-registry-sync mod).
optionally [ViaRewind](https://viaversion.com/rewind))**:
Your server can accept older versions. Your client can connect to newer versions.
Note: When using ViaFabric for versions older than 1.17, you need [Java 8 builds](https://ci.viaversion.com/)
- Server-side: See https://viaversion.com/
- Client-side:

View File

@ -14,6 +14,7 @@ plugins {
id "com.modrinth.minotaur" version "2.8.7"
id "fabric-loom" version "1.6-SNAPSHOT" apply false
id "com.github.ben-manes.versions" version "0.51.0"
id "xyz.wagyourtail.jvmdowngrader" version "0.6.1"
}
def ENV = System.getenv()
@ -129,17 +130,24 @@ subprojects.each {
remapJar.dependsOn("${it.path}:remapJar")
}
configurations {
includeJ8
}
jvmdg.dg(configurations.includeJ8)
dependencies {
// dummy version
minecraft("com.mojang:minecraft:1.14.4")
mappings("net.fabricmc:yarn:1.14.4+build.18:v2")
include("com.viaversion:viaversion:${rootProject.viaver_version}")
includeJ8("com.viaversion:viaversion:${rootProject.viaver_version}")
include("org.yaml:snakeyaml:${rootProject.yaml_version}")
include("com.github.TinfoilMC:ClientCommands:1.1.0")
}
remapJar {
nestedJars.from configurations.includeJ8
afterEvaluate {
subprojects.each {
nestedJars.from project("${it.path}").tasks.named("remapJar")
@ -166,7 +174,7 @@ processResources {
List<String> mcReleases = Arrays.stream(rootProject.publish_mc_versions.toString().split(","))
.map({ it -> it.trim() })
.collect(Collectors.toList())
List<String> javaVersions = IntStream.rangeClosed(8, 21)
List<String> javaVersions = IntStream.rangeClosed(8, 22)
.mapToObj { n -> (String) "Java $n" }
.collect(Collectors.toList())
String changelogMsg = "A changelog can be found at https://github.com/ViaVersion/ViaFabric/commits"

View File

@ -2,10 +2,10 @@
org.gradle.jvmargs=-Xms32M -Xmx4G -XX:+UseG1GC -XX:+UseStringDeduplication
loader_version=0.15.11
viaver_version=4.10.3-SNAPSHOT
viaver_version=5.0.0
yaml_version=2.2
publish_mc_versions=1.20.6, 1.20.4, 1.20.1, 1.19.4, 1.18.2, 1.17.1, 1.16.5, 1.15.2, 1.14.4, 1.12.2, 1.8.9
publish_mc_versions=1.21, 1.20.6, 1.20.4, 1.20.1, 1.19.4, 1.18.2, 1.17.1, 1.16.5, 1.15.2, 1.14.4, 1.12.2, 1.8.9
# example: 1.19.1-rc1. Can be a blank value
modrinth_mc_snapshot=
# example: 1.19-Snapshot. Can be a blank value

6
gradlew vendored
View File

@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#
##############################################################################
#
@ -200,7 +202,7 @@ fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
DEFAULT_JVM_OPTS='-Dfile.encoding=UTF-8 "-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
@ -246,4 +248,4 @@ eval "set -- $(
tr '\n' ' '
)" '"$@"'
exec "$JAVACMD" "$@"
exec "$JAVACMD" "$@"

6
gradlew.bat vendored
View File

@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@ -34,7 +36,7 @@ set APP_HOME=%DIRNAME%
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
set DEFAULT_JVM_OPTS=-Dfile.encoding=UTF-8 "-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
@ -89,4 +91,4 @@ exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
:omega

View File

@ -1,6 +1,7 @@
pluginManagement {
repositories {
gradlePluginPortal()
mavenCentral()
maven ("https://maven.fabricmc.net/")
}
}
@ -18,6 +19,7 @@ include("viafabric-mc1194")
include("viafabric-mc1201")
include("viafabric-mc1204")
include("viafabric-mc1206")
include("viafabric-mc121")
plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"

View File

@ -25,7 +25,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class LeakDetectSubCommand extends ViaSubCommand {
public class LeakDetectSubCommand implements ViaSubCommand {
@Override
public String name() {
return "leakdetect";
@ -60,6 +60,6 @@ public class LeakDetectSubCommand extends ViaSubCommand {
.filter(it -> it.startsWith(args[0]))
.collect(Collectors.toList());
}
return super.onTabComplete(sender, args);
return ViaSubCommand.super.onTabComplete(sender, args);
}
}

View File

@ -25,15 +25,17 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
public class VFConfig extends Config {
public static final String ENABLE_CLIENT_SIDE = "enable-client-side";
public static final String CLIENT_SIDE_VERSION = "client-side-version";
public static final String CLIENT_SIDE_FORCE_DISABLE = "client-side-force-disable";
public static final String HIDE_BUTTON = "hide-button";
public static final String IGNORE_REGISTRY_SYNC_ERRORS = "ignore-registry-sync-errors";
public VFConfig(File configFile) {
super(configFile);
public VFConfig(File configFile, Logger logger) {
super(configFile, logger);
reload();
}
@ -82,4 +84,8 @@ public class VFConfig extends Config {
public boolean isForcedDisable(String line) {
return getClientSideForceDisable().contains(line);
}
public boolean isIgnoreRegistrySyncErrors() {
return getBoolean(IGNORE_REGISTRY_SYNC_ERRORS, false);
}
}

View File

@ -84,7 +84,7 @@ public class FabricDecodeHandler extends MessageToMessageDecoder<ByteBuf> {
super.exceptionCaught(ctx, cause);
if ((PipelineUtil.containsCause(cause, InformativeException.class)
&& info.getProtocolInfo().getState() != State.HANDSHAKE)
&& info.getProtocolInfo().getServerState() != State.HANDSHAKE)
|| Via.getManager().debugHandler().enabled()) {
cause.printStackTrace();
}

View File

@ -24,16 +24,16 @@ import java.net.URL;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
public class FabricViaConfig extends AbstractViaConfig {
// Based on Sponge ViaVersion
private static final List<String> UNSUPPORTED = Arrays.asList("anti-xray-patch", "bungee-ping-interval",
"bungee-ping-save", "bungee-servers", "quick-move-action-fix", "nms-player-ticking",
"velocity-ping-interval", "velocity-ping-save", "velocity-servers",
private static final List<String> UNSUPPORTED = Arrays.asList("anti-xray-patch", "quick-move-action-fix",
"nms-player-ticking", "velocity-ping-interval", "velocity-ping-save", "velocity-servers",
"blockconnection-method", "change-1_9-hitbox", "change-1_14-hitbox");
public FabricViaConfig(File configFile) {
super(configFile);
public FabricViaConfig(File configFile, Logger logger) {
super(configFile, logger);
// Load config
reload();
}

View File

@ -24,6 +24,7 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.protocols.base.ServerboundHandshakePackets;
public class HostnameParserProtocol extends AbstractSimpleProtocol {
@ -34,8 +35,8 @@ public class HostnameParserProtocol extends AbstractSimpleProtocol {
registerServerbound(State.HANDSHAKE, ServerboundHandshakePackets.CLIENT_INTENTION.getId(), ServerboundHandshakePackets.CLIENT_INTENTION.getId(), new PacketHandlers() {
@Override
protected void register() {
map(Type.VAR_INT); // Protocol version
map(Type.STRING, new ValueTransformer<String, String>(Type.STRING) {
map(Types.VAR_INT); // Protocol version
map(Types.STRING, new ValueTransformer<String, String>(Types.STRING) {
@Override
public String transform(PacketWrapper packetWrapper, String s) {
return new AddressParser().parse(s).serverAddress;

View File

@ -70,7 +70,7 @@ public abstract class AbstractFabricPlatform implements ViaPlatform<UserConnecti
installNativeVersionProvider();
Path configDir = FabricLoader.getInstance().getConfigDir().resolve("ViaFabric");
dataFolder = configDir.toFile();
config = new FabricViaConfig(configDir.resolve("viaversion.yml").toFile());
config = new FabricViaConfig(configDir.resolve("viaversion.yml").toFile(), logger);
}
protected abstract void installNativeVersionProvider();
@ -180,11 +180,6 @@ public abstract class AbstractFabricPlatform implements ViaPlatform<UserConnecti
return true;
}
@Override
public boolean isOldClientsAllowed() {
return true;
}
@Override
public JsonObject getDump() {
JsonObject platformSpecific = new JsonObject();

View File

@ -29,10 +29,11 @@ import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.exception.CancelException;
import com.viaversion.viaversion.protocol.version.BaseVersionProvider;
import com.viaversion.viaversion.protocols.base.BaseProtocol1_16;
import com.viaversion.viaversion.protocols.base.BaseProtocol1_7;
import com.viaversion.viaversion.protocols.base.BaseVersionProvider;
import com.viaversion.viaversion.protocols.base.ClientboundStatusPackets;
import io.netty.channel.ChannelPipeline;
import net.fabricmc.loader.api.FabricLoader;
@ -138,14 +139,14 @@ public abstract class AbstractFabricVersionProvider extends BaseVersionProvider
}
private void handleMulticonnectPing(UserConnection connection, ProtocolInfo info, boolean blocked, ProtocolVersion serverVer) throws Exception {
if (info.getState() == State.STATUS
if (info.getServerState() == State.STATUS
&& info.getProtocolVersion() == -1
&& isMulticonnectHandler(connection.getChannel().pipeline())
&& (blocked || ProtocolUtils.isSupported(serverVer, getVersionForMulticonnect(serverVer)))) { // Intercept the connection
ProtocolVersion multiconnectSuggestion = blocked ? ProtocolVersion.unknown : getVersionForMulticonnect(serverVer);
getLogger().info("Sending " + multiconnectSuggestion + " for multiconnect version detector");
PacketWrapper newAnswer = PacketWrapper.create(ClientboundStatusPackets.STATUS_RESPONSE, null, connection);
newAnswer.write(Type.STRING, "{\"version\":{\"name\":\"viafabric integration\",\"protocol\":" + multiconnectSuggestion.getVersion() + "}}");
newAnswer.write(Types.STRING, "{\"version\":{\"name\":\"viafabric integration\",\"protocol\":" + multiconnectSuggestion.getVersion() + "}}");
newAnswer.send(info.getPipeline().contains(BaseProtocol1_16.class) ? BaseProtocol1_16.class : BaseProtocol1_7.class);
throw CancelException.generate();
}

View File

@ -28,11 +28,6 @@ public class FutureTaskId implements PlatformTask<Future<?>> {
this.object = object;
}
@Override
public Future<?> getObject() {
return object;
}
@Override
public void cancel() {
object.cancel(false);

View File

@ -12,3 +12,6 @@ hide-button: false
# This isn't always the address in multiplayer menu; It will use the SRV record pointer when present, Check the game log for the address.
# Uses https://wiki.vg/Mojang_API#Blocked_Servers format (mc.example.com, *.example.com, 192.168.0.1, 192.168.*)
client-side-force-disable: ["hypixel.net", "*.hypixel.net", "minemen.club", "*.minemen.club", "icantjoinlmfao.club"]
# Fabric registry synchronization will be disabled when installed server-side and validation errors are ignored when installed on client-side.
# Note: this setting only works on 1.20.4+ ViaFabric versions, and it might cause issues, use with caution.
ignore-registry-sync-errors: false

View File

@ -13,8 +13,8 @@
},
"depends": {
"fabricloader": ">=0.14.0",
"minecraft": ["1.8.9", "1.12.2", "1.14.4", "1.15.2", "1.16.5", "1.17.1", "1.18.2", "1.19.4", "1.20.1", "1.20.3", "1.20.4", "1.20.5", "1.20.6"],
"viaversion": ">=4.10.0"
"minecraft": ["1.8.9", "1.12.2", "1.14.4", "1.15.2", "1.16.5", "1.17.1", "1.18.2", "1.19.4", "1.20.1", "1.20.3", "1.20.4", "1.20.5", "1.20.6", "1.21"],
"viaversion": ">=5.0.0"
},
"breaks": {
"viafabricplus": "*"

View File

@ -80,7 +80,7 @@ public class ViaFabric implements ModInitializer {
registerCommandsV1();
config = new VFConfig(FabricLoader.getInstance().getConfigDir().resolve("ViaFabric")
.resolve("viafabric.yml").toFile());
.resolve("viafabric.yml").toFile(), JLOGGER);
manager.onServerLoaded();

View File

@ -19,12 +19,12 @@ package com.viaversion.fabric.mc1122.platform;
import com.viaversion.fabric.mc1122.providers.VFHandItemProvider;
import com.viaversion.fabric.mc1122.providers.FabricVersionProvider;
import com.viaversion.viaversion.protocols.v1_8to1_9.provider.HandItemProvider;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.platform.ViaPlatformLoader;
import com.viaversion.viaversion.api.protocol.version.VersionProvider;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider;
public class VFLoader implements ViaPlatformLoader {
@Override

View File

@ -21,7 +21,7 @@ import com.viaversion.fabric.mc1122.ViaFabric;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider;
import com.viaversion.viaversion.protocols.v1_8to1_9.provider.HandItemProvider;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.legacyfabric.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
@ -45,16 +45,16 @@ public class VFHandItemProvider extends HandItemProvider {
if (info.isClientSide()) {
return getClientItem();
} else if ((serverItem = serverPlayers.get(info.getProtocolInfo().getUuid())) != null) {
return new DataItem(serverItem);
return serverItem.copy();
}
return super.getHandItem(info);
}
private Item getClientItem() {
if (clientItem == null) {
return new DataItem(0, (byte) 0, (short) 0, null);
return new DataItem(0, (byte) 0, null);
}
return new DataItem(clientItem);
return clientItem.copy();
}
@Environment(EnvType.CLIENT)

View File

@ -94,7 +94,7 @@ public class ViaFabric implements ModInitializer {
registerCommandsV1();
config = new VFConfig(FabricLoader.getInstance().getConfigDir().resolve("ViaFabric")
.resolve("viafabric.yml").toFile());
.resolve("viafabric.yml").toFile(), JLOGGER);
manager.onServerLoaded();

View File

@ -20,6 +20,7 @@ package com.viaversion.fabric.mc1144.mixin.debug.client;
import com.viaversion.fabric.common.handler.CommonTransformer;
import com.viaversion.fabric.common.handler.FabricDecodeHandler;
import com.viaversion.viaversion.api.connection.ProtocolInfo;
import com.viaversion.viaversion.api.connection.UserConnection;
import io.netty.channel.ChannelHandler;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.hud.DebugHud;
@ -41,11 +42,12 @@ public class MixinDebugHud {
@SuppressWarnings("ConstantConditions") ChannelHandler viaDecoder = ((MixinClientConnectionAccessor) MinecraftClient.getInstance().getNetworkHandler()
.getConnection()).getChannel().pipeline().get(CommonTransformer.HANDLER_DECODER_NAME);
if (viaDecoder instanceof FabricDecodeHandler) {
ProtocolInfo protocol = ((FabricDecodeHandler) viaDecoder).getInfo().getProtocolInfo();
UserConnection connection = ((FabricDecodeHandler) viaDecoder).getInfo();
ProtocolInfo protocol = connection.getProtocolInfo();
if (protocol != null) {
ProtocolVersion serverVer = ProtocolVersion.getProtocol(protocol.getServerProtocolVersion());
ProtocolVersion clientVer = ProtocolVersion.getProtocol(protocol.getProtocolVersion());
line += " / C: " + clientVer + " S: " + serverVer + " A: " + protocol.getUser().isActive();
ProtocolVersion serverVer = protocol.serverProtocolVersion();
ProtocolVersion clientVer = protocol.protocolVersion();
line += " / C: " + clientVer + " S: " + serverVer + " A: " + connection.isActive();
}
}

View File

@ -20,13 +20,13 @@ package com.viaversion.fabric.mc1144.platform;
import com.viaversion.fabric.mc1144.providers.VFHandItemProvider;
import com.viaversion.fabric.mc1144.providers.FabricVersionProvider;
import com.viaversion.fabric.mc1144.providers.VFPlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.PlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.provider.PlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.v1_8to1_9.provider.HandItemProvider;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.platform.ViaPlatformLoader;
import com.viaversion.viaversion.api.protocol.version.VersionProvider;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider;
public class VFLoader implements ViaPlatformLoader {
@Override

View File

@ -19,6 +19,7 @@ package com.viaversion.fabric.mc1144.providers;
import com.viaversion.fabric.common.util.RemappingUtil;
import com.viaversion.fabric.mc1144.ViaFabric;
import com.viaversion.viaversion.protocols.v1_8to1_9.provider.HandItemProvider;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
@ -30,9 +31,9 @@ import net.minecraft.util.Identifier;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider;
public class VFHandItemProvider extends HandItemProvider {
public class VFHandItemProvider extends HandItemProvider
{
public Item clientItem = null;
@Override
@ -45,9 +46,9 @@ public class VFHandItemProvider extends HandItemProvider {
private Item getClientItem() {
if (clientItem == null) {
return new DataItem(0, (byte) 0, (short) 0, null);
return new DataItem(0, (byte) 0, null);
}
return new DataItem(clientItem);
return clientItem.copy();
}
@Environment(EnvType.CLIENT)

View File

@ -18,8 +18,8 @@
package com.viaversion.fabric.mc1144.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.PlayerLookTargetProvider;
import com.viaversion.viaversion.api.minecraft.BlockPosition;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.provider.PlayerLookTargetProvider;
import net.minecraft.client.MinecraftClient;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
@ -28,13 +28,13 @@ import net.minecraft.util.math.BlockPos;
public class VFPlayerLookTargetProvider extends PlayerLookTargetProvider {
@Override
public Position getPlayerLookTarget(UserConnection info) {
public BlockPosition getPlayerLookTarget(UserConnection info) {
if (!info.isClientSide()) return null;
final HitResult crosshairTarget = MinecraftClient.getInstance().crosshairTarget;
if (crosshairTarget instanceof BlockHitResult) {
final BlockPos pos = ((BlockHitResult) crosshairTarget).getBlockPos();
return new Position(pos.getX(), pos.getY(), pos.getZ());
return new BlockPosition(pos.getX(), pos.getY(), pos.getZ());
}
return null;
}

View File

@ -94,7 +94,7 @@ public class ViaFabric implements ModInitializer {
registerCommandsV1();
config = new VFConfig(FabricLoader.getInstance().getConfigDir().resolve("ViaFabric")
.resolve("viafabric.yml").toFile());
.resolve("viafabric.yml").toFile(), JLOGGER);
manager.onServerLoaded();

View File

@ -20,6 +20,7 @@ package com.viaversion.fabric.mc1152.mixin.debug.client;
import com.viaversion.fabric.common.handler.CommonTransformer;
import com.viaversion.fabric.common.handler.FabricDecodeHandler;
import com.viaversion.viaversion.api.connection.ProtocolInfo;
import com.viaversion.viaversion.api.connection.UserConnection;
import io.netty.channel.ChannelHandler;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.hud.DebugHud;
@ -41,11 +42,12 @@ public class MixinDebugHud {
@SuppressWarnings("ConstantConditions") ChannelHandler viaDecoder = ((MixinClientConnectionAccessor) MinecraftClient.getInstance().getNetworkHandler()
.getConnection()).getChannel().pipeline().get(CommonTransformer.HANDLER_DECODER_NAME);
if (viaDecoder instanceof FabricDecodeHandler) {
ProtocolInfo protocol = ((FabricDecodeHandler) viaDecoder).getInfo().getProtocolInfo();
UserConnection connection = ((FabricDecodeHandler) viaDecoder).getInfo();
ProtocolInfo protocol = connection.getProtocolInfo();
if (protocol != null) {
ProtocolVersion serverVer = ProtocolVersion.getProtocol(protocol.getServerProtocolVersion());
ProtocolVersion clientVer = ProtocolVersion.getProtocol(protocol.getProtocolVersion());
line += " / C: " + clientVer + " S: " + serverVer + " A: " + protocol.getUser().isActive();
ProtocolVersion serverVer = protocol.serverProtocolVersion();
ProtocolVersion clientVer = protocol.protocolVersion();
line += " / C: " + clientVer + " S: " + serverVer + " A: " + connection.isActive();
}
}

View File

@ -20,13 +20,13 @@ package com.viaversion.fabric.mc1152.platform;
import com.viaversion.fabric.mc1152.providers.VFHandItemProvider;
import com.viaversion.fabric.mc1152.providers.FabricVersionProvider;
import com.viaversion.fabric.mc1152.providers.VFPlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.PlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.provider.PlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.v1_8to1_9.provider.HandItemProvider;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.platform.ViaPlatformLoader;
import com.viaversion.viaversion.api.protocol.version.VersionProvider;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider;
public class VFLoader implements ViaPlatformLoader {
@Override

View File

@ -22,7 +22,7 @@ import com.viaversion.fabric.mc1152.ViaFabric;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider;
import com.viaversion.viaversion.protocols.v1_8to1_9.provider.HandItemProvider;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
@ -45,9 +45,9 @@ public class VFHandItemProvider extends HandItemProvider {
private Item getClientItem() {
if (clientItem == null) {
return new DataItem(0, (byte) 0, (short) 0, null);
return new DataItem(0, (byte) 0, null);
}
return new DataItem(clientItem);
return clientItem.copy();
}
@Environment(EnvType.CLIENT)

View File

@ -18,8 +18,8 @@
package com.viaversion.fabric.mc1152.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.PlayerLookTargetProvider;
import com.viaversion.viaversion.api.minecraft.BlockPosition;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.provider.PlayerLookTargetProvider;
import net.minecraft.client.MinecraftClient;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
@ -28,13 +28,13 @@ import net.minecraft.util.math.BlockPos;
public class VFPlayerLookTargetProvider extends PlayerLookTargetProvider {
@Override
public Position getPlayerLookTarget(UserConnection info) {
public BlockPosition getPlayerLookTarget(UserConnection info) {
if (!info.isClientSide()) return null;
final HitResult crosshairTarget = MinecraftClient.getInstance().crosshairTarget;
if (crosshairTarget instanceof BlockHitResult) {
final BlockPos pos = ((BlockHitResult) crosshairTarget).getBlockPos();
return new Position(pos.getX(), pos.getY(), pos.getZ());
return new BlockPosition(pos.getX(), pos.getY(), pos.getZ());
}
return null;
}

View File

@ -96,7 +96,7 @@ public class ViaFabric implements ModInitializer {
registerCommandsV1();
config = new VFConfig(FabricLoader.getInstance().getConfigDir().resolve("ViaFabric")
.resolve("viafabric.yml").toFile());
.resolve("viafabric.yml").toFile(), JLOGGER);
manager.onServerLoaded();

View File

@ -20,6 +20,7 @@ package com.viaversion.fabric.mc1165.mixin.debug.client;
import com.viaversion.fabric.common.handler.CommonTransformer;
import com.viaversion.fabric.common.handler.FabricDecodeHandler;
import com.viaversion.viaversion.api.connection.ProtocolInfo;
import com.viaversion.viaversion.api.connection.UserConnection;
import io.netty.channel.ChannelHandler;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.hud.DebugHud;
@ -41,11 +42,12 @@ public class MixinDebugHud {
@SuppressWarnings("ConstantConditions") ChannelHandler viaDecoder = ((MixinClientConnectionAccessor) MinecraftClient.getInstance().getNetworkHandler()
.getConnection()).getChannel().pipeline().get(CommonTransformer.HANDLER_DECODER_NAME);
if (viaDecoder instanceof FabricDecodeHandler) {
ProtocolInfo protocol = ((FabricDecodeHandler) viaDecoder).getInfo().getProtocolInfo();
UserConnection connection = ((FabricDecodeHandler) viaDecoder).getInfo();
ProtocolInfo protocol = connection.getProtocolInfo();
if (protocol != null) {
ProtocolVersion serverVer = ProtocolVersion.getProtocol(protocol.getServerProtocolVersion());
ProtocolVersion clientVer = ProtocolVersion.getProtocol(protocol.getProtocolVersion());
line += " / C: " + clientVer + " S: " + serverVer + " A: " + protocol.getUser().isActive();
ProtocolVersion serverVer = protocol.serverProtocolVersion();
ProtocolVersion clientVer = protocol.protocolVersion();
line += " / C: " + clientVer + " S: " + serverVer + " A: " + connection.isActive();
}
}

View File

@ -21,14 +21,14 @@ import com.viaversion.fabric.mc1165.providers.VFHandItemProvider;
import com.viaversion.fabric.mc1165.providers.FabricVersionProvider;
import com.viaversion.fabric.mc1165.providers.VFPlayerAbilitiesProvider;
import com.viaversion.fabric.mc1165.providers.VFPlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.PlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.provider.PlayerAbilitiesProvider;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.provider.PlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.provider.PlayerAbilitiesProvider;
import com.viaversion.viaversion.protocols.v1_8to1_9.provider.HandItemProvider;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.platform.ViaPlatformLoader;
import com.viaversion.viaversion.api.protocol.version.VersionProvider;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider;
public class VFLoader implements ViaPlatformLoader {
@Override

View File

@ -22,7 +22,7 @@ import com.viaversion.fabric.mc1165.ViaFabric;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider;
import com.viaversion.viaversion.protocols.v1_8to1_9.provider.HandItemProvider;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
@ -45,9 +45,9 @@ public class VFHandItemProvider extends HandItemProvider {
private Item getClientItem() {
if (clientItem == null) {
return new DataItem(0, (byte) 0, (short) 0, null);
return new DataItem(0, (byte) 0, null);
}
return new DataItem(clientItem);
return clientItem.copy();
}
@Environment(EnvType.CLIENT)

View File

@ -18,7 +18,7 @@
package com.viaversion.fabric.mc1165.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.provider.PlayerAbilitiesProvider;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.provider.PlayerAbilitiesProvider;
import net.minecraft.client.MinecraftClient;
public class VFPlayerAbilitiesProvider extends PlayerAbilitiesProvider {

View File

@ -18,8 +18,8 @@
package com.viaversion.fabric.mc1165.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.PlayerLookTargetProvider;
import com.viaversion.viaversion.api.minecraft.BlockPosition;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.provider.PlayerLookTargetProvider;
import net.minecraft.client.MinecraftClient;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
@ -28,13 +28,13 @@ import net.minecraft.util.math.BlockPos;
public class VFPlayerLookTargetProvider extends PlayerLookTargetProvider {
@Override
public Position getPlayerLookTarget(UserConnection info) {
public BlockPosition getPlayerLookTarget(UserConnection info) {
if (!info.isClientSide()) return null;
final HitResult crosshairTarget = MinecraftClient.getInstance().crosshairTarget;
if (crosshairTarget instanceof BlockHitResult) {
final BlockPos pos = ((BlockHitResult) crosshairTarget).getBlockPos();
return new Position(pos.getX(), pos.getY(), pos.getZ());
return new BlockPosition(pos.getX(), pos.getY(), pos.getZ());
}
return null;
}

View File

@ -96,7 +96,7 @@ public class ViaFabric implements ModInitializer {
registerCommandsV1();
config = new VFConfig(FabricLoader.getInstance().getConfigDir().resolve("ViaFabric")
.resolve("viafabric.yml").toFile());
.resolve("viafabric.yml").toFile(), JLOGGER);
manager.onServerLoaded();

View File

@ -20,6 +20,7 @@ package com.viaversion.fabric.mc1171.mixin.debug.client;
import com.viaversion.fabric.common.handler.CommonTransformer;
import com.viaversion.fabric.common.handler.FabricDecodeHandler;
import com.viaversion.viaversion.api.connection.ProtocolInfo;
import com.viaversion.viaversion.api.connection.UserConnection;
import io.netty.channel.ChannelHandler;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.hud.DebugHud;
@ -41,11 +42,12 @@ public class MixinDebugHud {
@SuppressWarnings("ConstantConditions") ChannelHandler viaDecoder = ((MixinClientConnectionAccessor) MinecraftClient.getInstance().getNetworkHandler()
.getConnection()).getChannel().pipeline().get(CommonTransformer.HANDLER_DECODER_NAME);
if (viaDecoder instanceof FabricDecodeHandler) {
ProtocolInfo protocol = ((FabricDecodeHandler) viaDecoder).getInfo().getProtocolInfo();
UserConnection connection = ((FabricDecodeHandler) viaDecoder).getInfo();
ProtocolInfo protocol = connection.getProtocolInfo();
if (protocol != null) {
ProtocolVersion serverVer = ProtocolVersion.getProtocol(protocol.getServerProtocolVersion());
ProtocolVersion clientVer = ProtocolVersion.getProtocol(protocol.getProtocolVersion());
line += " / C: " + clientVer + " S: " + serverVer + " A: " + protocol.getUser().isActive();
ProtocolVersion serverVer = protocol.serverProtocolVersion();
ProtocolVersion clientVer = protocol.protocolVersion();
line += " / C: " + clientVer + " S: " + serverVer + " A: " + connection.isActive();
}
}

View File

@ -21,14 +21,14 @@ import com.viaversion.fabric.mc1171.providers.VFHandItemProvider;
import com.viaversion.fabric.mc1171.providers.FabricVersionProvider;
import com.viaversion.fabric.mc1171.providers.VFPlayerAbilitiesProvider;
import com.viaversion.fabric.mc1171.providers.VFPlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.PlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.provider.PlayerAbilitiesProvider;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.provider.PlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.provider.PlayerAbilitiesProvider;
import com.viaversion.viaversion.protocols.v1_8to1_9.provider.HandItemProvider;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.platform.ViaPlatformLoader;
import com.viaversion.viaversion.api.protocol.version.VersionProvider;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider;
public class VFLoader implements ViaPlatformLoader {
@Override

View File

@ -22,7 +22,7 @@ import com.viaversion.fabric.mc1171.ViaFabric;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider;
import com.viaversion.viaversion.protocols.v1_8to1_9.provider.HandItemProvider;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
@ -45,9 +45,9 @@ public class VFHandItemProvider extends HandItemProvider {
private Item getClientItem() {
if (clientItem == null) {
return new DataItem(0, (byte) 0, (short) 0, null);
return new DataItem(0, (byte) 0, null);
}
return new DataItem(clientItem);
return clientItem.copy();
}
@Environment(EnvType.CLIENT)

View File

@ -18,7 +18,7 @@
package com.viaversion.fabric.mc1171.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.provider.PlayerAbilitiesProvider;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.provider.PlayerAbilitiesProvider;
import net.minecraft.client.MinecraftClient;
public class VFPlayerAbilitiesProvider extends PlayerAbilitiesProvider {

View File

@ -18,8 +18,8 @@
package com.viaversion.fabric.mc1171.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.PlayerLookTargetProvider;
import com.viaversion.viaversion.api.minecraft.BlockPosition;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.provider.PlayerLookTargetProvider;
import net.minecraft.client.MinecraftClient;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
@ -28,13 +28,13 @@ import net.minecraft.util.math.BlockPos;
public class VFPlayerLookTargetProvider extends PlayerLookTargetProvider {
@Override
public Position getPlayerLookTarget(UserConnection info) {
public BlockPosition getPlayerLookTarget(UserConnection info) {
if (!info.isClientSide()) return null;
final HitResult crosshairTarget = MinecraftClient.getInstance().crosshairTarget;
if (crosshairTarget instanceof BlockHitResult) {
final BlockPos pos = ((BlockHitResult) crosshairTarget).getBlockPos();
return new Position(pos.getX(), pos.getY(), pos.getZ());
return new BlockPosition(pos.getX(), pos.getY(), pos.getZ());
}
return null;
}

View File

@ -96,7 +96,7 @@ public class ViaFabric implements ModInitializer {
registerCommandsV1();
config = new VFConfig(FabricLoader.getInstance().getConfigDir().resolve("ViaFabric")
.resolve("viafabric.yml").toFile());
.resolve("viafabric.yml").toFile(), JLOGGER);
manager.onServerLoaded();

View File

@ -20,6 +20,7 @@ package com.viaversion.fabric.mc1182.mixin.debug.client;
import com.viaversion.fabric.common.handler.CommonTransformer;
import com.viaversion.fabric.common.handler.FabricDecodeHandler;
import com.viaversion.viaversion.api.connection.ProtocolInfo;
import com.viaversion.viaversion.api.connection.UserConnection;
import io.netty.channel.ChannelHandler;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.hud.DebugHud;
@ -41,11 +42,12 @@ public class MixinDebugHud {
@SuppressWarnings("ConstantConditions") ChannelHandler viaDecoder = ((MixinClientConnectionAccessor) MinecraftClient.getInstance().getNetworkHandler()
.getConnection()).getChannel().pipeline().get(CommonTransformer.HANDLER_DECODER_NAME);
if (viaDecoder instanceof FabricDecodeHandler) {
ProtocolInfo protocol = ((FabricDecodeHandler) viaDecoder).getInfo().getProtocolInfo();
UserConnection connection = ((FabricDecodeHandler) viaDecoder).getInfo();
ProtocolInfo protocol = connection.getProtocolInfo();
if (protocol != null) {
ProtocolVersion serverVer = ProtocolVersion.getProtocol(protocol.getServerProtocolVersion());
ProtocolVersion clientVer = ProtocolVersion.getProtocol(protocol.getProtocolVersion());
line += " / C: " + clientVer + " S: " + serverVer + " A: " + protocol.getUser().isActive();
ProtocolVersion serverVer = protocol.serverProtocolVersion();
ProtocolVersion clientVer = protocol.protocolVersion();
line += " / C: " + clientVer + " S: " + serverVer + " A: " + connection.isActive();
}
}

View File

@ -21,14 +21,14 @@ import com.viaversion.fabric.mc1182.providers.VFHandItemProvider;
import com.viaversion.fabric.mc1182.providers.FabricVersionProvider;
import com.viaversion.fabric.mc1182.providers.VFPlayerAbilitiesProvider;
import com.viaversion.fabric.mc1182.providers.VFPlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.PlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.provider.PlayerAbilitiesProvider;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.provider.PlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.provider.PlayerAbilitiesProvider;
import com.viaversion.viaversion.protocols.v1_8to1_9.provider.HandItemProvider;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.platform.ViaPlatformLoader;
import com.viaversion.viaversion.api.protocol.version.VersionProvider;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider;
public class VFLoader implements ViaPlatformLoader {
@Override

View File

@ -22,7 +22,7 @@ import com.viaversion.fabric.mc1182.ViaFabric;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider;
import com.viaversion.viaversion.protocols.v1_8to1_9.provider.HandItemProvider;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
@ -45,9 +45,9 @@ public class VFHandItemProvider extends HandItemProvider {
private Item getClientItem() {
if (clientItem == null) {
return new DataItem(0, (byte) 0, (short) 0, null);
return new DataItem(0, (byte) 0, null);
}
return new DataItem(clientItem);
return clientItem.copy();
}
@Environment(EnvType.CLIENT)

View File

@ -18,7 +18,7 @@
package com.viaversion.fabric.mc1182.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.provider.PlayerAbilitiesProvider;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.provider.PlayerAbilitiesProvider;
import net.minecraft.client.MinecraftClient;
public class VFPlayerAbilitiesProvider extends PlayerAbilitiesProvider {

View File

@ -18,8 +18,8 @@
package com.viaversion.fabric.mc1182.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.PlayerLookTargetProvider;
import com.viaversion.viaversion.api.minecraft.BlockPosition;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.provider.PlayerLookTargetProvider;
import net.minecraft.client.MinecraftClient;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
@ -28,13 +28,13 @@ import net.minecraft.util.math.BlockPos;
public class VFPlayerLookTargetProvider extends PlayerLookTargetProvider {
@Override
public Position getPlayerLookTarget(UserConnection info) {
public BlockPosition getPlayerLookTarget(UserConnection info) {
if (!info.isClientSide()) return null;
final HitResult crosshairTarget = MinecraftClient.getInstance().crosshairTarget;
if (crosshairTarget instanceof BlockHitResult) {
final BlockPos pos = ((BlockHitResult) crosshairTarget).getBlockPos();
return new Position(pos.getX(), pos.getY(), pos.getZ());
return new BlockPosition(pos.getX(), pos.getY(), pos.getZ());
}
return null;
}

View File

@ -96,7 +96,7 @@ public class ViaFabric implements ModInitializer {
registerCommandsV1();
config = new VFConfig(FabricLoader.getInstance().getConfigDir().resolve("ViaFabric")
.resolve("viafabric.yml").toFile());
.resolve("viafabric.yml").toFile(), JLOGGER);
manager.onServerLoaded();

View File

@ -20,6 +20,7 @@ package com.viaversion.fabric.mc1194.mixin.debug.client;
import com.viaversion.fabric.common.handler.CommonTransformer;
import com.viaversion.fabric.common.handler.FabricDecodeHandler;
import com.viaversion.viaversion.api.connection.ProtocolInfo;
import com.viaversion.viaversion.api.connection.UserConnection;
import io.netty.channel.ChannelHandler;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.hud.DebugHud;
@ -41,11 +42,12 @@ public class MixinDebugHud {
@SuppressWarnings("ConstantConditions") ChannelHandler viaDecoder = ((MixinClientConnectionAccessor) MinecraftClient.getInstance().getNetworkHandler()
.getConnection()).getChannel().pipeline().get(CommonTransformer.HANDLER_DECODER_NAME);
if (viaDecoder instanceof FabricDecodeHandler) {
ProtocolInfo protocol = ((FabricDecodeHandler) viaDecoder).getInfo().getProtocolInfo();
UserConnection connection = ((FabricDecodeHandler) viaDecoder).getInfo();
ProtocolInfo protocol = connection.getProtocolInfo();
if (protocol != null) {
ProtocolVersion serverVer = ProtocolVersion.getProtocol(protocol.getServerProtocolVersion());
ProtocolVersion clientVer = ProtocolVersion.getProtocol(protocol.getProtocolVersion());
line += " / C: " + clientVer + " S: " + serverVer + " A: " + protocol.getUser().isActive();
ProtocolVersion serverVer = protocol.serverProtocolVersion();
ProtocolVersion clientVer = protocol.protocolVersion();
line += " / C: " + clientVer + " S: " + serverVer + " A: " + connection.isActive();
}
}

View File

@ -21,14 +21,14 @@ import com.viaversion.fabric.mc1194.providers.VFHandItemProvider;
import com.viaversion.fabric.mc1194.providers.FabricVersionProvider;
import com.viaversion.fabric.mc1194.providers.VFPlayerAbilitiesProvider;
import com.viaversion.fabric.mc1194.providers.VFPlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.PlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.provider.PlayerAbilitiesProvider;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.provider.PlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.provider.PlayerAbilitiesProvider;
import com.viaversion.viaversion.protocols.v1_8to1_9.provider.HandItemProvider;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.platform.ViaPlatformLoader;
import com.viaversion.viaversion.api.protocol.version.VersionProvider;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider;
public class VFLoader implements ViaPlatformLoader {
@Override

View File

@ -22,7 +22,7 @@ import com.viaversion.fabric.mc1194.ViaFabric;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider;
import com.viaversion.viaversion.protocols.v1_8to1_9.provider.HandItemProvider;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
@ -45,9 +45,9 @@ public class VFHandItemProvider extends HandItemProvider {
private Item getClientItem() {
if (clientItem == null) {
return new DataItem(0, (byte) 0, (short) 0, null);
return new DataItem(0, (byte) 0, null);
}
return new DataItem(clientItem);
return clientItem.copy();
}
@Environment(EnvType.CLIENT)

View File

@ -18,7 +18,7 @@
package com.viaversion.fabric.mc1194.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.provider.PlayerAbilitiesProvider;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.provider.PlayerAbilitiesProvider;
import net.minecraft.client.MinecraftClient;
public class VFPlayerAbilitiesProvider extends PlayerAbilitiesProvider {

View File

@ -18,8 +18,8 @@
package com.viaversion.fabric.mc1194.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.PlayerLookTargetProvider;
import com.viaversion.viaversion.api.minecraft.BlockPosition;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.provider.PlayerLookTargetProvider;
import net.minecraft.client.MinecraftClient;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
@ -27,12 +27,12 @@ import net.minecraft.util.math.BlockPos;
public class VFPlayerLookTargetProvider extends PlayerLookTargetProvider {
@Override
public Position getPlayerLookTarget(UserConnection info) {
public BlockPosition getPlayerLookTarget(UserConnection info) {
if (!info.isClientSide()) return null;
if (MinecraftClient.getInstance().crosshairTarget instanceof BlockHitResult blockHitResult) {
final BlockPos pos = blockHitResult.getBlockPos();
return new Position(pos.getX(), pos.getY(), pos.getZ());
return new BlockPosition(pos.getX(), pos.getY(), pos.getZ());
}
return null;
}

View File

@ -96,7 +96,7 @@ public class ViaFabric implements ModInitializer {
registerCommandsV1();
config = new VFConfig(FabricLoader.getInstance().getConfigDir().resolve("ViaFabric")
.resolve("viafabric.yml").toFile());
.resolve("viafabric.yml").toFile(), JLOGGER);
manager.onServerLoaded();

View File

@ -20,6 +20,7 @@ package com.viaversion.fabric.mc1201.mixin.debug.client;
import com.viaversion.fabric.common.handler.CommonTransformer;
import com.viaversion.fabric.common.handler.FabricDecodeHandler;
import com.viaversion.viaversion.api.connection.ProtocolInfo;
import com.viaversion.viaversion.api.connection.UserConnection;
import io.netty.channel.ChannelHandler;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.hud.DebugHud;
@ -41,11 +42,12 @@ public class MixinDebugHud {
@SuppressWarnings("ConstantConditions") ChannelHandler viaDecoder = ((MixinClientConnectionAccessor) MinecraftClient.getInstance().getNetworkHandler()
.getConnection()).getChannel().pipeline().get(CommonTransformer.HANDLER_DECODER_NAME);
if (viaDecoder instanceof FabricDecodeHandler) {
ProtocolInfo protocol = ((FabricDecodeHandler) viaDecoder).getInfo().getProtocolInfo();
UserConnection connection = ((FabricDecodeHandler) viaDecoder).getInfo();
ProtocolInfo protocol = connection.getProtocolInfo();
if (protocol != null) {
ProtocolVersion serverVer = ProtocolVersion.getProtocol(protocol.getServerProtocolVersion());
ProtocolVersion clientVer = ProtocolVersion.getProtocol(protocol.getProtocolVersion());
line += " / C: " + clientVer + " S: " + serverVer + " A: " + protocol.getUser().isActive();
ProtocolVersion serverVer = protocol.serverProtocolVersion();
ProtocolVersion clientVer = protocol.protocolVersion();
line += " / C: " + clientVer + " S: " + serverVer + " A: " + connection.isActive();
}
}

View File

@ -21,14 +21,14 @@ import com.viaversion.fabric.mc1201.providers.VFHandItemProvider;
import com.viaversion.fabric.mc1201.providers.FabricVersionProvider;
import com.viaversion.fabric.mc1201.providers.VFPlayerAbilitiesProvider;
import com.viaversion.fabric.mc1201.providers.VFPlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.PlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.provider.PlayerAbilitiesProvider;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.provider.PlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.provider.PlayerAbilitiesProvider;
import com.viaversion.viaversion.protocols.v1_8to1_9.provider.HandItemProvider;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.platform.ViaPlatformLoader;
import com.viaversion.viaversion.api.protocol.version.VersionProvider;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider;
public class VFLoader implements ViaPlatformLoader {
@Override

View File

@ -22,7 +22,7 @@ import com.viaversion.fabric.mc1201.ViaFabric;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider;
import com.viaversion.viaversion.protocols.v1_8to1_9.provider.HandItemProvider;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
@ -45,9 +45,9 @@ public class VFHandItemProvider extends HandItemProvider {
private Item getClientItem() {
if (clientItem == null) {
return new DataItem(0, (byte) 0, (short) 0, null);
return new DataItem(0, (byte) 0, null);
}
return new DataItem(clientItem);
return clientItem.copy();
}
@Environment(EnvType.CLIENT)

View File

@ -18,7 +18,7 @@
package com.viaversion.fabric.mc1201.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.provider.PlayerAbilitiesProvider;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.provider.PlayerAbilitiesProvider;
import net.minecraft.client.MinecraftClient;
public class VFPlayerAbilitiesProvider extends PlayerAbilitiesProvider {

View File

@ -18,8 +18,8 @@
package com.viaversion.fabric.mc1201.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.PlayerLookTargetProvider;
import com.viaversion.viaversion.api.minecraft.BlockPosition;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.provider.PlayerLookTargetProvider;
import net.minecraft.client.MinecraftClient;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
@ -27,12 +27,12 @@ import net.minecraft.util.math.BlockPos;
public class VFPlayerLookTargetProvider extends PlayerLookTargetProvider {
@Override
public Position getPlayerLookTarget(UserConnection info) {
public BlockPosition getPlayerLookTarget(UserConnection info) {
if (!info.isClientSide()) return null;
if (MinecraftClient.getInstance().crosshairTarget instanceof BlockHitResult blockHitResult) {
final BlockPos pos = blockHitResult.getBlockPos();
return new Position(pos.getX(), pos.getY(), pos.getZ());
return new BlockPosition(pos.getX(), pos.getY(), pos.getZ());
}
return null;
}

View File

@ -96,7 +96,7 @@ public class ViaFabric implements ModInitializer {
registerCommandsV1();
config = new VFConfig(FabricLoader.getInstance().getConfigDir().resolve("ViaFabric")
.resolve("viafabric.yml").toFile());
.resolve("viafabric.yml").toFile(), JLOGGER);
manager.onServerLoaded();

View File

@ -0,0 +1,39 @@
/*
* This file is part of ViaFabric - https://github.com/ViaVersion/ViaFabric
* Copyright (C) 2018-2024 ViaVersion 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 com.viaversion.fabric.mc1204.mixin.debug;
import com.viaversion.fabric.mc1204.ViaFabric;
import net.fabricmc.fabric.impl.registry.sync.RegistrySyncManager;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerConfigurationNetworkHandler;
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.CallbackInfo;
@Mixin(value = RegistrySyncManager.class, remap = false)
public class MixinRegistrySyncManager {
@Inject(method = "configureClient", at = @At("HEAD"), cancellable = true)
private static void ignoreMissingRegistries(ServerConfigurationNetworkHandler handler, MinecraftServer server, CallbackInfo ci) {
if (ViaFabric.config.isIgnoreRegistrySyncErrors()) {
ci.cancel();
}
}
}

View File

@ -20,6 +20,7 @@ package com.viaversion.fabric.mc1204.mixin.debug.client;
import com.viaversion.fabric.common.handler.CommonTransformer;
import com.viaversion.fabric.common.handler.FabricDecodeHandler;
import com.viaversion.viaversion.api.connection.ProtocolInfo;
import com.viaversion.viaversion.api.connection.UserConnection;
import io.netty.channel.ChannelHandler;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.hud.DebugHud;
@ -41,11 +42,12 @@ public class MixinDebugHud {
@SuppressWarnings("ConstantConditions") ChannelHandler viaDecoder = ((MixinClientConnectionAccessor) MinecraftClient.getInstance().getNetworkHandler()
.getConnection()).getChannel().pipeline().get(CommonTransformer.HANDLER_DECODER_NAME);
if (viaDecoder instanceof FabricDecodeHandler) {
ProtocolInfo protocol = ((FabricDecodeHandler) viaDecoder).getInfo().getProtocolInfo();
UserConnection connection = ((FabricDecodeHandler) viaDecoder).getInfo();
ProtocolInfo protocol = connection.getProtocolInfo();
if (protocol != null) {
ProtocolVersion serverVer = ProtocolVersion.getProtocol(protocol.getServerProtocolVersion());
ProtocolVersion clientVer = ProtocolVersion.getProtocol(protocol.getProtocolVersion());
line += " / C: " + clientVer + " S: " + serverVer + " A: " + protocol.getUser().isActive();
ProtocolVersion serverVer = protocol.serverProtocolVersion();
ProtocolVersion clientVer = protocol.protocolVersion();
line += " / C: " + clientVer + " S: " + serverVer + " A: " + connection.isActive();
}
}

View File

@ -0,0 +1,49 @@
/*
* This file is part of ViaFabric - https://github.com/ViaVersion/ViaFabric
* Copyright (C) 2018-2024 ViaVersion 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 com.viaversion.fabric.mc1204.mixin.debug.client;
import com.viaversion.fabric.mc1204.ViaFabric;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import net.fabricmc.fabric.impl.registry.sync.RegistrySyncManager;
import net.minecraft.util.Identifier;
import org.slf4j.Logger;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.Map;
@Mixin(value = RegistrySyncManager.class, remap = false)
public class MixinRegistrySyncManager {
@Shadow
@Final
private static Logger LOGGER;
@Inject(method = "checkRemoteRemap", at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;error(Ljava/lang/String;)V", ordinal = 0), cancellable = true)
private static void ignoreMissingRegistries(Map<Identifier, Object2IntMap<Identifier>> map, CallbackInfo ci) {
if (ViaFabric.config.isIgnoreRegistrySyncErrors()) {
LOGGER.warn("Ignoring missing registries");
ci.cancel();
}
}
}

View File

@ -21,14 +21,14 @@ import com.viaversion.fabric.mc1204.providers.VFHandItemProvider;
import com.viaversion.fabric.mc1204.providers.FabricVersionProvider;
import com.viaversion.fabric.mc1204.providers.VFPlayerAbilitiesProvider;
import com.viaversion.fabric.mc1204.providers.VFPlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.PlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.provider.PlayerAbilitiesProvider;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.provider.PlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.provider.PlayerAbilitiesProvider;
import com.viaversion.viaversion.protocols.v1_8to1_9.provider.HandItemProvider;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.platform.ViaPlatformLoader;
import com.viaversion.viaversion.api.protocol.version.VersionProvider;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider;
public class VFLoader implements ViaPlatformLoader {
@Override

View File

@ -22,7 +22,7 @@ import com.viaversion.fabric.mc1204.ViaFabric;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider;
import com.viaversion.viaversion.protocols.v1_8to1_9.provider.HandItemProvider;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
@ -45,9 +45,9 @@ public class VFHandItemProvider extends HandItemProvider {
private Item getClientItem() {
if (clientItem == null) {
return new DataItem(0, (byte) 0, (short) 0, null);
return new DataItem(0, (byte) 0, null);
}
return new DataItem(clientItem);
return clientItem.copy();
}
@Environment(EnvType.CLIENT)

View File

@ -18,7 +18,7 @@
package com.viaversion.fabric.mc1204.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.provider.PlayerAbilitiesProvider;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.provider.PlayerAbilitiesProvider;
import net.minecraft.client.MinecraftClient;
public class VFPlayerAbilitiesProvider extends PlayerAbilitiesProvider {

View File

@ -18,8 +18,8 @@
package com.viaversion.fabric.mc1204.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.PlayerLookTargetProvider;
import com.viaversion.viaversion.api.minecraft.BlockPosition;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.provider.PlayerLookTargetProvider;
import net.minecraft.client.MinecraftClient;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
@ -27,12 +27,12 @@ import net.minecraft.util.math.BlockPos;
public class VFPlayerLookTargetProvider extends PlayerLookTargetProvider {
@Override
public Position getPlayerLookTarget(UserConnection info) {
public BlockPosition getPlayerLookTarget(UserConnection info) {
if (!info.isClientSide()) return null;
if (MinecraftClient.getInstance().crosshairTarget instanceof BlockHitResult blockHitResult) {
final BlockPos pos = blockHitResult.getBlockPos();
return new Position(pos.getX(), pos.getY(), pos.getZ());
return new BlockPosition(pos.getX(), pos.getY(), pos.getZ());
}
return null;
}

View File

@ -3,10 +3,12 @@
"compatibilityLevel": "JAVA_17",
"package": "com.viaversion.fabric.mc1204.mixin.debug",
"mixins": [
"MixinRegistrySyncManager"
],
"client": [
"client.MixinClientConnectionAccessor",
"client.MixinRegistrySyncManager",
"client.MixinClientConnection",
"client.MixinClientConnectionAccessor",
"client.MixinDebugHud"
],
"injectors": {

View File

@ -96,7 +96,7 @@ public class ViaFabric implements ModInitializer {
registerCommandsV1();
config = new VFConfig(FabricLoader.getInstance().getConfigDir().resolve("ViaFabric")
.resolve("viafabric.yml").toFile());
.resolve("viafabric.yml").toFile(), JLOGGER);
manager.onServerLoaded();

View File

@ -17,6 +17,7 @@
*/
package com.viaversion.fabric.mc1206.commands;
import com.viaversion.viaversion.util.ComponentUtil;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.command.CommandSource;
import net.minecraft.entity.Entity;
@ -43,7 +44,7 @@ public class NMSCommandSender implements ViaCommandSender {
}
public static MutableText fromLegacy(String legacy) {
return Text.Serialization.fromJson(legacy, DynamicRegistryManager.EMPTY);
return Text.Serialization.fromJson(ComponentUtil.legacyToJsonString(legacy), DynamicRegistryManager.EMPTY);
}
@Override

View File

@ -0,0 +1,39 @@
/*
* This file is part of ViaFabric - https://github.com/ViaVersion/ViaFabric
* Copyright (C) 2018-2024 ViaVersion 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 com.viaversion.fabric.mc1206.mixin.debug;
import com.viaversion.fabric.mc1206.ViaFabric;
import net.fabricmc.fabric.impl.registry.sync.RegistrySyncManager;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerConfigurationNetworkHandler;
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.CallbackInfo;
@Mixin(value = RegistrySyncManager.class, remap = false)
public class MixinRegistrySyncManager {
@Inject(method = "configureClient", at = @At("HEAD"), cancellable = true)
private static void ignoreMissingRegistries(ServerConfigurationNetworkHandler handler, MinecraftServer server, CallbackInfo ci) {
if (ViaFabric.config.isIgnoreRegistrySyncErrors()) {
ci.cancel();
}
}
}

View File

@ -20,6 +20,7 @@ package com.viaversion.fabric.mc1206.mixin.debug.client;
import com.viaversion.fabric.common.handler.CommonTransformer;
import com.viaversion.fabric.common.handler.FabricDecodeHandler;
import com.viaversion.viaversion.api.connection.ProtocolInfo;
import com.viaversion.viaversion.api.connection.UserConnection;
import io.netty.channel.ChannelHandler;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.hud.DebugHud;
@ -41,11 +42,12 @@ public class MixinDebugHud {
@SuppressWarnings("ConstantConditions") ChannelHandler viaDecoder = ((MixinClientConnectionAccessor) MinecraftClient.getInstance().getNetworkHandler()
.getConnection()).getChannel().pipeline().get(CommonTransformer.HANDLER_DECODER_NAME);
if (viaDecoder instanceof FabricDecodeHandler) {
ProtocolInfo protocol = ((FabricDecodeHandler) viaDecoder).getInfo().getProtocolInfo();
UserConnection connection = ((FabricDecodeHandler) viaDecoder).getInfo();
ProtocolInfo protocol = connection.getProtocolInfo();
if (protocol != null) {
ProtocolVersion serverVer = ProtocolVersion.getProtocol(protocol.getServerProtocolVersion());
ProtocolVersion clientVer = ProtocolVersion.getProtocol(protocol.getProtocolVersion());
line += " / C: " + clientVer + " S: " + serverVer + " A: " + protocol.getUser().isActive();
ProtocolVersion serverVer = protocol.serverProtocolVersion();
ProtocolVersion clientVer = protocol.protocolVersion();
line += " / C: " + clientVer + " S: " + serverVer + " A: " + connection.isActive();
}
}

View File

@ -0,0 +1,49 @@
/*
* This file is part of ViaFabric - https://github.com/ViaVersion/ViaFabric
* Copyright (C) 2018-2024 ViaVersion 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 com.viaversion.fabric.mc1206.mixin.debug.client;
import com.viaversion.fabric.mc1206.ViaFabric;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import net.fabricmc.fabric.impl.registry.sync.RegistrySyncManager;
import net.minecraft.util.Identifier;
import org.slf4j.Logger;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.Map;
@Mixin(value = RegistrySyncManager.class, remap = false)
public class MixinRegistrySyncManager {
@Shadow
@Final
private static Logger LOGGER;
@Inject(method = "checkRemoteRemap", at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;error(Ljava/lang/String;)V", ordinal = 0), cancellable = true)
private static void ignoreMissingRegistries(Map<Identifier, Object2IntMap<Identifier>> map, CallbackInfo ci) {
if (ViaFabric.config.isIgnoreRegistrySyncErrors()) {
LOGGER.warn("Ignoring missing registries");
ci.cancel();
}
}
}

View File

@ -31,6 +31,7 @@ import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.NetworkSide;
import net.minecraft.network.handler.HandlerNames;
import net.minecraft.network.handler.PacketSizeLogger;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@ -38,7 +39,6 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(ClientConnection.class)
public class MixinClientConnection {
@Shadow
@ -61,8 +61,8 @@ public class MixinClientConnection {
protocolPipeline.add(HostnameParserProtocol.INSTANCE);
}
pipeline.addBefore(clientSide ? "encoder" : "outbound_config", CommonTransformer.HANDLER_ENCODER_NAME, new FabricEncodeHandler(user));
pipeline.addBefore(clientSide ? "inbound_config" : "decoder", CommonTransformer.HANDLER_DECODER_NAME, new FabricDecodeHandler(user));
pipeline.addBefore(clientSide ? HandlerNames.ENCODER : HandlerNames.OUTBOUND_CONFIG, CommonTransformer.HANDLER_ENCODER_NAME, new FabricEncodeHandler(user));
pipeline.addBefore(clientSide ? HandlerNames.INBOUND_CONFIG : HandlerNames.DECODER, CommonTransformer.HANDLER_DECODER_NAME, new FabricDecodeHandler(user));
}
}
}

View File

@ -21,14 +21,14 @@ import com.viaversion.fabric.mc1206.providers.VFHandItemProvider;
import com.viaversion.fabric.mc1206.providers.FabricVersionProvider;
import com.viaversion.fabric.mc1206.providers.VFPlayerAbilitiesProvider;
import com.viaversion.fabric.mc1206.providers.VFPlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.PlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.provider.PlayerAbilitiesProvider;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.provider.PlayerLookTargetProvider;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.provider.PlayerAbilitiesProvider;
import com.viaversion.viaversion.protocols.v1_8to1_9.provider.HandItemProvider;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.platform.ViaPlatformLoader;
import com.viaversion.viaversion.api.protocol.version.VersionProvider;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider;
public class VFLoader implements ViaPlatformLoader {
@Override

View File

@ -22,7 +22,7 @@ import com.viaversion.fabric.mc1206.ViaFabric;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider;
import com.viaversion.viaversion.protocols.v1_8to1_9.provider.HandItemProvider;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
@ -45,9 +45,9 @@ public class VFHandItemProvider extends HandItemProvider {
private Item getClientItem() {
if (clientItem == null) {
return new DataItem(0, (byte) 0, (short) 0, null);
return new DataItem(0, (byte) 0, null);
}
return new DataItem(clientItem);
return clientItem.copy();
}
@Environment(EnvType.CLIENT)

View File

@ -18,7 +18,7 @@
package com.viaversion.fabric.mc1206.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.provider.PlayerAbilitiesProvider;
import com.viaversion.viaversion.protocols.v1_15_2to1_16.provider.PlayerAbilitiesProvider;
import net.minecraft.client.MinecraftClient;
public class VFPlayerAbilitiesProvider extends PlayerAbilitiesProvider {

View File

@ -18,8 +18,8 @@
package com.viaversion.fabric.mc1206.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.providers.PlayerLookTargetProvider;
import com.viaversion.viaversion.api.minecraft.BlockPosition;
import com.viaversion.viaversion.protocols.v1_12_2to1_13.provider.PlayerLookTargetProvider;
import net.minecraft.client.MinecraftClient;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
@ -27,12 +27,12 @@ import net.minecraft.util.math.BlockPos;
public class VFPlayerLookTargetProvider extends PlayerLookTargetProvider {
@Override
public Position getPlayerLookTarget(UserConnection info) {
public BlockPosition getPlayerLookTarget(UserConnection info) {
if (!info.isClientSide()) return null;
if (MinecraftClient.getInstance().crosshairTarget instanceof BlockHitResult blockHitResult) {
final BlockPos pos = blockHitResult.getBlockPos();
return new Position(pos.getX(), pos.getY(), pos.getZ());
return new BlockPosition(pos.getX(), pos.getY(), pos.getZ());
}
return null;
}

View File

@ -3,10 +3,12 @@
"compatibilityLevel": "JAVA_21",
"package": "com.viaversion.fabric.mc1206.mixin.debug",
"mixins": [
"MixinRegistrySyncManager"
],
"client": [
"client.MixinClientConnectionAccessor",
"client.MixinRegistrySyncManager",
"client.MixinClientConnection",
"client.MixinClientConnectionAccessor",
"client.MixinDebugHud"
],
"injectors": {

View File

@ -0,0 +1,11 @@
dependencies {
minecraft("com.mojang:minecraft:1.21")
mappings("net.fabricmc:yarn:1.21+build.1:v2")
modImplementation("net.fabricmc.fabric-api:fabric-api:0.100.1+1.21")
modImplementation("com.terraformersmc:modmenu:11.0.0-beta.1")
}
tasks.compileJava {
options.release.set(21)
}

View File

@ -0,0 +1,119 @@
/*
* This file is part of ViaFabric - https://github.com/ViaVersion/ViaFabric
* Copyright (C) 2018-2024 ViaVersion 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 com.viaversion.fabric.mc121;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import com.viaversion.fabric.common.config.VFConfig;
import com.viaversion.fabric.common.platform.FabricInjector;
import com.viaversion.fabric.common.protocol.HostnameParserProtocol;
import com.viaversion.fabric.common.util.JLoggerToLog4j;
import com.viaversion.fabric.mc121.commands.VFCommandHandler;
import com.viaversion.fabric.mc121.platform.FabricPlatform;
import com.viaversion.fabric.mc121.platform.VFLoader;
import com.viaversion.viaversion.ViaManagerImpl;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import io.netty.channel.DefaultEventLoop;
import io.netty.channel.EventLoop;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.command.CommandSource;
import org.apache.logging.log4j.LogManager;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.logging.Logger;
public class ViaFabric implements ModInitializer {
public static final Logger JLOGGER = new JLoggerToLog4j(LogManager.getLogger("ViaFabric"));
public static final ExecutorService ASYNC_EXECUTOR;
public static final EventLoop EVENT_LOOP;
public static final CompletableFuture<Void> INIT_FUTURE = new CompletableFuture<>();
public static VFConfig config;
static {
ThreadFactory factory = new ThreadFactoryBuilder().setDaemon(true).setNameFormat("ViaFabric-%d").build();
ASYNC_EXECUTOR = Executors.newFixedThreadPool(8, factory);
EVENT_LOOP = new DefaultEventLoop(factory);
EVENT_LOOP.submit(INIT_FUTURE::join); // https://github.com/ViaVersion/ViaFabric/issues/53 ugly workaround code but works tm
}
public static <S extends CommandSource> LiteralArgumentBuilder<S> command(String commandName) {
return LiteralArgumentBuilder.<S>literal(commandName)
.then(
RequiredArgumentBuilder
.<S, String>argument("args", StringArgumentType.greedyString())
.executes(((VFCommandHandler) Via.getManager().getCommandHandler())::execute)
.suggests(((VFCommandHandler) Via.getManager().getCommandHandler())::suggestion)
)
.executes(((VFCommandHandler) Via.getManager().getCommandHandler())::execute);
}
@Override
public void onInitialize() {
FabricPlatform platform = new FabricPlatform();
Via.init(ViaManagerImpl.builder()
.injector(new FabricInjector())
.loader(new VFLoader())
.commandHandler(new VFCommandHandler())
.platform(platform).build());
platform.init();
ViaManagerImpl manager = (ViaManagerImpl) Via.getManager();
manager.init();
HostnameParserProtocol.INSTANCE.initialize();
HostnameParserProtocol.INSTANCE.register(Via.getManager().getProviders());
ProtocolVersion.register(-2, "AUTO");
FabricLoader.getInstance().getEntrypoints("viafabric:via_api_initialized", Runnable.class).forEach(Runnable::run);
registerCommandsV1();
config = new VFConfig(FabricLoader.getInstance().getConfigDir().resolve("ViaFabric")
.resolve("viafabric.yml").toFile(), JLOGGER);
manager.onServerLoaded();
INIT_FUTURE.complete(null);
}
private void registerCommandsV1() {
try {
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated, env) -> dispatcher.register(command("viaversion")));
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated, env) -> dispatcher.register(command("viaver")));
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated, env) -> dispatcher.register(command("vvfabric")));
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(command("viafabricclient")));
}
} catch (NoClassDefFoundError ignored) {
JLOGGER.info("Couldn't register command as Fabric Commands V1 isn't installed");
}
}
}

View File

@ -0,0 +1,54 @@
/*
* This file is part of ViaFabric - https://github.com/ViaVersion/ViaFabric
* Copyright (C) 2018-2024 ViaVersion 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 com.viaversion.fabric.mc121;
import com.viaversion.fabric.mc121.gui.ViaConfigScreen;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
import net.fabricmc.fabric.api.client.screen.v1.Screens;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.ButtonTextures;
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.TexturedButtonWidget;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
public class ViaFabricClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
registerGui();
}
private void registerGui() {
try {
ScreenEvents.AFTER_INIT.register((client, screen, scaledWidth, scaledHeight) -> {
if (!(screen instanceof MultiplayerScreen)) return;
ButtonWidget enableClientSideViaVersion = new TexturedButtonWidget(scaledWidth / 2 + 113, 10,
40, 20, // Size
new ButtonTextures(Identifier.of("viafabric", "widget_unfocused"), Identifier.of("viafabric", "widget_focused")),
it -> MinecraftClient.getInstance().setScreen(new ViaConfigScreen(screen)),
Text.translatable("gui.via_button"));
if (ViaFabric.config.isHideButton()) enableClientSideViaVersion.visible = false;
Screens.getButtons(screen).add(enableClientSideViaVersion);
});
} catch (NoClassDefFoundError ignored) {
ViaFabric.JLOGGER.info("Couldn't register screen handler as Fabric Screen isn't installed");
}
}
}

View File

@ -0,0 +1,78 @@
/*
* This file is part of ViaFabric - https://github.com/ViaVersion/ViaFabric
* Copyright (C) 2018-2024 ViaVersion 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 com.viaversion.fabric.mc121.commands;
import com.viaversion.viaversion.api.command.ViaCommandSender;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.command.CommandSource;
import net.minecraft.entity.Entity;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import java.nio.charset.StandardCharsets;
import java.util.UUID;
public class NMSCommandSender implements ViaCommandSender {
private final CommandSource source;
public NMSCommandSender(CommandSource source) {
this.source = source;
}
@Override
public boolean hasPermission(String s) {
// https://gaming.stackexchange.com/questions/138602/what-does-op-permission-level-do
return source.hasPermissionLevel(3);
}
public static MutableText fromLegacy(String legacy) {
return Text.Serialization.fromJson(legacy, DynamicRegistryManager.EMPTY);
}
@Override
public void sendMessage(String s) {
if (source instanceof ServerCommandSource) {
((ServerCommandSource) source).sendFeedback(() -> fromLegacy(s), false);
} else if (source instanceof FabricClientCommandSource) {
((FabricClientCommandSource) source).sendFeedback(fromLegacy(s));
}
}
@Override
public UUID getUUID() {
if (source instanceof ServerCommandSource) {
Entity entity = ((ServerCommandSource) source).getEntity();
if (entity != null) return entity.getUuid();
} else if (source instanceof FabricClientCommandSource) {
return ((FabricClientCommandSource) source).getPlayer().getUuid();
}
return UUID.nameUUIDFromBytes(getName().getBytes(StandardCharsets.UTF_8));
}
@Override
public String getName() {
if (source instanceof ServerCommandSource) {
return ((ServerCommandSource) source).getName();
} else if (source instanceof FabricClientCommandSource) {
return ((FabricClientCommandSource) source).getPlayer().getName().getString();
}
return "?";
}
}

View File

@ -0,0 +1,72 @@
/*
* This file is part of ViaFabric - https://github.com/ViaVersion/ViaFabric
* Copyright (C) 2018-2024 ViaVersion 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 com.viaversion.fabric.mc121.commands;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import com.viaversion.fabric.common.commands.subs.LeakDetectSubCommand;
import com.viaversion.viaversion.commands.ViaCommandHandler;
import net.minecraft.command.CommandSource;
import java.util.concurrent.CompletableFuture;
public class VFCommandHandler extends ViaCommandHandler {
{
try {
registerSubCommand(new LeakDetectSubCommand());
} catch (Exception e) {
e.printStackTrace();
}
}
public int execute(CommandContext<? extends CommandSource> ctx) {
String[] args = new String[0];
try {
args = StringArgumentType.getString(ctx, "args").split(" ");
} catch (IllegalArgumentException ignored) {
}
onCommand(
new NMSCommandSender(ctx.getSource()),
args
);
return 1;
}
public CompletableFuture<Suggestions> suggestion(CommandContext<? extends CommandSource> ctx, SuggestionsBuilder builder) {
String[] args;
try {
args = StringArgumentType.getString(ctx, "args").split(" ", -1);
} catch (IllegalArgumentException ignored) {
args = new String[]{""};
}
String[] pref = args.clone();
pref[pref.length - 1] = "";
String prefix = String.join(" ", pref);
onTabComplete(new NMSCommandSender(ctx.getSource()), args)
.stream()
.map(it -> {
SuggestionsBuilder b = new SuggestionsBuilder(builder.getInput(), prefix.length() + builder.getStart());
b.suggest(it);
return b;
})
.forEach(builder::add);
return builder.buildFuture();
}
}

View File

@ -0,0 +1,36 @@
/*
* This file is part of ViaFabric - https://github.com/ViaVersion/ViaFabric
* Copyright (C) 2018-2024 ViaVersion 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 com.viaversion.fabric.mc121.gui;
import com.google.common.collect.ImmutableMap;
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;
import java.util.Map;
public class ModMenuConfig implements ModMenuApi {
@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return ViaConfigScreen::new;
}
@Override
public Map<String, ConfigScreenFactory<?>> getProvidedConfigScreenFactories() {
return ImmutableMap.of("viafabric", getModConfigScreenFactory());
}
}

View File

@ -0,0 +1,172 @@
/*
* This file is part of ViaFabric - https://github.com/ViaVersion/ViaFabric
* Copyright (C) 2018-2024 ViaVersion 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 com.viaversion.fabric.mc121.gui;
import com.viaversion.fabric.common.config.AbstractViaConfigScreen;
import com.viaversion.fabric.common.util.ProtocolUtils;
import com.viaversion.fabric.mc121.ViaFabric;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ConfirmScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.screen.ScreenTexts;
import net.minecraft.text.Text;
import java.util.concurrent.CompletableFuture;
@Environment(EnvType.CLIENT)
public class ViaConfigScreen extends Screen implements AbstractViaConfigScreen {
private static CompletableFuture<Void> latestProtocolSave;
private final Screen parent;
private TextFieldWidget protocolVersion;
public ViaConfigScreen(Screen parent) {
super(Text.translatable(TITLE_TRANSLATE_ID));
this.parent = parent;
}
@Override
protected void init() {
int entries = 0;
this.addDrawableChild(ButtonWidget
.builder(getClientSideText(), this::onClickClientSide)
.dimensions(calculatePosX(this.width, entries),
calculatePosY(this.height, entries), 150, 20)
.build());
entries++;
this.addDrawableChild(ButtonWidget
.builder(getHideViaButtonText(), this::onHideViaButton)
.dimensions(calculatePosX(this.width, entries),
calculatePosY(this.height, entries), 150, 20)
.build());
entries++;
protocolVersion = new TextFieldWidget(this.textRenderer,
calculatePosX(this.width, entries),
calculatePosY(this.height, entries),
150, 20, Text.translatable("gui.protocol_version_field.name"));
entries++;
protocolVersion.setTextPredicate(ProtocolUtils::isStartOfProtocolText);
protocolVersion.setChangedListener(this::onChangeVersionField);
int clientSideVersion = ViaFabric.config.getClientSideVersion();
protocolVersion.setText(ProtocolUtils.getProtocolName(clientSideVersion));
this.addDrawableChild(protocolVersion);
this.addDrawableChild(ButtonWidget
.builder(ScreenTexts.DONE, (it) -> close())
.dimensions(this.width / 2 - 100, this.height - 40, 200, 20)
.build());
}
private void onChangeVersionField(String text) {
protocolVersion.setSuggestion(null);
int newVersion = ViaFabric.config.getClientSideVersion();
Integer parsed = ProtocolUtils.parseProtocolId(text);
boolean validProtocol;
if (parsed != null) {
newVersion = parsed;
validProtocol = true;
} else {
validProtocol = false;
String[] suggestions = ProtocolUtils.getProtocolSuggestions(text);
if (suggestions.length == 1) {
protocolVersion.setSuggestion(suggestions[0].substring(text.length()));
}
}
protocolVersion.setEditableColor(getProtocolTextColor(ProtocolVersion.getProtocol(newVersion), validProtocol));
int finalNewVersion = newVersion;
if (latestProtocolSave == null) latestProtocolSave = CompletableFuture.completedFuture(null);
ViaFabric.config.setClientSideVersion(finalNewVersion);
latestProtocolSave = latestProtocolSave.thenRunAsync(ViaFabric.config::save, ViaFabric.ASYNC_EXECUTOR);
}
private void onClickClientSide(ButtonWidget widget) {
if (!ViaFabric.config.isClientSideEnabled()) {
MinecraftClient.getInstance().setScreen(new ConfirmScreen(
answer -> {
if (answer) {
ViaFabric.config.setClientSideEnabled(true);
ViaFabric.config.setClientSideVersion(-2); // AUTO
ViaFabric.config.save();
widget.setMessage(getClientSideText());
}
MinecraftClient.getInstance().setScreen(this);
},
Text.translatable("gui.enable_client_side.question"),
Text.translatable("gui.enable_client_side.warning"),
Text.translatable("gui.enable_client_side.enable"),
Text.translatable("gui.cancel")
));
} else {
ViaFabric.config.setClientSideEnabled(false);
ViaFabric.config.save();
}
widget.setMessage(getClientSideText());
}
@Override
public void removed() {
ViaFabric.config.save();
}
@Override
public void close() {
this.client.setScreen(this.parent);
}
private Text getClientSideText() {
return ViaFabric.config.isClientSideEnabled() ?
Text.translatable("gui.client_side.disable")
: Text.translatable("gui.client_side.enable");
}
private Text getHideViaButtonText() {
return ViaFabric.config.isHideButton() ?
Text.translatable("gui.hide_via_button.disable") : Text.translatable("gui.hide_via_button.enable");
}
private void onHideViaButton(ButtonWidget widget) {
ViaFabric.config.setHideButton(!ViaFabric.config.isHideButton());
ViaFabric.config.save();
widget.setMessage(getHideViaButtonText());
}
@Override
public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) {
super.render(drawContext, mouseX, mouseY, delta);
drawContext.drawCenteredTextWithShadow(this.textRenderer, this.title, this.width / 2, 20, 16777215);
}
@Override
public void tick() {
super.tick();
}
}

View File

@ -0,0 +1,63 @@
/*
* This file is part of ViaFabric - https://github.com/ViaVersion/ViaFabric
* Copyright (C) 2018-2024 ViaVersion 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 com.viaversion.fabric.mc121.mixin.address.client;
import com.viaversion.fabric.common.AddressParser;
import net.minecraft.client.network.Address;
import net.minecraft.client.network.AllowedAddressResolver;
import net.minecraft.client.network.ServerAddress;
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.callback.CallbackInfoReturnable;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.Optional;
@Mixin(AllowedAddressResolver.class)
public abstract class MixinAllowedAddressResolver {
@Shadow
public abstract Optional<Address> resolve(ServerAddress address);
@Inject(method = "resolve", at = @At(value = "HEAD"), cancellable = true)
private void resolveVF(ServerAddress address, CallbackInfoReturnable<Optional<Address>> cir) {
AddressParser viaAddr = new AddressParser().parse(address.getAddress());
if (viaAddr.viaSuffix == null) {
return;
}
ServerAddress realAddress = new ServerAddress(viaAddr.serverAddress, address.getPort());
cir.setReturnValue(resolve(realAddress).map(it -> viaFabric$addSuffix(it, viaAddr.getSuffixWithOptions())));
}
@Unique
private Address viaFabric$addSuffix(Address it, String viaSuffix) {
try {
return Address.create(new InetSocketAddress(
InetAddress.getByAddress(it.getHostName() + "." + viaSuffix,
it.getInetSocketAddress().getAddress().getAddress()), it.getPort()));
} catch (UnknownHostException e) {
throw new RuntimeException(e);
}
}
}

View File

@ -0,0 +1,39 @@
/*
* This file is part of ViaFabric - https://github.com/ViaVersion/ViaFabric
* Copyright (C) 2018-2024 ViaVersion 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 com.viaversion.fabric.mc121.mixin.debug;
import com.viaversion.fabric.mc121.ViaFabric;
import net.fabricmc.fabric.impl.registry.sync.RegistrySyncManager;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerConfigurationNetworkHandler;
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.CallbackInfo;
@Mixin(value = RegistrySyncManager.class, remap = false)
public class MixinRegistrySyncManager {
@Inject(method = "configureClient", at = @At("HEAD"), cancellable = true)
private static void ignoreMissingRegistries(ServerConfigurationNetworkHandler handler, MinecraftServer server, CallbackInfo ci) {
if (ViaFabric.config.isIgnoreRegistrySyncErrors()) {
ci.cancel();
}
}
}

View File

@ -0,0 +1,41 @@
/*
* This file is part of ViaFabric - https://github.com/ViaVersion/ViaFabric
* Copyright (C) 2018-2024 ViaVersion 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 com.viaversion.fabric.mc121.mixin.debug.client;
import io.netty.channel.ChannelHandlerContext;
import net.minecraft.network.ClientConnection;
import org.slf4j.Logger;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(ClientConnection.class)
public abstract class MixinClientConnection {
@Shadow
@Final
private static Logger LOGGER;
@Inject(method = "exceptionCaught", at = @At("TAIL"))
public void exceptionCaught(ChannelHandlerContext context, Throwable ex, CallbackInfo ci) {
LOGGER.error("Packet error", ex);
}
}

View File

@ -0,0 +1,29 @@
/*
* This file is part of ViaFabric - https://github.com/ViaVersion/ViaFabric
* Copyright (C) 2018-2024 ViaVersion 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 com.viaversion.fabric.mc121.mixin.debug.client;
import io.netty.channel.Channel;
import net.minecraft.network.ClientConnection;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(ClientConnection.class)
public interface MixinClientConnectionAccessor {
@Accessor
Channel getChannel();
}

View File

@ -0,0 +1,56 @@
/*
* This file is part of ViaFabric - https://github.com/ViaVersion/ViaFabric
* Copyright (C) 2018-2024 ViaVersion 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 com.viaversion.fabric.mc121.mixin.debug.client;
import com.viaversion.fabric.common.handler.CommonTransformer;
import com.viaversion.fabric.common.handler.FabricDecodeHandler;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.ProtocolInfo;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import io.netty.channel.ChannelHandler;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.hud.DebugHud;
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;
import java.util.List;
@Mixin(DebugHud.class)
public class MixinDebugHud {
@Inject(at = @At("RETURN"), method = "getLeftText")
protected void getLeftText(CallbackInfoReturnable<List<String>> info) {
String line = "[ViaFabric] I: " + Via.getManager().getConnectionManager().getConnections().size() + " (F: "
+ Via.getManager().getConnectionManager().getConnectedClients().size() + ")";
@SuppressWarnings("ConstantConditions") ChannelHandler viaDecoder = ((MixinClientConnectionAccessor) MinecraftClient.getInstance().getNetworkHandler()
.getConnection()).getChannel().pipeline().get(CommonTransformer.HANDLER_DECODER_NAME);
if (viaDecoder instanceof FabricDecodeHandler) {
UserConnection connection = ((FabricDecodeHandler) viaDecoder).getInfo();
ProtocolInfo protocol = connection.getProtocolInfo();
if (protocol != null) {
ProtocolVersion serverVer = protocol.serverProtocolVersion();
ProtocolVersion clientVer = protocol.protocolVersion();
line += " / C: " + clientVer + " S: " + serverVer + " A: " + connection.isActive();
}
}
info.getReturnValue().add(line);
}
}

View File

@ -0,0 +1,49 @@
/*
* This file is part of ViaFabric - https://github.com/ViaVersion/ViaFabric
* Copyright (C) 2018-2024 ViaVersion 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 com.viaversion.fabric.mc121.mixin.debug.client;
import com.viaversion.fabric.mc121.ViaFabric;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import net.fabricmc.fabric.impl.registry.sync.RegistrySyncManager;
import net.minecraft.util.Identifier;
import org.slf4j.Logger;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.Map;
@Mixin(value = RegistrySyncManager.class, remap = false)
public class MixinRegistrySyncManager {
@Shadow
@Final
private static Logger LOGGER;
@Inject(method = "checkRemoteRemap", at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;error(Ljava/lang/String;)V", ordinal = 0), cancellable = true)
private static void ignoreMissingRegistries(Map<Identifier, Object2IntMap<Identifier>> map, CallbackInfo ci) {
if (ViaFabric.config.isIgnoreRegistrySyncErrors()) {
LOGGER.warn("Ignoring missing registries");
ci.cancel();
}
}
}

View File

@ -0,0 +1,50 @@
/*
* This file is part of ViaFabric - https://github.com/ViaVersion/ViaFabric
* Copyright (C) 2018-2024 ViaVersion 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 com.viaversion.fabric.mc121.mixin.gui.client;
import com.viaversion.fabric.common.gui.ViaServerInfo;
import com.viaversion.fabric.common.handler.FabricDecodeHandler;
import com.viaversion.fabric.mc121.mixin.debug.client.MixinClientConnectionAccessor;
import net.minecraft.client.network.ServerInfo;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.listener.ClientQueryPacketListener;
import net.minecraft.network.packet.s2c.query.QueryResponseS2CPacket;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(targets = "net.minecraft.client.network.MultiplayerServerListPinger$1")
public abstract class MixinMultiplayerServerListPingerListener implements ClientQueryPacketListener {
@Accessor
abstract ClientConnection getField_3774(); // Synthetic
@Accessor
abstract ServerInfo getField_3776(); // Synthetic
@Inject(method = "onResponse(Lnet/minecraft/network/packet/s2c/query/QueryResponseS2CPacket;)V", at = @At(value = "HEAD"))
private void onResponseCaptureServerInfo(QueryResponseS2CPacket packet, CallbackInfo ci) {
FabricDecodeHandler decoder = ((MixinClientConnectionAccessor) this.getField_3774()).getChannel()
.pipeline().get(FabricDecodeHandler.class);
if (decoder != null) {
((ViaServerInfo) getField_3776()).viaFabric$setTranslating(decoder.getInfo().isActive());
((ViaServerInfo) getField_3776()).viaFabric$setServerVer(decoder.getInfo().getProtocolInfo().getServerProtocolVersion());
}
}
}

View File

@ -0,0 +1,61 @@
/*
* This file is part of ViaFabric - https://github.com/ViaVersion/ViaFabric
* Copyright (C) 2018-2024 ViaVersion 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 com.viaversion.fabric.mc121.mixin.gui.client;
import com.google.common.collect.Lists;
import com.viaversion.fabric.common.gui.ViaServerInfo;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
import net.minecraft.client.gui.screen.multiplayer.MultiplayerServerListWidget;
import net.minecraft.client.network.ServerInfo;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.Redirect;
import java.util.ArrayList;
import java.util.List;
@Mixin(MultiplayerServerListWidget.ServerEntry.class)
public class MixinServerEntry {
@Shadow
@Final
private ServerInfo server;
@ModifyArg(method = "render", at = @At(value = "INVOKE", ordinal = 0,
target = "Lnet/minecraft/client/gui/DrawContext;drawGuiTexture(Lnet/minecraft/util/Identifier;IIII)V"))
private Identifier redirectPingIcon(Identifier texture) {
if (((ViaServerInfo) this.server).viaFabric$translating() && texture.getPath().startsWith("server_list/ping")) {
return Identifier.of("viafabric", texture.getPath());
}
return texture;
}
@Redirect(method = "render", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/client/gui/screen/multiplayer/MultiplayerScreen;setTooltip(Lnet/minecraft/text/Text;)V"))
private void addServerVer(MultiplayerScreen instance, Text text) {
ProtocolVersion proto = ProtocolVersion.getProtocol(((ViaServerInfo) this.server).viaFabric$getServerVer());
List<Text> lines = new ArrayList<>();
lines.add(text);
lines.add(Text.translatable("gui.ping_version.translated", proto.getName(), proto.getVersion()));
instance.setTooltip(Lists.transform(lines, Text::asOrderedText));
}
}

View File

@ -0,0 +1,52 @@
/*
* This file is part of ViaFabric - https://github.com/ViaVersion/ViaFabric
* Copyright (C) 2018-2024 ViaVersion 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 com.viaversion.fabric.mc121.mixin.gui.client;
import com.viaversion.fabric.common.gui.ViaServerInfo;
import net.minecraft.client.network.ServerInfo;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
@Mixin(ServerInfo.class)
public class MixinServerInfo implements ViaServerInfo {
@Unique
private boolean viaFabric$translating;
@Unique
private int viaFabric$serverVer;
@Override
public int viaFabric$getServerVer() {
return viaFabric$serverVer;
}
@Override
public void viaFabric$setServerVer(int ver) {
this.viaFabric$serverVer = ver;
}
@Override
public boolean viaFabric$translating() {
return viaFabric$translating;
}
@Override
public void viaFabric$setTranslating(boolean via) {
this.viaFabric$translating = via;
}
}

View File

@ -0,0 +1,68 @@
/*
* This file is part of ViaFabric - https://github.com/ViaVersion/ViaFabric
* Copyright (C) 2018-2024 ViaVersion 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 com.viaversion.fabric.mc121.mixin.pipeline;
import com.viaversion.fabric.common.handler.CommonTransformer;
import com.viaversion.fabric.common.handler.FabricDecodeHandler;
import com.viaversion.fabric.common.handler.FabricEncodeHandler;
import com.viaversion.fabric.common.handler.PipelineReorderEvent;
import com.viaversion.fabric.common.protocol.HostnameParserProtocol;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.ProtocolPipeline;
import com.viaversion.viaversion.connection.UserConnectionImpl;
import com.viaversion.viaversion.protocol.ProtocolPipelineImpl;
import io.netty.channel.Channel;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.NetworkSide;
import net.minecraft.network.handler.HandlerNames;
import net.minecraft.network.handler.PacketSizeLogger;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(ClientConnection.class)
public class MixinClientConnection {
@Shadow
private Channel channel;
@Inject(method = "setCompressionThreshold", at = @At("RETURN"))
private void reorderCompression(int compressionThreshold, boolean rejectBad, CallbackInfo ci) {
channel.pipeline().fireUserEventTriggered(new PipelineReorderEvent());
}
@Inject(method = "addHandlers", at = @At("RETURN"))
private static void onAddHandlers(ChannelPipeline pipeline, NetworkSide side, boolean local, PacketSizeLogger packetSizeLogger, CallbackInfo ci) {
final Channel channel = pipeline.channel();
if (channel instanceof SocketChannel) {
final UserConnection user = new UserConnectionImpl(channel, side == NetworkSide.CLIENTBOUND);
final ProtocolPipeline protocolPipeline = new ProtocolPipelineImpl(user);
final boolean clientSide = user.isClientSide();
if (clientSide) {
protocolPipeline.add(HostnameParserProtocol.INSTANCE);
}
pipeline.addBefore(clientSide ? HandlerNames.ENCODER : HandlerNames.OUTBOUND_CONFIG, CommonTransformer.HANDLER_ENCODER_NAME, new FabricEncodeHandler(user));
pipeline.addBefore(clientSide ? HandlerNames.INBOUND_CONFIG : HandlerNames.DECODER, CommonTransformer.HANDLER_DECODER_NAME, new FabricDecodeHandler(user));
}
}
}

View File

@ -0,0 +1,44 @@
/*
* This file is part of ViaFabric - https://github.com/ViaVersion/ViaFabric
* Copyright (C) 2018-2024 ViaVersion 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 com.viaversion.fabric.mc121.mixin.pipeline.client;
import com.viaversion.fabric.mc121.ViaFabric;
import com.viaversion.fabric.mc121.service.ProtocolAutoDetector;
import io.netty.channel.ChannelFuture;
import net.minecraft.network.ClientConnection;
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;
import java.net.InetSocketAddress;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
@Mixin(ClientConnection.class)
public class MixinClientConnection {
@Inject(method = "connect(Ljava/net/InetSocketAddress;ZLnet/minecraft/network/ClientConnection;)Lio/netty/channel/ChannelFuture;", at = @At("HEAD"))
private static void onConnect(InetSocketAddress address, boolean useEpoll, ClientConnection connection, CallbackInfoReturnable<ChannelFuture> cir) {
try {
if (!ViaFabric.config.isClientSideEnabled()) return;
ProtocolAutoDetector.detectVersion(address).get(10, TimeUnit.SECONDS);
} catch (Exception e) {
ViaFabric.JLOGGER.log(Level.WARNING, "Could not auto-detect protocol for " + address + " " + e);
}
}
}

View File

@ -0,0 +1,34 @@
/*
* This file is part of ViaFabric - https://github.com/ViaVersion/ViaFabric
* Copyright (C) 2018-2024 ViaVersion 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 com.viaversion.fabric.mc121.mixin.shutdown.server;
import com.viaversion.viaversion.ViaManagerImpl;
import com.viaversion.viaversion.api.Via;
import net.minecraft.server.MinecraftServer;
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.CallbackInfo;
@Mixin(MinecraftServer.class)
public class MixinMinecraftServer {
@Inject(method = "stop", at = @At("TAIL"))
private void onStop(CallbackInfo ci) {
((ViaManagerImpl) Via.getManager()).destroy();
}
}

View File

@ -0,0 +1,28 @@
/*
* This file is part of ViaFabric - https://github.com/ViaVersion/ViaFabric
* Copyright (C) 2018-2024 ViaVersion 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 com.viaversion.fabric.mc121.platform;
import com.viaversion.fabric.common.platform.NativeVersionProvider;
import net.minecraft.SharedConstants;
public class FabricNativeVersionProvider implements NativeVersionProvider {
@Override
public int getNativeServerVersion() {
return SharedConstants.getGameVersion().getProtocolVersion();
}
}

Some files were not shown because too many files have changed in this diff Show More