diff --git a/common/src/main/java/net/infumia/pack/FileResourceMergerDefault.java b/common/src/main/java/net/infumia/pack/FileResourceMergerDefault.java index a9ec2fe..5215e5c 100644 --- a/common/src/main/java/net/infumia/pack/FileResourceMergerDefault.java +++ b/common/src/main/java/net/infumia/pack/FileResourceMergerDefault.java @@ -2,15 +2,30 @@ import java.util.Collection; import java.util.Collections; +import java.util.Comparator; import java.util.HashSet; +import java.util.Optional; import java.util.stream.Collectors; import net.kyori.adventure.key.Key; import team.unnamed.creative.atlas.Atlas; +import team.unnamed.creative.model.ItemOverride; +import team.unnamed.creative.model.ItemPredicate; import team.unnamed.creative.model.Model; final class FileResourceMergerDefault implements FileResourceMerger { static final FileResourceMerger INSTANCE = new FileResourceMergerDefault(); + static final Comparator OVERRIDE_COMPARATOR = Comparator.comparingInt(value -> { + final Optional first = value.predicate().stream().findFirst(); + if (!first.isPresent()) { + return 0; + } + final ItemPredicate predicate = first.get(); + if (predicate.name().equals("custom_model_data")) { + return (int) predicate.value(); + } + return 0; + }); private FileResourceMergerDefault() {} @@ -23,7 +38,7 @@ public Collection merge(final Collection resources) final MultiMap atlases = new MultiMap<>(); final MultiMap models = new MultiMap<>(); - final HashSet remainings = new HashSet<>(); + final HashSet remaining = new HashSet<>(); for (final FileResource resource : simplified) { if (resource instanceof FileResourceAtlas) { final Atlas atlas = ((FileResourceAtlas) resource).atlas; @@ -34,7 +49,7 @@ public Collection merge(final Collection resources) } // TODO: portlek, Merge more things. else { - remainings.add(resource); + remaining.add(resource); } } @@ -73,6 +88,7 @@ public Collection merge(final Collection resources) .stream() .map(Model::overrides) .flatMap(Collection::stream) + .sorted(FileResourceMergerDefault.OVERRIDE_COMPARATOR) .collect(Collectors.toList()) ); mergedModels.add(builder.build()); @@ -85,7 +101,7 @@ public Collection merge(final Collection resources) mergedResources.addAll( mergedModels.stream().map(FileResources::model).collect(Collectors.toSet()) ); - mergedResources.addAll(remainings); + mergedResources.addAll(remaining); return mergedResources; }