21
21
import java .util .Optional ;
22
22
import net .frozenblock .lib .worldgen .feature .api .features .config .ColumnWithDiskFeatureConfig ;
23
23
import net .minecraft .core .BlockPos ;
24
+ import net .minecraft .core .Direction ;
24
25
import net .minecraft .core .Holder ;
25
26
import net .minecraft .util .RandomSource ;
27
+ import net .minecraft .util .valueproviders .UniformInt ;
26
28
import net .minecraft .world .level .WorldGenLevel ;
27
29
import net .minecraft .world .level .block .Block ;
28
- import net .minecraft .world .level .block .Blocks ;
29
- import net .minecraft .world .level .block .BushBlock ;
30
- import net .minecraft .world .level .block .GrowingPlantBodyBlock ;
31
30
import net .minecraft .world .level .block .state .BlockState ;
32
31
import net .minecraft .world .level .levelgen .Heightmap .Types ;
33
32
import net .minecraft .world .level .levelgen .feature .Feature ;
@@ -46,70 +45,69 @@ public boolean place(@NotNull FeaturePlaceContext<ColumnWithDiskFeatureConfig> c
46
45
ColumnWithDiskFeatureConfig config = context .config ();
47
46
BlockPos blockPos = context .origin ();
48
47
WorldGenLevel level = context .level ();
49
- BlockPos s = blockPos .atY (level .getHeight (Types .MOTION_BLOCKING_NO_LEAVES , blockPos .getX (), blockPos .getZ ()) - 1 );
48
+ BlockPos surfacePos = blockPos .atY (level .getHeight (Types .MOTION_BLOCKING_NO_LEAVES , blockPos .getX (), blockPos .getZ ()) - 1 );
50
49
RandomSource random = level .getRandom ();
51
50
int radius = config .radius ().sample (random );
52
51
Optional <Holder <Block >> diskOptional = config .diskBlocks ().getRandomElement (random );
53
52
// DISK
54
53
if (diskOptional .isPresent ()) {
55
- BlockPos .MutableBlockPos mutableDisk = s .mutable ();
54
+ BlockPos .MutableBlockPos mutableDisk = surfacePos .mutable ();
56
55
BlockState disk = diskOptional .get ().value ().defaultBlockState ();
57
- int bx = s .getX ();
58
- int bz = s .getZ ();
56
+ int bx = surfacePos .getX ();
57
+ int bz = surfacePos .getZ ();
59
58
for (int x = bx - radius ; x <= bx + radius ; x ++) {
60
59
for (int z = bz - radius ; z <= bz + radius ; z ++) {
61
60
double distance = ((bx - x ) * (bx - x ) + ((bz - z ) * (bz - z )));
62
61
if (distance < radius * radius ) {
63
62
mutableDisk .set (x , level .getHeight (Types .MOTION_BLOCKING_NO_LEAVES , x , z ) - 1 , z );
64
- boolean fade = !mutableDisk .closerThan (s , radius * 0.8 );
63
+ boolean fade = !mutableDisk .closerThan (surfacePos , radius * 0.8D );
65
64
if (level .getBlockState (mutableDisk ).is (config .replaceableBlocks ())) {
66
65
generated = true ;
67
66
if (fade ) {
68
67
if (random .nextFloat () > 0.65F ) {
69
- level .setBlock (mutableDisk , disk , 3 );
68
+ level .setBlock (mutableDisk , disk , Block . UPDATE_ALL );
70
69
}
71
70
} else {
72
- level .setBlock (mutableDisk , disk , 3 );
71
+ level .setBlock (mutableDisk , disk , Block . UPDATE_ALL );
73
72
}
74
73
}
75
74
}
76
75
}
77
76
}
78
77
}
79
78
// COLUMN
80
- BlockPos startPos = blockPos .atY (level .getHeight (Types .MOTION_BLOCKING_NO_LEAVES , blockPos .getX (), blockPos .getZ ()) - 1 );
81
- BlockState column = config .state ();
82
- BlockPos .MutableBlockPos pos = startPos .mutable ();
83
- for (int i = 0 ; i < config .height ().sample (random ); i ++) {
84
- pos .set (pos .above ());
85
- BlockState state = level .getBlockState (pos );
86
- if (level .getBlockState (pos .below ()).is (Blocks .WATER )) {
87
- break ;
88
- }
89
- if (state .getBlock () instanceof GrowingPlantBodyBlock || state .getBlock () instanceof BushBlock || state .isAir ()) {
90
- level .setBlock (pos , column , 3 );
91
- generated = true ;
79
+ BlockState columnState = config .state ();
80
+ BlockPos .MutableBlockPos mutablePos = blockPos .mutable ();
81
+ int pillarHeight = config .height ().sample (random );
82
+ generated = placeAtPos (level , blockPos , mutablePos , columnState , pillarHeight ) || generated ;
83
+
84
+ int maxSurroundingPillarHeight = pillarHeight - 1 ;
85
+ if (maxSurroundingPillarHeight > 0 ) {
86
+ for (Direction direction : Direction .Plane .HORIZONTAL ) {
87
+ if (random .nextFloat () < config .surroundingPillarChance ()) {
88
+ generated = placeAtPos (level , blockPos .relative (direction ), mutablePos , columnState , UniformInt .of (1 , maxSurroundingPillarHeight ).sample (random )) || generated ;
89
+ }
92
90
}
93
91
}
94
- startPos = startPos .offset (-1 , 0 , 0 );
95
- generated = generated || place (config , level , random , startPos , column , pos );
96
- startPos = startPos .offset (1 , 0 , 1 );
97
- generated = generated || place (config , level , random , startPos , column , pos );
98
92
return generated ;
99
93
}
100
94
101
- private boolean place (@ NotNull ColumnWithDiskFeatureConfig config , @ NotNull WorldGenLevel level , RandomSource random , @ NotNull BlockPos startPos , BlockState column , BlockPos .@ NotNull MutableBlockPos pos ) {
95
+ private boolean placeAtPos (
96
+ @ NotNull WorldGenLevel level ,
97
+ @ NotNull BlockPos startPos ,
98
+ BlockPos .@ NotNull MutableBlockPos mutablePos ,
99
+ BlockState columnState ,
100
+ int height
101
+ ) {
102
102
boolean generated = false ;
103
- pos .set (startPos .atY (level .getHeight (Types .MOTION_BLOCKING_NO_LEAVES , startPos .getX (), startPos .getZ ()) - 1 ).mutable ());
104
- for (int i = 0 ; i < config .additionalHeight ().sample (random ); i ++) {
105
- pos .set (pos .above ());
106
- BlockState state = level .getBlockState (pos );
107
- if (level .getBlockState (pos .below ()).is (Blocks .WATER )) {
108
- break ;
109
- }
110
- if (state .getBlock () instanceof GrowingPlantBodyBlock || state .getBlock () instanceof BushBlock || state .isAir ()) {
111
- level .setBlock (pos , column , 3 );
112
- generated = true ;
103
+ mutablePos .set (startPos .atY (level .getHeight (Types .MOTION_BLOCKING_NO_LEAVES , startPos .getX (), startPos .getZ ()) - 1 ));
104
+ if (level .getBlockState (mutablePos ).getFluidState ().isEmpty ()) {
105
+ for (int i = 0 ; i < height ; i ++) {
106
+ BlockState state = level .getBlockState (mutablePos .move (Direction .UP ));
107
+ if (state .canBeReplaced ()) {
108
+ level .setBlock (mutablePos , columnState , Block .UPDATE_ALL );
109
+ generated = true ;
110
+ }
113
111
}
114
112
}
115
113
return generated ;
0 commit comments