Created new packet for requesting the last input tick from a client.

This commit is contained in:
2022-06-05 13:50:05 +01:00
parent a440fcc1ab
commit cd98b0c811

View File

@ -0,0 +1,30 @@
package dev.micle.loginprotection.network.server;
import dev.micle.loginprotection.network.NetworkManager;
import dev.micle.loginprotection.network.client.LastInputTickPacket;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraftforge.network.NetworkEvent;
import java.util.function.Supplier;
public class RequestLastInputTickPacket {
public RequestLastInputTickPacket() {}
public static void encode(final RequestLastInputTickPacket packet, final FriendlyByteBuf buffer) {
NetworkManager.writeVersionInfo(buffer, false);
}
public static RequestLastInputTickPacket decode(final FriendlyByteBuf buffer) {
NetworkManager.checkVersion(buffer);
return new RequestLastInputTickPacket();
}
public static void handle(final RequestLastInputTickPacket packet, final Supplier<NetworkEvent.Context> contextSupplier) {
final NetworkEvent.Context context = contextSupplier.get();
context.enqueueWork(() -> {
// Send last input tick packet back to server
NetworkManager.getChannel().sendToServer(new LastInputTickPacket());
});
context.setPacketHandled(true);
}
}