added more API for Fixes

This commit is contained in:
FlorianMichael 2023-02-24 22:46:48 +01:00
parent 4e1b2abd84
commit d67ee42b27
9 changed files with 75 additions and 57 deletions

View File

@ -5,7 +5,7 @@ minecraft_version=1.19.3
yarn_mappings=1.19.3+build.5
loader_version=0.14.14
mod_version=1.2.5
mod_version=1.3.5
maven_group=de.florianmichael
archives_base_name=viafabricplus

View File

@ -0,0 +1,25 @@
package de.florianmichael.viafabricplus.definition.v1_12_2;
import java.util.concurrent.ConcurrentLinkedDeque;
public class SyncInputExecutor {
private final static ConcurrentLinkedDeque<Runnable> keyboardInteractions = new ConcurrentLinkedDeque<>();
private final static ConcurrentLinkedDeque<Runnable> mouseInteractions = new ConcurrentLinkedDeque<>();
public static void callback() {
while (!mouseInteractions.isEmpty()) {
mouseInteractions.poll().run();
}
while (!keyboardInteractions.isEmpty()) {
keyboardInteractions.poll().run();
}
}
public static void trackKeyboardInteraction(Runnable interaction) {
keyboardInteractions.add(interaction);
}
public static void trackMouseInteraction(Runnable interaction) {
mouseInteractions.add(interaction);
}
}

View File

@ -0,0 +1,13 @@
package de.florianmichael.viafabricplus.definition.v1_8_x;
public class IdlePacketExecutor {
private static Runnable skipIdlePacketExecute;
public static void skipIdlePacket() {
skipIdlePacketExecute.run();
}
public static void registerIdlePacketSkipExecute(final Runnable runnable) {
skipIdlePacketExecute = runnable;
}
}

View File

@ -0,0 +1,24 @@
package de.florianmichael.viafabricplus.definition.v1_8_x;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.Protocol1_12To1_11_1;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3;
import de.florianmichael.viafabricplus.ViaFabricPlus;
import de.florianmichael.vialoadingbase.ViaLoadingBase;
import net.minecraft.client.network.ClientPlayNetworkHandler;
public class InventoryPacketSender {
public static void sendOpenInventoryAchievement(final ClientPlayNetworkHandler clientPlayNetworkHandler) throws Exception {
final UserConnection viaConnection = clientPlayNetworkHandler.getConnection().channel.attr(ViaFabricPlus.LOCAL_VIA_CONNECTION).get();
if (viaConnection != null && ViaLoadingBase.getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_11_1)) {
final PacketWrapper clientStatus = PacketWrapper.create(ServerboundPackets1_9_3.CLIENT_STATUS, viaConnection);
clientStatus.write(Type.VAR_INT, 2); // Open Inventory Achievement
clientStatus.sendToServer(Protocol1_12To1_11_1.class);
}
}
}

View File

@ -1,7 +0,0 @@
package de.florianmichael.viafabricplus.injection.access;
public interface IMinecraftClient {
void viafabricplus_trackKeyboardInteraction(final Runnable interaction);
void viafabricplus_trackMouseInteraction(final Runnable interaction);
}

View File

