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; /** * Asks the server to rename a project file: its copy in the saved project and * its live document move to the new name, the sessions of everyone editing it * follow, and the other editors are told * ({@link ClientboundRenameFilePayload}). */ public record ServerboundRenameFilePayload(String oldName, String newName) implements CustomPacketPayload { public static final Identifier RENAME_FILE_PAYLOAD_ID = Identifier.fromNamespaceAndPath(Codecraft.MOD_ID, "rename_file"); public static final CustomPacketPayload.Type TYPE = new CustomPacketPayload.Type<>(RENAME_FILE_PAYLOAD_ID); public static final StreamCodec CODEC = StreamCodec.composite( ByteBufCodecs.STRING_UTF8, ServerboundRenameFilePayload::oldName, ByteBufCodecs.STRING_UTF8, ServerboundRenameFilePayload::newName, ServerboundRenameFilePayload::new ); @Override public Type type() { return TYPE; } }