27
27
import net .minecraft .world .gen .densityfunction .DensityFunction .NoisePos ;
28
28
29
29
public class CloudCarver extends CaveCarver {
30
-
31
- private Random random ;
32
-
33
- private final LongSet topWrittenPositions = new LongOpenHashSet ();
34
-
35
30
public CloudCarver (Codec <CaveCarverConfig > codec ) {
36
31
super (codec );
37
32
}
@@ -62,25 +57,13 @@ public boolean carve(
62
57
ChunkPos chunkPos ,
63
58
CarvingMask carvingMask
64
59
) {
65
- this .random = random ;
66
- boolean result = super .carve (context , config , chunk , function , random , new AquiferSampler () {
67
- @ Override
68
- public BlockState apply (NoisePos pos , double density ) {
69
- BlockState state = sampler .apply (pos , density );
70
- return state != null && state .isAir () ? UBlocks .CLOUD .getDefaultState () : state ;
71
- }
72
-
73
- @ Override
74
- public boolean needsFluidTick () {
75
- return sampler .needsFluidTick ();
76
- }
77
-
78
- }, chunkPos , carvingMask );
60
+ CloudCarverContext carverContext = new CloudCarverContext (sampler , random );
61
+ boolean result = super .carve (context , config , chunk , function , random , carverContext , chunkPos , carvingMask );
79
62
BlockPos .Mutable mutable = new BlockPos .Mutable ();
80
- topWrittenPositions .forEach (l -> {
63
+ carverContext . topWrittenPositions .forEach (l -> {
81
64
processSurfaceBlocks (mutable .set (l ), context , config , chunk , random );
82
65
});
83
- topWrittenPositions .clear ();
66
+ carverContext . topWrittenPositions .clear ();
84
67
return result ;
85
68
}
86
69
@@ -99,17 +82,17 @@ protected void carveCave(
99
82
CarvingMask mask ,
100
83
Carver .SkipPredicate skipPredicate
101
84
) {
102
- if (random == null ) {
85
+ if (!( aquiferSampler instanceof CloudCarverContext c ) ) {
103
86
return ;
104
87
}
105
88
int maxY = context .getMinY () + context .getHeight ();
106
89
107
- int bubbleCount = 10 + random .nextInt (12 );
90
+ int bubbleCount = 10 + c . random .nextInt (12 );
108
91
for (int i = 0 ; i < bubbleCount ; i ++) {
109
- double width = 1.5 * xScale + random .nextTriangular (3 , 2 );
110
- double height = Math .min (width * yScale * (1 + random .nextFloat () * 2 ) + MathHelper .sin ((float ) (Math .PI / 2 )) * xScale , maxY - y );
111
- double bubbleX = x + (random .nextFloat () * 2 - 1 ) * width ;
112
- double bubbleZ = z + (random .nextFloat () * 2 - 1 ) * width ;
92
+ double width = 1.5 * xScale +c . random .nextTriangular (3 , 2 );
93
+ double height = Math .min (width * yScale * (1 + c . random .nextFloat () * 2 ) + MathHelper .sin ((float ) (Math .PI / 2 )) * xScale , maxY - y );
94
+ double bubbleX = x + (c . random .nextFloat () * 2 - 1 ) * width ;
95
+ double bubbleZ = z + (c . random .nextFloat () * 2 - 1 ) * width ;
113
96
carveRegion (context , config , chunk , posToBiome , aquiferSampler , bubbleX + 1.0 , y , bubbleZ , width , height , mask , skipPredicate );
114
97
}
115
98
}
@@ -136,17 +119,17 @@ protected void carveTunnels(
136
119
CarvingMask mask ,
137
120
Carver .SkipPredicate skipPredicate
138
121
) {
139
- if (random == null ) {
122
+ if (!( aquiferSampler instanceof CloudCarverContext c ) ) {
140
123
return ;
141
124
}
142
125
int maxY = context .getMinY () + context .getHeight ();
143
- int bubbleCount = 10 + random .nextInt (12 );
126
+ int bubbleCount = 10 + c . random .nextInt (12 );
144
127
for (int i = 0 ; i < bubbleCount ; i ++) {
145
- double width = /*1.5 + MathHelper.sin((float) (Math.PI / 2)) * xScale +*/ 1.5 * horizontalScale + random .nextInt (3 ) + w ;
146
- double height = width * (1 + random .nextFloat () * 2 ) * verticalScale * 0.2 ;
147
- double bubbleX = x + (random .nextFloat () * 2 - 1 ) * width * 1.5 ;
148
- double bubbleZ = z + (random .nextFloat () * 2 - 1 ) * width * 1.5 ;
149
- double bubbleY = y + random .nextFloat () * height * 0.5 ;
128
+ double width = /*1.5 + MathHelper.sin((float) (Math.PI / 2)) * xScale +*/ 1.5 * horizontalScale + c . random .nextInt (3 ) + w ;
129
+ double height = width * (1 + c . random .nextFloat () * 2 ) * verticalScale * 0.2 ;
130
+ double bubbleX = x + (c . random .nextFloat () * 2 - 1 ) * width * 1.5 ;
131
+ double bubbleZ = z + (c . random .nextFloat () * 2 - 1 ) * width * 1.5 ;
132
+ double bubbleY = y + c . random .nextFloat () * height * 0.5 ;
150
133
if (bubbleY + height < maxY ) {
151
134
carveRegion (context , config , chunk , posToBiome , aquiferSampler , bubbleX , bubbleY , bubbleZ , width , height , mask , skipPredicate );
152
135
}
@@ -168,10 +151,12 @@ protected boolean carveAtPoint(
168
151
) {
169
152
if (super .carveAtPoint (context , config , chunk , posToBiome , mask , pos , tmp , aquiferSampler , replacedGrassy )) {
170
153
tmp .set (pos ).move (Direction .DOWN );
171
- if (!topWrittenPositions .isEmpty ()) {
172
- topWrittenPositions .remove (tmp .asLong ());
154
+ if (aquiferSampler instanceof CloudCarverContext c ) {
155
+ if (!c .topWrittenPositions .isEmpty ()) {
156
+ c .topWrittenPositions .remove (tmp .asLong ());
157
+ }
158
+ c .topWrittenPositions .add (pos .asLong ());
173
159
}
174
- topWrittenPositions .add (pos .asLong ());
175
160
if (chunk .getBlockState (tmp ).isOf (UBlocks .SOGGY_CLOUD )) {
176
161
chunk .setBlockState (tmp , UBlocks .CLOUD .getDefaultState (), false );
177
162
}
@@ -185,4 +170,27 @@ protected void processSurfaceBlocks(BlockPos.Mutable pos, CarverContext context,
185
170
chunk .setBlockState (pos .move (Direction .DOWN ), UBlocks .SOGGY_CLOUD .getDefaultState (), false );
186
171
}
187
172
}
173
+
174
+ static class CloudCarverContext implements AquiferSampler {
175
+
176
+ private final AquiferSampler sampler ;
177
+ public final LongSet topWrittenPositions = new LongOpenHashSet ();
178
+ public final Random random ;
179
+
180
+ public CloudCarverContext (AquiferSampler sampler , Random random ) {
181
+ this .sampler = sampler ;
182
+ this .random = random ;
183
+ }
184
+
185
+ @ Override
186
+ public BlockState apply (NoisePos pos , double density ) {
187
+ BlockState state = sampler .apply (pos , density );
188
+ return state != null && state .isAir () ? UBlocks .CLOUD .getDefaultState () : state ;
189
+ }
190
+
191
+ @ Override
192
+ public boolean needsFluidTick () {
193
+ return sampler .needsFluidTick ();
194
+ }
195
+ }
188
196
}
0 commit comments