1
1
package com .cyao ;
2
2
3
+ import com .google .common .collect .Sets ;
3
4
import com .mojang .serialization .MapCodec ;
4
5
import com .mojang .serialization .codecs .RecordCodecBuilder ;
6
+ import net .minecraft .SharedConstants ;
5
7
import net .minecraft .block .BlockState ;
6
8
import net .minecraft .block .Blocks ;
7
9
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 ;
10
15
import net .minecraft .world .biome .source .BiomeSource ;
11
16
import net .minecraft .world .chunk .Chunk ;
12
- import net .minecraft .world .gen . GenerationStep ;
17
+ import net .minecraft .world .chunk . ChunkSection ;
13
18
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 .*;
16
20
import net .minecraft .world .gen .noise .NoiseConfig ;
17
21
22
+ import java .util .Set ;
23
+ import java .util .concurrent .CompletableFuture ;
24
+
18
25
public class PaperWorldGenerator extends NoiseChunkGenerator {
19
26
public static final MapCodec <PaperWorldGenerator > CODEC = RecordCodecBuilder .mapCodec (
20
27
instance -> instance .group (
@@ -30,15 +37,115 @@ public PaperWorldGenerator(BiomeSource biomeSource, RegistryEntry<ChunkGenerator
30
37
}
31
38
32
39
@ 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 ;
43
150
}
44
- }
151
+ }
0 commit comments