Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ neoform_version=2
neoforge_snapshot_next_stable=26.2

# renovate: net.neoforged.jst:jst-cli-bundle
jst_version=2.0.10
jst_version=2.0.11
legacyinstaller_version=3.0.+
# renovate: net.neoforged.installertools:installertools
installertools_version=4.0.17
Expand Down
25 changes: 22 additions & 3 deletions patches/net/minecraft/resources/RegistryDataLoader.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,36 @@
new RegistryDataLoader.RegistryData<>(Registries.BIOME, Biome.NETWORK_CODEC),
new RegistryDataLoader.RegistryData<>(Registries.CHAT_TYPE, ChatType.DIRECT_CODEC),
new RegistryDataLoader.RegistryData<>(Registries.TRIM_PATTERN, TrimPattern.DIRECT_CODEC),
@@ -162,7 +_,7 @@
@@ -162,21 +_,33 @@
new RegistryDataLoader.RegistryData<>(Registries.DIALOG, Dialog.DIRECT_CODEC),
new RegistryDataLoader.RegistryData<>(Registries.WORLD_CLOCK, WorldClock.DIRECT_CODEC),
new RegistryDataLoader.RegistryData<>(Registries.TIMELINE, Timeline.NETWORK_CODEC)
- );
+ )); // Neo: Keep the list so custom registries can be added later

+ /// @deprecated Neo: use [#load(ResourceManager, List, List, Executor, List)] instead
+ @Deprecated
public static CompletableFuture<RegistryAccess.Frozen> load(
ResourceManager resourceManager,
@@ -176,7 +_,7 @@
return new ResourceManagerRegistryLoadTask<>(data, Lifecycle.stable(), loadingErrors, resourceManager);
List<HolderLookup.RegistryLookup<?>> contextRegistries,
List<RegistryDataLoader.RegistryData<?>> registriesToLoad,
Executor executor
) {
+ return load(resourceManager, contextRegistries, registriesToLoad, executor, List.of());
+ }
+
+ public static CompletableFuture<RegistryAccess.Frozen> load(
+ ResourceManager resourceManager,
+ List<HolderLookup.RegistryLookup<?>> contextRegistries,
+ List<RegistryDataLoader.RegistryData<?>> registriesToLoad,
+ Executor executor,
+ List<Registry.PendingTags<?>> pendingTags
+ ) {
RegistryDataLoader.LoaderFactory loaderFactory = new RegistryDataLoader.LoaderFactory() {
@Override
public <T> RegistryLoadTask<T> create(RegistryDataLoader.RegistryData<T> data, Map<ResourceKey<?>, Exception> loadingErrors) {
- return new ResourceManagerRegistryLoadTask<>(data, Lifecycle.stable(), loadingErrors, resourceManager);
+ return new ResourceManagerRegistryLoadTask<>(data, Lifecycle.stable(), loadingErrors, resourceManager, pendingTags);
}
};
- return load(loaderFactory, contextRegistries, registriesToLoad, executor);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
--- a/net/minecraft/resources/ResourceManagerRegistryLoadTask.java
+++ b/net/minecraft/resources/ResourceManagerRegistryLoadTask.java
@@ -40,7 +_,7 @@
@@ -26,12 +_,22 @@
return new RegistrationInfo(knownPack, lifecycle);
});
private final ResourceManager resourceManager;
+ private final List<net.minecraft.core.Registry.PendingTags<?>> pendingTags;

+ /// @deprecated Neo: use [#ResourceManagerRegistryLoadTask(RegistryDataLoader.RegistryData, Lifecycle, Map, ResourceManager, List)] instead
+ @Deprecated
public ResourceManagerRegistryLoadTask(
RegistryDataLoader.RegistryData<T> data, Lifecycle lifecycle, Map<ResourceKey<?>, Exception> loadingErrors, ResourceManager resourceManager
) {
+ this(data, lifecycle, loadingErrors, resourceManager, List.of());
+ }
+
+ public ResourceManagerRegistryLoadTask(
+ RegistryDataLoader.RegistryData<T> data, Lifecycle lifecycle, Map<ResourceKey<?>, Exception> loadingErrors, ResourceManager resourceManager, List<net.minecraft.core.Registry.PendingTags<?>> pendingTags
+ ) {
super(data, lifecycle, loadingErrors);
this.resourceManager = resourceManager;
+ this.pendingTags = pendingTags;
}

