Skip to content

Commit 992b610

Browse files
committed
3 block wide world!
1 parent 6dd4e38 commit 992b610

File tree

4 files changed

+126
-719
lines changed

4 files changed

+126
-719
lines changed
+123-16
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
package com.cyao;
22

3+
import com.google.common.collect.Sets;
34
import com.mojang.serialization.MapCodec;
45
import com.mojang.serialization.codecs.RecordCodecBuilder;
6+
import net.minecraft.SharedConstants;
57
import net.minecraft.block.BlockState;
68
import net.minecraft.block.Blocks;
79
import net.minecraft.registry.entry.RegistryEntry;
8-
import net.minecraft.world.ChunkRegion;
9-
import net.minecraft.world.biome.source.BiomeAccess;
10+
import net.minecraft.util.Util;
11+
import net.minecraft.util.math.BlockPos;
12+
import net.minecraft.util.math.ChunkPos;
13+
import net.minecraft.util.math.MathHelper;
14+
import net.minecraft.world.Heightmap;
1015
import net.minecraft.world.biome.source.BiomeSource;
1116
import net.minecraft.world.chunk.Chunk;
12-
import net.minecraft.world.gen.GenerationStep;
17+
import net.minecraft.world.chunk.ChunkSection;
1318
import net.minecraft.world.gen.StructureAccessor;
14-
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
15-
import net.minecraft.world.gen.chunk.NoiseChunkGenerator;
19+
import net.minecraft.world.gen.chunk.*;
1620
import net.minecraft.world.gen.noise.NoiseConfig;
1721

