Skip to content

Commit

Permalink
Switch tag contains to something that won't crash after registries ar…
Browse files Browse the repository at this point in the history
…e frozen
  • Loading branch information
KnightMiner committed Apr 9, 2022
1 parent 27eaee6 commit 3e633a8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package slimeknights.mantle.recipe.helper;

import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -51,7 +50,7 @@ private static <T> Optional<T> getUncachedPreference(TagKey<T> tag) {
}
// streams have a lovely function to get the minimum element based on a comparator
// if the tag is empty, stream is empty so returns empty
return RegistryHelper.getTagStream(tag).filter(Holder::isBound).map(Holder::value).min(getComparator(registry));
return RegistryHelper.getTagValueStream(tag).min(getComparator(registry));
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/slimeknights/mantle/util/RegistryHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ public static <T> Stream<T> getTagValueStream(TagKey<T> key) {

/** Checks if the given tag contains the given registry object */
public static <T> boolean contains(Registry<T> registry, TagKey<T> tag, T value) {
return registry.createIntrusiveHolder(value).is(tag);
int index = registry.getId(value);
if (index == Registry.DEFAULT) {
return false;
}
return registry.getHolder(index).filter(holder -> holder.containsTag(tag)).isPresent();
}

/** Checks if the given tag contains the given registry object */
Expand Down

0 comments on commit 3e633a8

Please sign in to comment.