aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-vineflower/net/minecraft/util/worldupdate/WorldUpgrader.java.patch
diff options
context:
space:
mode:
Diffstat (limited to 'patch-remap/mache-vineflower/net/minecraft/util/worldupdate/WorldUpgrader.java.patch')
-rw-r--r--patch-remap/mache-vineflower/net/minecraft/util/worldupdate/WorldUpgrader.java.patch325
1 files changed, 325 insertions, 0 deletions
diff --git a/patch-remap/mache-vineflower/net/minecraft/util/worldupdate/WorldUpgrader.java.patch b/patch-remap/mache-vineflower/net/minecraft/util/worldupdate/WorldUpgrader.java.patch
new file mode 100644
index 0000000000..11f5e0881e
--- /dev/null
+++ b/patch-remap/mache-vineflower/net/minecraft/util/worldupdate/WorldUpgrader.java.patch
@@ -0,0 +1,325 @@
+--- a/net/minecraft/util/worldupdate/WorldUpgrader.java
++++ b/net/minecraft/util/worldupdate/WorldUpgrader.java
+@@ -2,8 +2,9 @@
+
+ import com.google.common.collect.ImmutableList;
+ import com.google.common.collect.ImmutableMap;
+-import com.google.common.collect.Lists;
+ import com.google.common.collect.ImmutableMap.Builder;
++import com.google.common.collect.Lists;
++import com.google.common.collect.UnmodifiableIterator;
+ import com.google.common.util.concurrent.ThreadFactoryBuilder;
+ import com.mojang.datafixers.DataFixer;
+ import com.mojang.logging.LogUtils;
+@@ -13,8 +14,10 @@
+ import java.io.File;
+ import java.io.IOException;
+ import java.nio.file.Path;
++import java.util.Iterator;
+ import java.util.List;
+ import java.util.ListIterator;
++import java.util.Optional;
+ import java.util.Set;
+ import java.util.concurrent.CompletionException;
+ import java.util.concurrent.ThreadFactory;
+@@ -41,8 +44,9 @@
+ import org.slf4j.Logger;
+
+ public class WorldUpgrader {
++
+ private static final Logger LOGGER = LogUtils.getLogger();
+- private static final ThreadFactory THREAD_FACTORY = new ThreadFactoryBuilder().setDaemon(true).build();
++ private static final ThreadFactory THREAD_FACTORY = (new ThreadFactoryBuilder()).setDaemon(true).build();
+ private final Registry<LevelStem> dimensions;
+ private final Set<ResourceKey<Level>> levels;
+ private final boolean eraseCache;
+@@ -55,21 +59,21 @@
+ private volatile int totalChunks;
+ private volatile int converted;
+ private volatile int skipped;
+- private final Reference2FloatMap<ResourceKey<Level>> progressMap = Reference2FloatMaps.synchronize(new Reference2FloatOpenHashMap<>());
++ private final Reference2FloatMap<ResourceKey<Level>> progressMap = Reference2FloatMaps.synchronize(new Reference2FloatOpenHashMap());
+ private volatile Component status = Component.translatable("optimizeWorld.stage.counting");
+ private static final Pattern REGEX = Pattern.compile("^r\\.(-?[0-9]+)\\.(-?[0-9]+)\\.mca$");
+ private final DimensionDataStorage overworldDataStorage;
+
+ public WorldUpgrader(LevelStorageSource.LevelStorageAccess levelStoarge, DataFixer dataFixer, Registry<LevelStem> dimensions, boolean eraseCache) {
+ this.dimensions = dimensions;
+- this.levels = dimensions.registryKeySet().stream().map(Registries::levelStemToLevel).collect(Collectors.toUnmodifiableSet());
++ this.levels = (Set) java.util.stream.Stream.of(levelStoarge.dimensionType).map(Registries::levelStemToLevel).collect(Collectors.toUnmodifiableSet()); // CraftBukkit
+ this.eraseCache = eraseCache;
+ this.dataFixer = dataFixer;
+ this.levelStorage = levelStoarge;
+ this.overworldDataStorage = new DimensionDataStorage(this.levelStorage.getDimensionPath(Level.OVERWORLD).resolve("data").toFile(), dataFixer);
+- this.thread = THREAD_FACTORY.newThread(this::work);
++ this.thread = WorldUpgrader.THREAD_FACTORY.newThread(this::work);
+ this.thread.setUncaughtExceptionHandler((thread, throwable) -> {
+- LOGGER.error("Error upgrading world", throwable);
++ WorldUpgrader.LOGGER.error("Error upgrading world", throwable);
+ this.status = Component.translatable("optimizeWorld.stage.failed");
+ this.finished = true;
+ });
+@@ -81,103 +85,120 @@
+
+ try {
+ this.thread.join();
+- } catch (InterruptedException var2) {
++ } catch (InterruptedException interruptedexception) {
++ ;
+ }
++
+ }
+
+ private void work() {
+ this.totalChunks = 0;
+ Builder<ResourceKey<Level>, ListIterator<ChunkPos>> builder = ImmutableMap.builder();
+
+- for (ResourceKey<Level> resourceKey : this.levels) {
+- List<ChunkPos> allChunkPos = this.getAllChunkPos(resourceKey);
+- builder.put(resourceKey, allChunkPos.listIterator());
+- this.totalChunks = this.totalChunks + allChunkPos.size();
++ List list;
++
++ for (Iterator iterator = this.levels.iterator(); iterator.hasNext(); this.totalChunks += list.size()) {
++ ResourceKey<Level> resourcekey = (ResourceKey) iterator.next();
++
++ list = this.getAllChunkPos(resourcekey);
++ builder.put(resourcekey, list.listIterator());
+ }
+
+ if (this.totalChunks == 0) {
+ this.finished = true;
+ } else {
+- float f = (float)this.totalChunks;
+- ImmutableMap<ResourceKey<Level>, ListIterator<ChunkPos>> map = builder.build();
++ float f = (float) this.totalChunks;
++ ImmutableMap<ResourceKey<Level>, ListIterator<ChunkPos>> immutablemap = builder.build();
+ Builder<ResourceKey<Level>, ChunkStorage> builder1 = ImmutableMap.builder();
++ Iterator iterator1 = this.levels.iterator();
+
+- for (ResourceKey<Level> resourceKey1 : this.levels) {
+- Path dimensionPath = this.levelStorage.getDimensionPath(resourceKey1);
+- builder1.put(resourceKey1, new ChunkStorage(dimensionPath.resolve("region"), this.dataFixer, true));
++ while (iterator1.hasNext()) {
++ ResourceKey<Level> resourcekey1 = (ResourceKey) iterator1.next();
++ Path path = this.levelStorage.getDimensionPath(resourcekey1);
++
++ builder1.put(resourcekey1, new ChunkStorage(path.resolve("region"), this.dataFixer, true));
+ }
+
+- ImmutableMap<ResourceKey<Level>, ChunkStorage> map1 = builder1.build();
+- long millis = Util.getMillis();
++ ImmutableMap<ResourceKey<Level>, ChunkStorage> immutablemap1 = builder1.build();
++ long i = Util.getMillis();
++
+ this.status = Component.translatable("optimizeWorld.stage.upgrading");
+
+ while (this.running) {
+ boolean flag = false;
+ float f1 = 0.0F;
+
+- for (ResourceKey<Level> resourceKey2 : this.levels) {
+- ListIterator<ChunkPos> listIterator = map.get(resourceKey2);
+- ChunkStorage chunkStorage = map1.get(resourceKey2);
+- if (listIterator.hasNext()) {
+- ChunkPos chunkPos = listIterator.next();
++ float f2;
++
++ for (Iterator iterator2 = this.levels.iterator(); iterator2.hasNext(); f1 += f2) {
++ ResourceKey<Level> resourcekey2 = (ResourceKey) iterator2.next();
++ ListIterator<ChunkPos> listiterator = (ListIterator) immutablemap.get(resourcekey2);
++ ChunkStorage ichunkloader = (ChunkStorage) immutablemap1.get(resourcekey2);
++
++ if (listiterator.hasNext()) {
++ ChunkPos chunkcoordintpair = (ChunkPos) listiterator.next();
+ boolean flag1 = false;
+
+ try {
+- CompoundTag compoundTag = chunkStorage.read(chunkPos).join().orElse(null);
+- if (compoundTag != null) {
+- int version = ChunkStorage.getVersion(compoundTag);
+- ChunkGenerator chunkGenerator = this.dimensions.getOrThrow(Registries.levelToLevelStem(resourceKey2)).generator();
+- CompoundTag compoundTag1 = chunkStorage.upgradeChunkTag(
+- resourceKey2, () -> this.overworldDataStorage, compoundTag, chunkGenerator.getTypeNameForDataFixer()
+- );
+- ChunkPos chunkPos1 = new ChunkPos(compoundTag1.getInt("xPos"), compoundTag1.getInt("zPos"));
+- if (!chunkPos1.equals(chunkPos)) {
+- LOGGER.warn("Chunk {} has invalid position {}", chunkPos, chunkPos1);
++ CompoundTag nbttagcompound = (CompoundTag) ((Optional) ichunkloader.read(chunkcoordintpair).join()).orElse((Object) null);
++
++ if (nbttagcompound != null) {
++ int j = ChunkStorage.getVersion(nbttagcompound);
++ ChunkGenerator chunkgenerator = ((LevelStem) this.dimensions.getOrThrow(Registries.levelToLevelStem(resourcekey2))).generator();
++ CompoundTag nbttagcompound1 = ichunkloader.upgradeChunkTag(Registries.levelToLevelStem(resourcekey2), () -> { // CraftBukkit
++ return this.overworldDataStorage;
++ }, nbttagcompound, chunkgenerator.getTypeNameForDataFixer(), chunkcoordintpair, null); // CraftBukkit
++ ChunkPos chunkcoordintpair1 = new ChunkPos(nbttagcompound1.getInt("xPos"), nbttagcompound1.getInt("zPos"));
++
++ if (!chunkcoordintpair1.equals(chunkcoordintpair)) {
++ WorldUpgrader.LOGGER.warn("Chunk {} has invalid position {}", chunkcoordintpair, chunkcoordintpair1);
+ }
+
+- boolean flag2 = version < SharedConstants.getCurrentVersion().getDataVersion().getVersion();
++ boolean flag2 = j < SharedConstants.getCurrentVersion().getDataVersion().getVersion();
++
+ if (this.eraseCache) {
+- flag2 = flag2 || compoundTag1.contains("Heightmaps");
+- compoundTag1.remove("Heightmaps");
+- flag2 = flag2 || compoundTag1.contains("isLightOn");
+- compoundTag1.remove("isLightOn");
+- ListTag list = compoundTag1.getList("sections", 10);
++ flag2 = flag2 || nbttagcompound1.contains("Heightmaps");
++ nbttagcompound1.remove("Heightmaps");
++ flag2 = flag2 || nbttagcompound1.contains("isLightOn");
++ nbttagcompound1.remove("isLightOn");
++ ListTag nbttaglist = nbttagcompound1.getList("sections", 10);
+
+- for (int i = 0; i < list.size(); i++) {
+- CompoundTag compound = list.getCompound(i);
+- flag2 = flag2 || compound.contains("BlockLight");
+- compound.remove("BlockLight");
+- flag2 = flag2 || compound.contains("SkyLight");
+- compound.remove("SkyLight");
++ for (int k = 0; k < nbttaglist.size(); ++k) {
++ CompoundTag nbttagcompound2 = nbttaglist.getCompound(k);
++
++ flag2 = flag2 || nbttagcompound2.contains("BlockLight");
++ nbttagcompound2.remove("BlockLight");
++ flag2 = flag2 || nbttagcompound2.contains("SkyLight");
++ nbttagcompound2.remove("SkyLight");
+ }
+ }
+
+ if (flag2) {
+- chunkStorage.write(chunkPos, compoundTag1);
++ ichunkloader.write(chunkcoordintpair, nbttagcompound1);
+ flag1 = true;
+ }
+ }
+- } catch (CompletionException | ReportedException var26) {
+- Throwable cause = var26.getCause();
+- if (!(cause instanceof IOException)) {
+- throw var26;
++ } catch (CompletionException | ReportedException reportedexception) {
++ Throwable throwable = reportedexception.getCause();
++
++ if (!(throwable instanceof IOException)) {
++ throw reportedexception;
+ }
+
+- LOGGER.error("Error upgrading chunk {}", chunkPos, cause);
++ WorldUpgrader.LOGGER.error("Error upgrading chunk {}", chunkcoordintpair, throwable);
+ }
+
+ if (flag1) {
+- this.converted++;
++ ++this.converted;
+ } else {
+- this.skipped++;
++ ++this.skipped;
+ }
+
+ flag = true;
+ }
+
+- float f2 = (float)listIterator.nextIndex() / f;
+- this.progressMap.put(resourceKey2, f2);
+- f1 += f2;
++ f2 = (float) listiterator.nextIndex() / f;
++ this.progressMap.put(resourcekey2, f2);
+ }
+
+ this.progress = f1;
+@@ -187,18 +208,21 @@
+ }
+
+ this.status = Component.translatable("optimizeWorld.stage.finished");
++ UnmodifiableIterator unmodifiableiterator = immutablemap1.values().iterator();
+
+- for (ChunkStorage chunkStorage1 : map1.values()) {
++ while (unmodifiableiterator.hasNext()) {
++ ChunkStorage ichunkloader1 = (ChunkStorage) unmodifiableiterator.next();
++
+ try {
+- chunkStorage1.close();
+- } catch (IOException var25) {
+- LOGGER.error("Error upgrading chunk", (Throwable)var25);
++ ichunkloader1.close();
++ } catch (IOException ioexception) {
++ WorldUpgrader.LOGGER.error("Error upgrading chunk", ioexception);
+ }
+ }
+
+ this.overworldDataStorage.save();
+- millis = Util.getMillis() - millis;
+- LOGGER.info("World optimizaton finished after {} ms", millis);
++ i = Util.getMillis() - i;
++ WorldUpgrader.LOGGER.info("World optimizaton finished after {} ms", i);
+ this.finished = true;
+ }
+ }
+@@ -206,28 +230,51 @@
+ private List<ChunkPos> getAllChunkPos(ResourceKey<Level> level) {
+ File file = this.levelStorage.getDimensionPath(level).toFile();
+ File file1 = new File(file, "region");
+- File[] files = file1.listFiles((file3, string) -> string.endsWith(".mca"));
+- if (files == null) {
++ File[] afile = file1.listFiles((file2, s) -> {
++ return s.endsWith(".mca");
++ });
++
++ if (afile == null) {
+ return ImmutableList.of();
+ } else {
+ List<ChunkPos> list = Lists.newArrayList();
++ File[] afile1 = afile;
++ int i = afile.length;
+
+- for (File file2 : files) {
+- Matcher matcher = REGEX.matcher(file2.getName());
++ for (int j = 0; j < i; ++j) {
++ File file2 = afile1[j];
++ Matcher matcher = WorldUpgrader.REGEX.matcher(file2.getName());
++
+ if (matcher.matches()) {
+- int i = Integer.parseInt(matcher.group(1)) << 5;
+- int i1 = Integer.parseInt(matcher.group(2)) << 5;
++ int k = Integer.parseInt(matcher.group(1)) << 5;
++ int l = Integer.parseInt(matcher.group(2)) << 5;
+
+- try (RegionFile regionFile = new RegionFile(file2.toPath(), file1.toPath(), true)) {
+- for (int i2 = 0; i2 < 32; i2++) {
+- for (int i3 = 0; i3 < 32; i3++) {
+- ChunkPos chunkPos = new ChunkPos(i2 + i, i3 + i1);
+- if (regionFile.doesChunkExist(chunkPos)) {
+- list.add(chunkPos);
++ try {
++ RegionFile regionfile = new RegionFile(file2.toPath(), file1.toPath(), true);
++
++ try {
++ for (int i1 = 0; i1 < 32; ++i1) {
++ for (int j1 = 0; j1 < 32; ++j1) {
++ ChunkPos chunkcoordintpair = new ChunkPos(i1 + k, j1 + l);
++
++ if (regionfile.doesChunkExist(chunkcoordintpair)) {
++ list.add(chunkcoordintpair);
++ }
+ }
+ }
++ } catch (Throwable throwable) {
++ try {
++ regionfile.close();
++ } catch (Throwable throwable1) {
++ throwable.addSuppressed(throwable1);
++ }
++
++ throw throwable;
+ }
+- } catch (Throwable var19) {
++
++ regionfile.close();
++ } catch (Throwable throwable2) {
++ ;
+ }
+ }
+ }