encoding cache
This commit is contained in:
		@@ -21,38 +21,40 @@ public record DCReg(DeferredRegister<DataComponentType<?>> reg) {
 | 
			
		||||
		return new DCReg(parent.make(BuiltInRegistries.DATA_COMPONENT_TYPE));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public <T> DCVal<T> reg(String id, Codec<T> codec, StreamCodec<? super RegistryFriendlyByteBuf, T> stream) {
 | 
			
		||||
		return new DCValImpl<>(reg.register(id, () -> DataComponentType.<T>builder().persistent(codec).networkSynchronized(stream).build()));
 | 
			
		||||
	public <T> DCVal<T> reg(String id, Codec<T> codec, StreamCodec<? super RegistryFriendlyByteBuf, T> stream, boolean cache) {
 | 
			
		||||
		var builder = DataComponentType.<T>builder().persistent(codec).networkSynchronized(stream);
 | 
			
		||||
		if (cache) builder.cacheEncoding();
 | 
			
		||||
		return new DCValImpl<>(reg.register(id, builder::build));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public <T> DCVal<T> reg(String id, Class<T> cls) {
 | 
			
		||||
	public <T> DCVal<T> reg(String id, Class<T> cls, boolean cache) {
 | 
			
		||||
		var cdc = new CodecAdaptor<>(cls);
 | 
			
		||||
		return new DCValImpl<>(reg.register(id, () -> DataComponentType.<T>builder().persistent(cdc).networkSynchronized(cdc.toNetwork()).build()));
 | 
			
		||||
		return reg(id, cdc, cdc.toNetwork(), cache);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public DCVal<Integer> intVal(String id) {
 | 
			
		||||
		return reg(id, Codec.INT, ByteBufCodecs.INT);
 | 
			
		||||
		return reg(id, Codec.INT, ByteBufCodecs.INT, false);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public DCVal<Double> doubleVal(String id) {
 | 
			
		||||
		return reg(id, Codec.DOUBLE, ByteBufCodecs.DOUBLE);
 | 
			
		||||
		return reg(id, Codec.DOUBLE, ByteBufCodecs.DOUBLE, false);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public DCVal<Long> longVal(String id) {
 | 
			
		||||
		return reg(id, Codec.LONG, ByteBufCodecs.VAR_LONG);
 | 
			
		||||
		return reg(id, Codec.LONG, ByteBufCodecs.VAR_LONG, false);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public DCVal<String> str(String id) {
 | 
			
		||||
		return reg(id, Codec.STRING, ByteBufCodecs.STRING_UTF8);
 | 
			
		||||
		return reg(id, Codec.STRING, ByteBufCodecs.STRING_UTF8, false);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public DCVal<UUID> 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> component(String id) {
 | 
			
		||||
		return reg(id, ComponentSerialization.CODEC, ComponentSerialization.STREAM_CODEC);
 | 
			
		||||
		return reg(id, ComponentSerialization.CODEC, ComponentSerialization.STREAM_CODEC, true);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private record DCValImpl<T>(DeferredHolder<DataComponentType<?>, DataComponentType<T>> val) implements DCVal<T> {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user