| 47 | import picocli.CommandLine; |
| 48 | |
| 49 | @CommandLine.Command( |
| 50 | name = "generator", |
| 51 | description = "Rewrite and generate API classes and its implementation for Paper" |
| 52 | ) |
| 53 | public class Main implements Callable<Integer> { |
| 54 | |
| 55 | @CommandLine.Option(names = {"--sourceset"}, required = true) |
| 56 | Path sourceSet; |
| 57 | |
| 58 | @CommandLine.Option(names = {"-cp", "--classpath"}, split = "[;:]", required = true) |
| 59 | Set<Path> classpath; |
| 60 | |
| 61 | @CommandLine.Option(names = {"--rewrite"}) |
| 62 | boolean isRewrite; |
| 63 | |
| 64 | @CommandLine.Option(names = {"--side"}, required = true) |
| 65 | String side; |
| 66 | |
| 67 | @CommandLine.Option(names = {"--bootstrap-tags"}) |
| 68 | boolean tagBootstrap; |
| 69 | |
| 70 | private static final Logger LOGGER = LogUtils.getLogger(); |
| 71 | |
| 72 | public static RegistryAccess.@MonotonicNonNull Frozen REGISTRY_ACCESS; |
| 73 | public static @MonotonicNonNull Map<TagKey<?>, String> EXPERIMENTAL_TAGS; |
| 74 | |
| 75 | public static CompletableFuture<Void> bootStrap(boolean withTags) { |
| 76 | SharedConstants.tryDetectVersion(); |
| 77 | Bootstrap.bootStrap(); |
| 78 | Bootstrap.validate(); |
| 79 | |
| 80 | PackRepository packRepository = ServerPacksSource.createVanillaTrustedRepository(); |
| 81 | FeatureFlagSet flags = FeatureFlags.REGISTRY.allFlags(); |
| 82 | MinecraftServer.configurePackRepository(packRepository, new WorldDataConfiguration(new DataPackConfig(FeatureFlags.REGISTRY.toNames(flags).stream().map(Identifier::getPath).toList(), List.of()), flags), true, false); |
| 83 | CloseableResourceManager resourceManager = new MultiPackResourceManager(PackType.SERVER_DATA, packRepository.openAllSelected()); |
| 84 | |
| 85 | LayeredRegistryAccess<RegistryLayer> layers = RegistryLayer.createRegistryAccess(); |
| 86 | List<Registry.PendingTags<?>> pendingTags = TagLoader.loadTagsForExistingRegistries(resourceManager, layers.getLayer(RegistryLayer.STATIC)); |
| 87 | List<HolderLookup.RegistryLookup<?>> worldGenLayer = TagLoader.buildUpdatedLookups(layers.getAccessForLoading(RegistryLayer.WORLDGEN), pendingTags); |
| 88 | RegistryAccess.Frozen frozenWorldgenRegistries = RegistryDataLoader.load(resourceManager, worldGenLayer, RegistryDataLoader.WORLDGEN_REGISTRIES, Util.backgroundExecutor()).join(); |
| 89 | layers = layers.replaceFrom(RegistryLayer.WORLDGEN, frozenWorldgenRegistries); |
| 90 | List<HolderLookup.RegistryLookup<?>> staticAndWorldgenLookups = Stream.concat(worldGenLayer.stream(), frozenWorldgenRegistries.listRegistries()).toList(); |
| 91 | RegistryAccess.Frozen dimensionRegistries = RegistryDataLoader.load(resourceManager, staticAndWorldgenLookups, RegistryDataLoader.DIMENSION_REGISTRIES, Util.backgroundExecutor()).join(); |
| 92 | layers = layers.replaceFrom(RegistryLayer.DIMENSIONS, dimensionRegistries); |
| 93 | REGISTRY_ACCESS = layers.compositeAccess().freeze(); |
| 94 | if (withTags) { |
| 95 | return ReloadableServerResources.loadResources( |
| 96 | resourceManager, |
| 97 | layers, |
| 98 | pendingTags, |
| 99 | flags, |
| 100 | Commands.CommandSelection.DEDICATED, |
| 101 | LevelBasedPermissionSet.GAMEMASTER, |
| 102 | Util.backgroundExecutor(), |
| 103 | Runnable::run |
| 104 | ).whenComplete((result, ex) -> { |
| 105 | if (ex != null) { |
| 106 | resourceManager.close(); |