Announce version spans once per world and rebuild the height map after block id changes

This commit is contained in:
Ruling-0 committed 2026-08-27 22:44:05 -05:00
1 parent de78b11610
commit 1df9b851ee
5 files changed
+60 -20

No files matched your search

@@ -13,6 +13,7 @@ import com.gtnewhorizons.postea.utility.IDRegistry;
import com.gtnewhorizons.postea.utility.MissingMappingHandler;
import com.gtnewhorizons.postea.utility.SimpleTransformationRegistry;
import com.gtnewhorizons.postea.utility.TransformerRegistry;
import com.gtnewhorizons.postea.utility.VersionedTransformerLog;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod;
@@ -67,6 +68,7 @@ public class Postea {
@Mod.EventHandler
public void serverStopped(FMLServerStoppedEvent event) {
IDRegistry.endWorld();
VersionedTransformerLog.clear();
}
@Mod.EventHandler
@@ -15,7 +15,6 @@ import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
import com.gtnewhorizons.postea.Postea;
import com.gtnewhorizons.postea.api.ChunkTransformContext;
import com.gtnewhorizons.postea.api.IVersionedTransformer;
import com.gtnewhorizons.postea.api.TriFunction;
@@ -77,14 +76,7 @@ public class ChunkFixerUtility {
int stored = VersionStamps.stored(stamps, transformer.key());
if (stored == current) continue;
ChunkTransformContext ctx = new ChunkTransformContext(chunk, world, tag, stored, current);
Postea.LOG.debug(
"{}: chunk {},{} in dimension {} from version {} to {}",
transformer.key(),
chunk.xPosition,
chunk.zPosition,
world.provider.dimensionId,
stored,
current);
VersionedTransformerLog.announce(transformer, stored, current);
try {
transformer.transformChunk(ctx);
} catch (Throwable t) {
@@ -101,12 +93,33 @@ public class ChunkFixerUtility {
blockIdsChanged |= ctx.blockIdsChanged();
}
if (!blockIdsChanged) return;
chunk.isLightPopulated = false;
// A section's block count is what decides whether it is saved at all, and writing through SubChunkAccess
// bypasses the bookkeeping ExtendedBlockStorage does in its own setters.
for (ExtendedBlockStorage section : chunk.getBlockStorageArray()) {
if (section != null) section.removeInvalidBlocks();
}
regenerateHeightMap(chunk);
chunk.isLightPopulated = false;
}
// Chunk.generateHeightMap is client-only and generateSkylightMap reaches into the world, so the height map is
// rebuilt here from the chunk's own storage, which is safe on the chunk I/O thread.
private static void regenerateHeightMap(Chunk chunk) {
int top = chunk.getTopFilledSegment() + 16 - 1;
chunk.heightMapMinimum = Integer.MAX_VALUE;
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
chunk.precipitationHeightMap[x + (z << 4)] = -999;
int y = top;
while (y > 0 && chunk.func_150808_b(x, y - 1, z) == 0) {
y--;
}
if (y > 0) {
chunk.heightMap[z << 4 | x] = y;
chunk.heightMapMinimum = Math.min(chunk.heightMapMinimum, y);
}
}
}
}
static CrashReport describe(Throwable cause, IVersionedTransformer transformer, int stored, int current,
@@ -5,7 +5,6 @@ import static net.minecraftforge.common.util.Constants.NBT.TAG_COMPOUND;
import static net.minecraftforge.common.util.Constants.NBT.TAG_INT;
import static net.minecraftforge.common.util.Constants.NBT.TAG_SHORT;
import java.util.ArrayList;
import java.util.function.Consumer;
import net.minecraft.nbt.NBTBase;
@@ -16,7 +15,8 @@ import net.minecraft.nbt.NBTTagList;
* Visits every serialized item stack in an NBT tree. A compound is a stack when it has a numeric {@code id} or an
* EndlessIDs {@code idExt} together with a {@code Count}. The walk is pre-order and descends into every compound
* and every list of compounds, so stacks nested inside another stack's {@code tag} (backpacks, storage cells) are
* visited too. Lists of lists are not descended.
* visited too. Lists of lists are not descended. A visitor may change or remove keys of the stack it is given; it
* must not touch other parts of the tree.
*/
public final class NbtItemStacks {
@@ -25,7 +25,7 @@ public final class NbtItemStacks {
public static void forEach(NBTBase root, Consumer<NBTTagCompound> visitor) {
if (root instanceof NBTTagCompound compound) {
if (isStack(compound)) visitor.accept(compound);
for (Object key : new ArrayList<>(compound.func_150296_c())) {
for (Object key : compound.func_150296_c()) {
forEach(compound.getTag((String) key), visitor);
}
} else if (root instanceof NBTTagList list && list.func_150303_d() == TAG_COMPOUND) {
@@ -4,7 +4,6 @@ import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ReportedException;
import com.gtnewhorizons.postea.Postea;
import com.gtnewhorizons.postea.api.IVersionedTransformer;
import com.gtnewhorizons.postea.api.PlayerDataTransformContext;
import com.gtnewhorizons.postea.api.VersionedReplacementManager;
@@ -27,12 +26,7 @@ public final class PlayerDataFixerUtility {
int current = transformer.currentVersion();
int stored = VersionStamps.stored(stamps, transformer.key());
if (stored == current) continue;
Postea.LOG.debug(
"{}: player {} from version {} to {}",
transformer.key(),
player.getCommandSenderName(),
stored,
current);
VersionedTransformerLog.announce(transformer, stored, current);
try {
transformer.transformPlayer(new PlayerDataTransformContext(player, tag, stored, current));
} catch (Throwable t) {
@@ -0,0 +1,31 @@
package com.gtnewhorizons.postea.utility;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import com.gtnewhorizons.postea.Postea;
import com.gtnewhorizons.postea.api.IVersionedTransformer;
/**
* Announces each version span a transformer is bringing data across once per world, instead of once per chunk.
*/
public final class VersionedTransformerLog {
private static final Set<String> ANNOUNCED = ConcurrentHashMap.newKeySet();
private VersionedTransformerLog() {}
public static void announce(IVersionedTransformer transformer, int stored, int current) {
if (ANNOUNCED.add(transformer.key() + ' ' + stored + ' ' + current)) {
Postea.LOG.info(
"{} is bringing saved data from version {} to {}",
transformer.key(),
stored == VersionStamps.UNSTAMPED ? "unstamped" : String.valueOf(stored),
current);
}
}
public static void clear() {
ANNOUNCED.clear();
}
}