Skip to content

Commit 9bc5f06

Browse files
committed
Ensure correct order of properties in generated ModelResourceLocation variant strings
Related: malte0811/FerriteCore#219
1 parent a70f76a commit 9bc5f06

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/main/java/org/embeddedt/modernfix/forge/dynresources/ModelLocationBuilder.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,17 @@ public class ModelLocationBuilder {
2121
private record PropertyData(ImmutableList<String> nameValuePairs, int maxPairLength) {}
2222

2323
public void generateForBlock(Set<ResourceLocation> destinationSet, Block block, ResourceLocation baseLocation) {
24-
var props = block.getStateDefinition().getProperties();
24+
// Make sure to iterate over the properties in the order of the getValues() map rather than using
25+
// StateDefinition.getProperties(), to match the logic in BlockModelShaper.statePropertiesToString.
26+
// In vanilla, these have the same order, because the backing implementation of getValues() is a map
27+
// that preserves insertion order. However, in some versions of FerriteCore, getValues() may not
28+
// preserve insertion order, but instead rely on hash order of the keys. This results in BlockModelShape
29+
// and ModelLocationBuilder producing different MRLs. Using the keySet produces the same ordering as
30+
// BlockModelShaper, provided that all states were built with the keys inserted in the same order into the same
31+
// map implementation (which should always be true in practice).
32+
// The above issue only seems to affect versions of FerriteCore after the switch to fastutil maps, but it
33+
// is harmless to be consistent on older versions too, especially if another mod backports the fastutil change.
34+
var props = block.defaultBlockState().getValues().keySet();
2535
List<ImmutableList<String>> optionsList = new ArrayList<>(props.size());
2636
int requiredBuilderSize = Math.max(0, props.size() - 1); // commas
2737
for (var prop : props) {

0 commit comments

Comments
 (0)