Skip to content

Commit a9162d9

Browse files
committed
fix some SonarQube/SonarLint issues
1 parent 15f1c1f commit a9162d9

File tree

5 files changed

+65
-67
lines changed

5 files changed

+65
-67
lines changed

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

Lines changed: 51 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,6 @@ public void generate(ChunkPos pos, World world, IChunkGenerator chunkGenerator,
8787

8888
}
8989

90-
private static final Vec3i[] offsets = {
91-
new Vec3i(-1,-1,-1),new Vec3i( 0,-1,-1),new Vec3i( 1,-1,-1),
92-
new Vec3i(-1, 0,-1),new Vec3i( 0, 0,-1),new Vec3i( 1, 0,-1),
93-
new Vec3i(-1, 1,-1),new Vec3i( 0, 1,-1),new Vec3i( 1, 1,-1),
94-
95-
new Vec3i(-1,-1, 0),new Vec3i( 0,-1, 0),new Vec3i( 1,-1, 0),
96-
new Vec3i(-1, 0, 0),new Vec3i( 0, 0, 0),new Vec3i( 1, 0, 0),
97-
new Vec3i(-1, 1, 0),new Vec3i( 0, 1, 0),new Vec3i( 1, 1, 0),
98-
99-
new Vec3i(-1,-1, 1),new Vec3i( 0,-1, 1),new Vec3i( 1,-1, 1),
100-
new Vec3i(-1, 0, 1),new Vec3i( 0, 0, 1),new Vec3i( 1, 0, 1),
101-
new Vec3i(-1, 1, 1),new Vec3i( 0, 1, 1),new Vec3i( 1, 1, 1)
102-
};
103-
10490
private static final Vec3i[] offsets_small = {
10591
new Vec3i( 0, 0, 0),new Vec3i( 1, 0, 0),
10692
new Vec3i( 0, 1, 0),new Vec3i( 1, 1, 0),
@@ -113,62 +99,72 @@ public void generate(ChunkPos pos, World world, IChunkGenerator chunkGenerator,
11399

114100
public static void spawnOre( BlockPos blockPos, IBlockState oreBlock, int quantity, World world, Random prng, IBlockState replaceBlock) {
115101
int count = quantity;
116-
if(quantity <= 8){
117-
int[] scrambledLUT = new int[offsetIndexRef_small.length];
118-
System.arraycopy(offsetIndexRef_small, 0, scrambledLUT, 0, scrambledLUT.length);
102+
int lutType = quantity <= 8?offsetIndexRef_small.length:offsetIndexRef.length;
103+
int[] lut = quantity <= 8?offsetIndexRef_small:offsetIndexRef;
104+
105+
if( quantity < 27 ) {
106+
int[] scrambledLUT = new int[lutType];
107+
System.arraycopy(lut, 0, scrambledLUT, 0, scrambledLUT.length);
119108
scramble(scrambledLUT,prng);
120109
while(count > 0){
121110
spawn(oreBlock,world,blockPos.add(offsets_small[scrambledLUT[--count]]),world.provider.getDimension(),true,replaceBlock);
122111
}
123112
return;
124113
}
125-
if(quantity < 27){
126-
int[] scrambledLUT = new int[offsetIndexRef.length];
127-
System.arraycopy(offsetIndexRef, 0, scrambledLUT, 0, scrambledLUT.length);
128-
scramble(scrambledLUT,prng);
129-
while(count > 0){
130-
spawn(oreBlock,world,blockPos.add(offsets[scrambledLUT[--count]]),world.provider.getDimension(),true,replaceBlock);
131-
}
132-
return;
133-
}
114+
115+
doSpawnFill( prng.nextBoolean(), world, blockPos, count, replaceBlock, oreBlock );
116+
117+
return;
118+
}
119+
120+
private static void doSpawnFill(boolean nextBoolean, World world, BlockPos blockPos, int quantity, IBlockState replaceBlock, IBlockState oreBlock ) {
121+
int count = quantity;
134122
double radius = Math.pow(quantity, 1.0/3.0) * (3.0 / 4.0 / Math.PI) + 2;
135123
int rSqr = (int)(radius * radius);
136-
fill:{
137-
if(prng.nextBoolean()){ // switch-up the direction of fill to reduce predictability
138-
// fill from north-east
139-
for(int dy = (int)(-1 * radius); dy < radius; dy++){
140-
for(int dz = (int)(-1 * radius); dz < radius; dz++){
141-
for(int dx = (int)(-1 * radius); dx < radius; dx++){
142-
if((dx*dx + dy*dy + dz*dz) <= rSqr){
143-
spawn(oreBlock,world,blockPos.add(dx,dy,dz),world.provider.getDimension(),true,replaceBlock);
144-
count--;
145-
}
146-
if(count <= 0) {
147-
break fill;
148-
}
149-
}
124+
if( nextBoolean ) {
125+
spawnMungeNE( world, blockPos, rSqr, radius, replaceBlock, count, oreBlock );
126+
} else {
127+
spawnMungeSW( world, blockPos, rSqr, radius, replaceBlock, count, oreBlock );
128+
}
129+
}
130+
131+
132+
private static void spawnMungeSW(World world, BlockPos blockPos, int rSqr, double radius,
133+
IBlockState replaceBlock, int count, IBlockState oreBlock) {
134+
int quantity = count;
135+
for(int dy = (int)(-1 * radius); dy < radius; dy++){
136+
for(int dx = (int)(radius); dx >= (int)(-1 * radius); dx--){
137+
for(int dz = (int)(radius); dz >= (int)(-1 * radius); dz--){
138+
if((dx*dx + dy*dy + dz*dz) <= rSqr){
139+
spawn(oreBlock,world,blockPos.add(dx,dy,dz),world.provider.getDimension(),true,replaceBlock);
140+
quantity--;
150141
}
151-
}
152-
} else {
153-
// fill from south-west
154-
for(int dy = (int)(-1 * radius); dy < radius; dy++){
155-
for(int dx = (int)(radius); dx >= (int)(-1 * radius); dx--){
156-
for(int dz = (int)(radius); dz >= (int)(-1 * radius); dz--){
157-
if((dx*dx + dy*dy + dz*dz) <= rSqr){
158-
spawn(oreBlock,world,blockPos.add(dx,dy,dz),world.provider.getDimension(),true,replaceBlock);
159-
count--;
160-
}
161-
if(count <= 0) {
162-
break fill;
163-
}
164-
}
142+
if(quantity <= 0) {
143+
return;
165144
}
166145
}
167146
}
168147
}
169-
return;
170148
}
171149

150+
151+
private static void spawnMungeNE(World world, BlockPos blockPos, int rSqr, double radius, IBlockState replaceBlock, int count, IBlockState oreBlock) {
152+
int quantity = count;
153+
for(int dy = (int)(-1 * radius); dy < radius; dy++){
154+
for(int dz = (int)(-1 * radius); dz < radius; dz++){
155+
for(int dx = (int)(-1 * radius); dx < radius; dx++){
156+
if((dx*dx + dy*dy + dz*dz) <= rSqr){
157+
spawn(oreBlock,world,blockPos.add(dx,dy,dz),world.provider.getDimension(),true,replaceBlock);
158+
quantity--;
159+
}
160+
if(quantity <= 0) {
161+
return;
162+
}
163+
}
164+
}
165+
}
166+
}
167+
172168
private static void scramble(int[] target, Random prng) {
173169
for(int i = target.length - 1; i > 0; i--){
174170
int n = prng.nextInt(i);

src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilderImpl.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ public SpawnBuilder newSpawnBuilder( @Nullable String name) {
3030

3131
@Override
3232
public DimensionBuilder create(SpawnBuilder... addedSpawns) {
33-
/* if( !spawns.containsKey(UNNAMED) ) {
34-
spawns.put(UNNAMED, new ArrayList<>() );
35-
}
36-
spawns.get(UNNAMED).addAll(Arrays.asList(addedSpawns).stream().collect(Collectors.<SpawnBuilder>toList()));
37-
*/ return this;
33+
return this;
3834
}
3935

4036
@Override

src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilderImpl.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@ public SpawnBuilderImpl() {
3131

3232
@Override
3333
public FeatureBuilder newFeatureBuilder(@Nullable String featureName) {
34+
String featName;
3435
this.featureGen = new FeatureBuilderImpl();
35-
if( OreSpawn.FEATURES.getFeature(featureName) == null ) {
36-
this.featureGen.setGenerator("default");
37-
return this.featureGen;
36+
if( OreSpawn.FEATURES.getFeature(featureName) == null || featureName == null) {
37+
featName = "default";
38+
} else {
39+
featName = featureName;
3840
}
3941

40-
this.featureGen.setGenerator(featureName);
42+
this.featureGen.setGenerator(featName);
4143
return this.featureGen;
4244
}
4345

src/main/java/com/mcmoddev/orespawn/util/StateUtil.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44
import net.minecraft.block.state.IBlockState;
55

66
public class StateUtil {
7+
private StateUtil() {
8+
throw new InstantiationError("This class cannot be instantiated!");
9+
}
10+
711
public static String serializeState(IBlockState state) {
812
String string = state.toString();
9-
string = string.substring(string.indexOf("[") + 1, string.length() - (string.endsWith("]") ? 1 : 0));
13+
string = string.substring(string.indexOf('[') + 1, string.length() - (string.endsWith("]") ? 1 : 0));
1014
if (string.equals(state.getBlock().getRegistryName().toString())) {
1115
string = "normal";
1216
}
@@ -16,7 +20,7 @@ public static String serializeState(IBlockState state) {
1620
public static IBlockState deserializeState(Block block, String state) {
1721
for (IBlockState validState : block.getBlockState().getValidStates()) {
1822
String string = validState.toString();
19-
string = string.substring(string.indexOf("[") + 1, string.length() - (string.endsWith("]") ? 1 : 0));
23+
string = string.substring(string.indexOf('[') + 1, string.length() - (string.endsWith("]") ? 1 : 0));
2024
if (string.equals(block.getRegistryName().toString())) {
2125
string = "";
2226
}

src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void generate(Random random, int chunkX, int chunkZ, World world, IChunkG
7171

7272
for( SpawnBuilder sE : entries ) {
7373
Biome biome = world.getBiomeProvider().getBiome(new BlockPos(chunkX*16, 64,chunkZ*16));
74-
if( sE.getBiomes().matches(biome) || sE.getBiomes().getBiomes().size() == 0 ) {
74+
if( sE.getBiomes().matches(biome) || sE.getBiomes().getBiomes().isEmpty() ) {
7575
IFeature currentFeatureGen = sE.getFeatureGen().getGenerator();
7676
IBlockState replacement = sE.getReplacementBlocks().get(0);
7777
if( replacement == null ) {

0 commit comments

Comments
 (0)