@ -1,12 +1,7 @@
package de.florianmichael.viafabricplus.injection.mixin.fixes;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_12to1_11_1.Protocol1_12To1_11_1;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3;
import de.florianmichael.viafabricplus.ViaFabricPlus;
import de.florianmichael.viafabricplus.injection.access.IMinecraftClient;
import de.florianmichael.viafabricplus.definition.v1_12_2.SyncInputExecutor;
import de.florianmichael.viafabricplus.definition.v1_8_x.InventoryPacketSender;
import de.florianmichael.viafabricplus.value.ValueHolder;
import de.florianmichael.vialoadingbase.ViaLoadingBase;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
@ -20,17 +15,14 @@ import net.minecraft.util.Hand;
import org.jetbrains.annotations.Nullable;
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.Redirect;
import org.spongepowered.asm.mixin.injection.Slice;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.concurrent.ConcurrentLinkedDeque;
@Mixin(MinecraftClient.class)
public abstract class MixinMinecraftClient implements IMinecraftClient {
public abstract class MixinMinecraftClient {
@Shadow
@Nullable
@ -80,45 +72,17 @@ public abstract class MixinMinecraftClient implements IMinecraftClient {
}
}
@Unique
private final ConcurrentLinkedDeque<Runnable> protocolhack_keyboardInteractions = new ConcurrentLinkedDeque<>();
@Unique
private final ConcurrentLinkedDeque<Runnable> protocolhack_mouseInteractions = new ConcurrentLinkedDeque<>();
@SuppressWarnings("ConstantConditions")
@Inject(method = "tick", at = @At(value = "FIELD", target = "Lnet/minecraft/client/MinecraftClient;currentScreen:Lnet/minecraft/client/gui/screen/Screen;",
ordinal = 4, shift = At.Shift.BEFORE))
public void injectTick(CallbackInfo ci) {
if (!ValueHolder.executeInputsInSync.getValue()) return;
while (!protocolhack_mouseInteractions.isEmpty()) {
protocolhack_mouseInteractions.poll().run();
}
while (!protocolhack_keyboardInteractions.isEmpty()) {
protocolhack_keyboardInteractions.poll().run();
}
SyncInputExecutor.callback();
}
@Inject(method = "handleInputEvents", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;hasRidingInventory()Z"))
private void onInventoryKeyPressed(CallbackInfo ci) throws Exception {
final UserConnection viaConnection = getNetworkHandler().getConnection().channel.attr(ViaFabricPlus.LOCAL_VIA_CONNECTION).get();
if (viaConnection != null && ViaLoadingBase.getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_11_1)) {
final PacketWrapper clientStatus = PacketWrapper.create(ServerboundPackets1_9_3.CLIENT_STATUS, viaConnection);
clientStatus.write(Type.VAR_INT, 2); // Open Inventory Achievement
clientStatus.sendToServer(Protocol1_12To1_11_1.class);
}
}
@Override
public void viafabricplus_trackKeyboardInteraction(Runnable interaction) {
this.protocolhack_keyboardInteractions.add(interaction);
}
@Override
public void viafabricplus_trackMouseInteraction(Runnable interaction) {
this.protocolhack_mouseInteractions.add(interaction);
if (getNetworkHandler() != null) InventoryPacketSender.sendOpenInventoryAchievement(getNetworkHandler());
}
}

View File

@ -2,6 +2,7 @@ package de.florianmichael.viafabricplus.injection.mixin.fixes.entity;
import com.mojang.authlib.GameProfile;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viafabricplus.definition.v1_8_x.IdlePacketExecutor;
import de.florianmichael.viafabricplus.injection.access.IClientPlayerEntity;
import de.florianmichael.viafabricplus.value.ValueHolder;
import de.florianmichael.vialoadingbase.ViaLoadingBase;
@ -95,6 +96,8 @@ public abstract class MixinClientPlayerEntity extends AbstractClientPlayerEntity
this.networkHandler.sendPacket(new PlayerMoveC2SPacket.LookAndOnGround(this.getYaw(), this.getPitch(), this.onGround));
} else if (this.lastOnGround != this.onGround || ValueHolder.sendIdlePacket.getValue()) {
this.networkHandler.sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(this.onGround));
} else {
IdlePacketExecutor.skipIdlePacket();
}
if (ViaLoadingBase.getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_8)) {
++this.ticksSinceLastPositionPacketSent;

View File

@ -1,7 +1,7 @@
package de.florianmichael.viafabricplus.injection.mixin.fixes.input;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viafabricplus.injection.access.IMinecraftClient;
import de.florianmichael.viafabricplus.definition.v1_12_2.SyncInputExecutor;
import de.florianmichael.viafabricplus.value.ValueHolder;
import de.florianmichael.vialoadingbase.ViaLoadingBase;
import net.minecraft.client.Keyboard;
@ -16,12 +16,10 @@ import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(Keyboard.class)
public class MixinKeyboard {
@Shadow @Final private MinecraftClient client;
@Redirect(method = "*", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/MinecraftClient;execute(Ljava/lang/Runnable;)V"))
public void redirectSync(MinecraftClient instance, Runnable runnable) {
if (ValueHolder.executeInputsInSync.getValue()) {
((IMinecraftClient) client).viafabricplus_trackKeyboardInteraction(runnable);
SyncInputExecutor.trackKeyboardInteraction(runnable);
return;
}

View File

@ -1,6 +1,6 @@
package de.florianmichael.viafabricplus.injection.mixin.fixes.input;
import de.florianmichael.viafabricplus.injection.access.IMinecraftClient;
import de.florianmichael.viafabricplus.definition.v1_12_2.SyncInputExecutor;
import de.florianmichael.viafabricplus.value.ValueHolder;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.Mouse;
@ -13,12 +13,10 @@ import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(value = Mouse.class, priority = 1001)
public class MixinMouse {
@Shadow @Final private MinecraftClient client;
@Redirect(method = { "method_29615", "method_22685", "method_22684" }, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/MinecraftClient;execute(Ljava/lang/Runnable;)V"))
public void redirectSync(MinecraftClient instance, Runnable runnable) {
if (ValueHolder.executeInputsInSync.getValue()) {
((IMinecraftClient) client).viafabricplus_trackMouseInteraction(runnable);
SyncInputExecutor.trackMouseInteraction(runnable);
return;
}