22+
import java.util.Set;
23+
import java.util.concurrent.CompletableFuture;
24+
1825
public class PaperWorldGenerator extends NoiseChunkGenerator {
1926
public static final MapCodec<PaperWorldGenerator> CODEC = RecordCodecBuilder.mapCodec(
2027
instance -> instance.group(
@@ -30,15 +37,115 @@ public PaperWorldGenerator(BiomeSource biomeSource, RegistryEntry<ChunkGenerator
3037
}
3138

3239
@Override
33-
public void carve(
34-
ChunkRegion chunkRegion,
35-
long seed,
36-
NoiseConfig noiseConfig,
37-
BiomeAccess biomeAccess,
38-
StructureAccessor structureAccessor,
39-
Chunk chunk,
40-
GenerationStep.Carver carverStep
41-
) {
42-
FlatMinecraft.LOGGER.info("Carving!");
40+
public CompletableFuture<Chunk> populateNoise(Blender blender, NoiseConfig noiseConfig, StructureAccessor structureAccessor, Chunk chunk) {
41+
GenerationShapeConfig generationShapeConfig = this.getSettings().value().generationShapeConfig().trimHeight(chunk.getHeightLimitView());
42+
int i = generationShapeConfig.minimumY();
43+
int j = MathHelper.floorDiv(i, generationShapeConfig.verticalCellBlockCount());
44+
int k = MathHelper.floorDiv(generationShapeConfig.height(), generationShapeConfig.verticalCellBlockCount());
45+
return k <= 0 ? CompletableFuture.completedFuture(chunk) : CompletableFuture.supplyAsync(Util.debugSupplier("wgen_fill_noise", () -> {
46+
int l = chunk.getSectionIndex(k * generationShapeConfig.verticalCellBlockCount() - 1 + i);
47+
int m = chunk.getSectionIndex(i);
48+
Set<ChunkSection> set = Sets.<ChunkSection>newHashSet();
49+
50+
for (int n = l; n >= m; n--) {
51+
ChunkSection chunkSection = chunk.getSection(n);
52+
chunkSection.lock();
53+
set.add(chunkSection);
54+
}
55+
56+
Chunk var20;
57+
try {
58+
var20 = this.populateNoise(blender, structureAccessor, noiseConfig, chunk, j, k);
59+
} finally {
60+
for (ChunkSection chunkSection3 : set) {
61+
chunkSection3.unlock();
62+
}
63+
}
64+
65+
return var20;
66+
}), Util.getMainWorkerExecutor());
67+
}
68+
69+
private Chunk populateNoise(Blender blender, StructureAccessor structureAccessor, NoiseConfig noiseConfig, Chunk chunk, int minimumCellY, int cellHeight) {
70+
ChunkNoiseSampler chunkNoiseSampler = chunk.getOrCreateChunkNoiseSampler(
71+
chunkx -> this.createChunkNoiseSampler(chunkx, structureAccessor, blender, noiseConfig)
72+
);
73+
Heightmap heightmap = chunk.getHeightmap(Heightmap.Type.OCEAN_FLOOR_WG);
74+
Heightmap heightmap2 = chunk.getHeightmap(Heightmap.Type.WORLD_SURFACE_WG);
75+
ChunkPos chunkPos = chunk.getPos();
76+
int i = chunkPos.getStartX();
77+
int j = chunkPos.getStartZ();
78+
AquiferSampler aquiferSampler = chunkNoiseSampler.getAquiferSampler();
79+
chunkNoiseSampler.sampleStartDensity();
80+
BlockPos.Mutable mutable = new BlockPos.Mutable();
81+
int k = chunkNoiseSampler.getHorizontalCellBlockCount();
82+
int l = chunkNoiseSampler.getVerticalCellBlockCount();
83+
int m = 16 / k;
84+
int n = 16 / k;
85+
86+
for (int o = 0; o < m; o++) {
87+
chunkNoiseSampler.sampleEndDensity(o);
88+
89+
for (int p = 0; p < n; p++) {
90+
int q = chunk.countVerticalSections() - 1;
91+
ChunkSection chunkSection = chunk.getSection(q);
92+
93+
for (int r = cellHeight - 1; r >= 0; r--) {
94+
chunkNoiseSampler.onSampledCellCorners(r, p);
95+
96+
for (int s = l - 1; s >= 0; s--) {
97+
int t = (minimumCellY + r) * l + s;
98+
int u = t & 15;
99+
int v = chunk.getSectionIndex(t);
100+
if (q != v) {
101+
q = v;
102+
chunkSection = chunk.getSection(v);
103+
}
104+
105+
double d = (double)s / (double)l;
106+
chunkNoiseSampler.interpolateY(t, d);
107+
108+
for (int w = 0; w < k; w++) {
109+
int x = i + o * k + w;
110+
int y = x & 15;
111+
double e = (double)w / (double)k;
112+
chunkNoiseSampler.interpolateX(x, e);
113+
114+
for (int z = 0; z < k; z++) {
115+
int aa = j + p * k + z;
116+
int ab = aa & 15;
117+
double f = (double)z / (double)k;
118+
chunkNoiseSampler.interpolateZ(aa, f);
119+
BlockState blockState = chunkNoiseSampler.sampleBlockState();
120+
if (blockState == null) {
121+
blockState = this.getSettings().value().defaultBlock();
122+
}
123+
124+
if (aa != -1 && aa != 0 && aa != 1) {
125+
blockState = AIR;
126+
continue;
127+
}
128+
129+
blockState = super.getBlockState(chunkNoiseSampler, x, t, aa, blockState);
130+
if (blockState != AIR && !SharedConstants.isOutsideGenerationArea(chunk.getPos())) {
131+
chunkSection.setBlockState(y, u, ab, blockState, false);
132+
heightmap.trackUpdate(y, t, ab, blockState);
133+
heightmap2.trackUpdate(y, t, ab, blockState);
134+
if (aquiferSampler.needsFluidTick() && !blockState.getFluidState().isEmpty()) {
135+
mutable.set(x, t, aa);
136+
chunk.markBlockForPostProcessing(mutable);
137+
}
138+
}
139+
}
140+
}
141+
}
142+
}
143+
}
144+
145+
chunkNoiseSampler.swapBuffers();
146+
}
147+
148+
chunkNoiseSampler.stopInterpolation();
149+
return chunk;
43150
}
44-
}
151+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"generator.flat-minecraft.paper_world": "Nothing but Void"
2+
"generator.flat-minecraft.paper_world": "2D world"
33
}

0 commit comments

Comments
 (0)