Skip to content

Commit 61e0fdc

Browse files
committed
lets use this nice wrapper class to pass around all the really complex bits
1 parent 3f34d99 commit 61e0fdc

File tree

6 files changed

+214
-131
lines changed

6 files changed

+214
-131
lines changed

src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import net.minecraft.block.state.IBlockState;
99
import net.minecraft.init.Blocks;
1010
import net.minecraft.util.math.BlockPos;
11+
import net.minecraft.util.math.ChunkPos;
1112
import net.minecraft.util.math.Vec3i;
1213
import net.minecraft.world.World;
1314
import net.minecraft.world.biome.Biome;
@@ -217,11 +218,16 @@ protected int getPoint( int lowerBound, int upperBound, int median ) {
217218
}
218219

219220

220-
protected void spawnMunge( World world, BlockPos blockPos, double radius, List<IBlockState> replace, int count,
221-
OreList possible, BiomeLocation biomes, boolean toPositive ) {
221+
protected void spawnMunge( FunctionParameterWrapper params, double radius, int count, boolean toPositive ) {
222222
int rSqr = (int)(radius * radius);
223223
int quantity = count;
224224

225+
OreList possible = params.getOres();
226+
World world = params.getWorld();
227+
BlockPos blockPos = params.getBlockPos();
228+
List<IBlockState> replace = params.getReplacements();
229+
BiomeLocation biomes = params.getBiomes();
230+
225231
for( int dy = (int)(-1 * radius); dy < radius; dy++ ) {
226232
for( int dx = getStart( toPositive, radius); endCheck( toPositive, dx, radius); dx = countItem(dx, toPositive) ) {
227233
for( int dz = getStart( toPositive, radius); endCheck( toPositive, dz, radius); dz = countItem(dz, toPositive) ) {
@@ -253,4 +259,81 @@ protected int getStart ( boolean toPositive, double radius ) {
253259
return ((int) (radius * (toPositive?1:-1)));
254260
}
255261

262+
public class FunctionParameterWrapper {
263+
private World world;
264+
private BlockPos blockPos;
265+
private List<IBlockState> replacements;
266+
private OreList ores;
267+
private BiomeLocation biomes;
268+
private ChunkPos chunkPos;
269+
private IBlockState block;
270+
271+
public FunctionParameterWrapper() {}
272+
273+
public FunctionParameterWrapper( FunctionParameterWrapper other ) {
274+
world = other.getWorld();
275+
blockPos = other.getBlockPos();
276+
replacements = other.getReplacements();
277+
ores = other.getOres();
278+
biomes = other.getBiomes();
279+
chunkPos = other.getChunkPos();
280+
block = other.getBlock();
281+
}
282+
283+
public BiomeLocation getBiomes () {
284+
return biomes;
285+
}
286+
287+
public void setBiomes ( BiomeLocation biomes ) {
288+
this.biomes = biomes;
289+
}
290+
291+
public World getWorld () {
292+
return world;
293+
}
294+
295+
public void setWorld ( World world ) {
296+
this.world = world;
297+
}
298+
299+
public BlockPos getBlockPos () {
300+
return blockPos;
301+
}
302+
303+
public void setBlockPos ( BlockPos blockPos ) {
304+
this.blockPos = blockPos;
305+
}
306+
307+
public List<IBlockState> getReplacements () {
308+
return replacements;
309+
}
310+
311+
public void setReplacements ( List<IBlockState> replacements ) {
312+
this.replacements = replacements;
313+
}
314+
315+
public OreList getOres () {
316+
return ores;
317+
}
318+
319+
public void setOres ( OreList ores ) {
320+
this.ores = ores;
321+
}
322+
323+
public ChunkPos getChunkPos () {
324+
return chunkPos;
325+
}
326+
327+
public void setChunkPos ( ChunkPos chunkPos ) {
328+
this.chunkPos = chunkPos;
329+
}
330+
331+
public IBlockState getBlock () {
332+
return block;
333+
}
334+
335+
public void setBlock ( IBlockState block ) {
336+
this.block = block;
337+
}
338+
}
256339
}

src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -70,74 +70,73 @@ public void generate( World world, IChunkGenerator chunkGenerator, IChunkProvide
7070
int x = blockX + xRand - (maxSpread / 2);
7171
int y = random.nextInt(maxHeight - minHeight) + minHeight;
7272
int z = blockZ + zRand - (maxSpread / 2);
73-
int[] keyParams = new int[] { clusterSize, variance, clusterCount, maxSpread, minHeight, maxHeight};
7473

75-
spawnCluster(ores, new BlockPos(x,y,z), keyParams, random, world, blockReplace, biomes);
74+
FunctionParameterWrapper fp = new FunctionParameterWrapper();
75+
fp.setBlockPos( new BlockPos(x, y, z) );
76+
fp.setWorld( world );
77+
fp.setReplacements( blockReplace );
78+
fp.setBiomes( biomes );
79+
fp.setOres( ores );
80+
81+
spawnCluster( clusterSize, variance, clusterCount, maxSpread, minHeight, maxHeight, fp );
7682
}
7783
tries--;
7884
}
7985
}
8086

81-
private enum parms {
82-
SIZE, VARIANCE, CCOUNT, MAXSPREAD, MINHEIGHT, MAXHEIGHT
83-
}
84-
85-
private void spawnCluster ( OreList ores, BlockPos blockPos, int[] params, Random random, World world, List<IBlockState> blockReplace, BiomeLocation biomes ) {
86-
int size = params[parms.SIZE.ordinal()];
87-
int variance = params[parms.VARIANCE.ordinal()];
88-
int clusterCount = params[parms.CCOUNT.ordinal()];
89-
int maxSpread = params[parms.MAXSPREAD.ordinal()];
90-
87+
private void spawnCluster ( int clusterSize, int variance, int clusterCount, int maxSpread, int minHeight,
88+
int maxHeight, FunctionParameterWrapper params ) {
9189
// spawn a cluster at the center, then a bunch around the outside...
92-
int r = size - variance;
90+
int r = clusterSize - variance;
9391
if(variance > 0){
94-
r += random.nextInt(2 * variance) - variance;
92+
r += this.random.nextInt(2 * variance) - variance;
9593
}
9694

97-
spawnChunk(ores, world, blockPos, r, world.provider.getDimension(), blockReplace, random, biomes);
95+
spawnChunk(params, r);
9896

99-
int count = random.nextInt(clusterCount - 1); // always at least the first, but vary inside that
97+
int count = this.random.nextInt(clusterCount - 1); // always at least the first, but vary inside that
10098
if( variance > 0) {
101-
count += random.nextInt(2 * variance) - variance;
99+
count += this.random.nextInt(2 * variance) - variance;
102100
}
103101

104102
while( count >= 0 ) {
105-
r = size - variance;
103+
r = clusterSize - variance;
106104
if(variance > 0){
107-
r += random.nextInt(2 * variance) - variance;
105+
r += this.random.nextInt(2 * variance) - variance;
108106
}
109107

110108
int radius = maxSpread/2;
111109

112110
int xp = getPoint(-radius, radius, 0);
113-
int yp = getPoint(params[parms.MINHEIGHT.ordinal()], params[parms.MAXHEIGHT.ordinal()], (params[parms.MAXHEIGHT.ordinal()] - params[parms.MINHEIGHT.ordinal()])/2);
111+
int yp = getPoint(minHeight, maxHeight, (maxHeight - minHeight)/2);
114112
int zp = getPoint(-radius, radius, 0);
115113

116-
BlockPos p = blockPos.add( xp, yp, zp );
117-
118-
spawnChunk(ores, world, p, r, world.provider.getDimension(), blockReplace, random, biomes );
114+
BlockPos p = params.getBlockPos().add( xp, yp, zp );
115+
FunctionParameterWrapper np = new FunctionParameterWrapper( params );
116+
np.setBlockPos( p );
117+
spawnChunk(np, r);
119118

120119
count -= r;
121120
}
122121
}
123122

124-
private void spawnChunk ( OreList ores, World world, BlockPos blockPos, int quantity, int dimension, List<IBlockState> blockReplace,
125-
Random prng, BiomeLocation biomes ) {
123+
private void spawnChunk ( FunctionParameterWrapper params, int quantity ) {
126124
int count = quantity;
127125
int lutType = (quantity < 8)?offsetIndexRef_small.length:offsetIndexRef.length;
128126
int[] lut = (quantity < 8)?offsetIndexRef_small:offsetIndexRef;
129127
Vec3i[] offs = new Vec3i[lutType];
130128

131129
System.arraycopy((quantity < 8)?offsets_small:offsets, 0, offs, 0, lutType);
132-
130+
131+
int dimension = params.getWorld().provider.getDimension();
133132
if( quantity < 27 ) {
134133
int[] scrambledLUT = new int[lutType];
135134
System.arraycopy(lut, 0, scrambledLUT, 0, scrambledLUT.length);
136-
scramble(scrambledLUT,prng);
135+
scramble(scrambledLUT,this.random);
137136
int z = 0;
138137
while(count > 0){
139-
IBlockState oreBlock = ores.getRandomOre(prng).getOre();
140-
if( !spawn(oreBlock,world,blockPos.add(offs[scrambledLUT[--count]]),dimension,true,blockReplace, biomes ) ) {
138+
IBlockState oreBlock = params.getOres().getRandomOre(this.random).getOre();
139+
if( !spawn(oreBlock,params.getWorld(),params.getBlockPos().add(offs[scrambledLUT[--count]]),dimension,true, params.getReplacements(), params.getBiomes() ) ) {
141140
count++;
142141
z++;
143142
} else {
@@ -152,15 +151,15 @@ private void spawnChunk ( OreList ores, World world, BlockPos blockPos, int quan
152151
return;
153152
}
154153

155-
doSpawnFill( prng.nextBoolean(), world, blockPos, count, blockReplace, ores, biomes );
154+
doSpawnFill( this.random.nextBoolean(), count, params );
156155
}
157156

158-
private void doSpawnFill ( boolean nextBoolean, World world, BlockPos blockPos, int quantity, List<IBlockState> blockReplace, OreList possibleOres, BiomeLocation biomes ) {
157+
private void doSpawnFill ( boolean nextBoolean, int quantity, FunctionParameterWrapper params ) {
159158
double radius = Math.pow(quantity, 1.0/3.0) * (3.0 / 4.0 / Math.PI) + 2;
160159
if( nextBoolean ) {
161-
spawnMunge( world, blockPos, radius, blockReplace, quantity, possibleOres, biomes, false );
160+
spawnMunge( params, radius, quantity, false );
162161
} else {
163-
spawnMunge( world, blockPos, radius, blockReplace, quantity, possibleOres, biomes, true );
162+
spawnMunge( params, radius, quantity, true );
164163
}
165164
}
166165

src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ public void generate( World world, IChunkGenerator chunkGenerator, IChunkProvide
5656
float freq = params.get(Constants.FormatBits.FREQUENCY).getAsFloat();
5757
int size = params.get(Constants.FormatBits.NODE_SIZE).getAsInt();
5858

59+
FunctionParameterWrapper fp = new FunctionParameterWrapper();
60+
fp.setWorld( world );
61+
fp.setReplacements( replaceBlock );
62+
fp.setBiomes( biomes );
63+
fp.setOres( ores );
64+
5965
if(freq >= 1){
6066
for(int i = 0; i < freq; i++){
6167
int x = blockX + random.nextInt(16);
@@ -68,7 +74,9 @@ public void generate( World world, IChunkGenerator chunkGenerator, IChunkProvide
6874
} else {
6975
r = 0;
7076
}
71-
spawnOre( new BlockPos(x,y,z), ores, size + r, world, random, replaceBlock, biomes);
77+
78+
fp.setBlockPos( new BlockPos(x, y, z) );
79+
spawnOre( fp, size + r );
7280
}
7381
} else if(random.nextFloat() < freq){
7482
int x = blockX + random.nextInt(8);
@@ -80,13 +88,14 @@ public void generate( World world, IChunkGenerator chunkGenerator, IChunkProvide
8088
} else {
8189
r = 0;
8290
}
83-
84-
spawnOre( new BlockPos(x,y,z), ores, size + r, world, random, replaceBlock, biomes);
91+
92+
fp.setBlockPos( new BlockPos(x, y, z) );
93+
spawnOre( fp, size + r );
8594
}
8695

8796
}
8897

89-
private void spawnOre ( BlockPos blockPos, OreList possibleOres, int quantity, World world, Random prng, List<IBlockState> replaceBlock, BiomeLocation biomes ) {
98+
private void spawnOre ( FunctionParameterWrapper params, int quantity ) {
9099
int count = quantity;
91100
int lutType = (quantity < 8)?offsetIndexRef_small.length:offsetIndexRef.length;
92101
int[] lut = (quantity < 8)?offsetIndexRef_small:offsetIndexRef;
@@ -97,23 +106,24 @@ private void spawnOre ( BlockPos blockPos, OreList possibleOres, int quantity, W
97106
if( quantity < 27 ) {
98107
int[] scrambledLUT = new int[lutType];
99108
System.arraycopy(lut, 0, scrambledLUT, 0, scrambledLUT.length);
100-
scramble(scrambledLUT,prng);
109+
scramble(scrambledLUT, this.random);
101110
while(count > 0){
102-
IBlockState oreBlock = possibleOres.getRandomOre(prng).getOre();
103-
spawn(oreBlock,world,blockPos.add(offs[scrambledLUT[--count]]),world.provider.getDimension(),true,replaceBlock, biomes );
111+
IBlockState oreBlock = params.getOres().getRandomOre(this.random).getOre();
112+
spawn(oreBlock, params.getWorld(),params.getBlockPos().add(offs[scrambledLUT[--count]]),
113+
params.getWorld().provider.getDimension(),true, params.getReplacements(), params.getBiomes() );
104114
}
105115
return;
106116
}
107117

108-
doSpawnFill( prng.nextBoolean(), world, blockPos, count, replaceBlock, possibleOres, biomes );
118+
doSpawnFill( this.random.nextBoolean(), count, params );
109119
}
110120

111-
private void doSpawnFill ( boolean nextBoolean, World world, BlockPos blockPos, int quantity, List<IBlockState> replaceBlock, OreList possibleOres, BiomeLocation biomes ) {
121+
private void doSpawnFill ( boolean nextBoolean, int quantity, FunctionParameterWrapper params ) {
112122
double radius = Math.pow(quantity, 1.0/3.0) * (3.0 / 4.0 / Math.PI) + 2;
113123
if( nextBoolean ) {
114-
spawnMunge( world, blockPos, radius, replaceBlock, quantity, possibleOres, biomes, true );
124+
spawnMunge( params, radius, quantity, false );
115125
} else {
116-
spawnMunge( world, blockPos, radius, replaceBlock, quantity, possibleOres, biomes, false );
126+
spawnMunge( params, radius, quantity, true );
117127
}
118128
}
119129

src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,14 @@ public void generate( World world, IChunkGenerator chunkGenerator, IChunkProvide
9494
r += random.nextInt(2 * variance) - variance;
9595
}
9696

97-
if( !spawnCloud(ores, new BlockPos(x,y,z), new int[] { r, maxSpread, minHeight, maxHeight }, random, world, blockReplace, biomes) &&
98-
tryCount < 5 ) {
97+
FunctionParameterWrapper fp = new FunctionParameterWrapper();
98+
fp.setBlockPos( new BlockPos(x, y, z) );
99+
fp.setWorld( world );
100+
fp.setReplacements( blockReplace );
101+
fp.setBiomes( biomes );
102+
fp.setOres( ores );
103+
104+
if( !spawnCloud( r, maxSpread, minHeight, maxHeight, fp) && tryCount < 5 ) {
99105
// make another try!
100106
tries++;
101107
frequency = 100;
@@ -109,16 +115,11 @@ public void generate( World world, IChunkGenerator chunkGenerator, IChunkProvide
109115
}
110116
}
111117

112-
private enum parms {
113-
SIZE, MAXSPREAD, MINHEIGHT, MAXHEIGHT
114-
}
115-
116-
private boolean spawnCloud ( OreList ores, BlockPos blockPos, int[] params, Random random, World world, List<IBlockState> blockReplace, BiomeLocation biomes ) {
118+
private boolean spawnCloud ( int size, int maxSpread, int minHeight, int maxHeight, FunctionParameterWrapper params ) {
117119
// spawn one right at the center here, then generate for the cloud and do the math
118-
int size = params[parms.SIZE.ordinal()];
119-
int maxSpread = params[parms.MAXSPREAD.ordinal()];
120-
121-
if( !spawn(ores.getRandomOre(random).getOre(), world, blockPos, world.provider.getDimension(), true, blockReplace, biomes ) ) {
120+
121+
if( !spawn(params.getOres().getRandomOre(random).getOre(), params.getWorld(), params.getBlockPos(),
122+
params.getWorld().provider.getDimension(), true, params.getReplacements(), params.getBiomes() ) ) {
122123
return false;
123124
}
124125

@@ -128,24 +129,25 @@ private boolean spawnCloud ( OreList ores, BlockPos blockPos, int[] params, Rand
128129

129130
while( count > 0 ) {
130131
int xp = getPoint(0, maxSpread, radius);
131-
int yp = getPoint(params[parms.MINHEIGHT.ordinal()], params[parms.MAXHEIGHT.ordinal()], (params[parms.MAXHEIGHT.ordinal()] - params[parms.MINHEIGHT.ordinal()])/2);
132+
int yp = getPoint(minHeight, maxHeight, (maxHeight - minHeight)/2);
132133
int zp = getPoint(0, maxSpread, radius);
133134

134-
BlockPos p = blockPos.add( xp, yp, zp );
135+
BlockPos p = params.getBlockPos().add( xp, yp, zp );
135136

136137
int z = 0;
137-
while ( z < 5 && !spawn(ores.getRandomOre(random).getOre(), world, p, world.provider.getDimension(), true, blockReplace, biomes ) ) {
138+
while ( z < 5 && !spawn(params.getOres().getRandomOre(random).getOre(), params.getWorld(), p,
139+
params.getWorld().provider.getDimension(), true, params.getReplacements(), params.getBiomes())) {
138140
xp = getPoint(0, maxSpread, radius);
139-
yp = getPoint(params[parms.MINHEIGHT.ordinal()], params[parms.MAXHEIGHT.ordinal()], (params[parms.MAXHEIGHT.ordinal()] - params[parms.MINHEIGHT.ordinal()])/2);
141+
yp = getPoint(minHeight, maxHeight, (maxHeight - minHeight)/2);
140142
zp = getPoint(0, maxSpread, radius);
141143

142-
p = blockPos.add( xp, yp, zp );
144+
p = params.getBlockPos().add( xp, yp, zp );
143145

144146
z++;
145147
}
146148

147149
if( z >= 5 && !alreadySpewed ) {
148-
OreSpawn.LOGGER.info("unable to achieve requested cloud density for cloud centered at %s", blockPos);
150+
OreSpawn.LOGGER.info("unable to achieve requested cloud density for cloud centered at %s", params.getBlockPos());
149151
alreadySpewed = true;
150152
}
151153

0 commit comments

Comments
 (0)