Skip to content

Commit

Permalink
fix runtime not being available on multiple unification tags
Browse files Browse the repository at this point in the history
  • Loading branch information
rlnt committed Oct 22, 2024
1 parent 9769c25 commit 5d76128
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ and this project adheres to [Semantic Versioning].

## 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 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.world.item.ItemStack;
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.StoneVariants;
import com.almostreliable.unified.api.unification.TagSubstitutions;
Expand Down Expand Up @@ -117,15 +118,22 @@ public boolean isUnifiedIngredientItem(Ingredient ingredient, ItemStack item) {

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 void put(TagKey<Item> tag, UnificationEntry<Item> entry) {
if (createdEntries.contains(entry)) {
throw new IllegalStateException("entry " + entry + " already created");
if (entriesToTags.containsKey(entry)) {
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);
}

Expand Down

0 comments on commit 5d76128

Please sign in to comment.