mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-16 10:34:49 +00:00
Fix DatapackBuiltinEntriesProvider issues with forge registries, Fixes #9874
This commit is contained in:
9 files changed
+208
-29
No files matched your search
@@ -12,13 +12,7 @@ import net.minecraft.resources.RegistryDataLoader;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@ApiStatus.Internal
|
||||
@@ -26,8 +20,7 @@ public final class DataPackRegistriesHooks {
|
||||
private DataPackRegistriesHooks() {} // utility class
|
||||
|
||||
private static final Map<ResourceKey<? extends Registry<?>>, RegistrySynchronization.NetworkedRegistryData<?>> NETWORKABLE_REGISTRIES = new LinkedHashMap<>();
|
||||
private static final List<RegistryDataLoader.RegistryData<?>> DATA_PACK_REGISTRIES = new ArrayList<>(RegistryDataLoader.WORLDGEN_REGISTRIES);
|
||||
private static final List<RegistryDataLoader.RegistryData<?>> DATA_PACK_REGISTRIES_VIEW = Collections.unmodifiableList(DATA_PACK_REGISTRIES);
|
||||
private static final List<RegistryDataLoader.RegistryData<?>> WORLDGEN_REGISTRIES = new ArrayList<>();
|
||||
private static final Set<ResourceKey<? extends Registry<?>>> SYNCED_CUSTOM_REGISTRIES = new HashSet<>();
|
||||
private static final Set<ResourceKey<? extends Registry<?>>> SYNCED_CUSTOM_REGISTRIES_VIEW = Collections.unmodifiableSet(SYNCED_CUSTOM_REGISTRIES);
|
||||
|
||||
@@ -44,7 +37,7 @@ public final class DataPackRegistriesHooks {
|
||||
/* Internal forge method, registers a datapack registry codec and folder. */
|
||||
static <T> void addRegistryCodec(DataPackRegistryEvent.DataPackRegistryData<T> data) {
|
||||
RegistryDataLoader.RegistryData<T> loaderData = data.loaderData();
|
||||
DATA_PACK_REGISTRIES.add(loaderData);
|
||||
WORLDGEN_REGISTRIES.add(loaderData);
|
||||
if (data.networkCodec() != null) {
|
||||
SYNCED_CUSTOM_REGISTRIES.add(loaderData.key());
|
||||
NETWORKABLE_REGISTRIES.put(loaderData.key(), new RegistrySynchronization.NetworkedRegistryData<>(loaderData.key(), data.networkCodec()));
|
||||
@@ -55,12 +48,27 @@ public final class DataPackRegistriesHooks {
|
||||
* {@return An unmodifiable view of the list of datapack registries}.
|
||||
* These registries are loaded from per-world datapacks on server startup.
|
||||
*/
|
||||
@Deprecated // Use RegistryDataLoader#WORLDGEN_REGISTRIES instead
|
||||
public static List<RegistryDataLoader.RegistryData<?>> getDataPackRegistries() {
|
||||
return DATA_PACK_REGISTRIES_VIEW;
|
||||
return Collections.unmodifiableList(WORLDGEN_REGISTRIES);
|
||||
}
|
||||
|
||||
@Deprecated // Use RegistryDataLoader#WORLDGEN_REGISTRIES instead
|
||||
public static Stream<RegistryDataLoader.RegistryData<?>> getDataPackRegistriesWithDimensions() {
|
||||
return Stream.concat(DATA_PACK_REGISTRIES_VIEW.stream(), RegistryDataLoader.DIMENSION_REGISTRIES.stream());
|
||||
return WORLDGEN_REGISTRIES.stream();
|
||||
}
|
||||
|
||||
/**
|
||||
* Captures a mutable view of {@link RegistryDataLoader#WORLDGEN_REGISTRIES} so that we can register modded entries during the registry event.
|
||||
* All uses should use that field instead of this class.
|
||||
* @param vanilla The vanilla worldgen registries
|
||||
* @return An unmodifiable list of worldgen registries
|
||||
*/
|
||||
public static List<RegistryDataLoader.RegistryData<?>> grabWorldgenRegistries(RegistryDataLoader.RegistryData<?>... vanilla) {
|
||||
if (!StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE).getCallerClass().equals(RegistryDataLoader.class))
|
||||
throw new IllegalCallerException("Attempted to call DataPackRegistriesHooks#grabWorldgenRegistries!");
|
||||
WORLDGEN_REGISTRIES.addAll(Arrays.asList(vanilla));
|
||||
return Collections.unmodifiableList(WORLDGEN_REGISTRIES);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user