From ee4b83fa999cb6012298866ad0ae995a671efbf2 Mon Sep 17 00:00:00 2001 From: tom lee Date: Sun, 20 Mar 2022 13:42:12 +0800 Subject: [PATCH] Fix StructFeatManager to work on 1.18.2 + Update core --- .gitignore | 5 +- build.properties | 1 - .../common/wrappers/world/BiomeWrapper.java | 2 +- .../BatchGenerationEnvironment.java | 2 +- .../worldGeneration/ThreadedParameters.java | 8 +- .../WorldGenStructFeatManager.java | 93 +++++++++++++++---- core | 2 +- 7 files changed, 85 insertions(+), 28 deletions(-) delete mode 100644 build.properties diff --git a/.gitignore b/.gitignore index 953800454..a07e0864a 100644 --- a/.gitignore +++ b/.gitignore @@ -50,4 +50,7 @@ classes/ Merged/ # file from notepad++ -*.bak \ No newline at end of file +*.bak + +# file genearated via MC version switching using preprocessor +build.properties \ No newline at end of file diff --git a/build.properties b/build.properties deleted file mode 100644 index ae4f3e14a..000000000 --- a/build.properties +++ /dev/null @@ -1 +0,0 @@ -MC_VERSION_1_18_2= diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/world/BiomeWrapper.java b/common/src/main/java/com/seibel/lod/common/wrappers/world/BiomeWrapper.java index 7651d4ecc..820b75bdc 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/world/BiomeWrapper.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/world/BiomeWrapper.java @@ -65,7 +65,7 @@ public class BiomeWrapper implements IBiomeWrapper { int colorInt; - switch (biome.getBiomeCategory()) + switch (biome.biomeCategory) { case NETHER: diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/BatchGenerationEnvironment.java b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/BatchGenerationEnvironment.java index 5945ddee4..c3bafe16f 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/BatchGenerationEnvironment.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/BatchGenerationEnvironment.java @@ -424,7 +424,7 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv region = new LightedWorldGenRegion(params.level, lightEngine, referencedChunks, ChunkStatus.STRUCTURE_STARTS, refRange, e.lightMode, generator); adaptor.setRegion(region); - e.tParam.makeStructFeat(region); + e.tParam.makeStructFeat(region, params); genChunks = new ArrayGridList<>(referencedChunks, RANGE_TO_RANGE_EMPTY_EXTENSION, referencedChunks.gridSize - RANGE_TO_RANGE_EMPTY_EXTENSION); generateDirect(e, genChunks, e.target, region); diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/ThreadedParameters.java b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/ThreadedParameters.java index 5c1cc82e1..dc34cd3ed 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/ThreadedParameters.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/ThreadedParameters.java @@ -6,13 +6,14 @@ import com.seibel.lod.common.wrappers.worldGeneration.mimicObject.WorldGenStruct import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.WorldGenLevel; +import net.minecraft.world.level.levelgen.WorldGenSettings; import net.minecraft.world.level.levelgen.structure.StructureCheck; public final class ThreadedParameters { private static final ThreadLocal localParam = new ThreadLocal(); final ServerLevel level; - public final WorldGenStructFeatManager structFeat; + public WorldGenStructFeatManager structFeat = null; public final StructureCheck structCheck; boolean isValid = true; public final PerfCalculator perf = new PerfCalculator(); @@ -38,11 +39,10 @@ public final class ThreadedParameters structCheck = new StructureCheck(param.chunkScanner, param.registry, param.structures, param.level.dimension(), param.generator, level, param.generator.getBiomeSource(), param.worldSeed, param.fixerUpper); - structFeat = new WorldGenStructFeatManager(level, param.worldGenSettings, null, structCheck); } - public void makeStructFeat(WorldGenLevel genLevel) + public void makeStructFeat(WorldGenLevel genLevel, GlobalParameters param) { - structFeat.setGenLevel(genLevel); + structFeat = new WorldGenStructFeatManager(param.worldGenSettings, genLevel, structCheck); } } \ No newline at end of file diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/mimicObject/WorldGenStructFeatManager.java b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/mimicObject/WorldGenStructFeatManager.java index 0952e52be..349e18291 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/mimicObject/WorldGenStructFeatManager.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/mimicObject/WorldGenStructFeatManager.java @@ -1,7 +1,11 @@ package com.seibel.lod.common.wrappers.worldGeneration.mimicObject; +import java.util.Iterator; import java.util.List; -import java.util.stream.Stream; +import java.util.Map; +import java.util.Objects; +import java.util.function.Consumer; +import java.util.function.Predicate; import com.google.common.collect.ImmutableList; @@ -17,58 +21,61 @@ import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.chunk.ChunkAccess; import net.minecraft.world.level.chunk.ChunkStatus; import net.minecraft.world.level.levelgen.WorldGenSettings; +import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; import net.minecraft.world.level.levelgen.feature.StructureFeature; import net.minecraft.world.level.levelgen.structure.StructureCheck; import net.minecraft.world.level.levelgen.structure.StructureStart; public class WorldGenStructFeatManager extends StructureFeatureManager { - WorldGenLevel genLevel; + final WorldGenLevel genLevel; WorldGenSettings worldGenSettings; StructureCheck structureCheck; - public WorldGenStructFeatManager(LevelAccessor levelAccessor, WorldGenSettings worldGenSettings, + public WorldGenStructFeatManager(WorldGenSettings worldGenSettings, WorldGenLevel genLevel, StructureCheck structureCheck) { - super(levelAccessor, worldGenSettings, structureCheck); + super(genLevel, worldGenSettings, structureCheck); this.genLevel = genLevel; this.worldGenSettings = worldGenSettings; } - - public void setGenLevel(WorldGenLevel genLevel) { - this.genLevel = genLevel; - } @Override public WorldGenStructFeatManager forWorldGenRegion(WorldGenRegion worldGenRegion) { if (worldGenRegion == genLevel) return this; - return new WorldGenStructFeatManager(worldGenRegion, worldGenSettings, worldGenRegion, structureCheck); + return new WorldGenStructFeatManager(worldGenSettings, worldGenRegion, structureCheck); + } + + private ChunkAccess _getChunk(int x, int z, ChunkStatus status) { + if (genLevel == null) return null; + return genLevel.getChunk(x, z, status, false); } @Override public boolean hasAnyStructureAt(BlockPos blockPos) { SectionPos sectionPos = SectionPos.of(blockPos); - ChunkAccess chunk = genLevel.getChunk(sectionPos.x(), sectionPos.z(), ChunkStatus.STRUCTURE_REFERENCES, - false); + ChunkAccess chunk = _getChunk(sectionPos.x(), sectionPos.z(), ChunkStatus.STRUCTURE_REFERENCES); if (chunk == null) return false; return chunk.hasAnyStructureReferences(); } + + + #if MC_VERSION_1_18_1 @Override @SuppressWarnings({ "rawtypes", "unchecked" }) public List> startsForFeature(SectionPos sectionPos, - StructureFeature structureFeature) { - if (genLevel == null) - return List.of(); - ChunkAccess chunk = genLevel.getChunk(sectionPos.x(), sectionPos.z(), ChunkStatus.STRUCTURE_REFERENCES, - false); - if (chunk == null) - return List.of(); + StructureFeature structureFeature) { + + ChunkAccess chunk = _getChunk(sectionPos.x(), sectionPos.z(), ChunkStatus.STRUCTURE_REFERENCES); + if (chunk == null) return List.of(); + + // Copied from StructureFeatureManager::startsForFeature(...) with slight tweaks LongSet longSet = chunk.getReferencesForFeature(structureFeature); ImmutableList.Builder builder = ImmutableList.builder(); LongIterator longIterator = longSet.iterator(); while (longIterator.hasNext()) { long l = (Long)longIterator.next(); SectionPos sectPos = SectionPos.of(new ChunkPos(l), genLevel.getMinSection()); - ChunkAccess startChunk = genLevel.getChunk(sectPos.x(), sectPos.z(), ChunkStatus.STRUCTURE_STARTS, false); + ChunkAccess startChunk = _getChunk(sectPos.x(), sectPos.z(), ChunkStatus.STRUCTURE_STARTS); if (startChunk == null) continue; StructureStart structureStart = this.getStartForFeature(sectPos, structureFeature, startChunk); if (structureStart == null || !structureStart.isValid()) continue; @@ -76,4 +83,52 @@ public class WorldGenStructFeatManager extends StructureFeatureManager { } return builder.build(); } + #elif MC_VERSION_1_18_2 + + @Override + public List startsForFeature(SectionPos sectionPos, Predicate> predicate) { + ChunkAccess chunk = _getChunk(sectionPos.x(), sectionPos.z(), ChunkStatus.STRUCTURE_REFERENCES); + if (chunk == null) return List.of(); + + // Copied from StructureFeatureManager::startsForFeature(...) + Map, LongSet> map = chunk.getAllReferences(); + + ImmutableList.Builder builder = ImmutableList.builder(); + Iterator, LongSet>> var5 = map.entrySet().iterator(); + + while(var5.hasNext()) { + Map.Entry, LongSet> entry = var5.next(); + ConfiguredStructureFeature configuredStructureFeature = entry.getKey(); + if (predicate.test(configuredStructureFeature)) { + LongSet var10002 = (LongSet)entry.getValue(); + Objects.requireNonNull(builder); + this.fillStartsForFeature(configuredStructureFeature, var10002, builder::add); + } + } + + return builder.build(); + } + + @Override + public List startsForFeature(SectionPos sectionPos, ConfiguredStructureFeature configuredStructureFeature) { + ChunkAccess chunk = _getChunk(sectionPos.x(), sectionPos.z(), ChunkStatus.STRUCTURE_REFERENCES); + if (chunk == null) return List.of(); + + // Copied from StructureFeatureManager::startsForFeature(...) + LongSet longSet = chunk.getReferencesForFeature(configuredStructureFeature); + ImmutableList.Builder builder = ImmutableList.builder(); + Objects.requireNonNull(builder); + this.fillStartsForFeature(configuredStructureFeature, longSet, builder::add); + return builder.build(); + } + + @Override + public Map, LongSet> getAllStructuresAt(BlockPos blockPos) { + SectionPos sectionPos = SectionPos.of(blockPos); + ChunkAccess chunk = _getChunk(sectionPos.x(), sectionPos.z(), ChunkStatus.STRUCTURE_REFERENCES); + if (chunk == null) return Map.of(); + return chunk.getAllReferences(); + } + #endif + } \ No newline at end of file diff --git a/core b/core index 6cd0281d0..8f534fb51 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 6cd0281d0e1a2a76be26d166c3127b2521e8fd79 +Subproject commit 8f534fb51cc2a35ac07967485494302431469959