Skip to content

Commit 5a3e630

Browse files
committed
Decompiling minecraft source
1 parent 0524939 commit 5a3e630

File tree

2 files changed

+46
-51
lines changed

2 files changed

+46
-51
lines changed

src/main/java/com/cyao/FlatMinecraft.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ public class FlatMinecraft implements ModInitializer {
1313

1414
@Override
1515
public void onInitialize() {
16-
LOGGER.info("Initializing mod");
16+
LOGGER.info("Initializing 2D Minecraft");
1717

18-
Registry.register(Registries.CHUNK_GENERATOR,
19-
Identifier.of(MOD_ID, "paper_world"),
20-
PaperWorldGenerator.CODEC);
18+
Registry.register(Registries.CHUNK_GENERATOR, Identifier.of(MOD_ID, "paper_world"), PaperWorldGenerator.CODEC);
2119
}
2220
}

src/main/java/com/cyao/PaperWorldGenerator.java

+44-47
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ public CompletableFuture<Chunk> populateNoise(Blender blender, NoiseConfig noise
5353
set.add(chunkSection);
5454
}
5555

56-
boolean var19 = false;
56+
boolean updatingChunk = false;
5757

58-
Chunk var21;
58+
Chunk newChunk;
5959
try {
60-
var19 = true;
61-
var21 = this.populateNoise(blender, structureAccessor, noiseConfig, chunk, j, k);
62-
var19 = false;
60+
updatingChunk = true;
61+
newChunk = this.populateNoise(blender, structureAccessor, noiseConfig, chunk, j, k);
62+
updatingChunk = false;
6363
} finally {
64-
if (var19) {
64+
if (updatingChunk) {
6565
for (ChunkSection chunkSection3 : set) {
6666
chunkSection3.unlock();
6767
}
@@ -72,7 +72,7 @@ public CompletableFuture<Chunk> populateNoise(Blender blender, NoiseConfig noise
7272
chunkSection2.unlock();
7373
}
7474

75-
return var21;
75+
return newChunk;
7676
}, Util.getMainWorkerExecutor().named("wgen_fill_noise"));
7777
}
7878

