RegistryPatchGenerator .java

net.minecraft.data.registries.RegistryPatchGenerator (class): members: contextFuture, vanillaFuture, createReloadableLookup, createWorldLookup, vanilla.

net.minecraft.data.registriesclass56 linescommon2.7 KB

API Surface (2)

CompletableFuture<RegistrySetBuilder.PatchedRegistries> createWorldLookup(final CompletableFuture<HolderLookup.Provider> vanilla, final RegistrySetBuilder packBuilder)
CompletableFuture<RegistrySetBuilder.PatchedRegistries> createReloadableLookup(final CompletableFuture<HolderLookup.Provider> contextFuture, final CompletableFuture<HolderLookup.Provider> vanillaFuture, final RegistrySetBuilder packBuilder)

Fields & Constants (3)

vanilla
contextFuture
vanillaFuture

Full Source

RegistryPatchGenerator.java56 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.data.registries;
2
3
import java.util.concurrent.CompletableFuture;
4
import net.minecraft.core.Cloner;
5
import net.minecraft.core.HolderLookup;
6
import net.minecraft.core.Registry;
7
import net.minecraft.core.RegistryAccess;
8
import net.minecraft.core.RegistrySetBuilder;
9
import net.minecraft.core.registries.BuiltInRegistries;
10
import net.minecraft.core.registries.Registries;
11
import net.minecraft.resources.RegistryDataLoader;
12
import net.minecraft.resources.ResourceKey;
13
import net.minecraft.world.level.storage.loot.LootDataType;
14
15
public class RegistryPatchGenerator {
16
	private static boolean hasAnyPatchedElement(final RegistrySetBuilder.PatchedRegistries newRegistries, final ResourceKey<? extends Registry<?>> registry) {
17
		return newRegistries.patches().lookup(registry).flatMap(lookup -> lookup.listElements().findAny()).isPresent();
18
	}
19
20
	public static CompletableFuture<RegistrySetBuilder.PatchedRegistries> createWorldLookup(
21
		final CompletableFuture<HolderLookup.Provider> vanilla, final RegistrySetBuilder packBuilder
22
	) {
23
		return vanilla.thenApply(parent -> {
24
			RegistryAccess.Frozen staticRegistries = RegistryAccess.fromRegistryOfRegistries(BuiltInRegistries.REGISTRY);
25
			Cloner.Factory cloner = new Cloner.Factory();
26
			RegistryDataLoader.WORLD_REGISTRIES.forEach(registryData -> registryData.runWithArguments(cloner::addCodec));
27
			RegistrySetBuilder.PatchedRegistries newRegistries = packBuilder.buildPatch(staticRegistries, parent, cloner);
28
			boolean hasAnyPatchedBiomes = hasAnyPatchedElement(newRegistries, Registries.BIOME);
29
			boolean hasAnyPatchedFeatures = hasAnyPatchedElement(newRegistries, Registries.PLACED_FEATURE);
30
			if (hasAnyPatchedBiomes || hasAnyPatchedFeatures) {
31
				VanillaRegistries.validateThatAllBiomeFeaturesHaveBiomeFilter(newRegistries.full());
32
			}
33
34
			return newRegistries;
35
		});
36
	}
37
38
	public static CompletableFuture<RegistrySetBuilder.PatchedRegistries> createReloadableLookup(
39
		final CompletableFuture<HolderLookup.Provider> contextFuture,
40
		final CompletableFuture<HolderLookup.Provider> vanillaFuture,
41
		final RegistrySetBuilder packBuilder
42
	) {
43
		return contextFuture.thenCombine(vanillaFuture, (context, vanilla) -> {
44
			Cloner.Factory cloner = new Cloner.Factory();
45
			RegistryDataLoader.RELOADABLE_REGISTRIES.forEach(registryData -> registryData.runWithArguments(cloner::addCodec));
46
			RegistrySetBuilder.PatchedRegistries newRegistries = packBuilder.buildPatch(context, vanilla, cloner);
47
			boolean hasAnyPatchedLootData = LootDataType.values().anyMatch(type -> hasAnyPatchedElement(newRegistries, type.registryKey()));
48
			if (hasAnyPatchedLootData) {
49
				VanillaRegistries.validateLootData(newRegistries.full());
50
			}
51
52
			return newRegistries;
53
		});
54
	}
55
}
56

Decompiled Minecraft 26.3 source of RegistryPatchGenerator (net/minecraft/data/registries/RegistryPatchGenerator.java) with Mojang official mappings, stored verbatim on the site.