Skip to content

Commit 59cd0df

Browse files
committed
This appears to fix the biome blacklist/whitelist issue
1 parent f2673cd commit 59cd0df

File tree

7 files changed

+141
-113
lines changed

7 files changed

+141
-113
lines changed

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

Lines changed: 64 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
import java.util.Random;
1010
import java.util.Map.Entry;
1111

12+
import com.google.common.collect.ImmutableSet;
1213
import com.google.gson.JsonObject;
1314
import com.mcmoddev.orespawn.OreSpawn;
1415

1516
import com.mcmoddev.orespawn.impl.location.BiomeLocationComposition;
16-
import com.mcmoddev.orespawn.impl.location.BiomeLocationSingle;
1717
import net.minecraft.block.state.IBlockState;
1818
import net.minecraft.init.Blocks;
1919
import net.minecraft.util.math.BlockPos;
@@ -34,66 +34,86 @@ public FeatureBase( Random rand ) {
3434
this.random = rand;
3535
}
3636

37+
private String getBiomeName( Biome biome ) {
38+
return ForgeRegistries.BIOMES.getKey( biome ).toString();
39+
}
40+
41+
private boolean fullMatch( ImmutableSet<BiomeLocation> locs, Biome biome ) {
42+
for( BiomeLocation b : locs ) {
43+
for( Biome bm : b.getBiomes () ) {
44+
if( bm.equals( biome ) )
45+
return true;
46+
}
47+
}
48+
return false;
49+
}
50+
3751
protected boolean biomeMatch( Biome chunkBiome, BiomeLocation inp ) {
3852
if( inp.getBiomes().isEmpty () ) {
3953
return false;
4054
}
4155

4256
if( inp instanceof BiomeLocationComposition ) {
4357
BiomeLocationComposition loc = (BiomeLocationComposition) inp;
44-
BiomeLocationSingle it = new BiomeLocationSingle ( chunkBiome );
45-
boolean exclMatch = loc.getExclusions().contains(it);
46-
boolean inclMatch = loc.getInclusions().contains(it);
58+
boolean exclMatch = fullMatch( loc.getExclusions(), chunkBiome );
59+
boolean inclMatch = fullMatch( loc.getInclusions(), chunkBiome );
4760

4861
if ( (loc.getInclusions().isEmpty() || inclMatch) && !exclMatch ) {
4962
return false;
5063
}
5164
} else if( inp.matches( chunkBiome ) ) {
5265
return false;
5366
}
54-
5567
return true;
5668
}
5769

