Skip to content

Commit 44cf528

Browse files
committed
more linter cleanups - we're slowly getting the numbers of stuff reported in SonarLint down
1 parent 6ed46d0 commit 44cf528

File tree

3 files changed

+25
-38
lines changed

3 files changed

+25
-38
lines changed

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

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,25 @@
11
package com.mcmoddev.orespawn.api;
22

3-
import java.util.Collections;
4-
import java.util.Deque;
5-
import java.util.HashMap;
6-
import java.util.LinkedList;
7-
import java.util.List;
8-
import java.util.Map;
9-
import java.util.Random;
10-
import java.util.Map.Entry;
11-
123
import com.google.common.collect.ImmutableSet;
134
import com.google.gson.JsonObject;
145
import com.mcmoddev.orespawn.OreSpawn;
15-
166
import com.mcmoddev.orespawn.impl.location.BiomeLocationComposition;
177
import net.minecraft.block.state.IBlockState;
188
import net.minecraft.init.Blocks;
199
import net.minecraft.util.math.BlockPos;
2010
import net.minecraft.util.math.Vec3i;
2111
import net.minecraft.world.World;
2212
import net.minecraft.world.biome.Biome;
23-
import net.minecraftforge.fml.common.registry.ForgeRegistries;
13+
14+
import java.util.*;
15+
import java.util.Map.Entry;
2416