@Override
@@ -40,7 +_,8 @@
return CompletableFuture.<Map<Identifier, Resource>>supplyAsync(() -> lister.listMatchingResources(this.resourceManager), executor)
.thenCompose(
registryResources -> {
- RegistryOps<JsonElement> ops = RegistryOps.create(JsonOps.INSTANCE, context);
+ RegistryOps<JsonElement> ops = new net.neoforged.neoforge.common.conditions.ConditionalOps<>(RegistryOps.create(JsonOps.INSTANCE, context), net.neoforged.neoforge.common.conditions.ICondition.IContext.TAGS_INVALID);
+ var conditionContext = new net.neoforged.neoforge.common.conditions.ConditionContext(pendingTags, context, net.minecraft.world.flag.FeatureFlags.VANILLA_SET);
+ RegistryOps<JsonElement> ops = new net.neoforged.neoforge.common.conditions.ConditionalOps<>(RegistryOps.create(JsonOps.INSTANCE, context), conditionContext);
return ParallelMapTransform.schedule(
(Map<Identifier, Resource>)registryResources,
(resourceId, thunk) -> {
10 changes: 10 additions & 0 deletions patches/net/minecraft/server/ReloadableServerRegistries.java.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
--- a/net/minecraft/server/ReloadableServerRegistries.java
+++ b/net/minecraft/server/ReloadableServerRegistries.java
@@ -44,7 +_,8 @@
context.getAccessForLoading(RegistryLayer.RELOADABLE), updatedContextTags
);
HolderLookup.Provider loadingContextWithTags = HolderLookup.Provider.create(contextRegistriesWithTags.stream());
- RegistryOps<JsonElement> ops = loadingContextWithTags.createSerializationContext(JsonOps.INSTANCE);
+ var conditionContext = new net.neoforged.neoforge.common.conditions.ConditionContext(updatedContextTags, RegistryAccess.EMPTY, loadingContextWithTags, net.minecraft.world.flag.FeatureFlags.VANILLA_SET);
+ RegistryOps<JsonElement> ops = new net.neoforged.neoforge.common.conditions.ConditionalOps<>(loadingContextWithTags.createSerializationContext(JsonOps.INSTANCE), conditionContext);
List<CompletableFuture<WritableRegistry<?>>> registryLoads = LootDataType.values()
.map(type -> scheduleRegistryLoad((LootDataType<?>)type, ops, manager, executor))
.toList();
@@ -60,7 +_,16 @@
return CompletableFuture.supplyAsync(() -> {
WritableRegistry<T> registry = new MappedRegistry<>(type.registryKey(), Lifecycle.experimental());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
+ // Neo: Store registries and create context object
+ this.registryAccess = fullLayers.compositeAccess();
+ this.loadingContext = loadingContext;
+ this.context = new net.neoforged.neoforge.common.conditions.ConditionContext(this.postponedTags, registryAccess, enabledFeatures);
+ this.context = new net.neoforged.neoforge.common.conditions.ConditionContext(this.postponedTags, this.registryAccess, this.loadingContext, enabledFeatures);
}

public ServerFunctionLibrary getFunctionLibrary() {
Expand Down
11 changes: 10 additions & 1 deletion patches/net/minecraft/server/WorldLoader.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@
RegistryAccess.Frozen worldgenLoadContext = initialLayers.getAccessForLoading(RegistryLayer.WORLDGEN);
List<HolderLookup.RegistryLookup<?>> worldgenContextRegistries = TagLoader.buildUpdatedLookups(worldgenLoadContext, staticLayerTags);
- return RegistryDataLoader.load(resources, worldgenContextRegistries, RegistryDataLoader.WORLDGEN_REGISTRIES, backgroundExecutor)
+ return RegistryDataLoader.load(resources, worldgenContextRegistries, net.neoforged.neoforge.registries.DataPackRegistriesHooks.getDataPackRegistries(), backgroundExecutor)
+ return RegistryDataLoader.load(resources, worldgenContextRegistries, net.neoforged.neoforge.registries.DataPackRegistriesHooks.getDataPackRegistries(), backgroundExecutor, staticLayerTags)
.thenComposeAsync(
loadedWorldgenRegistries -> {
List<HolderLookup.RegistryLookup<?>> dimensionContextRegistries = Stream.concat(
@@ -47,7 +_,7 @@
)
.toList();
return RegistryDataLoader.load(
- resources, dimensionContextRegistries, RegistryDataLoader.DIMENSION_REGISTRIES, backgroundExecutor
+ resources, dimensionContextRegistries, RegistryDataLoader.DIMENSION_REGISTRIES, backgroundExecutor, staticLayerTags
)
.thenComposeAsync(
initialWorldgenDimensions -> {
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,44 @@
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderGetter;
import net.minecraft.core.HolderSet;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.resources.RegistryOps;
import net.minecraft.resources.ResourceKey;
import net.minecraft.tags.TagKey;
import net.minecraft.world.flag.FeatureFlagSet;

public class ConditionContext implements ICondition.IContext {
private final Map<TagKey<?>, List<? extends Holder<?>>> pendingContents;
private final FeatureFlagSet enabledFeatures;
private final RegistryAccess registryAccess;
private final HolderGetter.Provider registries;

/// @deprecated Use [#ConditionContext(List, RegistryAccess, HolderGetter.Provider, FeatureFlagSet)] instead
@Deprecated(forRemoval = true, since = "26.2")
public ConditionContext(List<Registry.PendingTags<?>> pendingTags, RegistryAccess registryAccess, FeatureFlagSet enabledFeatures) {
this(pendingTags, registryAccess, registryAccess, enabledFeatures);
}

public ConditionContext(List<Registry.PendingTags<?>> pendingTags, RegistryOps.RegistryInfoLookup context, FeatureFlagSet enabledFeatures) {
HolderGetter.Provider registries = new HolderGetter.Provider() {
@Override
public <T> Optional<? extends HolderGetter<T>> lookup(ResourceKey<? extends Registry<? extends T>> key) {
Optional<RegistryOps.RegistryInfo<T>> lookup = context.lookup(key);
return lookup.map(RegistryOps.RegistryInfo::getter);
}
};
this(pendingTags, RegistryAccess.EMPTY, registries, enabledFeatures);
}

public ConditionContext(List<Registry.PendingTags<?>> pendingTags, RegistryAccess registryAccess, HolderGetter.Provider registries, FeatureFlagSet enabledFeatures) {
this.pendingContents = new IdentityHashMap<>();
this.registryAccess = registryAccess;
this.registries = registries;
this.enabledFeatures = enabledFeatures;

for (Registry.PendingTags<?> tags : pendingTags) {
Expand All @@ -36,18 +60,28 @@

@Override
public <T> boolean isTagLoaded(TagKey<T> key) {
return this.pendingContents.containsKey(key);
return this.registries.get(key).isPresent();
}

@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public <T> Collection<Holder<T>> getTag(TagKey<T> key) {
Optional<List<Holder<T>>> holders = this.registries.get(key).filter(HolderSet.Named::isBound).map(HolderSet.Named::contents);
if (holders.isPresent()) {
return holders.get();
}

List<? extends Holder<?>> contents = this.pendingContents.get(key);
return contents != null ? (Collection) contents : List.of();
}

@Override
public HolderGetter.Provider registries() {
return registries;
}

@Override
public RegistryAccess registryAccess() {

Check warning on line 84 in src/main/java/net/neoforged/neoforge/common/conditions/ConditionContext.java

View workflow job for this annotation

GitHub Actions / build

[removal] registryAccess() in IContext has been deprecated and marked for removal

Check warning on line 84 in src/main/java/net/neoforged/neoforge/common/conditions/ConditionContext.java

View workflow job for this annotation

GitHub Actions / check-local-changes

[removal] registryAccess() in IContext has been deprecated and marked for removal

Check warning on line 84 in src/main/java/net/neoforged/neoforge/common/conditions/ConditionContext.java

View workflow job for this annotation

GitHub Actions / build

registryAccess() in IContext has been deprecated and marked for removal
return registryAccess;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,12 @@ public <T> DataResult<Pair<Optional<WithConditions<A>>, T>> decode(DynamicOps<T>
return contextDataResult.flatMap(contextCarrier -> {
final ICondition.IContext context = contextCarrier.getFirst();

final boolean conditionsMatch = conditions.stream().allMatch(c -> c.test(context));
final boolean conditionsMatch;
try {
conditionsMatch = conditions.stream().allMatch(c -> c.test(context));
} catch (Throwable t) {
return DataResult.error(t::getMessage);
}
if (!conditionsMatch)
return DataResult.success(Pair.of(Optional.empty(), input));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Optional;
import java.util.function.Function;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderGetter;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.Registry.PendingTags;
import net.minecraft.core.RegistryAccess;
Expand Down Expand Up @@ -115,15 +116,23 @@ default <T> Collection<Holder<T>> getTag(TagKey<T> key) {
return List.of();
}

/// Provides the context registries with partially bound tags for the currently active reload if
/// this context is used for a datapack reload.
///
/// @return the context registries of the active reload
default HolderGetter.Provider registries() {
return RegistryAccess.EMPTY;
}

/// Provides access to the loaded registries if this context is used for a datapack reload.
///
/// @apiNote The returned [RegistryAccess] does NOT provide access to the tags loaded during the active reload.
/// To resolve tags the [HolderLookup.Provider] provided via [ContextAwareReloadListener#getRegistryLookup()]
/// must be used instead.
/// To resolve tags the [HolderLookup.Provider] provided via [#registries()] or
/// [ContextAwareReloadListener#getRegistryLookup()] must be used instead.
///
/// @return The [RegistryAccess] context for the currently active reload.
///
/// @deprecated Use [ContextAwareReloadListener#getRegistryLookup()] instead
/// @deprecated Use [#registries()] or [ContextAwareReloadListener#getRegistryLookup()] instead
@Deprecated(forRemoval = true, since = "26.1.2")
default RegistryAccess registryAccess() {
return RegistryAccess.EMPTY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private RegisteredCondition(Identifier registryType, Identifier registryName) {

@Override
public boolean test(IContext context) {
return context.registryAccess().holder(registryKey).map(Holder::isBound).orElse(false);
return context.registries().get(registryKey).map(Holder::isBound).orElse(false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

/**
* Game tests are registered on client or server startup.
* It is run in {@link net.minecraft.resources.RegistryDataLoader#load(ResourceManager, List, List, java.util.concurrent.Executor)} if {@link GameTestHooks#isGametestEnabled} returns true.
* It is run in {@link net.minecraft.resources.RegistryDataLoader#load(ResourceManager, List, List, List, java.util.concurrent.Executor)} if {@link GameTestHooks#isGametestEnabled} returns true.
* <p>
* Fired on the Mod bus, see {@link IModBusEvent}.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/META-INF/accesstransformer.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public net.minecraft.commands.CommandSourceStack source # source
public net.minecraft.commands.arguments.selector.EntitySelectorParser finalizePredicates()V # finalizePredicates
public net.minecraft.commands.arguments.selector.EntitySelectorParser parseOptions()V # parseOptions
public net.minecraft.commands.arguments.selector.options.EntitySelectorOptions register(Ljava/lang/String;Lnet/minecraft/commands/arguments/selector/options/EntitySelectorOptions$Modifier;Ljava/util/function/Predicate;Lnet/minecraft/network/chat/Component;)V # register
public net.minecraft.core.HolderSet$Named contents()Ljava/util/List;
public net.minecraft.core.HolderSet$1 contents()Ljava/util/List;
protected net.minecraft.core.IdMapper nextId # nextId
protected net.minecraft.core.IdMapper tToId # tToId - internal map
protected net.minecraft.core.IdMapper idToT # idToT - internal index list
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"neoforge:conditions": [
{
"type": "neoforge:not",
"value": {
"type": "neoforge:registered",
"value": "nope:no_such_item"
}
}
],
"asset_id": "neotests_datapack_registry_conditions:absent_static_object",
"decal": false,
"description": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"neoforge:conditions": [
{
"type": "neoforge:tag_empty",
"tag": "nope:no_such_item_tag"
}
],
"asset_id": "neotests_datapack_registry_conditions:absent_static_tag",
"decal": false,
"description": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"neoforge:conditions": [
{
"type": "neoforge:tag_empty",
"tag": "c:drinks/juice"
}
],
"asset_id": "neotests_datapack_registry_conditions:present_empty_static_tag",
"decal": false,
"description": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"neoforge:conditions": [
{
"type": "neoforge:not",
"value": {
"type": "neoforge:tag_empty",
"tag": "c:eggs"
}
}
],
"asset_id": "neotests_datapack_registry_conditions:present_non_empty_static_tag",
"decal": false,
"description": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"neoforge:conditions": [
{
"type": "neoforge:registered",
"value": "minecraft:redstone"
}
],
"asset_id": "neotests_datapack_registry_conditions:present_static_object",
"decal": false,
"description": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"neoforge:conditions": [
{
"type": "neoforge:not",
"value": {
"type": "neoforge:registered",
"registry": "minecraft:worldgen/biome",
"value": "nope:no_such_biome"
}
}
],
"type": "minecraft:crafting_special_repairitem"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"neoforge:conditions": [
{
"type": "neoforge:tag_empty",
"registry": "minecraft:worldgen/biome",
"tag": "nope:no_such_biome_tag"
}
],
"type": "minecraft:crafting_special_repairitem"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"neoforge:conditions": [
{
"type": "neoforge:not",
"value": {
"type": "neoforge:registered",
"registry": "minecraft:loot_table",
"value": "nope:no_such_loot_table"
}
}
],
"type": "minecraft:crafting_special_repairitem"
}
Loading
Loading