SPIGOT-6802: Fix major issues with --forceUpgrade

More to come

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot 2021-11-23 17:13:52 +11:00
parent 90f6dfa935
commit 820ad30036
6 changed files with 46 additions and 54 deletions

View file

@ -1,15 +1,18 @@
--- a/net/minecraft/server/level/PlayerChunkMap.java
+++ b/net/minecraft/server/level/PlayerChunkMap.java
@@ -95,6 +95,8 @@
@@ -95,6 +95,11 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+import org.bukkit.entity.Player; // CraftBukkit
+// CraftBukkit start
+import net.minecraft.world.level.levelgen.GeneratorSettings;
+import org.bukkit.entity.Player;
+// CraftBukkit end
+
public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.e {
private static final byte CHUNK_TYPE_REPLACEABLE = -1;
@@ -133,6 +135,27 @@
@@ -133,6 +138,27 @@
private final Queue<Runnable> unloadQueue;
int viewDistance;
@ -37,7 +40,7 @@
public PlayerChunkMap(WorldServer worldserver, Convertable.ConversionSession convertable_conversionsession, DataFixer datafixer, DefinedStructureManager definedstructuremanager, Executor executor, IAsyncTaskHandler<Runnable> iasynctaskhandler, ILightAccess ilightaccess, ChunkGenerator chunkgenerator, WorldLoadListener worldloadlistener, ChunkStatusUpdateListener chunkstatusupdatelistener, Supplier<WorldPersistentData> supplier, int i, boolean flag) {
super(convertable_conversionsession.getDimensionPath(worldserver.dimension()).resolve("region"), datafixer, flag);
this.visibleChunkMap = this.updatingChunkMap.clone();
@@ -326,9 +349,12 @@
@@ -326,9 +352,12 @@
return completablefuture1.thenApply((list1) -> {
List<IChunkAccess> list2 = Lists.newArrayList();
@ -52,7 +55,7 @@
final Either<IChunkAccess, PlayerChunk.Failure> either = (Either) iterator.next();
Optional<IChunkAccess> optional = either.left();
@@ -435,7 +461,7 @@
@@ -435,7 +464,7 @@
this.flushWorker();
} else {
this.visibleChunkMap.values().stream().filter(PlayerChunk::wasAccessibleSinceLastSave).forEach((playerchunk) -> {
@ -61,7 +64,7 @@
if (ichunkaccess instanceof ProtoChunkExtension || ichunkaccess instanceof Chunk) {
this.save(ichunkaccess);
@@ -488,7 +514,7 @@
@@ -488,7 +517,7 @@
private void scheduleUnload(long i, PlayerChunk playerchunk) {
CompletableFuture<IChunkAccess> completablefuture = playerchunk.getChunkToSave();
@ -70,7 +73,7 @@
CompletableFuture<IChunkAccess> completablefuture1 = playerchunk.getChunkToSave();
if (completablefuture1 != completablefuture) {
@@ -664,7 +690,21 @@
@@ -664,7 +693,21 @@
private static void postLoadProtoChunk(WorldServer worldserver, List<NBTTagCompound> list) {
if (!list.isEmpty()) {
@ -93,7 +96,7 @@
}
}
@@ -894,7 +934,8 @@
@@ -894,7 +937,8 @@
return ichunkaccess instanceof Chunk ? Optional.of((Chunk) ichunkaccess) : Optional.empty();
});
@ -103,7 +106,7 @@
return chunk.getBlockEntities().size();
}).orElse(0), tickingtracker.getTicketDebugString(i), tickingtracker.getLevel(i), optional1.map((chunk) -> {
return chunk.getBlockTicks().count();
@@ -907,7 +948,7 @@
@@ -907,7 +951,7 @@
private static String printFuture(CompletableFuture<Either<Chunk, PlayerChunk.Failure>> completablefuture) {
try {
@ -112,16 +115,16 @@
return either != null ? (String) either.map((chunk) -> {
return "done";
@@ -925,7 +966,7 @@
@@ -925,7 +969,7 @@
private NBTTagCompound readChunk(ChunkCoordIntPair chunkcoordintpair) throws IOException {
NBTTagCompound nbttagcompound = this.read(chunkcoordintpair);
- return nbttagcompound == null ? null : this.upgradeChunkTag(this.level.dimension(), this.overworldDataStorage, nbttagcompound, this.generator.getTypeNameForDataFixer());
+ return nbttagcompound == null ? null : this.upgradeChunkTag(this.level.getTypeKey(), this.overworldDataStorage, nbttagcompound, this.generator.getTypeNameForDataFixer(), chunkcoordintpair, level); // CraftBukkit
+ return nbttagcompound == null ? null : this.upgradeChunkTag(GeneratorSettings.levelToLevelStem(this.level.getTypeKey()), this.overworldDataStorage, nbttagcompound, this.generator.getTypeNameForDataFixer(), chunkcoordintpair, level); // CraftBukkit
}
boolean anyPlayerCloseEnoughForSpawning(ChunkCoordIntPair chunkcoordintpair) {
@@ -1349,7 +1390,7 @@
@@ -1349,7 +1393,7 @@
public final Set<ServerPlayerConnection> seenBy = Sets.newIdentityHashSet();
public EntityTracker(Entity entity, int i, int j, boolean flag) {
@ -130,7 +133,7 @@
this.entity = entity;
this.range = i;
this.lastSectionPos = SectionPosition.of(entity);
@@ -1402,12 +1443,20 @@
@@ -1402,12 +1446,20 @@
public void updatePlayer(EntityPlayer entityplayer) {
if (entityplayer != this.entity) {

View file

@ -5,7 +5,7 @@
import org.apache.logging.log4j.Logger;
+// CraftBukkit start
+import net.minecraft.world.level.dimension.DimensionManager;
+import net.minecraft.world.level.dimension.WorldDimension;
+// CraftBukkit end
+
public class WorldUpgrader {
@ -16,7 +16,7 @@
private volatile int converted;
private volatile int skipped;
- private final Object2FloatMap<ResourceKey<World>> progressMap = Object2FloatMaps.synchronize(new Object2FloatOpenCustomHashMap(SystemUtils.identityStrategy()));
+ private final Object2FloatMap<ResourceKey<DimensionManager>> progressMap = Object2FloatMaps.synchronize(new Object2FloatOpenCustomHashMap(SystemUtils.identityStrategy())); // CraftBukkit
+ private final Object2FloatMap<ResourceKey<WorldDimension>> progressMap = Object2FloatMaps.synchronize(new Object2FloatOpenCustomHashMap(SystemUtils.identityStrategy())); // CraftBukkit
private volatile IChatBaseComponent status = new ChatMessage("optimizeWorld.stage.counting");
private static final Pattern REGEX = Pattern.compile("^r\\.(-?[0-9]+)\\.(-?[0-9]+)\\.mca$");
private final WorldPersistentData overworldDataStorage;
@ -26,14 +26,14 @@
this.totalChunks = 0;
- Builder<ResourceKey<World>, ListIterator<ChunkCoordIntPair>> builder = ImmutableMap.builder();
- ImmutableSet<ResourceKey<World>> immutableset = this.worldGenSettings.levels();
+ Builder<ResourceKey<DimensionManager>, ListIterator<ChunkCoordIntPair>> builder = ImmutableMap.builder(); // CraftBukkit
+ ImmutableSet<ResourceKey<DimensionManager>> immutableset = this.worldGenSettings.levels(); // CraftBukkit
+ Builder<ResourceKey<WorldDimension>, ListIterator<ChunkCoordIntPair>> builder = ImmutableMap.builder(); // CraftBukkit
+ ImmutableSet<ResourceKey<WorldDimension>> immutableset = ImmutableSet.of(levelStorage.dimensionType); // CraftBukkit
List list;
for (UnmodifiableIterator unmodifiableiterator = immutableset.iterator(); unmodifiableiterator.hasNext(); this.totalChunks += list.size()) {
- ResourceKey<World> resourcekey = (ResourceKey) unmodifiableiterator.next();
+ ResourceKey<DimensionManager> resourcekey = (ResourceKey) unmodifiableiterator.next(); // CraftBukkit
+ ResourceKey<WorldDimension> resourcekey = (ResourceKey) unmodifiableiterator.next(); // CraftBukkit
list = this.getAllChunkPos(resourcekey);
builder.put(resourcekey, list.listIterator());
@ -43,21 +43,21 @@
float f = (float) this.totalChunks;
- ImmutableMap<ResourceKey<World>, ListIterator<ChunkCoordIntPair>> immutablemap = builder.build();
- Builder<ResourceKey<World>, IChunkLoader> builder1 = ImmutableMap.builder();
+ ImmutableMap<ResourceKey<DimensionManager>, ListIterator<ChunkCoordIntPair>> immutablemap = builder.build(); // CraftBukkit
+ Builder<ResourceKey<DimensionManager>, IChunkLoader> builder1 = ImmutableMap.builder(); // CraftBukkit
+ ImmutableMap<ResourceKey<WorldDimension>, ListIterator<ChunkCoordIntPair>> immutablemap = builder.build(); // CraftBukkit
+ Builder<ResourceKey<WorldDimension>, IChunkLoader> builder1 = ImmutableMap.builder(); // CraftBukkit
UnmodifiableIterator unmodifiableiterator1 = immutableset.iterator();
while (unmodifiableiterator1.hasNext()) {
- ResourceKey<World> resourcekey1 = (ResourceKey) unmodifiableiterator1.next();
- Path path = this.levelStorage.getDimensionPath(resourcekey1);
+ ResourceKey<DimensionManager> resourcekey1 = (ResourceKey) unmodifiableiterator1.next(); // CraftBukkit
+ ResourceKey<WorldDimension> resourcekey1 = (ResourceKey) unmodifiableiterator1.next(); // CraftBukkit
+ Path path = this.levelStorage.getDimensionPath((ResourceKey) null); // CraftBukkit
builder1.put(resourcekey1, new IChunkLoader(path.resolve("region"), this.dataFixer, true));
}
- ImmutableMap<ResourceKey<World>, IChunkLoader> immutablemap1 = builder1.build();
+ ImmutableMap<ResourceKey<DimensionManager>, IChunkLoader> immutablemap1 = builder1.build(); // CraftBukkit
+ ImmutableMap<ResourceKey<WorldDimension>, IChunkLoader> immutablemap1 = builder1.build(); // CraftBukkit
long i = SystemUtils.getMillis();
this.status = new ChatMessage("optimizeWorld.stage.upgrading");
@ -66,12 +66,16 @@
for (UnmodifiableIterator unmodifiableiterator2 = immutableset.iterator(); unmodifiableiterator2.hasNext(); f1 += f2) {
- ResourceKey<World> resourcekey2 = (ResourceKey) unmodifiableiterator2.next();
+ ResourceKey<DimensionManager> resourcekey2 = (ResourceKey) unmodifiableiterator2.next(); // CraftBukkit
+ ResourceKey<WorldDimension> resourcekey2 = (ResourceKey) unmodifiableiterator2.next(); // CraftBukkit
ListIterator<ChunkCoordIntPair> listiterator = (ListIterator) immutablemap.get(resourcekey2);
IChunkLoader ichunkloader = (IChunkLoader) immutablemap1.get(resourcekey2);
@@ -141,7 +145,7 @@
ChunkGenerator chunkgenerator = ((WorldDimension) this.worldGenSettings.dimensions().get(GeneratorSettings.levelToLevelStem(resourcekey2))).generator();
@@ -138,10 +142,10 @@
if (nbttagcompound != null) {
int j = IChunkLoader.getVersion(nbttagcompound);
- ChunkGenerator chunkgenerator = ((WorldDimension) this.worldGenSettings.dimensions().get(GeneratorSettings.levelToLevelStem(resourcekey2))).generator();
+ ChunkGenerator chunkgenerator = ((WorldDimension) this.worldGenSettings.dimensions().get(resourcekey2)).generator(); // CraftBukkit
NBTTagCompound nbttagcompound1 = ichunkloader.upgradeChunkTag(resourcekey2, () -> {
return this.overworldDataStorage;
- }, nbttagcompound, chunkgenerator.getTypeNameForDataFixer());
@ -85,7 +89,7 @@
- private List<ChunkCoordIntPair> getAllChunkPos(ResourceKey<World> resourcekey) {
- File file = this.levelStorage.getDimensionPath(resourcekey).toFile();
+ private List<ChunkCoordIntPair> getAllChunkPos(ResourceKey<DimensionManager> resourcekey) { // CraftBukkit
+ private List<ChunkCoordIntPair> getAllChunkPos(ResourceKey<WorldDimension> resourcekey) { // CraftBukkit
+ File file = this.levelStorage.getDimensionPath((ResourceKey) null).toFile(); // CraftBukkit
File file1 = new File(file, "region");
File[] afile = file1.listFiles((file2, s) -> {

View file

@ -9,7 +9,7 @@
+import net.minecraft.server.level.WorldServer;
+import net.minecraft.world.level.GeneratorAccess;
+import net.minecraft.world.level.chunk.ChunkStatus;
+import net.minecraft.world.level.dimension.DimensionManager;
+import net.minecraft.world.level.dimension.WorldDimension;
+// CraftBukkit end
+
public class IChunkLoader implements AutoCloseable {
@ -46,7 +46,7 @@
+ return false;
+ }
+
+ public NBTTagCompound upgradeChunkTag(ResourceKey<DimensionManager> resourcekey, Supplier<WorldPersistentData> supplier, NBTTagCompound nbttagcompound, Optional<ResourceKey<Codec<? extends ChunkGenerator>>> optional, ChunkCoordIntPair pos, @Nullable GeneratorAccess generatoraccess) throws IOException {
+ public NBTTagCompound upgradeChunkTag(ResourceKey<WorldDimension> resourcekey, Supplier<WorldPersistentData> supplier, NBTTagCompound nbttagcompound, Optional<ResourceKey<Codec<? extends ChunkGenerator>>> optional, ChunkCoordIntPair pos, @Nullable GeneratorAccess generatoraccess) throws IOException {
+ // CraftBukkit end
int i = getVersion(nbttagcompound);
@ -70,7 +70,7 @@
}
- public static void injectDatafixingContext(NBTTagCompound nbttagcompound, ResourceKey<World> resourcekey, Optional<ResourceKey<Codec<? extends ChunkGenerator>>> optional) {
+ public static void injectDatafixingContext(NBTTagCompound nbttagcompound, ResourceKey<DimensionManager> resourcekey, Optional<ResourceKey<Codec<? extends ChunkGenerator>>> optional) { // CraftBukkit
+ public static void injectDatafixingContext(NBTTagCompound nbttagcompound, ResourceKey<WorldDimension> resourcekey, Optional<ResourceKey<Codec<? extends ChunkGenerator>>> optional) { // CraftBukkit
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
nbttagcompound1.putString("dimension", resourcekey.location().toString());

View file

@ -34,31 +34,16 @@
}
}
@@ -159,17 +164,19 @@
}
}
- public ImmutableSet<ResourceKey<World>> levels() {
+ // CraftBukkit start
+ public ImmutableSet<ResourceKey<DimensionManager>> levels() {
return (ImmutableSet) this.dimensions().entrySet().stream().map(Entry::getKey).map(GeneratorSettings::levelStemToLevel).collect(ImmutableSet.toImmutableSet());
}
- public static ResourceKey<World> levelStemToLevel(ResourceKey<WorldDimension> resourcekey) {
- return ResourceKey.create(IRegistry.DIMENSION_REGISTRY, resourcekey.location());
+ public static ResourceKey<DimensionManager> levelStemToLevel(ResourceKey<WorldDimension> resourcekey) {
+ return ResourceKey.create(IRegistry.DIMENSION_TYPE_REGISTRY, resourcekey.location());
@@ -167,7 +172,7 @@
return ResourceKey.create(IRegistry.DIMENSION_REGISTRY, resourcekey.location());
}
- public static ResourceKey<WorldDimension> levelToLevelStem(ResourceKey<World> resourcekey) {
+ public static ResourceKey<WorldDimension> levelToLevelStem(ResourceKey<DimensionManager> resourcekey) {
+ public static ResourceKey<WorldDimension> levelToLevelStem(ResourceKey<DimensionManager> resourcekey) { // CraftBukkit
return ResourceKey.create(IRegistry.LEVEL_STEM_REGISTRY, resourcekey.location());
}
+ // CraftBukkit end
public boolean isDebug() {
return this.overworld() instanceof ChunkProviderDebug;
@@ -246,7 +253,7 @@
@@ -246,7 +251,7 @@
switch (b0) {
case 0:
JsonObject jsonobject = !s.isEmpty() ? ChatDeserializer.parse(s) : new JsonObject();

View file

@ -5,7 +5,7 @@
import net.minecraft.world.level.storage.WorldPersistentData;
+// CraftBukkit start
+import net.minecraft.world.level.dimension.DimensionManager;
+import net.minecraft.world.level.dimension.WorldDimension;
+// CraftBukkit end
+
public class PersistentStructureLegacy {
@ -17,18 +17,18 @@
- public static PersistentStructureLegacy getLegacyStructureHandler(ResourceKey<World> resourcekey, @Nullable WorldPersistentData worldpersistentdata) {
- if (resourcekey == World.OVERWORLD) {
+ public static PersistentStructureLegacy getLegacyStructureHandler(ResourceKey<DimensionManager> resourcekey, @Nullable WorldPersistentData worldpersistentdata) { // CraftBukkit
+ if (resourcekey == DimensionManager.OVERWORLD_LOCATION) { // CraftBukkit
+ public static PersistentStructureLegacy getLegacyStructureHandler(ResourceKey<WorldDimension> resourcekey, @Nullable WorldPersistentData worldpersistentdata) { // CraftBukkit
+ if (resourcekey == WorldDimension.OVERWORLD) { // CraftBukkit
return new PersistentStructureLegacy(worldpersistentdata, ImmutableList.of("Monument", "Stronghold", "Village", "Mineshaft", "Temple", "Mansion"), ImmutableList.of("Village", "Mineshaft", "Mansion", "Igloo", "Desert_Pyramid", "Jungle_Pyramid", "Swamp_Hut", "Stronghold", "Monument"));
} else {
ImmutableList immutablelist;
- if (resourcekey == World.NETHER) {
+ if (resourcekey == DimensionManager.NETHER_LOCATION) { // CraftBukkit
+ if (resourcekey == WorldDimension.NETHER) { // CraftBukkit
immutablelist = ImmutableList.of("Fortress");
return new PersistentStructureLegacy(worldpersistentdata, immutablelist, immutablelist);
- } else if (resourcekey == World.END) {
+ } else if (resourcekey == DimensionManager.END_LOCATION) { // CraftBukkit
+ } else if (resourcekey == WorldDimension.END) { // CraftBukkit
immutablelist = ImmutableList.of("EndCity");
return new PersistentStructureLegacy(worldpersistentdata, immutablelist, immutablelist);
} else {

View file

@ -42,7 +42,7 @@
private final String levelId;
private final Map<SavedFile, Path> resources = Maps.newHashMap();
+ // CraftBukkit start
+ private final ResourceKey<WorldDimension> dimensionType;
+ public final ResourceKey<WorldDimension> dimensionType;
- public ConversionSession(String s) throws IOException {
+ public ConversionSession(String s, ResourceKey<WorldDimension> dimensionType) throws IOException {