Skip to content

Commit 3f34d99

Browse files
committed
fix up some stuff to be less complex and make the linter happy
1 parent ea198c0 commit 3f34d99

File tree

5 files changed

+91
-150
lines changed

5 files changed

+91
-150
lines changed

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.google.gson.JsonObject;
55
import com.mcmoddev.orespawn.OreSpawn;
66
import com.mcmoddev.orespawn.impl.location.BiomeLocationComposition;
7+
import com.mcmoddev.orespawn.util.OreList;
78
import net.minecraft.block.state.IBlockState;
89
import net.minecraft.init.Blocks;
910
import net.minecraft.util.math.BlockPos;
@@ -215,4 +216,41 @@ protected int getPoint( int lowerBound, int upperBound, int median ) {
215216
return t - median;
216217
}
217218

219+
220+
protected void spawnMunge( World world, BlockPos blockPos, double radius, List<IBlockState> replace, int count,
221+
OreList possible, BiomeLocation biomes, boolean toPositive ) {
222+
int rSqr = (int)(radius * radius);
223+
int quantity = count;
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( getABC(dx, dy, dz) <= rSqr ) {
229+
IBlockState oreBlock = possible.getRandomOre( this.random ).getOre();
230+
spawn( oreBlock, world, blockPos.add(dx,dy,dz), world.provider.getDimension(), true, replace, biomes );
231+
if( --quantity <= 0 ) {
232+
return;
233+
}
234+
}
235+
}
236+
}
237+
}
238+
}
239+
240+
protected int getABC ( int dx, int dy, int dz ) {
241+
return (dx*dx + dy*dy + dz*dz);
242+
}
243+
244+
protected int countItem ( int dx, boolean toPositive ) {
245+
return toPositive?dx + 1:dx - 1;
246+
}
247+
248+
protected boolean endCheck ( boolean toPositive, int dx, double radius ) {
249+
return toPositive ? (dx >= getStart( toPositive, radius )) : (dx < radius);
250+
}
251+
252+
protected int getStart ( boolean toPositive, double radius ) {
253+
return ((int) (radius * (toPositive?1:-1)));
254+
}
255+
218256
}

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
package com.mcmoddev.orespawn.api;
22

33
import java.util.Random;
4-
import java.util.List;
54

65
import com.google.gson.JsonObject;
7-
import com.mcmoddev.orespawn.util.OreList;
86

9-
import net.minecraft.block.state.IBlockState;
10-
import net.minecraft.util.math.ChunkPos;
117
import net.minecraft.world.World;
128
import net.minecraft.world.gen.IChunkGenerator;
139
import net.minecraft.world.chunk.IChunkProvider;

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

Lines changed: 6 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
package com.mcmoddev.orespawn.impl.features;
22

3-
import java.util.Collections;
4-
import java.util.LinkedList;
5-
import java.util.List;
6-
import java.util.Random;
7-
83
import com.google.gson.JsonObject;
94
import com.mcmoddev.orespawn.OreSpawn;
105
import com.mcmoddev.orespawn.api.BiomeLocation;
@@ -13,7 +8,6 @@
138
import com.mcmoddev.orespawn.api.IFeature;
149
import com.mcmoddev.orespawn.data.Constants;
1510
import com.mcmoddev.orespawn.util.OreList;
16-
1711
import net.minecraft.block.state.IBlockState;
1812
import net.minecraft.util.math.BlockPos;
1913
import net.minecraft.util.math.ChunkPos;
@@ -22,6 +16,10 @@
2216
import net.minecraft.world.chunk.IChunkProvider;
2317
import net.minecraft.world.gen.IChunkGenerator;
2418

