mirror of
https://github.com/GTNewHorizons/Postea.git
synced 2026-11-25 22:44:51 +00:00
Fix stale and missing columns in the versioned transformer height map rebuild
This commit is contained in:
3 files changed
+89
-21
No files matched your search
@@ -98,30 +98,10 @@ public class ChunkFixerUtility {
|
||||
for (ExtendedBlockStorage section : chunk.getBlockStorageArray()) {
|
||||
if (section != null) section.removeInvalidBlocks();
|
||||
}
|
||||
regenerateHeightMap(chunk);
|
||||
HeightMaps.regenerate(chunk);
|
||||
chunk.isLightPopulated = false;
|
||||
}
|
||||
|
||||
/// Rebuilds the height map from the chunk's own storage, which is safe on the chunk I/O thread.
|
||||
/// `Chunk.generateHeightMap` is client-only and `generateSkylightMap` reaches into the world.
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static CrashReport describe(Throwable cause, IVersionedTransformer transformer, int stored, int current,
|
||||
String subjectName, String subject) {
|
||||
CrashReport report = CrashReport.makeCrashReport(cause, "Running versioned transformer " + transformer.key());
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.gtnewhorizons.postea.utility;
|
||||
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
/// Rebuilds a chunk's height map from the chunk's own storage, which is safe on the chunk I/O thread.
|
||||
/// `Chunk.generateHeightMap` is client-only and `generateSkylightMap` reaches into the world.
|
||||
final class HeightMaps {
|
||||
|
||||
private HeightMaps() {}
|
||||
|
||||
static void regenerate(Chunk chunk) {
|
||||
int top = chunk.getTopFilledSegment() + 16;
|
||||
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--;
|
||||
}
|
||||
chunk.heightMap[z << 4 | x] = y;
|
||||
chunk.heightMapMinimum = Math.min(chunk.heightMapMinimum, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.gtnewhorizons.postea.utility;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class HeightMapsTest {
|
||||
|
||||
/// A chunk with empty sections at `sections`, opaque only at positions set through [#setOpaque], with no block
|
||||
/// registry behind it.
|
||||
private static final class OpacityChunk extends Chunk {
|
||||
|
||||
private final Set<Long> opaque = new HashSet<>();
|
||||
|
||||
OpacityChunk(int... sections) {
|
||||
super(null, 0, 0);
|
||||
for (int section : sections) getBlockStorageArray()[section] = new ExtendedBlockStorage(section << 4, true);
|
||||
}
|
||||
|
||||
void setOpaque(int x, int y, int z) {
|
||||
opaque.add(position(x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int func_150808_b(int x, int y, int z) {
|
||||
return opaque.contains(position(x, y, z)) ? 255 : 0;
|
||||
}
|
||||
|
||||
private static long position(int x, int y, int z) {
|
||||
return ((long) y << 8) | (z << 4) | x;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void anEmptiedColumnGetsHeightZero() {
|
||||
OpacityChunk chunk = new OpacityChunk(0);
|
||||
chunk.setOpaque(0, 10, 0);
|
||||
chunk.heightMap[5 << 4 | 3] = 64;
|
||||
|
||||
HeightMaps.regenerate(chunk);
|
||||
|
||||
assertEquals(0, chunk.heightMap[5 << 4 | 3]);
|
||||
assertEquals(11, chunk.heightMap[0]);
|
||||
assertEquals(0, chunk.heightMapMinimum);
|
||||
}
|
||||
|
||||
@Test
|
||||
void aBlockAtTheTopOfTheWorldGetsHeight256() {
|
||||
OpacityChunk chunk = new OpacityChunk(15);
|
||||
chunk.setOpaque(7, 255, 9);
|
||||
|
||||
HeightMaps.regenerate(chunk);
|
||||
|
||||
assertEquals(256, chunk.heightMap[9 << 4 | 7]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user