- obey mobSpawning=false flag during chunk-gen
- fix a couple more biome lookup funcs - expose stronghold spread setting
This commit is contained in:
parent
f5db6995f2
commit
8bfbbc5276
@ -25,7 +25,11 @@ public class WorldLookup {
|
||||
|
||||
public Cell<Terrain> getCell(int x, int z) {
|
||||
Cell<Terrain> cell = new Cell<>();
|
||||
applyCell(cell, x, z);
|
||||
return cell;
|
||||
}
|
||||
|
||||
public void applyCell(Cell<Terrain> cell, int x, int z) {
|
||||
heightmap.apply(cell, x, z);
|
||||
|
||||
// approximation - actual beaches depend on steepness but that's too expensive to calculate
|
||||
@ -38,7 +42,5 @@ public class WorldLookup {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return cell;
|
||||
}
|
||||
}
|
||||
|
@ -76,38 +76,55 @@ public class BiomeProvider extends AbstractBiomeProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Biome> getBiomesInSquare(int centerX, int centerY, int centerZ, int sideLength) {
|
||||
int minX = centerX - (sideLength >> 2);
|
||||
int minZ = centerZ - (sideLength >> 2);
|
||||
int maxX = centerX + (sideLength >> 2);
|
||||
int maxZ = centerZ + (sideLength >> 2);
|
||||
Set<Biome> biomes = Sets.newHashSet();
|
||||
context.heightmap.visit(minX, minZ, maxX, maxZ, (cell, x, z) -> {
|
||||
Biome biome = getBiome(cell, minX + x, minZ + z);
|
||||
biomes.add(biome);
|
||||
});
|
||||
return biomes;
|
||||
public Set<Biome> getBiomesInSquare(int centerX, int centerY, int centerZ, int radius) {
|
||||
int minX = centerX - radius >> 2;
|
||||
int minZ = centerZ - radius >> 2;
|
||||
int maxX = centerX + radius >> 2;
|
||||
int maxZ = centerZ + radius >> 2;
|
||||
int rangeX = maxX - minX + 1;
|
||||
int rangeZ = maxZ - minZ + 1;
|
||||
Set<Biome> set = Sets.newHashSet();
|
||||
Cell<Terrain> cell = new Cell<>();
|
||||
for(int dz = 0; dz < rangeZ; ++dz) {
|
||||
for(int dx = 0; dx < rangeX; ++dx) {
|
||||
int x = (minX + dx) << 2;
|
||||
int z = (minZ + dz) << 2;
|
||||
worldLookup.applyCell(cell, x, z);
|
||||
Biome biome = getBiome(cell, x, z);
|
||||
set.add(biome);
|
||||
}
|
||||
}
|
||||
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPos findBiomePosition(int centerX, int centerY, int centerZ, int range, List<Biome> biomes, Random random) {
|
||||
int minX = centerX - (range >> 2);
|
||||
int minZ = centerZ - (range >> 2);
|
||||
int maxX = centerX + (range >> 2);
|
||||
int maxZ = centerZ + (range >> 2);
|
||||
Set<Biome> matchBiomes = new HashSet<>(biomes);
|
||||
SearchContext search = new SearchContext();
|
||||
context.heightmap.visit(minX, minZ, maxX, maxZ, (cell, x, z) -> {
|
||||
Biome biome = getBiome(cell, minX + x, minZ + z);
|
||||
if (matchBiomes.contains(biome)) {
|
||||
if (search.first || random.nextInt(search.count + 1) == 0) {
|
||||
search.first = false;
|
||||
search.pos.setPos(minX + x, 0, minZ + z);
|
||||
int minX = centerX - range >> 2;
|
||||
int minZ = centerZ - range >> 2;
|
||||
int maxX = centerX + range >> 2;
|
||||
int maxZ = centerZ + range >> 2;
|
||||
int rangeX = maxX - minX + 1;
|
||||
int rangeZ = maxZ - minZ + 1;
|
||||
int y = centerY >> 2;
|
||||
BlockPos blockpos = null;
|
||||
int attempts = 0;
|
||||
|
||||
Cell<Terrain> cell = new Cell<>();
|
||||
for(int dz = 0; dz < rangeZ; ++dz) {
|
||||
for(int dx = 0; dx < rangeX; ++dx) {
|
||||
int x = (minX + dx) << 2;
|
||||
int z = (minZ + dz) << 2;
|
||||
worldLookup.applyCell(cell, x, z);
|
||||
if (biomes.contains(getBiome(cell, x, z))) {
|
||||
if (blockpos == null || random.nextInt(attempts + 1) == 0) {
|
||||
blockpos = new BlockPos(x, y, z);
|
||||
}
|
||||
++attempts;
|
||||
}
|
||||
++search.count;
|
||||
}
|
||||
});
|
||||
return search.pos;
|
||||
}
|
||||
return blockpos;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
package com.terraforged.mod.chunk;
|
||||
|
||||
import com.terraforged.mod.chunk.fix.SpawnFix;
|
||||
import com.terraforged.mod.util.annotation.Name;
|
||||
import com.terraforged.mod.util.annotation.Ref;
|
||||
import net.minecraft.entity.EntityClassification;
|
||||
@ -107,20 +108,24 @@ public abstract class ObfHelperChunkGenerator<T extends GenerationSettings> exte
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void spawnMobs(ServerWorld worldIn, boolean spawnHostileMobs, boolean spawnPeacefulMobs) {
|
||||
phantomSpawner.tick(worldIn, spawnHostileMobs, spawnPeacefulMobs);
|
||||
patrolSpawner.tick(worldIn, spawnHostileMobs, spawnPeacefulMobs);
|
||||
catSpawner.tick(worldIn, spawnHostileMobs, spawnPeacefulMobs);
|
||||
public final void spawnMobs(WorldGenRegion region) {
|
||||
// vanilla does NOT check the mobSpawning gamerule before calling this
|
||||
if (SpawnFix.canSpawnMobs()) {
|
||||
int chunkX = region.getMainChunkX();
|
||||
int chunkZ = region.getMainChunkZ();
|
||||
Biome biome = region.getChunk(chunkX, chunkZ).getBiomes().getNoiseBiome(0, 0, 0);
|
||||
SharedSeedRandom sharedseedrandom = new SharedSeedRandom();
|
||||
sharedseedrandom.setDecorationSeed(region.getSeed(), chunkX << 4, chunkZ << 4);
|
||||
WorldEntitySpawner.performWorldGenSpawning(region, biome, chunkX, chunkZ, sharedseedrandom);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void spawnMobs(WorldGenRegion region) {
|
||||
int chunkX = region.getMainChunkX();
|
||||
int chunkZ = region.getMainChunkZ();
|
||||
Biome biome = region.getChunk(chunkX, chunkZ).getBiomes().getNoiseBiome(0, 0, 0);
|
||||
SharedSeedRandom sharedseedrandom = new SharedSeedRandom();
|
||||
sharedseedrandom.setDecorationSeed(region.getSeed(), chunkX << 4, chunkZ << 4);
|
||||
WorldEntitySpawner.performWorldGenSpawning(region, biome, chunkX, chunkZ, sharedseedrandom);
|
||||
public final void spawnMobs(ServerWorld worldIn, boolean spawnHostileMobs, boolean spawnPeacefulMobs) {
|
||||
// vanilla does check the mobSpawning gamerule before calling this
|
||||
phantomSpawner.tick(worldIn, spawnHostileMobs, spawnPeacefulMobs);
|
||||
patrolSpawner.tick(worldIn, spawnHostileMobs, spawnPeacefulMobs);
|
||||
catSpawner.tick(worldIn, spawnHostileMobs, spawnPeacefulMobs);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -34,6 +34,7 @@ public class TerraGenSettings extends OverworldGenSettings {
|
||||
super.villageDistance *= settings.villageDistance;
|
||||
super.mansionDistance *= settings.mansionDistance;
|
||||
super.strongholdDistance *= settings.strongholdDistance;
|
||||
super.strongholdSpread *= settings.strongholdSpread;
|
||||
super.biomeFeatureDistance *= settings.biomeStructureDistance;
|
||||
super.oceanMonumentSpacing *= settings.oceanMonumentSpacing;
|
||||
super.oceanMonumentSeparation *= settings.oceanMonumentSeparation;
|
||||
|
@ -0,0 +1,26 @@
|
||||
package com.terraforged.mod.chunk.fix;
|
||||
|
||||
import net.minecraft.world.GameRules;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE)
|
||||
public class SpawnFix {
|
||||
|
||||
private static final AtomicBoolean MOB_SPAWNING = new AtomicBoolean();
|
||||
|
||||
@SubscribeEvent
|
||||
public static void tick(TickEvent.WorldTickEvent event) {
|
||||
if (event.phase == TickEvent.Phase.START && event.side.isServer()) {
|
||||
boolean mobSpawning = event.world.getGameRules().get(GameRules.DO_MOB_SPAWNING).get();
|
||||
MOB_SPAWNING.set(mobSpawning);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean canSpawnMobs() {
|
||||
return MOB_SPAWNING.get();
|
||||
}
|
||||
}
|
@ -34,15 +34,19 @@ public class StructureSettings {
|
||||
|
||||
@Range(min = 1, max = 10)
|
||||
@Comment("Controls the distance between villages")
|
||||
public int villageDistance = 4;
|
||||
public int villageDistance = 2;
|
||||
|
||||
@Range(min = 1, max = 10)
|
||||
@Comment("Controls the distance between mansions")
|
||||
public int mansionDistance = 4;
|
||||
public int mansionDistance = 2;
|
||||
|
||||
@Range(min = 1, max = 10)
|
||||
@Comment("Controls the distance between strongholds")
|
||||
public int strongholdDistance = 4;
|
||||
public int strongholdDistance = 2;
|
||||
|
||||
@Range(min = 1, max = 10)
|
||||
@Comment("Controls the distance between strongholds")
|
||||
public int strongholdSpread = 2;
|
||||
|
||||
@Range(min = 1, max = 10)
|
||||
@Comment("Controls the distance between biome structures")
|
||||
@ -50,9 +54,9 @@ public class StructureSettings {
|
||||
|
||||
@Range(min = 1, max = 10)
|
||||
@Comment("Controls the distance between ocean monuments")
|
||||
public int oceanMonumentSpacing = 4;
|
||||
public int oceanMonumentSpacing = 2;
|
||||
|
||||
@Range(min = 1, max = 10)
|
||||
@Comment("Controls the separation between ocean monuments")
|
||||
public int oceanMonumentSeparation = 4;
|
||||
public int oceanMonumentSeparation = 2;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user