Added proper fix for the idle packet in <= 1.8

This commit is contained in:
FlorianMichael 2023-10-24 16:51:42 +02:00
parent 484c8ba9a8
commit 3fed59dbda
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
18 changed files with 357 additions and 25 deletions

View File

@ -37,13 +37,18 @@ public class ViaForgeConfig extends Config {
return Collections.emptyList();
}
@Override
public void set(String path, Object value) {
super.set(path, value);
save(); // Automatically save the config when something changes
}
public int getClientSideVersion() {
return getInt(CLIENT_SIDE_VERSION, 0);
}
public void setClientSideVersion(final int version) {
set(CLIENT_SIDE_VERSION, version);
save();
}
public boolean isShowMainMenuButton() {

View File

@ -18,8 +18,10 @@
package de.florianmichael.viaforge.common.protocolhack;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.platform.providers.ViaProviders;
import com.viaversion.viaversion.api.protocol.version.VersionProvider;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
import de.florianmichael.viaforge.common.protocolhack.provider.ViaForgeVersionProvider;
import net.raphimc.vialoader.impl.viaversion.VLLoader;
@ -32,5 +34,12 @@ public class ViaForgeVLLoader extends VLLoader {
final ViaProviders providers = Via.getManager().getProviders();
providers.use(VersionProvider.class, new ViaForgeVersionProvider());
providers.use(MovementTransmitterProvider.class, new MovementTransmitterProvider() {
@Override
public void sendPlayer(UserConnection userConnection) {
// We are on the client side, so we can handle the idle packet properly
}
});
}
}

View File

@ -0,0 +1,37 @@
package de.florianmichael.viaforge.mixin.impl.fixes;
import com.mojang.authlib.GameProfile;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.world.World;
import net.raphimc.vialoader.util.VersionEnum;
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;
@Mixin(EntityPlayerSP.class)
public class MixinEntityPlayerSP extends AbstractClientPlayer {
@Shadow private boolean prevOnGround;
public MixinEntityPlayerSP(World worldIn, GameProfile playerProfile) {
super(worldIn, playerProfile);
}
@Redirect(method = "onUpdateWalkingPlayer", at = @At(value = "FIELD", target = "Lnet/minecraft/client/entity/EntityPlayerSP;prevOnGround:Z", ordinal = 0))
public boolean emulateIdlePacket(EntityPlayerSP instance) {
if (ViaForgeCommon.getManager().getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) {
// <= 1.8 spams the idle packet instead of only sending it when the ground state changes
// So we invert the original logic:
// if (prevOnGround != onGround) sendPacket
// To be like:
// if (!onGround != onGround) sendPacket
// Which is the same as:
// if (true) sendPacket
return !onGround;
}
return prevOnGround;
}
}

View File

@ -5,11 +5,14 @@
"package": "de.florianmichael.viaforge.mixin.impl",
"refmap": "mixins.viaforge-mc112.refmap.json",
"mixins": [
"MixinNetworkManager",
"MixinNetworkManager_5",
"MixinGuiMainMenu",
"MixinGuiMultiplayer",
"MixinGuiScreenServerList"
"MixinGuiScreenServerList",
"MixinNetworkManager",
"MixinNetworkManager_5"
],
"verbose": true
"verbose": true,
"client": [
"fixes.MixinEntityPlayerSP"
]
}

View File

@ -0,0 +1,37 @@
package de.florianmichael.viaforge.mixin.fixes;
import com.mojang.authlib.GameProfile;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import net.minecraft.client.entity.player.AbstractClientPlayerEntity;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.client.world.ClientWorld;
import net.raphimc.vialoader.util.VersionEnum;
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;
@Mixin(ClientPlayerEntity.class)
public class MixinClientPlayerEntity extends AbstractClientPlayerEntity {
@Shadow private boolean lastOnGround;
public MixinClientPlayerEntity(ClientWorld world, GameProfile profile) {
super(world, profile);
}
@Redirect(method = "sendPosition", at = @At(value = "FIELD", target = "Lnet/minecraft/client/entity/player/ClientPlayerEntity;lastOnGround:Z", ordinal = 0))
public boolean emulateIdlePacket(ClientPlayerEntity instance) {
if (ViaForgeCommon.getManager().getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) {
// <= 1.8 spams the idle packet instead of only sending it when the ground state changes
// So we invert the original logic:
// if (prevOnGround != onGround) sendPacket
// To be like:
// if (!onGround != onGround) sendPacket
// Which is the same as:
// if (true) sendPacket
return !onGround;
}
return lastOnGround;
}
}

