Skip to content

Commit f2673cd

Browse files
committed
lots of cleanups and an attempt at getting the biome whitelist/blacklist code functional
1 parent 5833960 commit f2673cd

22 files changed

+204
-159
lines changed

src/main/java/com/mcmoddev/orespawn/EventHandlers.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ public class EventHandlers {
3939
private Deque<ChunkPos> chunks;
4040
private Deque<ChunkPos> retroChunks;
4141

42-
public EventHandlers() {
42+
EventHandlers () {
4343
chunks = new ConcurrentLinkedDeque<>();
4444
retroChunks = new ConcurrentLinkedDeque<>();
4545
}
4646

47-
List<EventType> vanillaEvents = Arrays.asList(EventType.ANDESITE, EventType.COAL, EventType.DIAMOND, EventType.DIORITE, EventType.DIRT,
47+
private List<EventType> vanillaEvents = Arrays.asList(EventType.ANDESITE, EventType.COAL, EventType.DIAMOND, EventType.DIORITE, EventType.DIRT,
4848
EventType.EMERALD, EventType.GOLD, EventType.GRANITE, EventType.GRAVEL, EventType.IRON, EventType.LAPIS, EventType.REDSTONE,
4949
EventType.QUARTZ, EventType.SILVERFISH);
5050

@@ -140,8 +140,8 @@ private boolean compFeatures(NBTTagList tagList, int dim) {
140140
.collect(Collectors.toList()));
141141
}
142142

143-
List<SpawnBuilder> spc = new LinkedList<>();
144-
spawns.stream().map( DimensionBuilder::getAllSpawns ).forEach( spc::addAll );
143+
// List<SpawnBuilder> spc = new LinkedList<>();
144+
// spawns.stream().map( DimensionBuilder::getAllSpawns ).forEach( spc::addAll );
145145

146146
List<FeatureBuilder> featureList = new LinkedList<>();
147147

src/main/java/com/mcmoddev/orespawn/OreSpawn.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ public class OreSpawn {
5151
public static final Logger LOGGER = LogManager.getFormatterLogger(Constants.MODID);
5252
public static final OS3API API = new OS3APIImpl();
5353
public static final OS3Writer writer = new OS3Writer();
54-
public static final EventHandlers eventHandlers = new EventHandlers();
54+
static final EventHandlers eventHandlers = new EventHandlers();
5555
public static final FeatureRegistry FEATURES = new FeatureRegistry();
5656
protected static final Map<Integer, List<SpawnBuilder>> spawns = new HashMap<>();
5757

58-
public static final FlatBedrock flatBedrock= new FlatBedrock();
58+
static final FlatBedrock flatBedrock= new FlatBedrock();
5959

6060
public static Map<Integer, List<SpawnBuilder>> getSpawns() {
6161
return spawns;

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@
1212
import com.google.gson.JsonObject;
1313
import com.mcmoddev.orespawn.OreSpawn;
1414

15+
import com.mcmoddev.orespawn.impl.location.BiomeLocationComposition;
16+
import com.mcmoddev.orespawn.impl.location.BiomeLocationSingle;
1517
import net.minecraft.block.state.IBlockState;
1618
import net.minecraft.init.Blocks;
1719
import net.minecraft.util.math.BlockPos;
1820
import net.minecraft.util.math.Vec3i;
1921
import net.minecraft.world.World;
22+
import net.minecraft.world.biome.Biome;
23+
import net.minecraftforge.fml.common.registry.ForgeRegistries;
2024

2125
public class FeatureBase {
2226
private static final int MAX_CACHE_SIZE = 2048;
@@ -29,7 +33,28 @@ public class FeatureBase {
2933
public FeatureBase( Random rand ) {
3034
this.random = rand;
3135
}
32-
36+
37+
protected boolean biomeMatch( Biome chunkBiome, BiomeLocation inp ) {
38+
if( inp.getBiomes().isEmpty () ) {
39+
return false;
40+
}
41+
42+
if( inp instanceof BiomeLocationComposition ) {
43+
BiomeLocationComposition loc = (BiomeLocationComposition) inp;
44+
BiomeLocationSingle it = new BiomeLocationSingle ( chunkBiome );
45+
boolean exclMatch = loc.getExclusions().contains(it);
46+
boolean inclMatch = loc.getInclusions().contains(it);
47+
48+
if ( (loc.getInclusions().isEmpty() || inclMatch) && !exclMatch ) {
49+
return false;
50+
}
51+
} else if( inp.matches( chunkBiome ) ) {
52+
return false;
53+
}
54+
55+
return true;
56+
}
57+
3358
protected void runCache(int chunkX, int chunkZ, World world, List<IBlockState> blockReplace) {
3459
Vec3i chunkCoord = new Vec3i(chunkX, chunkZ, world.provider.getDimension());
3560
Map<BlockPos,IBlockState> cache = retrieveCache(chunkCoord);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414

1515
public interface IFeature {
1616
void generate(ChunkPos pos, World world, IChunkGenerator chunkGenerator,
17-
IChunkProvider chunkProvider, JsonObject parameters, OreList ores, List<IBlockState> blockReplace );
17+
IChunkProvider chunkProvider, JsonObject parameters, OreList ores, List<IBlockState> blockReplace,
18+
BiomeLocation biomes );
1819

1920
void setRandom(Random rand);
2021

src/main/java/com/mcmoddev/orespawn/data/Constants.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ private V2() {}
8585
}
8686
public final class BiomeStuff {
8787
private BiomeStuff() {}
88-
public static final String WHITELIST = "inclusions";
89-
public static final String BLACKLIST = "exclusions";
88+
public static final String WHITELIST = "includes";
89+
public static final String BLACKLIST = "excludes";
9090
}
9191
public final class DefaultFeatureProperties {
9292
private DefaultFeatureProperties() {}

src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public void addFeature(String name, String className) {
101101
private IFeature getInstance(String className) {
102102
Class<?> featureClazz;
103103
Constructor<?> featureCons;
104-
IFeature feature = null;
104+
IFeature feature;
105105
try {
106106
featureClazz = Class.forName(className);
107107
featureCons = featureClazz.getConstructor();
@@ -117,7 +117,7 @@ private IFeature getInstance(String className) {
117117

118118
public void loadFeaturesFile(File file) {
119119
JsonParser parser = new JsonParser();
120-
String rawJson = "[]";
120+
String rawJson;
121121
JsonArray elements;
122122
try {
123123
rawJson = FileUtils.readFileToString(file, Charset.defaultCharset());
@@ -156,7 +156,6 @@ public void writeFeatures(File file) {
156156
CrashReport report = CrashReport.makeCrashReport(e, "Failed writing config " + file.getName());
157157
report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION);
158158
OreSpawn.LOGGER.info(report.getCompleteReport());
159-
return;
160-
}
159+
}
161160
}
162161
}

src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
package com.mcmoddev.orespawn.data;
22

3-
import java.util.ArrayList;
4-
import java.util.Arrays;
5-
import java.util.Collections;
6-
import java.util.HashMap;
7-
import java.util.List;
8-
import java.util.Map;
9-
103
import com.mcmoddev.orespawn.util.StateUtil;
11-
124
import net.minecraft.block.Block;
135
import net.minecraft.block.state.IBlockState;
146
import net.minecraft.item.ItemStack;
157
import net.minecraft.util.ResourceLocation;
168
import net.minecraftforge.fml.common.registry.ForgeRegistries;
179
import net.minecraftforge.oredict.OreDictionary;
1810

11+
import java.util.*;
12+
13+
import static java.util.Arrays.asList;
14+
1915
public class ReplacementsRegistry {
2016
private static Map<String,IBlockState> blocks = new HashMap<>();
2117

@@ -32,7 +28,7 @@ public static List<IBlockState> getDimensionDefault(int dimension) {
3228
}
3329
return rv;
3430
}
35-
return Arrays.asList(ForgeRegistries.BLOCKS.getValue(new ResourceLocation(names[dimension+1])).getDefaultState());
31+
return asList(ForgeRegistries.BLOCKS.getValue(new ResourceLocation(names[dimension+1])).getDefaultState());
3632
}
3733

3834
public static IBlockState getBlock(String name) {

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import com.google.gson.JsonObject;
77
import com.mcmoddev.orespawn.OreSpawn;
8+
import com.mcmoddev.orespawn.api.BiomeLocation;
89
import com.mcmoddev.orespawn.api.FeatureBase;
910
import com.mcmoddev.orespawn.api.IFeature;
1011
import com.mcmoddev.orespawn.data.Constants;
@@ -20,17 +21,17 @@
2021

2122
public class ClusterGenerator extends FeatureBase implements IFeature {
2223

23-
public ClusterGenerator(Random rand) {
24+
private ClusterGenerator ( Random rand ) {
2425
super(rand);
2526
}
2627

2728
public ClusterGenerator() {
28-
super( new Random() );
29+
this( new Random() );
2930
}
3031

3132
@Override
32-
public void generate(ChunkPos pos, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider,
33-
JsonObject parameters, OreList ores, List<IBlockState> blockReplace) {
33+
public void generate( ChunkPos pos, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider,
34+
JsonObject parameters, OreList ores, List<IBlockState> blockReplace, BiomeLocation biomes) {
3435
// First, load cached blocks for neighboring chunk ore spawns
3536
int chunkX = pos.x;
3637
int chunkZ = pos.z;
@@ -53,15 +54,16 @@ public void generate(ChunkPos pos, World world, IChunkGenerator chunkGenerator,
5354
int clusterSize = parameters.get(Constants.FormatBits.NODE_SIZE).getAsInt();
5455
int clusterCount = parameters.get(Constants.FormatBits.NODE_COUNT).getAsInt();
5556

57+
if( biomeMatch(world.getBiome( new BlockPos( blockX, 64, blockZ ) ), biomes ) ) return;
58+
5659
while( tries > 0 ) {
5760
if( this.random.nextInt(100) <= frequency ) {
5861
int xRand = random.nextInt(16);
5962
int zRand = random.nextInt(16);
60-
int mSp = maxSpread;
61-
62-
int x = blockX + xRand - (mSp / 2);
63+
64+
int x = blockX + xRand - (maxSpread / 2);
6365
int y = random.nextInt(maxHeight - minHeight) + minHeight;
64-
int z = blockZ + zRand - (mSp / 2);
66+
int z = blockZ + zRand - (maxSpread / 2);
6567
int[] params = new int[] { clusterSize, variance, clusterCount, maxSpread, minHeight, maxHeight};
6668

6769
spawnCluster(ores, new BlockPos(x,y,z), params, random, world, blockReplace);
@@ -86,7 +88,7 @@ private int getPoint( int lowerBound, int upperBound, int median ) {
8688
}
8789

8890
private enum parms {
89-
SIZE, VARIANCE, CCOUNT, MAXSPREAD, MINHEIGHT, MAXHEIGHT;
91+
SIZE, VARIANCE, CCOUNT, MAXSPREAD, MINHEIGHT, MAXHEIGHT
9092
}
9193

9294
private void spawnCluster(OreList ores, BlockPos blockPos, int[] params, Random random, World world, List<IBlockState> blockReplace) {
@@ -117,7 +119,7 @@ private void spawnCluster(OreList ores, BlockPos blockPos, int[] params, Random
117119
int radius = maxSpread/2;
118120

119121
int xp = getPoint(-radius, radius, 0);
120-
int yp = getPoint(-radius, radius, 0);
122+
int yp = getPoint(params[parms.MINHEIGHT.ordinal()], params[parms.MAXHEIGHT.ordinal()], (params[parms.MAXHEIGHT.ordinal()] - params[parms.MINHEIGHT.ordinal()])/2);
121123
int zp = getPoint(-radius, radius, 0);
122124

123125
BlockPos p = blockPos.add( xp, yp, zp );
@@ -163,13 +165,12 @@ private void spawnChunk(OreList ores, World world, BlockPos blockPos, int quanti
163165
}
164166

165167
private void doSpawnFill(boolean nextBoolean, World world, BlockPos blockPos, int quantity, List<IBlockState> blockReplace, OreList possibleOres ) {
166-
int count = quantity;
167168
double radius = Math.pow(quantity, 1.0/3.0) * (3.0 / 4.0 / Math.PI) + 2;
168169
int rSqr = (int)(radius * radius);
169170
if( nextBoolean ) {
170-
spawnMungeNE( world, blockPos, rSqr, radius, blockReplace, count, possibleOres );
171+
spawnMungeNE( world, blockPos, rSqr, radius, blockReplace, quantity, possibleOres );
171172
} else {
172-
spawnMungeSW( world, blockPos, rSqr, radius, blockReplace, count, possibleOres );
173+
spawnMungeSW( world, blockPos, rSqr, radius, blockReplace, quantity, possibleOres );
173174
}
174175
}
175176

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.Random;
55

66
import com.google.gson.JsonObject;
7+
import com.mcmoddev.orespawn.api.BiomeLocation;
78
import com.mcmoddev.orespawn.api.FeatureBase;
89
import com.mcmoddev.orespawn.api.IFeature;
910
import com.mcmoddev.orespawn.data.Constants;
@@ -27,7 +28,8 @@ public DefaultFeatureGenerator() {
2728

2829
@Override
2930
public void generate(ChunkPos pos, World world, IChunkGenerator chunkGenerator,
30-
IChunkProvider chunkProvider, JsonObject parameters, OreList ores, List<IBlockState> replaceBlock ) {
31+
IChunkProvider chunkProvider, JsonObject parameters, OreList ores, List<IBlockState> replaceBlock,
32+
BiomeLocation biomes ) {
3133
// First, load cached blocks for neighboring chunk ore spawns
3234
int chunkX = pos.x;
3335
int chunkZ = pos.z;
@@ -46,7 +48,9 @@ public void generate(ChunkPos pos, World world, IChunkGenerator chunkGenerator,
4648
int vari = parameters.get(Constants.FormatBits.VARIATION).getAsInt();
4749
float freq = parameters.get(Constants.FormatBits.FREQUENCY).getAsFloat();
4850
int size = parameters.get(Constants.FormatBits.NODE_SIZE).getAsInt();
49-
51+
52+
if( biomeMatch(world.getBiome( new BlockPos( blockX, 64, blockZ ) ), biomes ) ) return;
53+
5054
if(freq >= 1){
5155
for(int i = 0; i < freq; i++){
5256
int x = blockX + random.nextInt(16);
@@ -77,7 +81,7 @@ public void generate(ChunkPos pos, World world, IChunkGenerator chunkGenerator,
7781

7882
}
7983

80-
public void spawnOre( BlockPos blockPos, OreList possibleOres, int quantity, World world, Random prng, List<IBlockState> replaceBlock) {
84+
private void spawnOre ( BlockPos blockPos, OreList possibleOres, int quantity, World world, Random prng, List<IBlockState> replaceBlock ) {
8185
int count = quantity;
8286
int lutType = (quantity < 8)?offsetIndexRef_small.length:offsetIndexRef.length;
8387
int[] lut = (quantity < 8)?offsetIndexRef_small:offsetIndexRef;
@@ -97,18 +101,15 @@ public void spawnOre( BlockPos blockPos, OreList possibleOres, int quantity, Wor
97101
}
98102

99103
doSpawnFill( prng.nextBoolean(), world, blockPos, count, replaceBlock, possibleOres );
100-
101-
return;
102104
}
103105

104106
private void doSpawnFill(boolean nextBoolean, World world, BlockPos blockPos, int quantity, List<IBlockState> replaceBlock, OreList possibleOres ) {
105-
int count = quantity;
106107
double radius = Math.pow(quantity, 1.0/3.0) * (3.0 / 4.0 / Math.PI) + 2;
107108
int rSqr = (int)(radius * radius);
108109
if( nextBoolean ) {
109-
spawnMungeNE( world, blockPos, rSqr, radius, replaceBlock, count, possibleOres );
110+
spawnMungeNE( world, blockPos, rSqr, radius, replaceBlock, quantity, possibleOres );
110111
} else {
111-
spawnMungeSW( world, blockPos, rSqr, radius, replaceBlock, count, possibleOres );
112+
spawnMungeSW( world, blockPos, rSqr, radius, replaceBlock, quantity, possibleOres );
112113
}
113114
}
114115

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import com.google.gson.JsonObject;
77
import com.mcmoddev.orespawn.OreSpawn;
8+
import com.mcmoddev.orespawn.api.BiomeLocation;
89
import com.mcmoddev.orespawn.api.FeatureBase;
910
import com.mcmoddev.orespawn.api.IFeature;
1011
import com.mcmoddev.orespawn.data.Constants;
@@ -19,17 +20,17 @@
1920

2021
public class NormalCloudGenerator extends FeatureBase implements IFeature {
2122

22-
public NormalCloudGenerator(Random rand) {
23+
private NormalCloudGenerator ( Random rand ) {
2324
super(rand);
2425
}
2526

2627
public NormalCloudGenerator() {
27-
super( new Random() );
28+
this( new Random() );
2829
}
2930

3031
@Override
3132
public void generate(ChunkPos pos, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider,
32-
JsonObject parameters, OreList ores, List<IBlockState> blockReplace) {
33+
JsonObject parameters, OreList ores, List<IBlockState> blockReplace, BiomeLocation biomes) {
3334
// First, load cached blocks for neighboring chunk ore spawns
3435
int chunkX = pos.x;
3536
int chunkZ = pos.z;
@@ -71,7 +72,9 @@ public void generate(ChunkPos pos, World world, IChunkGenerator chunkGenerator,
7172

7273
int fSave = frequency;
7374
int tryCount = 0;
74-
75+
76+
if( biomeMatch(world.getBiome( new BlockPos( blockX, 64, blockZ ) ), biomes ) ) return;
77+
7578
while( tries > 0 ) {
7679
if( this.random.nextInt(100) <= frequency ) {
7780
frequency = fSave;
@@ -116,7 +119,7 @@ private int getPoint( int lowerBound, int upperBound, int median ) {
116119
}
117120

118121
private enum parms {
119-
SIZE, MAXSPREAD, MINHEIGHT, MAXHEIGHT;
122+
SIZE, MAXSPREAD, MINHEIGHT, MAXHEIGHT
120123
}
121124

122125
private boolean spawnCloud(OreList ores, BlockPos blockPos, int[] params, Random random, World world, List<IBlockState> blockReplace) {
@@ -134,15 +137,15 @@ private boolean spawnCloud(OreList ores, BlockPos blockPos, int[] params, Random
134137

135138
while( count > 0 ) {
136139
int xp = getPoint(0, maxSpread, radius);
137-
int yp = getPoint(0, maxSpread, radius);
140+
int yp = getPoint(params[parms.MINHEIGHT.ordinal()], params[parms.MAXHEIGHT.ordinal()], (params[parms.MAXHEIGHT.ordinal()] - params[parms.MINHEIGHT.ordinal()])/2);
138141
int zp = getPoint(0, maxSpread, radius);
139142

140143
BlockPos p = blockPos.add( xp, yp, zp );
141144

142145
int z = 0;
143146
while ( z < 5 && !spawn(ores.getRandomOre(random).getOre(), world, p, world.provider.getDimension(), true, blockReplace) ) {
144147
xp = getPoint(0, maxSpread, radius);
145-
yp = getPoint(0, maxSpread, radius);
148+
yp = getPoint(params[parms.MINHEIGHT.ordinal()], params[parms.MAXHEIGHT.ordinal()], (params[parms.MAXHEIGHT.ordinal()] - params[parms.MINHEIGHT.ordinal()])/2);
146149
zp = getPoint(0, maxSpread, radius);
147150

148151
p = blockPos.add( xp, yp, zp );

0 commit comments

Comments
 (0)