|
3 | 3 | import me.char321.chunkcacher.WorldCache; |
4 | 4 | import net.minecraft.util.math.ChunkPos; |
5 | 5 | import net.minecraft.world.gen.chunk.ChunkGenerator; |
| 6 | +import net.minecraft.world.gen.chunk.StructuresConfig; |
6 | 7 | import org.spongepowered.asm.mixin.Final; |
7 | 8 | import org.spongepowered.asm.mixin.Mixin; |
8 | 9 | import org.spongepowered.asm.mixin.Shadow; |
|
17 | 18 | @Mixin(ChunkGenerator.class) |
18 | 19 | public class ChunkGeneratorMixin { |
19 | 20 |
|
20 | | - @Shadow @Final private List<ChunkPos> strongholdPositions; |
| 21 | + @Shadow |
| 22 | + @Final |
| 23 | + private List<ChunkPos> strongholdPositions; |
| 24 | + |
| 25 | + @Shadow |
| 26 | + @Final |
| 27 | + private StructuresConfig structuresConfig; |
21 | 28 |
|
22 | 29 | @Inject(method = "generateStrongholdPositions", at = @At("HEAD")) |
23 | 30 | private void applyCachedStrongholds(CallbackInfo ci) { |
24 | | - if (WorldCache.shouldCache() && WorldCache.strongholdCache != null && this.strongholdPositions.isEmpty()) { |
| 31 | + // this.structuresConfig.getStronghold() == StructuresConfig.DEFAULT_STRONGHOLD works for vanilla world generation because only the overworld will use DEFAULT_STRONGHOLD, |
| 32 | + // but it may fail with datapacks, mods or 20w14∞ adding new dimensions |
| 33 | + if (WorldCache.shouldCache() && this.structuresConfig.getStronghold() == StructuresConfig.DEFAULT_STRONGHOLD && WorldCache.strongholdCache != null && this.strongholdPositions.isEmpty()) { |
25 | 34 | this.strongholdPositions.addAll(WorldCache.strongholdCache); |
26 | 35 | } |
27 | 36 | } |
28 | 37 |
|
29 | 38 | @Inject(method = "generateStrongholdPositions", at = @At("TAIL")) |
30 | 39 | private void cacheStrongholds(CallbackInfo ci) { |
31 | | - if (WorldCache.shouldCache() && WorldCache.strongholdCache == null) { |
| 40 | + if (WorldCache.shouldCache() && this.structuresConfig.getStronghold() == StructuresConfig.DEFAULT_STRONGHOLD && WorldCache.strongholdCache == null) { |
32 | 41 | WorldCache.strongholdCache = Collections.unmodifiableList(new ArrayList<>(this.strongholdPositions)); |
33 | 42 | } |
34 | 43 | } |
|
0 commit comments