40 lines
1.6 KiB
Java
40 lines
1.6 KiB
Java
package com.aranroig.payloads;
|
|
|
|
import com.aranroig.Codecraft;
|
|
import net.minecraft.network.RegistryFriendlyByteBuf;
|
|
import net.minecraft.network.codec.ByteBufCodecs;
|
|
import net.minecraft.network.codec.StreamCodec;
|
|
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
|
import net.minecraft.resources.Identifier;
|
|
|
|
/**
|
|
* The authoritative contents of {@code file} at {@code version}. Sent in reply
|
|
* to {@link ServerboundOpenDocumentPayload}, and again whenever the server
|
|
* finds that a client's copy is too old to be rebased onto the live one.
|
|
*/
|
|
public record ClientboundDocumentStatePayload(String file, String text, int version) implements CustomPacketPayload {
|
|
|
|
public static final Identifier DOCUMENT_STATE_PAYLOAD_ID = Identifier.fromNamespaceAndPath(Codecraft.MOD_ID, "document_state");
|
|
|
|
public static final CustomPacketPayload.Type<ClientboundDocumentStatePayload> TYPE = new CustomPacketPayload.Type<>(DOCUMENT_STATE_PAYLOAD_ID);
|
|
|
|
public static final StreamCodec<RegistryFriendlyByteBuf, ClientboundDocumentStatePayload> CODEC =
|
|
StreamCodec.composite(
|
|
ByteBufCodecs.STRING_UTF8,
|
|
ClientboundDocumentStatePayload::file,
|
|
|
|
ByteBufCodecs.STRING_UTF8,
|
|
ClientboundDocumentStatePayload::text,
|
|
|
|
ByteBufCodecs.VAR_INT,
|
|
ClientboundDocumentStatePayload::version,
|
|
|
|
ClientboundDocumentStatePayload::new
|
|
);
|
|
|
|
@Override
|
|
public Type<? extends CustomPacketPayload> type() {
|
|
return TYPE;
|
|
}
|
|
}
|