Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@ public record DataComponentAdapter<NMS, API>(
) {
static final Function<Void, Unit> API_TO_UNIT_CONVERTER = $ -> Unit.INSTANCE;

static final Function API_TO_UNIMPLEMENTED_CONVERTER = $ -> {
throw new UnsupportedOperationException("Cannot convert an API value to an unimplemented type");
};

public boolean isValued() {
return this.apiToVanilla != API_TO_UNIT_CONVERTER;
}

public boolean isUnimplemented() {
return this.apiToVanilla == API_TO_UNIMPLEMENTED_CONVERTER;
}

public NMS toVanilla(final API value) {
final NMS nms = this.apiToVanilla.apply(value);
if (this.codecValidation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public final class DataComponentAdapters {
throw new UnsupportedOperationException("Cannot convert the Unit type to an API value");
};

static final Function UNIMPLEMENTED_TO_API_CONVERTER = $ -> {
throw new UnsupportedOperationException("Cannot convert the an unimplemented type to an API value");
};

static final Map<ResourceKey<DataComponentType<?>>, DataComponentAdapter<?, ?>> ADAPTERS = new HashMap<>();

public static void bootstrap() {
Expand Down Expand Up @@ -136,10 +140,9 @@ public static void bootstrap() {
// register(DataComponents.LOCK, PaperLockCode::new);
register(DataComponents.CONTAINER_LOOT, PaperSeededContainerLoot::new);

// TODO: REMOVE THIS... we want to build the PR... so lets just make things UNTYPED!
for (final Map.Entry<ResourceKey<DataComponentType<?>>, DataComponentType<?>> componentType : BuiltInRegistries.DATA_COMPONENT_TYPE.entrySet()) {
if (!ADAPTERS.containsKey(componentType.getKey())) {
registerUntyped((DataComponentType<Unit>) componentType.getValue());
registerUnimplemented(componentType.getValue());
}
}
}
Expand All @@ -152,6 +155,10 @@ private static <COMMON> void registerIdentity(final DataComponentType<COMMON> ty
registerInternal(type, Function.identity(), Function.identity(), true);
}

public static <NMS> void registerUnimplemented(final DataComponentType<NMS> type) {
registerInternal(type, UNIMPLEMENTED_TO_API_CONVERTER, DataComponentAdapter.API_TO_UNIMPLEMENTED_CONVERTER, false);
}

private static <NMS, API extends Handleable<NMS>> void register(final DataComponentType<NMS> type, final Function<NMS, API> vanillaToApi) {
registerInternal(type, vanillaToApi, Handleable::getHandle, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ public static <NMS> DataComponentType of(final NamespacedKey key, final net.mine
if (adapter == null) {
throw new IllegalArgumentException("No adapter found for " + key);
}
if (adapter.isValued()) {
if (adapter.isUnimplemented()) {
return new Unimplemented<>(key, type, adapter);
} else if (adapter.isValued()) {
return new ValuedImpl<>(key, type, adapter);
} else {
return new NonValuedImpl<>(key, type, adapter);
Expand Down Expand Up @@ -105,4 +107,15 @@ public static final class ValuedImpl<T, NMS> extends PaperDataComponentType<T, N
super(key, type, adapter);
}
}

public static final class Unimplemented<T, NMS> extends PaperDataComponentType<T, NMS> {

public Unimplemented(
final NamespacedKey key,
final net.minecraft.core.component.DataComponentType<NMS> type,
final DataComponentAdapter<NMS, T> adapter
) {
super(key, type, adapter);
}
}
}