package com.aranroig.editor; import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.codec.ByteBufCodecs; import net.minecraft.network.codec.StreamCodec; public class EditorFile { public static final StreamCodec STREAM_CODEC = StreamCodec.composite( ByteBufCodecs.STRING_UTF8, EditorFile::getName, ByteBufCodecs.STRING_UTF8, EditorFile::getText, EditorFile::new ); public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( Codec.STRING.fieldOf("name").forGetter(EditorFile::getName), Codec.STRING.fieldOf("text").forGetter(EditorFile::getText) ).apply(instance, EditorFile::new) ); // Class with file info private String name; private String text; public EditorFile(String name, String text) { this.name = name; this.text = text; } public String getName() { return name; } public String getText() { return text; } public void setText(String text) { this.text = text; } }