Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into 1.20-recode
Browse files Browse the repository at this point in the history
# Conflicts:
#	gradle.properties
  • Loading branch information
FlorianMichael committed Jun 7, 2023
2 parents 2501084 + b352d97 commit 69e2263
Show file tree
Hide file tree
Showing 30 changed files with 204 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# Why another protocol translator?
ViaFabricPlus is intended to replace [multiconnect](https://github.com/Earthcomputer/multiconnect), and it also promises more compactness and stability. ViaFabricPlus can do everything multiconnect could do, but supports more Minecraft versions (listed below) and has more protocol changes implemented.
### Supported Server versions
- Release (1.0.0 - 1.20 [1.20-rc1])
- Release (1.0.0 - 1.20 [1.20])
- Beta (b1.0 - b1.8.1)
- Alpha (a1.0.15 - a1.2.6)
- Classic (c0.0.15 - c0.30 including [CPE](https://wiki.vg/Classic_Protocol_Extension))
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ loader_version=0.14.21
fabric_api_version=0.83.0+1.20

# viafabricplus
mod_version=2.7.5-SNAPSHOT
mod_version=2.7.6-SNAPSHOT
maven_group=de.florianmichael
archives_base_name=viafabricplus

Expand All @@ -18,13 +18,13 @@ raknet_transport_version=1.0.0.CR1-SNAPSHOT
classic4j_version=1.2.0

# viaversion (and required) libs
viaversion_version=4.7.0-1.20-rc1-SNAPSHOT
viabackwards_version=4.7.0-1.20-pre5-SNAPSHOT
viaversion_version=4.7.0
viabackwards_version=4.7.0
snake_yml_version=2.0

# raphimc libs
vialegacy_version=2.2.17-SNAPSHOT
viaaprilfools_version=2.0.7-SNAPSHOT
viaaprilfools_version=2.0.8-SNAPSHOT
viabedrock_version=0.0.1-SNAPSHOT
minecraftauth_version=2.1.4-SNAPSHOT
vialoader_version=2.2.5-SNAPSHOT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ public class GeneralSettings extends SettingGroup {
Text.translatable("words.viafabricplus.rb")
);
public final BooleanSetting removeNotAvailableItemsFromCreativeTab = new BooleanSetting(this, Text.translatable("general.viafabricplus.creative"), true);
public final BooleanSetting allowClassicProtocolCommandUsage = new BooleanSetting(this, Text.translatable("general.viafabricplus.classiccommands"), true);
public final BooleanSetting automaticallyChangeValuesBasedOnTheCurrentVersion = new BooleanSetting(this, Text.translatable("general.viafabricplus.protocolsync"), true);
public final BooleanSetting showSuperSecretSettings = new BooleanSetting(this, Text.translatable("general.viafabricplus.secret"), true);
public final BooleanSetting showExtraInformationInDebugHud = new BooleanSetting(this, Text.translatable("general.viafabricplus.extrainformation"), true);
public final BooleanSetting showClassicLoadingProgressInConnectScreen = new BooleanSetting(this, Text.translatable("general.viafabricplus.classicloading"), true);
public final BooleanSetting autoDetectVersion = new BooleanSetting(this, Text.translatable("general.viafabricplus.autodetect"), false);
public final BooleanSetting showAdvertisedServerVersion = new BooleanSetting(this, Text.translatable("general.viafabricplus.advertised"), true);

public GeneralSettings() {
super(Text.translatable("settings.viafabricplus.general"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@ public interface IServerInfo {

VersionEnum viafabricplus_forcedVersion();
void viafabricplus_forceVersion(VersionEnum version);

boolean viafabricplus_enabled();
void viafabricplus_enable();

int viafabricplus_translatingVersion();
void viafabricplus_setTranslatingVersion(final int version);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viafabricplus.injection.mixin.base;

import de.florianmichael.viafabricplus.injection.access.IServerInfo;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
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.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(targets = "net.minecraft.client.network.MultiplayerServerListPinger$1")
public abstract class MixinMultiplayerServerListPinger_1 implements ClientQueryPacketListener {

@Final
@Shadow
ClientConnection field_3774;

@Final
@Shadow
ServerInfo field_3776;

@Inject(method = "onResponse(Lnet/minecraft/network/packet/s2c/query/QueryResponseS2CPacket;)V", at = @At("HEAD"))
public void trackTranslatingState(QueryResponseS2CPacket packet, CallbackInfo ci) {
if (field_3774.channel.hasAttr(ProtocolHack.LOCAL_VIA_CONNECTION)) {
((IServerInfo) field_3776).viafabricplus_enable();

final var userConnection = field_3774.channel.attr(ProtocolHack.LOCAL_VIA_CONNECTION).get();
((IServerInfo) field_3776).viafabricplus_setTranslatingVersion(userConnection.getProtocolInfo().getServerProtocolVersion());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.florianmichael.viafabricplus.injection.mixin.base;

import de.florianmichael.viafabricplus.base.settings.groups.GeneralSettings;
import de.florianmichael.viafabricplus.injection.access.IServerInfo;
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.raphimc.vialoader.util.VersionEnum;
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.Redirect;

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

@Mixin(MultiplayerServerListWidget.ServerEntry.class)
public class MixinMultiplayerServerListWidget_ServerEntry {

@Shadow @Final private ServerInfo server;

@Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/multiplayer/MultiplayerScreen;setMultiplayerScreenTooltip(Ljava/util/List;)V", ordinal = 0))
public void showTranslatingInformation(MultiplayerScreen instance, List<Text> tooltip) {
final List<Text> tooltipOverwrite = new ArrayList<>(tooltip);
if (GeneralSettings.INSTANCE.showAdvertisedServerVersion.getValue()) {
final IServerInfo accessor = ((IServerInfo) server);
if (accessor.viafabricplus_enabled()) {
final var versionEnum = VersionEnum.fromProtocolId(accessor.viafabricplus_translatingVersion());

tooltipOverwrite.add(Text.translatable("words.viafabricplus.translate", versionEnum != VersionEnum.UNKNOWN ? versionEnum.getName() + " (" + versionEnum.getVersion() + ")" : accessor.viafabricplus_translatingVersion()));
tooltipOverwrite.add(Text.translatable("words.viafabricplus.serverversion", server.version.getString() + " (" + server.protocolVersion + ")"));
}
}
instance.setMultiplayerScreenTooltip(tooltipOverwrite);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,30 @@ private static void loadForcedVersion(NbtCompound root, CallbackInfoReturnable<S
public void trackForcedVersion(ServerInfo serverInfo, CallbackInfo ci) {
viafabricplus_forceVersion(((IServerInfo) serverInfo).viafabricplus_forcedVersion());
}

@Unique
private boolean viafabricplus_enabled;

@Override
public boolean viafabricplus_enabled() {
return viafabricplus_enabled;
}

@Override
public void viafabricplus_enable() {
viafabricplus_enabled = true;
}

@Unique
private int viafabricplus_translatingVersion;

@Override
public int viafabricplus_translatingVersion() {
return viafabricplus_translatingVersion;
}

@Override
public void viafabricplus_setTranslatingVersion(int version) {
viafabricplus_translatingVersion = version;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import net.raphimc.vialoader.util.VersionEnum;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ServerboundPackets1_16_2;
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.Protocol1_17To1_16_4;
Expand All @@ -44,6 +43,7 @@
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -69,12 +69,22 @@ public abstract class MixinClientPlayerInteractionManager {
@Final
private ClientPlayNetworkHandler networkHandler;

@Shadow
private BlockPos currentBreakingPos;

@Unique
private ItemStack viafabricplus_oldCursorStack;

@Unique
private List<ItemStack> viafabricplus_oldItems;

@Inject(method = "breakBlock", at = @At("TAIL"))
public void resetBlockBreaking(BlockPos pos, CallbackInfoReturnable<Boolean> cir) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_14_3)) {
this.currentBreakingPos = new BlockPos(this.currentBreakingPos.getX(), -1, this.currentBreakingPos.getZ());
}
}

@Inject(method = "attackEntity", at = @At("HEAD"))
private void injectAttackEntity(PlayerEntity player, Entity target, CallbackInfo ci) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8) && player instanceof IClientPlayerEntity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import de.florianmichael.viafabricplus.base.settings.groups.DebugSettings;
import net.raphimc.vialoader.util.VersionEnum;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.network.ClientPlayerEntity;
Expand Down Expand Up @@ -76,6 +75,14 @@ private boolean preventGenericInteract(ActionResult instance) {
return instance.isAccepted();
}

@Redirect(method = "handleBlockBreaking", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isUsingItem()Z"))
public boolean allowBlockBreakAndItemUsageAtTheSameTime(ClientPlayerEntity instance) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_7_6tor1_7_10)) {
return false;
}
return instance.isUsingItem();
}

@Redirect(method = "tick", at = @At(value = "FIELD", target = "Lnet/minecraft/client/MinecraftClient;attackCooldown:I", ordinal = 1))
public int unwrapOperation(MinecraftClient instance) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.entity;

import com.mojang.authlib.GameProfile;
import net.minecraft.world.GameMode;
import net.raphimc.vialoader.util.VersionEnum;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viafabricplus.base.settings.groups.DebugSettings;
import de.florianmichael.viafabricplus.definition.v1_8.ArmorPointCalculation;
import de.florianmichael.viafabricplus.injection.access.IClientPlayerEntity;
Expand Down Expand Up @@ -167,6 +167,14 @@ public void removeSprintingPacket(ClientPlayerEntity instance) {
}
}

@Redirect(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isClimbing()Z"))
public boolean alwaysSendPacket(ClientPlayerEntity instance) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_15_1)) {
return false;
}
return isClimbing();
}

@Redirect(method = "autoJump", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;inverseSqrt(F)F"))
public float useFastInverse(float x) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_19_3)) {
Expand All @@ -180,6 +188,14 @@ public float useFastInverse(float x) {
return MathHelper.inverseSqrt(x);
}

@Override
public boolean isCreative() {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_7_6tor1_7_10)) {
return client.interactionManager.getCurrentGameMode() == GameMode.CREATIVE;
}
return super.isCreative();
}

@Override
public int getArmor() {
if (VisualSettings.INSTANCE.emulateArmorHud.getValue()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
*/
package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.entity;

import net.minecraft.util.Hand;
import net.raphimc.vialoader.util.VersionEnum;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viafabricplus.base.settings.groups.VisualSettings;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import net.minecraft.entity.EntityDimensions;
Expand All @@ -31,7 +31,6 @@
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.Identifier;
import net.minecraft.world.World;
import net.raphimc.viabedrock.api.BedrockProtocolVersion;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand Down Expand Up @@ -115,6 +114,13 @@ private float modifySneakEyeHeight(float prevEyeHeight) {
}
}

@Redirect(method = "dropItem(Lnet/minecraft/item/ItemStack;ZZ)Lnet/minecraft/entity/ItemEntity;", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;swingHand(Lnet/minecraft/util/Hand;)V"))
public void dontSwingHand(PlayerEntity instance, Hand hand) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_15_2)) return;

instance.swingHand(hand);
}

@Unique
public boolean viafabricplus_isSprinting;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ private static void initMaps(CallbackInfo ci) {
viafabricplus_remaps.put("1.16.4/5", new Pair<>("1.16.4-1.16.5", null));
viafabricplus_remaps.put("1.18/1.18.1", new Pair<>("1.18-1.18.1", null));
viafabricplus_remaps.put("1.19.1/2", new Pair<>("1.19.1-1.19.2", null));
viafabricplus_remaps.put("1.20", new Pair<>("1.20-rc1", null));
}

@Redirect(method = "<clinit>", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/protocol/version/ProtocolVersion;register(ILjava/lang/String;)Lcom/viaversion/viaversion/api/protocol/version/ProtocolVersion;"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14;
import com.viaversion.viaversion.protocols.protocol1_14_4to1_14_3.ClientboundPackets1_14_4;
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4;
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.metadata.MetadataRewriter1_15To1_14_4;
import com.viaversion.viaversion.rewriter.EntityRewriter;
Expand All @@ -35,7 +35,7 @@

@SuppressWarnings("DataFlowIssue")
@Mixin(MetadataRewriter1_15To1_14_4.class)
public abstract class MixinMetadataRewriter1_15To1_14_4 extends EntityRewriter<ClientboundPackets1_14, Protocol1_15To1_14_4> {
public abstract class MixinMetadataRewriter1_15To1_14_4 extends EntityRewriter<ClientboundPackets1_14_4, Protocol1_15To1_14_4> {

public MixinMetadataRewriter1_15To1_14_4(Protocol1_15To1_14_4 protocol) {
super(protocol);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class PackFormatsMappings {
private final static Map<Integer, GameVersion> protocolMap = new HashMap<>();

public static void load() {
registerVersion(VersionEnum.r1_20, 15, "1.20 Release Candidate 1", "1.20-rc1");
registerVersion(VersionEnum.r1_20, 15, "1.20");
registerVersion(VersionEnum.r1_19_4, 13, "1.19.4");
registerVersion(VersionEnum.r1_19_3, 12, "1.19.3");
registerVersion(VersionEnum.r1_19_1tor1_19_2, 9, "1.19.2");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class ViaFabricPlusBaseVersionProvider extends BaseVersionProvider {

// Based on https://github.com/ViaVersion/ViaFabric/blob/main/viafabric-mc119/src/main/java/com/viaversion/fabric/mc119/service/ProtocolAutoDetector.java
private final static LoadingCache<InetSocketAddress, CompletableFuture<VersionEnum>> AUTO_DETECTION_CACHE = CacheBuilder.newBuilder().
expireAfterWrite(30, TimeUnit.SECONDS).
expireAfterWrite(10, TimeUnit.MINUTES).
build(CacheLoader.from(address -> {
CompletableFuture<VersionEnum> future = new CompletableFuture<>();

Expand Down
1 change: 0 additions & 1 deletion src/main/resources/assets/viafabricplus/lang/cs_cz.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"general.viafabricplus.classicloading": "Zobrazit progres načítání mapy při připojování ke classic serveru",
"general.viafabricplus.main": "Umístění hlavního tlačítka",
"general.viafabricplus.creative": "Odstranit nedostupné předměty z inventáře tvořivé hry",
"general.viafabricplus.classiccommands": "Povolit classic příkazy",
"general.viafabricplus.protocolsync": "Automaticky změnit nastavení podle zvolené verze",

"experimental.viafabricplus.chunkborderfix": "Opravit okraje chunků",
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/assets/viafabricplus/lang/de_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"general.viafabricplus.classicloading": "Lade-Fortschritt in der Classic anzeigen",
"general.viafabricplus.main": "Position des Haupt-Buttons",
"general.viafabricplus.creative": "Nicht verfügbare Items von Kreativ-Tab entfernen",
"general.viafabricplus.classiccommands": "Classic Protocol Command-Nutzung erlauben",
"general.viafabricplus.protocolsync": "Einstellungen automatisch an die aktuelle Version anpassen",

"debug.viafabricplus.sequence": "Sequencing deaktivieren",
Expand Down
Loading

0 comments on commit 69e2263

Please sign in to comment.