@@ -64,7 +64,7 @@ public void generate( World world, IChunkGenerator chunkGenerator, IChunkProvide
6464 int sc ;
6565 HeightRange hr = new HeightRange (minHeight , maxHeight );
6666 BlockPos spot = chooseSpot (chunkX , chunkZ , hr );
67- sc = spawnAtSpot ( spot , thisNode , hr , world , blockReplace , ores , pos , biomes );
67+ sc = spawnAtSpot ( spot , new Object [] { thisNode , hr } , world , blockReplace , ores , pos , biomes );
6868
6969 // bit of feedback - if we underproduce or overproduce a node, the next one gets a correction
7070 if ( sc != thisNode && sc != 0 ) {
@@ -83,15 +83,19 @@ public void generate( World world, IChunkGenerator chunkGenerator, IChunkProvide
8383 }
8484 }
8585
86- private int spawnAtSpot ( BlockPos spot , int nodeSize , HeightRange heightRange , World world ,
86+ private int spawnAtSpot ( BlockPos spot , Object [] oParams , World world ,
8787 List <IBlockState > blockReplace , OreList ores , ChunkPos pos , BiomeLocation biomes ) {
8888 int spawned = 0 ;
8989 int c ;
9090
91+ int nodeSize = (int )oParams [0 ];
92+ HeightRange heightRange = (HeightRange )oParams [1 ];
93+
9194 BlockPos act = spot ;
9295 int counter = nodeSize ;
96+
9397 while ( counter > 0 && spawned < nodeSize ) {
94- c = spawnOreNode ( act , nodeSize , heightRange , pos , blockReplace , ores , world , biomes );
98+ c = spawnOreNode ( act , oParams , pos , blockReplace , ores , world , biomes );
9599 if ( c == 0 ) {
96100 OreSpawn .LOGGER .debug ("Unable to place block at %s (chunk %s)" , spot , pos );
97101 act = chooseSpot ( Math .floorDiv (spot .getX (),16 ), Math .floorDiv (spot .getZ (), 16 ), heightRange );
@@ -102,8 +106,11 @@ private int spawnAtSpot ( BlockPos spot, int nodeSize, HeightRange heightRange,
102106 return spawned ;
103107 }
104108
105- private int spawnOreNode ( BlockPos spot , int nodeSize , HeightRange heightRange , ChunkPos pos ,
109+ private int spawnOreNode ( BlockPos spot , Object [] oParams , ChunkPos pos ,
106110 List <IBlockState > blockReplace , OreList ores , World world , BiomeLocation biomes ) {
111+ int nodeSize = (int )oParams [0 ];
112+ HeightRange heightRange = (HeightRange )oParams [1 ];
113+
107114 int count = nodeSize ;
108115 int lutType = (nodeSize < 8 )?offsetIndexRef_small .length :offsetIndexRef .length ;
109116 int [] lut = (nodeSize < 8 )?offsetIndexRef_small :offsetIndexRef ;
@@ -129,7 +136,7 @@ private int spawnOreNode ( BlockPos spot, int nodeSize, HeightRange heightRange,
129136 return nc ;
130137 }
131138
132- return spawnFill ( spot , ores , nodeSize , blockReplace , heightRange , pos , world , biomes );
139+ return spawnFill ( new Object [] { spot , ores , nodeSize , heightRange , pos }, blockReplace , world , biomes );
133140 }
134141
135142 private BlockPos fixMungeOffset (Vec3i offset , BlockPos spot , HeightRange heightRange , ChunkPos pos ) {
@@ -189,75 +196,63 @@ private int rescaleOffset(final int offsetIn, final int centerIn, final int mini
189196 return workingPoint - centerIn ;
190197 }
191198
192- private int spawnFill ( BlockPos spot , OreList ores , int nodeSize , List <IBlockState > blockReplace , HeightRange heightRange ,
193- ChunkPos pos , World world , BiomeLocation biomes ) {
199+ private int spawnFill ( Object [] oParams , List <IBlockState > blockReplace , World world , BiomeLocation biomes ) {
200+ BlockPos spot = (BlockPos )oParams [0 ];
201+ OreList ores = (OreList )oParams [1 ];
202+ int nodeSize = (int )oParams [2 ];
203+ HeightRange heightRange = (HeightRange )oParams [3 ];
204+ ChunkPos pos = (ChunkPos )oParams [4 ];
205+
194206 double radius = Math .pow (nodeSize , 1.0 /3.0 ) * (3.0 / 4.0 / Math .PI ) + 2 ;
195207 int rSqr = (int )Math .ceil (radius * radius );
196208 if ( this .random .nextBoolean () ) {
197- return spawnMungeNE ( world , new Object [] { spot , pos , heightRange }, new int [] { rSqr , nodeSize }, radius , blockReplace , ores , biomes );
209+ return spawnPrecise ( world , new Object [] { spot , pos , heightRange , false }, new int [] { rSqr , nodeSize }, radius , blockReplace , ores , biomes );
198210 } else {
199- return spawnMungeSW ( world , new Object [] { spot , pos , heightRange }, new int [] { rSqr , nodeSize }, radius , blockReplace , ores , biomes );
211+ return spawnPrecise ( world , new Object [] { spot , pos , heightRange , true }, new int [] { rSqr , nodeSize }, radius , blockReplace , ores , biomes );
200212 }
201213 }
202214
203- private int spawnMungeSW ( World world , Object [] oParams , int [] iParams , double radius , List <IBlockState > blockReplace , OreList ores , BiomeLocation biomes ) {
204- int quantity = iParams [1 ];
215+ private int spawnPrecise ( World world , Object [] oParams , int [] iParams , double radius , List <IBlockState > blockReplace , OreList ores , BiomeLocation biomes ) {
205216 int rSqr = iParams [0 ];
217+ int quantity = iParams [1 ];
206218 int nc = 0 ;
207-
219+
208220 BlockPos spot = (BlockPos )oParams [0 ];
209221 ChunkPos pos = (ChunkPos )oParams [1 ];
210222 HeightRange heightRange = (HeightRange )oParams [2 ];
211-
212- for (int dy = (int )(-1 * radius ); dy < radius ; dy ++){
213- for (int dx = (int )(radius ); dx >= (int )(-1 * radius ); dx --){
214- for (int dz = (int )(radius ); dz >= (int )(-1 * radius ); dz --){
215- int total = dx *dx + dy *dy + dz *dz ;
216- if (total <= rSqr ){
217- BlockPos p = fixMungeOffset (new Vec3i (dx , dy , dz ), spot , heightRange , pos );
218- nc += doMungeSpawn (ores ,world , p , blockReplace , biomes );
223+ boolean toPositive = (boolean )oParams [3 ];
224+
225+ for ( int dy = (int )(-1 * radius ); dy < radius ; dy ++ ) {
226+ for ( int dx = getStart ( toPositive , radius ); endCheck ( toPositive , dx , radius ); dx = countItem (dx , toPositive ) ) {
227+ for ( int dz = getStart ( toPositive , radius ); endCheck ( toPositive , dz , radius ); dz = countItem (dz , toPositive ) ) {
228+ if ( doCheckSpawn ( new int [] { dx , dy , dz , rSqr }, ores , world , blockReplace , new Object [] { spot , pos , heightRange , biomes } ) >= 0 ) {
229+ nc ++;
219230 quantity --;
220- }
221-
222- if (quantity <= 0 || nc >= iParams [1 ]) {
223- return nc ;
231+
232+ if ( nc >= iParams [1 ] || quantity <= 0 ) return nc ;
224233 }
225234 }
226235 }
227236 }
228237 return nc ;
229238 }
230-
231- private int doMungeSpawn (OreList ores , World world , BlockPos spot , List <IBlockState > blockReplace , BiomeLocation biomes ) {
232- return spawn (ores .getRandomOre (this .random ).getOre (),world ,spot ,world .provider .getDimension (),true ,blockReplace , biomes )?1 :0 ;
233- }
234239
235- private int spawnMungeNE ( World world , Object [] oParams , int [] iParams , double radius , List <IBlockState > blockReplace , OreList ores , BiomeLocation biomes ) {
236- int rSqr = iParams [0 ];
237- int quantity = iParams [1 ];
238- int nc = 0 ;
239-
240+ private int doCheckSpawn ( int [] iParams , OreList ores , World world , List <IBlockState > blockReplace , Object [] oParams ) {
241+ int dx = iParams [0 ];
242+ int dy = iParams [1 ];
243+ int dz = iParams [ 2 ] ;
244+ int rSqr = iParams [ 3 ];
240245 BlockPos spot = (BlockPos )oParams [0 ];
241246 ChunkPos pos = (ChunkPos )oParams [1 ];
242247 HeightRange heightRange = (HeightRange )oParams [2 ];
243-
244- for (int dy = (int )(-1 * radius ); dy < radius ; dy ++){
245- for (int dz = (int )(-1 * radius ); dz < radius ; dz ++){
246- for (int dx = (int )(-1 * radius ); dx < radius ; dx ++){
247- int total = dx *dx + dy *dy + dz *dz ;
248- if (total <= rSqr ){
249- BlockPos p = fixMungeOffset (new Vec3i (dx , dy , dz ), spot , heightRange , pos );
250- nc += doMungeSpawn (ores ,world , p , blockReplace , biomes );
251- quantity --;
252- }
253-
254- if (quantity <= 0 || nc >= iParams [1 ]) {
255- return nc ;
256- }
257- }
258- }
248+ BiomeLocation biomes = (BiomeLocation )oParams [3 ];
249+
250+ if ( getABC (dx , dy , dz ) <= rSqr ) {
251+ BlockPos p = fixMungeOffset ( new Vec3i ( dx , dy , dz ), spot , heightRange , pos );
252+ IBlockState bl = ores .getRandomOre ( this .random ).getOre ();
253+ return spawn ( bl , world , p , world .provider .getDimension (), true , blockReplace , biomes ) ? 1 : 0 ;
259254 }
260- return nc ;
255+ return - 1 ;
261256 }
262257
263258 private int getPoint ( int lowerBound , int upperBound ) {
0 commit comments