diff --git a/gradle.properties b/gradle.properties index 247e7f5..a9ac03d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,7 +18,7 @@ loader_version_range=[2,) mod_id=l2core mod_name=L2Core mod_license=LGPL-2.1 -mod_version=3.0.3-pre7 +mod_version=3.0.3-pre8 mod_group_id=dev.xkmc mod_authors=lcy0x1 mod_description=Core Library mod for all L2 mods diff --git a/src/main/java/dev/xkmc/l2core/init/reg/simple/DCReg.java b/src/main/java/dev/xkmc/l2core/init/reg/simple/DCReg.java index 2e035a3..a58848b 100644 --- a/src/main/java/dev/xkmc/l2core/init/reg/simple/DCReg.java +++ b/src/main/java/dev/xkmc/l2core/init/reg/simple/DCReg.java @@ -21,38 +21,40 @@ public record DCReg(DeferredRegister> reg) { return new DCReg(parent.make(BuiltInRegistries.DATA_COMPONENT_TYPE)); } - public DCVal reg(String id, Codec codec, StreamCodec stream) { - return new DCValImpl<>(reg.register(id, () -> DataComponentType.builder().persistent(codec).networkSynchronized(stream).build())); + public DCVal reg(String id, Codec codec, StreamCodec stream, boolean cache) { + var builder = DataComponentType.builder().persistent(codec).networkSynchronized(stream); + if (cache) builder.cacheEncoding(); + return new DCValImpl<>(reg.register(id, builder::build)); } - public DCVal reg(String id, Class cls) { + public DCVal reg(String id, Class cls, boolean cache) { var cdc = new CodecAdaptor<>(cls); - return new DCValImpl<>(reg.register(id, () -> DataComponentType.builder().persistent(cdc).networkSynchronized(cdc.toNetwork()).build())); + return reg(id, cdc, cdc.toNetwork(), cache); } public DCVal intVal(String id) { - return reg(id, Codec.INT, ByteBufCodecs.INT); + return reg(id, Codec.INT, ByteBufCodecs.INT, false); } public DCVal doubleVal(String id) { - return reg(id, Codec.DOUBLE, ByteBufCodecs.DOUBLE); + return reg(id, Codec.DOUBLE, ByteBufCodecs.DOUBLE, false); } public DCVal longVal(String id) { - return reg(id, Codec.LONG, ByteBufCodecs.VAR_LONG); + return reg(id, Codec.LONG, ByteBufCodecs.VAR_LONG, false); } public DCVal str(String id) { - return reg(id, Codec.STRING, ByteBufCodecs.STRING_UTF8); + return reg(id, Codec.STRING, ByteBufCodecs.STRING_UTF8, false); } public DCVal uuid(String id) { return reg(id, Codec.STRING.xmap(UUID::fromString, UUID::toString), - StreamCodec.of((b, e) -> FriendlyByteBuf.writeUUID(b, e), b -> FriendlyByteBuf.readUUID(b))); + StreamCodec.of((b, e) -> FriendlyByteBuf.writeUUID(b, e), b -> FriendlyByteBuf.readUUID(b)), true); } public DCVal component(String id) { - return reg(id, ComponentSerialization.CODEC, ComponentSerialization.STREAM_CODEC); + return reg(id, ComponentSerialization.CODEC, ComponentSerialization.STREAM_CODEC, true); } private record DCValImpl(DeferredHolder, DataComponentType> val) implements DCVal {