19+
import java.util.LinkedList;
20+
import java.util.List;
21+
import java.util.Random;
22+
2523
public class ClusterGenerator extends FeatureBase implements IFeature {
2624

2725
private ClusterGenerator ( Random rand ) {
@@ -159,56 +157,14 @@ private void spawnChunk ( OreList ores, World world, BlockPos blockPos, int quan
159157

160158
private void doSpawnFill ( boolean nextBoolean, World world, BlockPos blockPos, int quantity, List<IBlockState> blockReplace, OreList possibleOres, BiomeLocation biomes ) {
161159
double radius = Math.pow(quantity, 1.0/3.0) * (3.0 / 4.0 / Math.PI) + 2;
162-
int rSqr = (int)(radius * radius);
163160
if( nextBoolean ) {
164-
spawnMungeNE( world, blockPos, rSqr, radius, blockReplace, quantity, possibleOres, biomes );
161+
spawnMunge( world, blockPos, radius, blockReplace, quantity, possibleOres, biomes, false );
165162
} else {
166-
spawnMungeSW( world, blockPos, rSqr, radius, blockReplace, quantity, possibleOres, biomes );
167-
}
168-
}
169-
170-
171-
private void spawnMungeSW ( World world, BlockPos blockPos, int rSqr, double radius,
172-
List<IBlockState> blockReplace, int count, OreList possibleOres, BiomeLocation biomes ) {
173-
Random prng = this.random;
174-
int quantity = count;
175-
for(int dy = (int)(-1 * radius); dy < radius; dy++){
176-
for(int dx = (int)(radius); dx >= (int)(-1 * radius); dx--){
177-
for(int dz = (int)(radius); dz >= (int)(-1 * radius); dz--){
178-
if((dx*dx + dy*dy + dz*dz) <= rSqr){
179-
IBlockState oreBlock = possibleOres.getRandomOre(prng).getOre();
180-
spawn(oreBlock,world,blockPos.add(dx,dy,dz),world.provider.getDimension(),true,blockReplace, biomes );
181-
quantity--;
182-
}
183-
if(quantity <= 0) {
184-
return;
185-
}
186-
}
187-
}
163+
spawnMunge( world, blockPos, radius, blockReplace, quantity, possibleOres, biomes, true );
188164
}
189165
}
190166

191167

192-
private void spawnMungeNE ( World world, BlockPos blockPos, int rSqr, double radius,
193-
List<IBlockState> blockReplace, int count, OreList possibleOres, BiomeLocation biomes ) {
194-
Random prng = this.random;
195-
int quantity = count;
196-
for(int dy = (int)(-1 * radius); dy < radius; dy++){
197-
for(int dz = (int)(-1 * radius); dz < radius; dz++){
198-
for(int dx = (int)(-1 * radius); dx < radius; dx++){
199-
if((dx*dx + dy*dy + dz*dz) <= rSqr){
200-
IBlockState oreBlock = possibleOres.getRandomOre(prng).getOre();
201-
spawn(oreBlock,world,blockPos.add(dx,dy,dz),world.provider.getDimension(),true,blockReplace, biomes );
202-
quantity--;
203-
}
204-
if(quantity <= 0) {
205-
return;
206-
}
207-
}
208-
}
209-
}
210-
}
211-
212168
@Override
213169
public void setRandom(Random rand) {
214170
this.random = rand;

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

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -111,53 +111,9 @@ private void spawnOre ( BlockPos blockPos, OreList possibleOres, int quantity, W
111111
private void doSpawnFill ( boolean nextBoolean, World world, BlockPos blockPos, int quantity, List<IBlockState> replaceBlock, OreList possibleOres, BiomeLocation biomes ) {
112112
double radius = Math.pow(quantity, 1.0/3.0) * (3.0 / 4.0 / Math.PI) + 2;
113113
if( nextBoolean ) {
114-
spawnMungeNE( world, blockPos, radius, replaceBlock, quantity, possibleOres, biomes );
114+
spawnMunge( world, blockPos, radius, replaceBlock, quantity, possibleOres, biomes, true );
115115
} else {
116-
spawnMungeSW( world, blockPos, radius, replaceBlock, quantity, possibleOres, biomes );
117-
}
118-
}
119-
120-
121-
private void spawnMungeSW ( World world, BlockPos blockPos, double radius,
122-
List<IBlockState> replaceBlock, int count, OreList possibleOres, BiomeLocation biomes ) {
123-
Random prng = this.random;
124-
int rSqr = (int)(radius * radius);
125-
int quantity = count;
126-
for(int dy = (int)(-1 * radius); dy < radius; dy++){
127-
for(int dx = (int)(radius); dx >= (int)(-1 * radius); dx--){
128-
for(int dz = (int)(radius); dz >= (int)(-1 * radius); dz--){
129-
if((dx*dx + dy*dy + dz*dz) <= rSqr){
130-
IBlockState oreBlock = possibleOres.getRandomOre(prng).getOre();
131-
spawn(oreBlock,world,blockPos.add(dx,dy,dz),world.provider.getDimension(),true,replaceBlock, biomes );
132-
quantity--;
133-
}
134-
if(quantity <= 0) {
135-
return;
136-
}
137-
}
138-
}
139-
}
140-
}
141-
142-
143-
private void spawnMungeNE ( World world, BlockPos blockPos, double radius,
144-
List<IBlockState> replaceBlock, int count, OreList possibleOres, BiomeLocation biomes ) {
145-
Random prng = this.random;
146-
int rSqr = (int)(radius * radius);
147-
int quantity = count;
148-
for(int dy = (int)(-1 * radius); dy < radius; dy++){
149-
for(int dz = (int)(-1 * radius); dz < radius; dz++){
150-
for(int dx = (int)(-1 * radius); dx < radius; dx++){
151-
if((dx*dx + dy*dy + dz*dz) <= rSqr){
152-
IBlockState oreBlock = possibleOres.getRandomOre(prng).getOre();
153-
spawn(oreBlock,world,blockPos.add(dx,dy,dz),world.provider.getDimension(),true,replaceBlock, biomes );
154-
quantity--;
155-
}
156-
if(quantity <= 0) {
157-
return;
158-
}
159-
}
160-
}
116+
spawnMunge( world, blockPos, radius, replaceBlock, quantity, possibleOres, biomes, false );
161117
}
162118
}
163119

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

Lines changed: 45 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)