2517
public class FeatureBase {
2618
private static final int MAX_CACHE_SIZE = 2048;
2719
/** overflow cache so that ores that spawn at edge of chunk can
2820
* appear in the neighboring chunk without triggering a chunk-load */
29-
protected static final Map<Vec3i,Map<BlockPos,IBlockState>> overflowCache = new HashMap<>(MAX_CACHE_SIZE);
30-
protected static final Deque<Vec3i> cacheOrder = new LinkedList<>();
21+
private static final Map<Vec3i,Map<BlockPos,IBlockState>> overflowCache = new HashMap<>(MAX_CACHE_SIZE);
22+
private static final Deque<Vec3i> cacheOrder = new LinkedList<>();
3123
protected Random random;
3224

3325
public FeatureBase( Random rand ) {
@@ -44,7 +36,7 @@ private boolean fullMatch( ImmutableSet<BiomeLocation> locs, Biome biome ) {
4436
return false;
4537
}
4638

47-
protected boolean biomeMatch( Biome chunkBiome, BiomeLocation inp ) {
39+
private boolean biomeMatch ( Biome chunkBiome, BiomeLocation inp ) {
4840
if( inp.getBiomes().isEmpty () ) {
4941
return false;
5042
}
@@ -69,7 +61,7 @@ protected void runCache(int chunkX, int chunkZ, World world, List<IBlockState> b
6961

7062
if( !cache.isEmpty() ) { // if there is something in the cache, try to spawn it
7163
for(Entry<BlockPos,IBlockState> ent : cache.entrySet()){
72-
spawnNoCheck( cache.get(ent.getKey()), world, ent.getKey(), world.provider.getDimension(), false, blockReplace );
64+
spawnNoCheck( cache.get(ent.getKey()), world, ent.getKey(), world.provider.getDimension(), blockReplace );
7365
}
7466
}
7567
}
@@ -116,27 +108,28 @@ private boolean spawnOrCache ( World world, BlockPos coord, List<IBlockState> bl
116108
cacheOverflowBlock(oreBlock,coord,dimension);
117109
return true;
118110
}
111+
119112
return false;
120113
}
121114

122-
protected boolean spawnNoCheck( IBlockState oreBlock, World world, BlockPos coord, int dimension, boolean cacheOverflow,
123-
List<IBlockState> blockReplace ) {
115+
private void spawnNoCheck ( IBlockState oreBlock, World world, BlockPos coord, int dimension,
116+
List<IBlockState> blockReplace ) {
124117
if( oreBlock == null ) {
125118
OreSpawn.LOGGER.fatal("FeatureBase.spawn() called with a null ore!");
126-
return false;
119+
return;
127120
}
128121

129122
BlockPos np = mungeFixYcoord(coord);
130123

131124
if( coord.getY() >= world.getHeight()) {
132125
OreSpawn.LOGGER.warn("Asked to spawn %s above build limit at %s", oreBlock, coord);
133-
return false;
126+
return;
134127
}
135128

136-
return spawnOrCache(world,np,blockReplace,oreBlock,cacheOverflow,dimension);
129+
spawnOrCache(world,np,blockReplace,oreBlock,false,dimension);
137130
}
138131

139-
protected void cacheOverflowBlock(IBlockState bs, BlockPos coord, int dimension){
132+
private void cacheOverflowBlock ( IBlockState bs, BlockPos coord, int dimension ){
140133
Vec3i chunkCoord = new Vec3i(coord.getX() >> 4, coord.getY() >> 4, dimension);
141134
if(overflowCache.containsKey(chunkCoord)){
142135
cacheOrder.addLast(chunkCoord);
@@ -145,20 +138,20 @@ protected void cacheOverflowBlock(IBlockState bs, BlockPos coord, int dimension)
145138
overflowCache.get(drop).clear();
146139
overflowCache.remove(drop);
147140
}
148-
overflowCache.put(chunkCoord, new HashMap<BlockPos,IBlockState>());
141+
overflowCache.put(chunkCoord, new HashMap<>());
149142
}
150143
Map<BlockPos,IBlockState> cache = overflowCache.getOrDefault(chunkCoord, new HashMap<>());
151144
cache.put(coord, bs);
152145
}
153146

154-
protected Map<BlockPos,IBlockState> retrieveCache(Vec3i chunkCoord ){
147+
private Map<BlockPos,IBlockState> retrieveCache ( Vec3i chunkCoord ){
155148
if(overflowCache.containsKey(chunkCoord)){
156149
Map<BlockPos,IBlockState> cache =overflowCache.get(chunkCoord);
157150
cacheOrder.remove(chunkCoord);
158151
overflowCache.remove(chunkCoord);
159152
return cache;
160153
} else {
161-
return Collections.<BlockPos,IBlockState>emptyMap();
154+
return Collections.emptyMap();
162155
}
163156
}
164157

@@ -171,12 +164,8 @@ protected void scramble(int[] target, Random prng) {
171164
}
172165
}
173166

174-
protected boolean canReplace(IBlockState target, List<IBlockState> blockToReplace) {
175-
if( target.getBlock().equals(Blocks.AIR) ) {
176-
return false;
177-
} else {
178-
return blockToReplace.contains(target);
179-
}
167+
private boolean canReplace ( IBlockState target, List<IBlockState> blockToReplace ) {
168+
return !target.getBlock().equals( Blocks.AIR ) && blockToReplace.contains( target );
180169
}
181170

182171
protected static final Vec3i[] offsets_small = {
@@ -211,7 +200,7 @@ protected static void mergeDefaults(JsonObject parameters, JsonObject defaultPar
211200
});
212201
}
213202

214-
protected double triangularDistribution(double a, double b, double c) {
203+
private double triangularDistribution ( double a, double b, double c ) {
215204
double base = (c - a) / (b - a);
216205
double rand = this.random.nextDouble();
217206
if (rand < base) {

src/main/java/com/mcmoddev/orespawn/json/os3/readers/OS3V1Reader.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,15 @@ public JsonObject parseJson(JsonObject entries, String fileName) {
4242
JsonObject biomeObj = new JsonObject();
4343
biomeObj.add(biomes.size()<1?ConfigNames.BiomeStuff.BLACKLIST:ConfigNames.BiomeStuff.WHITELIST, biomes);
4444
oreOut.add("biomes", biomeObj);
45+
oreOut.add("biomes", new JsonObject());
46+
oreOut.addProperty("name", getBlockName(ore));
47+
break;
4548
case "1":
4649
oreOut.add("biomes", new JsonObject());
4750
oreOut.addProperty("name", getBlockName(ore));
4851
break;
52+
default:
53+
break;
4954
}
5055
dimData.add(oreOut);
5156
}

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,18 @@
55

66
import com.google.common.collect.ImmutableList;
77
import com.mcmoddev.orespawn.OreSpawn;
8-
import com.mcmoddev.orespawn.api.BiomeLocation;
98
import com.mcmoddev.orespawn.api.IFeature;
109
import com.mcmoddev.orespawn.api.os3.SpawnBuilder;
1110
import com.mcmoddev.orespawn.data.Config;
1211
import com.mcmoddev.orespawn.data.Constants;
1312
import com.mcmoddev.orespawn.data.ReplacementsRegistry;
1413

15-
import com.mcmoddev.orespawn.impl.location.BiomeLocationComposition;
1614
import net.minecraft.block.Block;
1715
import net.minecraft.block.state.IBlockState;
1816
import net.minecraft.init.Blocks;
1917
import net.minecraft.item.ItemBlock;
20-
import net.minecraft.util.math.BlockPos;
2118
import net.minecraft.util.math.ChunkPos;
2219
import net.minecraft.world.World;
23-
import net.minecraft.world.biome.Biome;
2420
import net.minecraft.world.gen.IChunkGenerator;
2521
import net.minecraft.world.chunk.IChunkProvider;
2622
import net.minecraftforge.fml.common.IWorldGenerator;
@@ -60,9 +56,6 @@ public void generate(Random random, int chunkX, int chunkZ, World world, IChunkG
6056
entries.addAll(this.dimensions.get(OreSpawn.API.dimensionWildcard()));
6157
}
6258

63-
BlockPos genLocBase = new BlockPos( chunkX*16, 64, chunkZ*16);
64-
Biome chunkBiome = world.getBiome ( genLocBase );
65-
6659
entries.stream()
6760
.filter( SpawnBuilder::enabled )
6861
.filter( sb -> !Config.getBoolean ( Constants.RETROGEN_KEY ) || (sb.retrogen () || Config.getBoolean ( Constants.FORCE_RETROGEN_KEY )) )

0 commit comments

Comments
 (0)