Mojira Archive
MC-252369

Feature Cycle detected where no cycle exists

To Reproduce

  • Try and create a world with the attached datapack.
  • Notice that Minecraft crashes, saying the datapack contains a feature cycle.
  • The datapack doesn't contain a feature cycle.

The datapack:

The datapack in question contains two biomes, of which the only notable part is two features:

 

// biomes/plains.json
"features": [
  ["minecraft:feature_1", "minecraft:feature_2"]
]

// biomes/forest.json
"features": [
  ["minecraft:feature_2", "minecraft:feature_3"]
]

// Each of placed_feature/feature_1.json, placed_feature/feature_2.json, and placed_feature/feature_3.json are identical (this is important)
{
  "feature": {
    "type": "minecraft:no_op",
    "config": {}
  },
  "placement": []
} 

As you can see, this does not contain a feature cycle.

 

 

Explanation

In 1.18.2, many world generation related objects became Java records, and this change meant that they now have an override of equals() and hashCode() which operates on their fields. What this means is that two separate placed features can return true, when queried through equals():

 

  • PlacedFeature is a record, so it uses equality of components,
    • The `feature` component is a Holder.Direct<>, which is a record,
      • The `value` component is a ConfiguredFeature which is a record,
        • And the `feature` and `config` are both equal, since the features' have the same type, and `NoneFeatureConfiguration` has a single instance.
    • The `placements` component is a list, which is empty, and therefor equal.

 

As a result of this, `buildFeaturesPerStep`, which in many places uses `java.util.TreeMap`, `java.util.TreeSet`, and `it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap`, all of which use equals() semantics to determine if two objects are equal, not identity equality. So in trying to detect a cycle, it treats different features as identical, and thus detects a cycle where no cycle is present.

 

Unresolved

Alex O'Neill

2022-05-31, 01:57 AM

2023-09-06, 02:37 PM

12

10

Confirmed

Low

Platform

Custom Worlds

1.18.2, 1.19 Pre-release 4, 1.19 Release Candidate 2, 1.19

-