View File

@ -4,14 +4,17 @@
"compatibilityLevel": "JAVA_8",
"package": "de.florianmichael.viaforge.mixin",
"mixins": [
"MixinNetworkManager",
"MixinNetworkManager_1",
"MixinMainMenuScreen",
"MixinMultiplayerScreen",
"MixinNetworkManager",
"MixinNetworkManager_1",
"MixinServerListScreen"
],
"injectors": {
"defaultRequire": 1
},
"refmap": "mixins.viaforge-mc114.refmap.json"
"refmap": "mixins.viaforge-mc114.refmap.json",
"client": [
"fixes.MixinClientPlayerEntity"
]
}

View File

@ -0,0 +1,37 @@
package de.florianmichael.viaforge.mixin.fixes;
import com.mojang.authlib.GameProfile;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import net.minecraft.client.entity.player.AbstractClientPlayerEntity;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.client.world.ClientWorld;
import net.raphimc.vialoader.util.VersionEnum;
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;
@Mixin(ClientPlayerEntity.class)
public class MixinClientPlayerEntity extends AbstractClientPlayerEntity {
@Shadow private boolean lastOnGround;
public MixinClientPlayerEntity(ClientWorld world, GameProfile profile) {
super(world, profile);
}
@Redirect(method = "sendPosition", at = @At(value = "FIELD", target = "Lnet/minecraft/client/entity/player/ClientPlayerEntity;lastOnGround:Z", ordinal = 0))
public boolean emulateIdlePacket(ClientPlayerEntity instance) {
if (ViaForgeCommon.getManager().getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) {
// <= 1.8 spams the idle packet instead of only sending it when the ground state changes
// So we invert the original logic:
// if (prevOnGround != onGround) sendPacket
// To be like:
// if (!onGround != onGround) sendPacket
// Which is the same as:
// if (true) sendPacket
return !onGround;
}
return lastOnGround;
}
}

View File

@ -4,14 +4,17 @@
"compatibilityLevel": "JAVA_8",
"package": "de.florianmichael.viaforge.mixin",
"mixins": [
"MixinNetworkManager",
"MixinNetworkManager_1",
"MixinMainMenuScreen",
"MixinMultiplayerScreen",
"MixinNetworkManager",
"MixinNetworkManager_1",
"MixinServerListScreen"
],
"injectors": {
"defaultRequire": 1
},
"refmap": "mixins.viaforge-mc115.refmap.json"
"refmap": "mixins.viaforge-mc115.refmap.json",
"client": [
"fixes.MixinClientPlayerEntity"
]
}

View File

@ -0,0 +1,37 @@
package de.florianmichael.viaforge.mixin.fixes;
import com.mojang.authlib.GameProfile;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import net.minecraft.client.entity.player.AbstractClientPlayerEntity;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.client.world.ClientWorld;
import net.raphimc.vialoader.util.VersionEnum;
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;
@Mixin(ClientPlayerEntity.class)
public class MixinClientPlayerEntity extends AbstractClientPlayerEntity {
@Shadow private boolean lastOnGround;
public MixinClientPlayerEntity(ClientWorld world, GameProfile profile) {
super(world, profile);
}
@Redirect(method = "sendPosition", at = @At(value = "FIELD", target = "Lnet/minecraft/client/entity/player/ClientPlayerEntity;lastOnGround:Z", ordinal = 0))
public boolean emulateIdlePacket(ClientPlayerEntity instance) {
if (ViaForgeCommon.getManager().getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) {
// <= 1.8 spams the idle packet instead of only sending it when the ground state changes
// So we invert the original logic:
// if (prevOnGround != onGround) sendPacket
// To be like:
// if (!onGround != onGround) sendPacket
// Which is the same as:
// if (true) sendPacket
return !onGround;
}
return lastOnGround;
}
}