58-
protected void runCache(int chunkX, int chunkZ, World world, List<IBlockState> blockReplace) {
70+
protected void runCache(int chunkX, int chunkZ, World world, List<IBlockState> blockReplace ) {
5971
Vec3i chunkCoord = new Vec3i(chunkX, chunkZ, world.provider.getDimension());
6072
Map<BlockPos,IBlockState> cache = retrieveCache(chunkCoord);
6173

6274
if( !cache.isEmpty() ) { // if there is something in the cache, try to spawn it
6375
for(Entry<BlockPos,IBlockState> ent : cache.entrySet()){
64-
spawn( cache.get(ent.getKey()), world, ent.getKey(), world.provider.getDimension(), false, blockReplace);
76+
spawnNoCheck( cache.get(ent.getKey()), world, ent.getKey(), world.provider.getDimension(), false, blockReplace );
6577
}
6678
}
6779
}
68-
69-
protected boolean spawn(IBlockState oreBlock, World world, BlockPos coord, int dimension, boolean cacheOverflow,
70-
List<IBlockState> blockReplace) {
80+
81+
protected boolean spawn( IBlockState oreBlock, World world, BlockPos coord, int dimension, boolean cacheOverflow,
82+
List<IBlockState> blockReplace, BiomeLocation biomes ) {
7183
if( oreBlock == null ) {
7284
OreSpawn.LOGGER.fatal("FeatureBase.spawn() called with a null ore!");
7385
return false;
7486
}
75-
87+
7688
List<IBlockState> blockToReplace = blockReplace;
77-
78-
BlockPos np;
79-
80-
if(coord.getY() < 0 ) {
81-
int newYCoord = coord.getY() * -1;
82-
np = new BlockPos( coord.getX(), newYCoord, coord.getZ() );
83-
} else {
84-
np = new BlockPos( coord );
85-
}
86-
89+
90+
Biome thisBiome = world.getBiome ( coord );
91+
if( biomeMatch ( thisBiome, biomes ) ) return false;
92+
93+
BlockPos np = mungeFixYcoord(coord);
94+
8795
if( coord.getY() >= world.getHeight()) {
8896
OreSpawn.LOGGER.warn("Asked to spawn %s above build limit at %s", oreBlock, coord);
8997
return false;
9098
}
91-
92-
99+
100+
return spawnOrCache(world,np,blockReplace,oreBlock,cacheOverflow,dimension);
101+
}
102+
103+
private BlockPos mungeFixYcoord ( BlockPos coord ) {
104+
if(coord.getY() < 0 ) {
105+
int newYCoord = coord.getY() * -1;
106+
return new BlockPos( coord.getX(), newYCoord, coord.getZ() );
107+
} else {
108+
return new BlockPos( coord );
109+
}
110+
}
111+
112+
private boolean spawnOrCache ( World world, BlockPos coord, List<IBlockState> blockReplace, IBlockState oreBlock, boolean cacheOverflow, int dimension ) {
93113
if(world.isBlockLoaded(coord)){
94114
IBlockState targetBlock = world.getBlockState(coord);
95-
if(canReplace(targetBlock,blockToReplace)) {
96-
world.setBlockState(np, oreBlock, 22);
115+
if(canReplace(targetBlock,blockReplace)) {
116+
world.setBlockState(coord, oreBlock, 22);
97117
return true;
98118
} else {
99119
return false;
@@ -102,11 +122,28 @@ protected boolean spawn(IBlockState oreBlock, World world, BlockPos coord, int d
102122
cacheOverflowBlock(oreBlock,coord,dimension);
103123
return true;
104124
}
105-
106-
//if it gets here by some strange twist...
107125
return false;
108126
}
109127

128+
protected boolean spawnNoCheck( IBlockState oreBlock, World world, BlockPos coord, int dimension, boolean cacheOverflow,
129+
List<IBlockState> blockReplace ) {
130+
if( oreBlock == null ) {
131+
OreSpawn.LOGGER.fatal("FeatureBase.spawn() called with a null ore!");
132+
return false;
133+
}
134+
135+
List<IBlockState> blockToReplace = blockReplace;
136+
137+
BlockPos np = mungeFixYcoord(coord);
138+
139+
if( coord.getY() >= world.getHeight()) {
140+
OreSpawn.LOGGER.warn("Asked to spawn %s above build limit at %s", oreBlock, coord);
141+
return false;
142+
}
143+
144+
return spawnOrCache(world,np,blockReplace,oreBlock,cacheOverflow,dimension);
145+
}
146+
110147
protected void cacheOverflowBlock(IBlockState bs, BlockPos coord, int dimension){
111148
Vec3i chunkCoord = new Vec3i(coord.getX() >> 4, coord.getY() >> 4, dimension);
112149
if(overflowCache.containsKey(chunkCoord)){

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

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ public void generate( ChunkPos pos, World world, IChunkGenerator chunkGenerator,
5454
int clusterSize = parameters.get(Constants.FormatBits.NODE_SIZE).getAsInt();
5555
int clusterCount = parameters.get(Constants.FormatBits.NODE_COUNT).getAsInt();
5656

57-
if( biomeMatch(world.getBiome( new BlockPos( blockX, 64, blockZ ) ), biomes ) ) return;
58-
5957
while( tries > 0 ) {
6058
if( this.random.nextInt(100) <= frequency ) {
6159
int xRand = random.nextInt(16);
@@ -66,7 +64,7 @@ public void generate( ChunkPos pos, World world, IChunkGenerator chunkGenerator,
6664
int z = blockZ + zRand - (maxSpread / 2);
6765
int[] params = new int[] { clusterSize, variance, clusterCount, maxSpread, minHeight, maxHeight};
6866

69-
spawnCluster(ores, new BlockPos(x,y,z), params, random, world, blockReplace);
67+
spawnCluster(ores, new BlockPos(x,y,z), params, random, world, blockReplace, biomes);
7068
}
7169
tries--;
7270
}
@@ -91,7 +89,7 @@ private enum parms {
9189
SIZE, VARIANCE, CCOUNT, MAXSPREAD, MINHEIGHT, MAXHEIGHT
9290
}
9391

94-
private void spawnCluster(OreList ores, BlockPos blockPos, int[] params, Random random, World world, List<IBlockState> blockReplace) {
92+
private void spawnCluster ( OreList ores, BlockPos blockPos, int[] params, Random random, World world, List<IBlockState> blockReplace, BiomeLocation biomes ) {
9593
int size = params[parms.SIZE.ordinal()];
9694
int variance = params[parms.VARIANCE.ordinal()];
9795
int clusterCount = params[parms.CCOUNT.ordinal()];
@@ -103,7 +101,7 @@ private void spawnCluster(OreList ores, BlockPos blockPos, int[] params, Random
103101
r += random.nextInt(2 * variance) - variance;
104102
}
105103

106-
spawnChunk(ores, world, blockPos, r, world.provider.getDimension(), blockReplace, random);
104+
spawnChunk(ores, world, blockPos, r, world.provider.getDimension(), blockReplace, random, biomes);
107105

108106
int count = random.nextInt(clusterCount - 1); // always at least the first, but vary inside that
109107
if( variance > 0) {
@@ -124,14 +122,14 @@ private void spawnCluster(OreList ores, BlockPos blockPos, int[] params, Random
124122

125123
BlockPos p = blockPos.add( xp, yp, zp );
126124

127-
spawnChunk(ores, world, p, r, world.provider.getDimension(), blockReplace, random);
125+
spawnChunk(ores, world, p, r, world.provider.getDimension(), blockReplace, random, biomes );
128126

129127
count -= r;
130128
}
131129
}
132130

133-
private void spawnChunk(OreList ores, World world, BlockPos blockPos, int quantity, int dimension, List<IBlockState> blockReplace,
134-
Random prng) {
131+
private void spawnChunk ( OreList ores, World world, BlockPos blockPos, int quantity, int dimension, List<IBlockState> blockReplace,
132+
Random prng, BiomeLocation biomes ) {
135133
int count = quantity;
136134
int lutType = (quantity < 8)?offsetIndexRef_small.length:offsetIndexRef.length;
137135
int[] lut = (quantity < 8)?offsetIndexRef_small:offsetIndexRef;
@@ -146,7 +144,7 @@ private void spawnChunk(OreList ores, World world, BlockPos blockPos, int quanti
146144
int z = 0;
147145
while(count > 0){
148146
IBlockState oreBlock = ores.getRandomOre(prng).getOre();
149-
if( !spawn(oreBlock,world,blockPos.add(offs[scrambledLUT[--count]]),dimension,true,blockReplace) ) {
147+
if( !spawn(oreBlock,world,blockPos.add(offs[scrambledLUT[--count]]),dimension,true,blockReplace, biomes ) ) {
150148
count++;
151149
z++;
152150
} else {
@@ -161,30 +159,30 @@ private void spawnChunk(OreList ores, World world, BlockPos blockPos, int quanti
161159
return;
162160
}
163161

164-
doSpawnFill( prng.nextBoolean(), world, blockPos, count, blockReplace, ores );
162+
doSpawnFill( prng.nextBoolean(), world, blockPos, count, blockReplace, ores, biomes );
165163
}
166164

167-
private void doSpawnFill(boolean nextBoolean, World world, BlockPos blockPos, int quantity, List<IBlockState> blockReplace, OreList possibleOres ) {
165+
private void doSpawnFill ( boolean nextBoolean, World world, BlockPos blockPos, int quantity, List<IBlockState> blockReplace, OreList possibleOres, BiomeLocation biomes ) {
168166
double radius = Math.pow(quantity, 1.0/3.0) * (3.0 / 4.0 / Math.PI) + 2;
169167
int rSqr = (int)(radius * radius);
170168
if( nextBoolean ) {
171-
spawnMungeNE( world, blockPos, rSqr, radius, blockReplace, quantity, possibleOres );
169+
spawnMungeNE( world, blockPos, rSqr, radius, blockReplace, quantity, possibleOres, biomes );
172170
} else {
173-
spawnMungeSW( world, blockPos, rSqr, radius, blockReplace, quantity, possibleOres );
171+
spawnMungeSW( world, blockPos, rSqr, radius, blockReplace, quantity, possibleOres, biomes );
174172
}
175173
}
176174

177175

178-
private void spawnMungeSW(World world, BlockPos blockPos, int rSqr, double radius,
179-
List<IBlockState> blockReplace, int count, OreList possibleOres ) {
176+
private void spawnMungeSW ( World world, BlockPos blockPos, int rSqr, double radius,
177+
List<IBlockState> blockReplace, int count, OreList possibleOres, BiomeLocation biomes ) {
180178
Random prng = this.random;
181179
int quantity = count;
182180
for(int dy = (int)(-1 * radius); dy < radius; dy++){
183181
for(int dx = (int)(radius); dx >= (int)(-1 * radius); dx--){
184182
for(int dz = (int)(radius); dz >= (int)(-1 * radius); dz--){
185183
if((dx*dx + dy*dy + dz*dz) <= rSqr){
186184
IBlockState oreBlock = possibleOres.getRandomOre(prng).getOre();
187-
spawn(oreBlock,world,blockPos.add(dx,dy,dz),world.provider.getDimension(),true,blockReplace);
185+
spawn(oreBlock,world,blockPos.add(dx,dy,dz),world.provider.getDimension(),true,blockReplace, biomes );
188186
quantity--;
189187
}
190188
if(quantity <= 0) {
@@ -196,16 +194,16 @@ private void spawnMungeSW(World world, BlockPos blockPos, int rSqr, double radiu
196194
}
197195

198196

199-
private void spawnMungeNE(World world, BlockPos blockPos, int rSqr, double radius,
200-
List<IBlockState> blockReplace, int count, OreList possibleOres) {
197+
private void spawnMungeNE ( World world, BlockPos blockPos, int rSqr, double radius,
198+
List<IBlockState> blockReplace, int count, OreList possibleOres, BiomeLocation biomes ) {
201199
Random prng = this.random;
202200
int quantity = count;
203201
for(int dy = (int)(-1 * radius); dy < radius; dy++){
204202
for(int dz = (int)(-1 * radius); dz < radius; dz++){
205203
for(int dx = (int)(-1 * radius); dx < radius; dx++){
206204
if((dx*dx + dy*dy + dz*dz) <= rSqr){
207205
IBlockState oreBlock = possibleOres.getRandomOre(prng).getOre();
208-
spawn(oreBlock,world,blockPos.add(dx,dy,dz),world.provider.getDimension(),true,blockReplace);
206+
spawn(oreBlock,world,blockPos.add(dx,dy,dz),world.provider.getDimension(),true,blockReplace, biomes );
209207
quantity--;
210208
}
211209
if(quantity <= 0) {

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

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ public void generate(ChunkPos pos, World world, IChunkGenerator chunkGenerator,
4949
float freq = parameters.get(Constants.FormatBits.FREQUENCY).getAsFloat();
5050
int size = parameters.get(Constants.FormatBits.NODE_SIZE).getAsInt();
5151

52-
if( biomeMatch(world.getBiome( new BlockPos( blockX, 64, blockZ ) ), biomes ) ) return;
53-
5452
if(freq >= 1){
5553
for(int i = 0; i < freq; i++){
5654
int x = blockX + random.nextInt(16);
@@ -63,7 +61,7 @@ public void generate(ChunkPos pos, World world, IChunkGenerator chunkGenerator,
6361
} else {
6462
r = 0;
6563
}
66-
spawnOre( new BlockPos(x,y,z), ores, size + r, world, random, replaceBlock);
64+
spawnOre( new BlockPos(x,y,z), ores, size + r, world, random, replaceBlock, biomes);
6765
}
6866
} else if(random.nextFloat() < freq){
6967
int x = blockX + random.nextInt(8);
@@ -76,12 +74,12 @@ public void generate(ChunkPos pos, World world, IChunkGenerator chunkGenerator,
7674
r = 0;
7775
}
7876

79-
spawnOre( new BlockPos(x,y,z), ores, size + r, world, random, replaceBlock);
77+
spawnOre( new BlockPos(x,y,z), ores, size + r, world, random, replaceBlock, biomes);
8078
}
8179

8280
}
8381

84-
private void spawnOre ( BlockPos blockPos, OreList possibleOres, int quantity, World world, Random prng, List<IBlockState> replaceBlock ) {
82+
private void spawnOre ( BlockPos blockPos, OreList possibleOres, int quantity, World world, Random prng, List<IBlockState> replaceBlock, BiomeLocation biomes ) {
8583
int count = quantity;
8684
int lutType = (quantity < 8)?offsetIndexRef_small.length:offsetIndexRef.length;
8785
int[] lut = (quantity < 8)?offsetIndexRef_small:offsetIndexRef;
@@ -95,35 +93,35 @@ private void spawnOre ( BlockPos blockPos, OreList possibleOres, int quantity, W
9593
scramble(scrambledLUT,prng);
9694
while(count > 0){
9795
IBlockState oreBlock = possibleOres.getRandomOre(prng).getOre();
98-
spawn(oreBlock,world,blockPos.add(offs[scrambledLUT[--count]]),world.provider.getDimension(),true,replaceBlock);
96+
spawn(oreBlock,world,blockPos.add(offs[scrambledLUT[--count]]),world.provider.getDimension(),true,replaceBlock, biomes );
9997
}
10098
return;
10199
}
102100

103-
doSpawnFill( prng.nextBoolean(), world, blockPos, count, replaceBlock, possibleOres );
101+
doSpawnFill( prng.nextBoolean(), world, blockPos, count, replaceBlock, possibleOres, biomes );
104102
}
105103

106-
private void doSpawnFill(boolean nextBoolean, World world, BlockPos blockPos, int quantity, List<IBlockState> replaceBlock, OreList possibleOres ) {
104+
private void doSpawnFill ( boolean nextBoolean, World world, BlockPos blockPos, int quantity, List<IBlockState> replaceBlock, OreList possibleOres, BiomeLocation biomes ) {
107105
double radius = Math.pow(quantity, 1.0/3.0) * (3.0 / 4.0 / Math.PI) + 2;
108106
int rSqr = (int)(radius * radius);
109107
if( nextBoolean ) {
110-
spawnMungeNE( world, blockPos, rSqr, radius, replaceBlock, quantity, possibleOres );
108+
spawnMungeNE( world, blockPos, rSqr, radius, replaceBlock, quantity, possibleOres, biomes );
111109
} else {
112-
spawnMungeSW( world, blockPos, rSqr, radius, replaceBlock, quantity, possibleOres );
110+
spawnMungeSW( world, blockPos, rSqr, radius, replaceBlock, quantity, possibleOres, biomes );
113111
}
114112
}
115113

116114

117-
private void spawnMungeSW(World world, BlockPos blockPos, int rSqr, double radius,
118-
List<IBlockState> replaceBlock, int count, OreList possibleOres) {
115+
private void spawnMungeSW ( World world, BlockPos blockPos, int rSqr, double radius,
116+
List<IBlockState> replaceBlock, int count, OreList possibleOres, BiomeLocation biomes ) {
119117
Random prng = this.random;
120118
int quantity = count;
121119
for(int dy = (int)(-1 * radius); dy < radius; dy++){
122120
for(int dx = (int)(radius); dx >= (int)(-1 * radius); dx--){
123121
for(int dz = (int)(radius); dz >= (int)(-1 * radius); dz--){
124122
if((dx*dx + dy*dy + dz*dz) <= rSqr){
125123
IBlockState oreBlock = possibleOres.getRandomOre(prng).getOre();
126-
spawn(oreBlock,world,blockPos.add(dx,dy,dz),world.provider.getDimension(),true,replaceBlock);
124+
spawn(oreBlock,world,blockPos.add(dx,dy,dz),world.provider.getDimension(),true,replaceBlock, biomes );
127125
quantity--;
128126
}
129127
if(quantity <= 0) {
@@ -135,16 +133,16 @@ private void spawnMungeSW(World world, BlockPos blockPos, int rSqr, double radiu
135133
}
136134

137135

138-
private void spawnMungeNE(World world, BlockPos blockPos, int rSqr, double radius,
139-
List<IBlockState> replaceBlock, int count, OreList possibleOres) {
136+
private void spawnMungeNE ( World world, BlockPos blockPos, int rSqr, double radius,
137+
List<IBlockState> replaceBlock, int count, OreList possibleOres, BiomeLocation biomes ) {
140138
Random prng = this.random;
141139
int quantity = count;
142140
for(int dy = (int)(-1 * radius); dy < radius; dy++){
143141
for(int dz = (int)(-1 * radius); dz < radius; dz++){
144142
for(int dx = (int)(-1 * radius); dx < radius; dx++){
145143
if((dx*dx + dy*dy + dz*dz) <= rSqr){
146144
IBlockState oreBlock = possibleOres.getRandomOre(prng).getOre();
147-
spawn(oreBlock,world,blockPos.add(dx,dy,dz),world.provider.getDimension(),true,replaceBlock);
145+
spawn(oreBlock,world,blockPos.add(dx,dy,dz),world.provider.getDimension(),true,replaceBlock, biomes );
148146
quantity--;
149147
}
150148
if(quantity <= 0) {

0 commit comments

Comments
 (0)