| 1 | package net.minecraft.world.item.slot;
|
| 2 |
|
| 3 | import com.mojang.datafixers.util.Either;
|
| 4 | import com.mojang.serialization.Codec;
|
| 5 | import com.mojang.serialization.MapCodec;
|
| 6 | import net.minecraft.core.Holder;
|
| 7 | import net.minecraft.core.HolderSet;
|
| 8 | import net.minecraft.core.Registry;
|
| 9 | import net.minecraft.core.registries.BuiltInRegistries;
|
| 10 | import net.minecraft.core.registries.Registries;
|
| 11 | import net.minecraft.core.registries.codec.RegistryCodecs;
|
| 12 |
|
| 13 | public interface SlotSources {
|
| 14 | Codec<SlotSource> TYPED_CODEC = BuiltInRegistries.SLOT_SOURCE_TYPE.byNameCodec().dispatch(SlotSource::codec, c -> c);
|
| 15 | Codec<SlotSource> DIRECT_CODEC = Codec.lazyInitialized(
|
| 16 | () -> Codec.either(TYPED_CODEC, GroupSlotSource.INLINE_CODEC)
|
| 17 | .xmap(
|
| 18 | typedOrInline -> typedOrInline.map(e -> (SlotSource)e, e -> (SlotSource)e),
|
| 19 | slotSource -> slotSource instanceof GroupSlotSource composite ? Either.right(composite) : Either.left(slotSource)
|
| 20 | )
|
| 21 | );
|
| 22 | Codec<Holder<SlotSource>> CODEC = RegistryCodecs.holder(Registries.SLOT_SOURCE, DIRECT_CODEC);
|
| 23 | Codec<HolderSet<SlotSource>> LIST_CODEC = RegistryCodecs.holderSet(Registries.SLOT_SOURCE, TYPED_CODEC);
|
| 24 |
|
| 25 | static MapCodec<? extends SlotSource> bootstrap(final Registry<MapCodec<? extends SlotSource>> registry) {
|
| 26 | Registry.register(registry, "group", GroupSlotSource.MAP_CODEC);
|
| 27 | Registry.register(registry, "filtered", FilteredSlotSource.MAP_CODEC);
|
| 28 | Registry.register(registry, "limit_slots", LimitSlotSource.MAP_CODEC);
|
| 29 | Registry.register(registry, "slot_range", RangeSlotSource.MAP_CODEC);
|
| 30 | Registry.register(registry, "contents", ContentsSlotSource.MAP_CODEC);
|
| 31 | return Registry.register(registry, "empty", EmptySlotSource.MAP_CODEC);
|
| 32 | }
|
| 33 | }
|
| 34 |
|