| 1 | package net.minecraft.world.level.storage.loot;
|
| 2 |
|
| 3 | import com.mojang.serialization.Codec;
|
| 4 | import com.mojang.serialization.DataResult;
|
| 5 | import java.util.Map;
|
| 6 | import java.util.stream.Collectors;
|
| 7 | import java.util.stream.Stream;
|
| 8 | import net.minecraft.core.component.DataComponentType;
|
| 9 | import net.minecraft.core.component.DataComponents;
|
| 10 | import net.minecraft.core.registries.BuiltInRegistries;
|
| 11 | import net.minecraft.world.item.component.BundleContents;
|
| 12 | import net.minecraft.world.item.component.ChargedProjectiles;
|
| 13 | import net.minecraft.world.item.component.ItemContainerContents;
|
| 14 |
|
| 15 | public interface ContainerComponentManipulators {
|
| 16 | ContainerComponentManipulator<ItemContainerContents> CONTAINER = new ContainerComponentManipulator<>(DataComponents.CONTAINER, ItemContainerContents.EMPTY);
|
| 17 | ContainerComponentManipulator<BundleContents> BUNDLE_CONTENTS = new ContainerComponentManipulator<>(DataComponents.BUNDLE_CONTENTS, BundleContents.EMPTY);
|
| 18 | ContainerComponentManipulator<ChargedProjectiles> CHARGED_PROJECTILES = new ContainerComponentManipulator<>(
|
| 19 | DataComponents.CHARGED_PROJECTILES, ChargedProjectiles.EMPTY
|
| 20 | );
|
| 21 | Map<DataComponentType<?>, ContainerComponentManipulator<?>> ALL_MANIPULATORS = Stream.of(CONTAINER, BUNDLE_CONTENTS, CHARGED_PROJECTILES)
|
| 22 | .collect(Collectors.toMap(ContainerComponentManipulator::type, e -> (ContainerComponentManipulator<?>)e));
|
| 23 | Codec<ContainerComponentManipulator<?>> CODEC = BuiltInRegistries.DATA_COMPONENT_TYPE.byNameCodec().comapFlatMap(type -> {
|
| 24 | ContainerComponentManipulator<?> manipulator = ALL_MANIPULATORS.get(type);
|
| 25 | return manipulator != null ? DataResult.success(manipulator) : DataResult.error(() -> "No items in component");
|
| 26 | }, ContainerComponentManipulator::type);
|
| 27 | }
|
| 28 |
|