This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package com.aranroig.payloads;
|
||||
|
||||
import com.aranroig.Codecraft;
|
||||
import com.aranroig.editor.Edit;
|
||||
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;
|
||||
|
||||
/**
|
||||
* One keystroke's worth of changes to {@code file}, made against version
|
||||
* {@code baseVersion} of it. The server rebases the edit onto the current
|
||||
* version, applies it, and hands it to everyone else editing the file.
|
||||
*/
|
||||
public record ServerboundEditPayload(String file, int baseVersion, Edit edit) implements CustomPacketPayload {
|
||||
|
||||
public static final Identifier EDIT_PAYLOAD_ID = Identifier.fromNamespaceAndPath(Codecraft.MOD_ID, "edit");
|
||||
|
||||
public static final CustomPacketPayload.Type<ServerboundEditPayload> TYPE = new CustomPacketPayload.Type<>(EDIT_PAYLOAD_ID);
|
||||
|
||||
public static final StreamCodec<RegistryFriendlyByteBuf, ServerboundEditPayload> CODEC =
|
||||
StreamCodec.composite(
|
||||
ByteBufCodecs.STRING_UTF8,
|
||||
ServerboundEditPayload::file,
|
||||
|
||||
ByteBufCodecs.VAR_INT,
|
||||
ServerboundEditPayload::baseVersion,
|
||||
|
||||
Edit.STREAM_CODEC,
|
||||
ServerboundEditPayload::edit,
|
||||
|
||||
ServerboundEditPayload::new
|
||||
);
|
||||
|
||||
@Override
|
||||
public Type<? extends CustomPacketPayload> type() {
|
||||
return TYPE;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user