|
8 | 8 | import net.minecraft.world.gen.feature.PlacedFeature; |
9 | 9 | import net.minecraft.world.gen.feature.util.PlacedFeatureIndexer; |
10 | 10 | import org.spongepowered.asm.mixin.Mixin; |
| 11 | +import org.spongepowered.asm.mixin.Unique; |
11 | 12 |
|
12 | 13 | import java.util.List; |
13 | 14 | import java.util.function.Function; |
14 | 15 |
|
15 | 16 | @Mixin(PlacedFeatureIndexer.class) |
16 | 17 | public class MixinPlacedFeatureIndexer { |
| 18 | + @Unique |
| 19 | + private static final ThreadLocal<Boolean> BIOLITH_RECURSION = ThreadLocal.withInitial(() -> false); |
| 20 | + |
17 | 21 | @WrapMethod(method = "collectIndexedFeatures") |
18 | 22 | private static <T> List<PlacedFeatureIndexer.IndexedFeatures> biolith$wrapFeatureIndexer(List<T> biomes, Function<T, List<RegistryEntryList<PlacedFeature>>> biomesToPlacedFeaturesList, boolean listInvolvedBiomesOnFailure, Operation<List<PlacedFeatureIndexer.IndexedFeatures>> original) { |
19 | 23 | List<PlacedFeatureIndexer.IndexedFeatures> features; |
20 | 24 |
|
21 | 25 | if (Biolith.getConfigManager().getGeneralConfig().forceResilientFeatureIndexer()) { |
22 | 26 | Biolith.LOGGER.info("Using Biolith's resilient feature indexer (force_resilient_feature_indexer = true)."); |
23 | 27 | features = ResilientPlacedFeatureIndexer.collectIndexedFeatures(biomes, biomesToPlacedFeaturesList); |
| 28 | + } else if (BIOLITH_RECURSION.get()) { |
| 29 | + // The original is recursive; don't catch its exceptions when it's calling itself. |
| 30 | + features = original.call(biomes, biomesToPlacedFeaturesList, listInvolvedBiomesOnFailure); |
24 | 31 | } else { |
| 32 | + BIOLITH_RECURSION.set(true); |
25 | 33 | try { |
26 | 34 | features = original.call(biomes, biomesToPlacedFeaturesList, listInvolvedBiomesOnFailure); |
27 | 35 | } catch (IllegalStateException e) { |
28 | 36 | Biolith.LOGGER.warn(e.getMessage()); |
29 | 37 | Biolith.LOGGER.warn("Vanilla feature indexer failed; retrying with Biolith's resilient feature indexer..."); |
30 | 38 | features = ResilientPlacedFeatureIndexer.collectIndexedFeatures(biomes, biomesToPlacedFeaturesList); |
31 | 39 | } |
| 40 | + BIOLITH_RECURSION.set(false); |
32 | 41 | } |
33 | 42 |
|
34 | 43 | return features; |
|
0 commit comments