mirror of
https://github.com/PaperMC/Paper.git
synced 2025-05-19 13:40:24 -07:00
Add type to represent unimplemented data component types (#12222)
This commit is contained in:
parent
8e69d981fa
commit
2526fe063a
@ -15,10 +15,18 @@ public record DataComponentAdapter<NMS, API>(
|
|||||||
) {
|
) {
|
||||||
static final Function<Void, Unit> API_TO_UNIT_CONVERTER = $ -> Unit.INSTANCE;
|
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() {
|
public boolean isValued() {
|
||||||
return this.apiToVanilla != API_TO_UNIT_CONVERTER;
|
return this.apiToVanilla != API_TO_UNIT_CONVERTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isUnimplemented() {
|
||||||
|
return this.apiToVanilla == API_TO_UNIMPLEMENTED_CONVERTER;
|
||||||
|
}
|
||||||
|
|
||||||
public NMS toVanilla(final API value) {
|
public NMS toVanilla(final API value) {
|
||||||
final NMS nms = this.apiToVanilla.apply(value);
|
final NMS nms = this.apiToVanilla.apply(value);
|
||||||
if (this.codecValidation) {
|
if (this.codecValidation) {
|
||||||
|
@ -63,6 +63,10 @@ public final class DataComponentAdapters {
|
|||||||
throw new UnsupportedOperationException("Cannot convert the Unit type to an API value");
|
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<>();
|
static final Map<ResourceKey<DataComponentType<?>>, DataComponentAdapter<?, ?>> ADAPTERS = new HashMap<>();
|
||||||
|
|
||||||
public static void bootstrap() {
|
public static void bootstrap() {
|
||||||
@ -136,10 +140,9 @@ public final class DataComponentAdapters {
|
|||||||
// register(DataComponents.LOCK, PaperLockCode::new);
|
// register(DataComponents.LOCK, PaperLockCode::new);
|
||||||
register(DataComponents.CONTAINER_LOOT, PaperSeededContainerLoot::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()) {
|
for (final Map.Entry<ResourceKey<DataComponentType<?>>, DataComponentType<?>> componentType : BuiltInRegistries.DATA_COMPONENT_TYPE.entrySet()) {
|
||||||
if (!ADAPTERS.containsKey(componentType.getKey())) {
|
if (!ADAPTERS.containsKey(componentType.getKey())) {
|
||||||
registerUntyped((DataComponentType<Unit>) componentType.getValue());
|
registerUnimplemented(componentType.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -152,6 +155,10 @@ public final class DataComponentAdapters {
|
|||||||
registerInternal(type, Function.identity(), Function.identity(), true);
|
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) {
|
private static <NMS, API extends Handleable<NMS>> void register(final DataComponentType<NMS> type, final Function<NMS, API> vanillaToApi) {
|
||||||
registerInternal(type, vanillaToApi, Handleable::getHandle, false);
|
registerInternal(type, vanillaToApi, Handleable::getHandle, false);
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,9 @@ public abstract class PaperDataComponentType<T, NMS> implements DataComponentTyp
|
|||||||
if (adapter == null) {
|
if (adapter == null) {
|
||||||
throw new IllegalArgumentException("No adapter found for " + key);
|
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);
|
return new ValuedImpl<>(key, type, adapter);
|
||||||
} else {
|
} else {
|
||||||
return new NonValuedImpl<>(key, type, adapter);
|
return new NonValuedImpl<>(key, type, adapter);
|
||||||
@ -105,4 +107,15 @@ public abstract class PaperDataComponentType<T, NMS> implements DataComponentTyp
|
|||||||
super(key, type, adapter);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user