50 lines
1.3 KiB
Java
50 lines
1.3 KiB
Java
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<RegistryFriendlyByteBuf, EditorFile> STREAM_CODEC =
|
|
StreamCodec.composite(
|
|
ByteBufCodecs.STRING_UTF8,
|
|
EditorFile::getName,
|
|
|
|
ByteBufCodecs.STRING_UTF8,
|
|
EditorFile::getText,
|
|
|
|
EditorFile::new
|
|
);
|
|
|
|
public static final Codec<EditorFile> 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;
|
|
}
|
|
|
|
}
|