View File

@ -4,14 +4,17 @@
"compatibilityLevel": "JAVA_8",
"package": "de.florianmichael.viaforge.mixin",
"mixins": [
"MixinNetworkManager",
"MixinNetworkManager_1",
"MixinMainMenuScreen",
"MixinMultiplayerScreen",
"MixinNetworkManager",
"MixinNetworkManager_1",
"MixinServerListScreen"
],
"injectors": {
"defaultRequire": 1
},
"refmap": "mixins.viaforge-mc116.refmap.json"
"refmap": "mixins.viaforge-mc116.refmap.json",
"client": [
"fixes.MixinClientPlayerEntity"
]
}

View File

@ -0,0 +1,37 @@
package de.florianmichael.viaforge.mixin.fixes;
import com.mojang.authlib.GameProfile;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.player.AbstractClientPlayer;
import net.minecraft.client.player.LocalPlayer;
import net.raphimc.vialoader.util.VersionEnum;
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;
@Mixin(LocalPlayer.class)
public class MixinLocalPlayer extends AbstractClientPlayer {
@Shadow private boolean lastOnGround;
public MixinLocalPlayer(ClientLevel level, GameProfile profile) {
super(level, profile);
}
@Redirect(method = "sendPosition", at = @At(value = "FIELD", target = "Lnet/minecraft/client/player/LocalPlayer;lastOnGround:Z", ordinal = 0))
public boolean emulateIdlePacket(LocalPlayer instance) {
if (ViaForgeCommon.getManager().getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) {
// <= 1.8 spams the idle packet instead of only sending it when the ground state changes
// So we invert the original logic:
// if (prevOnGround != onGround) sendPacket
// To be like:
// if (!onGround != onGround) sendPacket
// Which is the same as:
// if (true) sendPacket
return !onGround;
}
return lastOnGround;
}
}

View File

@ -6,9 +6,10 @@
"mixins": [
"MixinConnection",
"MixinConnection_1",
"MixinTitleScreen",
"MixinDirectJoinServerScreen",
"MixinJoinMultiplayerScreen",
"MixinDirectJoinServerScreen"
"MixinTitleScreen",
"fixes.MixinLocalPlayer"
],
"injectors": {
"defaultRequire": 1

View File

@ -0,0 +1,37 @@
package de.florianmichael.viaforge.mixin.fixes;
import com.mojang.authlib.GameProfile;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.player.AbstractClientPlayer;
import net.minecraft.client.player.LocalPlayer;
import net.raphimc.vialoader.util.VersionEnum;
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;
@Mixin(LocalPlayer.class)
public class MixinLocalPlayer extends AbstractClientPlayer {
@Shadow private boolean lastOnGround;
public MixinLocalPlayer(ClientLevel level, GameProfile profile) {
super(level, profile);
}
@Redirect(method = "sendPosition", at = @At(value = "FIELD", target = "Lnet/minecraft/client/player/LocalPlayer;lastOnGround:Z", ordinal = 0))
public boolean emulateIdlePacket(LocalPlayer instance) {
if (ViaForgeCommon.getManager().getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) {
// <= 1.8 spams the idle packet instead of only sending it when the ground state changes
// So we invert the original logic:
// if (prevOnGround != onGround) sendPacket
// To be like:
// if (!onGround != onGround) sendPacket
// Which is the same as:
// if (true) sendPacket
return !onGround;
}
return lastOnGround;
}
}

View File

@ -6,12 +6,15 @@
"mixins": [
"MixinConnection",
"MixinConnection_1",
"MixinTitleScreen",
"MixinDirectJoinServerScreen",
"MixinJoinMultiplayerScreen",
"MixinDirectJoinServerScreen"
"MixinTitleScreen"
],
"injectors": {
"defaultRequire": 1
},
"refmap": "mixins.viaforge-mc118.refmap.json"
"refmap": "mixins.viaforge-mc118.refmap.json",
"client": [
"fixes.MixinLocalPlayer"
]
}