@@ -83,66 +83,63 @@ private Chunk populateNoise(Blender blender, StructureAccessor structureAccessor
8383
Heightmap heightmap = chunk.getHeightmap(Heightmap.Type.OCEAN_FLOOR_WG);
8484
Heightmap heightmap2 = chunk.getHeightmap(Heightmap.Type.WORLD_SURFACE_WG);
8585
ChunkPos chunkPos = chunk.getPos();
86-
int i = chunkPos.getStartX();
87-
int j = chunkPos.getStartZ();
86+
int startX = chunkPos.getStartX();
87+
int startZ = chunkPos.getStartZ();
8888
AquiferSampler aquiferSampler = chunkNoiseSampler.getAquiferSampler();
8989
chunkNoiseSampler.sampleStartDensity();
9090
BlockPos.Mutable mutable = new BlockPos.Mutable();
91-
int k = chunkNoiseSampler.getHorizontalCellBlockCount();
92-
int l = chunkNoiseSampler.getVerticalCellBlockCount();
93-
int m = 16 / k;
94-
int n = 16 / k;
91+
int horizBlockCount = chunkNoiseSampler.getHorizontalCellBlockCount();
92+
int vertBlockCount = chunkNoiseSampler.getVerticalCellBlockCount();
93+
int horizontalDensity = 16 / horizBlockCount;
9594

96-
for (int o = 0; o < m; o++) {
97-
chunkNoiseSampler.sampleEndDensity(o);
95+
for (int horiz1 = 0; horiz1 < horizontalDensity; horiz1++) {
96+
chunkNoiseSampler.sampleEndDensity(horiz1)0b1 (int horiz2 = 0; horiz2 < horizontalDensity; horiz2++) {
97+
int verticalSectionCount = chunk.countVerticalSections() - 1;
98+
ChunkSection chunkSection = chunk.getSection(verticalSectionCount);
9899

99-
for (int p = 0; p < n; p++) {
100-
int q = chunk.countVerticalSections() - 1;
101-
ChunkSection chunkSection = chunk.getSection(q);
100+
for (int height = cellHeight - 1; height >= 0; height--) {
101+
chunkNoiseSampler.onSampledCellCorners(height, horiz2);
102102

103-
for (int r = cellHeight - 1; r >= 0; r--) {
104-
chunkNoiseSampler.onSampledCellCorners(r, p);
105-
106-
for (int s = l - 1; s >= 0; s--) {
107-
int t = (minimumCellY + r) * l + s;
108-
int u = t & 15;
103+
for (int layer = vertBlockCount - 1; layer >= 0; layer--) {
104+
int t = (minimumCellY + height) * vertBlockCount + layer;
105+
int u = t & 0b1111;
109106
int v = chunk.getSectionIndex(t);
110-
if (q != v) {
111-
q = v;
107+
if (verticalSectionCount != v) {
108+
verticalSectionCount = v;
112109
chunkSection = chunk.getSection(v);
113110
}
114111

115-
double d = (double)s / (double)l;
116-
chunkNoiseSampler.interpolateY(t, d);
112+
double normalLayer = (double)layer / (double)vertBlockCount;
113+
chunkNoiseSampler.interpolateY(t, normalLayer);
117114

118-
for (int w = 0; w < k; w++) {
119-
int x = i + o * k + w;
120-
int y = x & 15;
121-
double e = (double)w / (double)k;
115+
for (int w = 0; w < horizBlockCount; w++) {
116+
int x = startX + horiz1 * horizBlockCount + w;
117+
int y = x & 0b1111;
118+
double e = (double)w / (double)horizBlockCount;
122119
chunkNoiseSampler.interpolateX(x, e);
123120

124-
for (int z = 0; z < k; z++) {
125-
int aa = j + p * k + z;
126-
int ab = aa & 15;
127-
double f = (double)z / (double)k;
128-
chunkNoiseSampler.interpolateZ(aa, f);
121+
for (int z = 0; z < horizBlockCount; z++) {
122+
int blockZ = startZ + horiz2 * horizBlockCount + z;
123+
double normalZ = (double)z / (double)horizBlockCount;
124+
chunkNoiseSampler.interpolateZ(blockZ, normalZ);
129125
BlockState blockState = chunkNoiseSampler.sampleBlockState();
130-
if (blockState == null) {
131-
blockState = this.getSettings().value().defaultBlock();
132-
}
133126

134-
if (aa != -1 && aa != 0 && aa != 1) {
135-
blockState = AIR;
127+
if (blockZ < -1 || blockZ > 1) {
136128
continue;
137129
}
138130

139-
blockState = super.getBlockState(chunkNoiseSampler, x, t, aa, blockState);
131+
if (blockState == null) {
132+
blockState = this.getSettings().value().defaultBlock();
133+
}
134+
135+
int maskedBlockZ = blockZ & 0b1111;
136+
blockState = super.getBlockState(chunkNoiseSampler, x, t, blockZ, blockState);
140137
if (blockState != AIR && !SharedConstants.isOutsideGenerationArea(chunk.getPos())) {
141-
chunkSection.setBlockState(y, u, ab, blockState, false);
142-
heightmap.trackUpdate(y, t, ab, blockState);
143-
heightmap2.trackUpdate(y, t, ab, blockState);
138+
chunkSection.setBlockState(y, u, maskedBlockZ, blockState, false);
139+
heightmap.trackUpdate(y, t, maskedBlockZ, blockState);
140+
heightmap2.trackUpdate(y, t, maskedBlockZ, blockState);
144141
if (aquiferSampler.needsFluidTick() && !blockState.getFluidState().isEmpty()) {
145-
mutable.set(x, t, aa);
142+
mutable.set(x, t, blockZ);
146143
chunk.markBlockForPostProcessing(mutable);
147144
}
148145
}

0 commit comments

Comments
 (0)