fix runtime not being available on multiple unification tags

This commit is contained in:
rlnt 2024-10-22 14:21:29 +02:00
parent 9769c25a1c
commit 5d76128d1b
No known key found for this signature in database
2 changed files with 14 additions and 4 deletions

View file

@ -7,8 +7,10 @@ and this project adheres to [Semantic Versioning].
## Unreleased ## Unreleased
- added better logging for cases where items are assigned to multiple unification tags
- fixed crash when runtime isn't loaded ([#101](https://github.com/AlmostReliable/almostunified/issues/101)) - fixed crash when runtime isn't loaded ([#101](https://github.com/AlmostReliable/almostunified/issues/101))
- fixed newly created custom tags not being considered for unification - fixed newly created custom tags not being considered for unification
- fixed runtime not being available when items are assigned to multiple unification tags
## [1.2.0] - 2024-10-06 ## [1.2.0] - 2024-10-06

View file

@ -7,6 +7,7 @@ import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.Ingredient;
import com.almostreliable.unified.AlmostUnifiedCommon;
import com.almostreliable.unified.api.unification.ModPriorities; import com.almostreliable.unified.api.unification.ModPriorities;
import com.almostreliable.unified.api.unification.StoneVariants; import com.almostreliable.unified.api.unification.StoneVariants;
import com.almostreliable.unified.api.unification.TagSubstitutions; import com.almostreliable.unified.api.unification.TagSubstitutions;
@ -117,15 +118,22 @@ public final class UnificationLookupImpl implements UnificationLookup {
public static class Builder { public static class Builder {
private final Set<UnificationEntry<Item>> createdEntries = new HashSet<>(); private final Map<UnificationEntry<Item>, TagKey<Item>> entriesToTags = new HashMap<>();
private final Map<TagKey<Item>, Set<UnificationEntry<Item>>> tagsToEntries = new HashMap<>(); private final Map<TagKey<Item>, Set<UnificationEntry<Item>>> tagsToEntries = new HashMap<>();
private void put(TagKey<Item> tag, UnificationEntry<Item> entry) { private void put(TagKey<Item> tag, UnificationEntry<Item> entry) {
if (createdEntries.contains(entry)) { if (entriesToTags.containsKey(entry)) {
throw new IllegalStateException("entry " + entry + " already created"); var boundTag = entriesToTags.get(entry);
AlmostUnifiedCommon.LOGGER.error(
"Unification entry for item '{}' with tag '#{}' is already part of tag '#{}'.",
entry.id(),
tag.location(),
boundTag.location()
);
return;
} }
createdEntries.add(entry); entriesToTags.put(entry, tag);
tagsToEntries.computeIfAbsent(tag, $ -> new HashSet<>()).add(entry); tagsToEntries.computeIfAbsent(tag, $ -> new HashSet<>()).add(entry);
} }