View File

@ -0,0 +1,37 @@
package de.florianmichael.viaforge.mixin.fixes;
import com.mojang.authlib.GameProfile;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.player.AbstractClientPlayer;
import net.minecraft.client.player.LocalPlayer;
import net.raphimc.vialoader.util.VersionEnum;
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;
@Mixin(LocalPlayer.class)
public class MixinLocalPlayer extends AbstractClientPlayer {
@Shadow private boolean lastOnGround;
public MixinLocalPlayer(ClientLevel level, GameProfile profile) {
super(level, profile);
}
@Redirect(method = "sendPosition", at = @At(value = "FIELD", target = "Lnet/minecraft/client/player/LocalPlayer;lastOnGround:Z", ordinal = 0))
public boolean emulateIdlePacket(LocalPlayer instance) {
if (ViaForgeCommon.getManager().getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) {
// <= 1.8 spams the idle packet instead of only sending it when the ground state changes
// So we invert the original logic:
// if (prevOnGround != onGround) sendPacket
// To be like:
// if (!onGround != onGround) sendPacket
// Which is the same as:
// if (true) sendPacket
return !onGround;
}
return lastOnGround;
}
}

View File

@ -6,12 +6,15 @@
"mixins": [
"MixinConnection",
"MixinConnection_1",
"MixinTitleScreen",
"MixinDirectJoinServerScreen",
"MixinJoinMultiplayerScreen",
"MixinDirectJoinServerScreen"
"MixinTitleScreen"
],
"injectors": {
"defaultRequire": 1
},
"refmap": "mixins.viaforge-mc119.refmap.json"
"refmap": "mixins.viaforge-mc119.refmap.json",
"client": [
"fixes.MixinLocalPlayer"
]
}

View File

@ -0,0 +1,37 @@
package de.florianmichael.viaforge.mixin.fixes;
import com.mojang.authlib.GameProfile;
import de.florianmichael.viaforge.common.ViaForgeCommon;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.player.AbstractClientPlayer;
import net.minecraft.client.player.LocalPlayer;
import net.raphimc.vialoader.util.VersionEnum;
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;
@Mixin(LocalPlayer.class)
public class MixinLocalPlayer extends AbstractClientPlayer {
@Shadow private boolean lastOnGround;
public MixinLocalPlayer(ClientLevel level, GameProfile profile) {
super(level, profile);
}
@Redirect(method = "sendPosition", at = @At(value = "FIELD", target = "Lnet/minecraft/client/player/LocalPlayer;lastOnGround:Z", ordinal = 0))
public boolean emulateIdlePacket(LocalPlayer instance) {
if (ViaForgeCommon.getManager().getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) {
// <= 1.8 spams the idle packet instead of only sending it when the ground state changes
// So we invert the original logic:
// if (prevOnGround != onGround) sendPacket
// To be like:
// if (!onGround != onGround) sendPacket
// Which is the same as:
// if (true) sendPacket
return !onGround();
}
return lastOnGround;
}
}

View File

@ -6,12 +6,15 @@
"mixins": [
"MixinConnection",
"MixinConnection_1",
"MixinTitleScreen",
"MixinDirectJoinServerScreen",
"MixinJoinMultiplayerScreen",
"MixinDirectJoinServerScreen"
"MixinTitleScreen"
],
"injectors": {
"defaultRequire": 1
},
"refmap": "mixins.viaforge-mc120.refmap.json"
"refmap": "mixins.viaforge-mc120.refmap.json",
"client": [
"fixes.MixinLocalPlayer"
]
}