Skip to content

Commit

Permalink
fix automated hiding of stone strata variants
Browse files Browse the repository at this point in the history
  • Loading branch information
rlnt committed Mar 17, 2024
1 parent 461b93f commit ab51ba3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog],
and this project adheres to [Semantic Versioning].

## Unreleased

### Fixed
- fixed automatic hiding of stone strata variants (bug introduced in 0.9.0)
- fixed a bug where stone stratas were not correctly identified (Fabric only)

## [0.9.1] - 2024-03-17

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static StoneStrataHandler create(List<String> stoneStrataIds, Set<UnifyTa
var stoneStrataTagMap = tagMap.filtered(stoneStrataTags::contains, item -> true);
Pattern tagMatcher = Pattern.compile(switch (AlmostUnifiedPlatform.INSTANCE.getPlatform()) {
case FORGE -> "forge:ores/.+";
case FABRIC -> "(c:ores/.+|c:.+_ores)";
case FABRIC -> "(c:ores/.+|(minecraft|c):.+_ores)";
});
return new StoneStrataHandler(stoneStrataIds, tagMatcher, stoneStrataTagMap);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,32 @@ public static Multimap<UnifyTag<Item>, ResourceLocation> createHidingMap() {
var itemsByTag = tagMap.getEntriesByTag(unifyTag);
if (Utils.allSameNamespace(itemsByTag)) continue;

ResourceLocation preferredItem = repMap.getPreferredItemForTag(unifyTag, $ -> true);
if (preferredItem == null) continue;
// it's not enough to exclude the preferred item from hiding because it would hide stone stratas
Set<ResourceLocation> replacements = new HashSet<>();
for (ResourceLocation item : itemsByTag) {
ResourceLocation replacement = repMap.getReplacementForItem(item);
replacements.add(replacement == null ? item : replacement);
}

Set<ResourceLocation> itemsToHide = getItemsToHide(unifyTag, itemsByTag, preferredItem);
if (itemsToHide == null) continue;
hidingMap.putAll(unifyTag, itemsToHide);
Set<ResourceLocation> itemsToHide = getItemsToHide(unifyTag, itemsByTag, replacements);
if (itemsToHide != null) {
hidingMap.putAll(unifyTag, itemsToHide);
}

Set<ResourceLocation> refItemsToHide = getRefItemsToHide(unifyTag, ownerships, preferredItem);
hidingMap.putAll(unifyTag, refItemsToHide);
Set<ResourceLocation> refItemsToHide = getRefItemsToHide(unifyTag, ownerships, replacements);
if (!refItemsToHide.isEmpty()) {
hidingMap.putAll(unifyTag, refItemsToHide);
}
}

return hidingMap;
}

@Nullable
private static Set<ResourceLocation> getItemsToHide(UnifyTag<Item> unifyTag, Set<ResourceLocation> itemsByTag, ResourceLocation preferredItem) {
private static Set<ResourceLocation> getItemsToHide(UnifyTag<Item> unifyTag, Set<ResourceLocation> itemsByTag, Set<ResourceLocation> replacements) {
Set<ResourceLocation> itemsToHide = new HashSet<>();
for (ResourceLocation item : itemsByTag) {
if (!item.equals(preferredItem)) {
if (!replacements.contains(item)) {
itemsToHide.add(item);
}
}
Expand All @@ -73,7 +80,7 @@ private static Set<ResourceLocation> getItemsToHide(UnifyTag<Item> unifyTag, Set
return itemsToHide;
}

private static Set<ResourceLocation> getRefItemsToHide(UnifyTag<Item> unifyTag, TagOwnerships ownerships, ResourceLocation preferredItem) {
private static Set<ResourceLocation> getRefItemsToHide(UnifyTag<Item> unifyTag, TagOwnerships ownerships, Set<ResourceLocation> replacements) {
var refTags = ownerships.getRefsByOwner(unifyTag);
Set<ResourceLocation> refItemsToHide = new HashSet<>();

Expand All @@ -82,7 +89,7 @@ private static Set<ResourceLocation> getRefItemsToHide(UnifyTag<Item> unifyTag,

BuiltInRegistries.ITEM.getTagOrEmpty(asTagKey).forEach(holder -> {
ResourceLocation item = BuiltInRegistries.ITEM.getKey(holder.value());
if (item.equals(preferredItem)) return;
if (replacements.contains(item)) return;
refItemsToHide.add(item);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,7 @@ public static List<String> getTags(AlmostUnifiedPlatform.Platform platform) {
}

public static List<String> getIgnoredRecipeTypes(AlmostUnifiedPlatform.Platform platform) {
return switch (platform) {
default -> List.of("cucumber:shaped_tag");
};
return List.of("cucumber:shaped_tag");
}

public static JsonCompare.CompareSettings getDefaultDuplicateRules(AlmostUnifiedPlatform.Platform platform) {
Expand Down

0 comments on commit ab51ba3

Please sign in to comment.