- 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) {
|
public Cell<Terrain> getCell(int x, int z) {
|
||||||
Cell<Terrain> cell = new Cell<>();
|
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);
|
heightmap.apply(cell, x, z);
|
||||||
|
|
||||||
// approximation - actual beaches depend on steepness but that's too expensive to calculate
|
// approximation - actual beaches depend on steepness but that's too expensive to calculate
|
||||||
@ -38,7 +42,5 @@ public class WorldLookup {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return cell;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,38 +76,55 @@ public class BiomeProvider extends AbstractBiomeProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Biome> getBiomesInSquare(int centerX, int centerY, int centerZ, int sideLength) {
|
public Set<Biome> getBiomesInSquare(int centerX, int centerY, int centerZ, int radius) {
|
||||||
int minX = centerX - (sideLength >> 2);
|
int minX = centerX - radius >> 2;
|
||||||
int minZ = centerZ - (sideLength >> 2);
|
int minZ = centerZ - radius >> 2;
|
||||||
int maxX = centerX + (sideLength >> 2);
|
int maxX = centerX + radius >> 2;
|
||||||
int maxZ = centerZ + (sideLength >> 2);
|
int maxZ = centerZ + radius >> 2;
|
||||||
Set<Biome> biomes = Sets.newHashSet();
|
int rangeX = maxX - minX + 1;
|
||||||
context.heightmap.visit(minX, minZ, maxX, maxZ, (cell, x, z) -> {
|
int rangeZ = maxZ - minZ + 1;
|
||||||
Biome biome = getBiome(cell, minX + x, minZ + z);
|
Set<Biome> set = Sets.newHashSet();
|
||||||
biomes.add(biome);
|
Cell<Terrain> cell = new Cell<>();
|
||||||
});
|
for(int dz = 0; dz < rangeZ; ++dz) {
|
||||||
return biomes;
|
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
|
@Override
|
||||||
public BlockPos findBiomePosition(int centerX, int centerY, int centerZ, int range, List<Biome> biomes, Random random) {
|
public BlockPos findBiomePosition(int centerX, int centerY, int centerZ, int range, List<Biome> biomes, Random random) {
|
||||||
int minX = centerX - (range >> 2);
|
int minX = centerX - range >> 2;
|
||||||
int minZ = centerZ - (range >> 2);
|
int minZ = centerZ - range >> 2;
|
||||||
int maxX = centerX + (range >> 2);
|
int maxX = centerX + range >> 2;
|
||||||
int maxZ = centerZ + (range >> 2);
|
int maxZ = centerZ + range >> 2;
|
||||||
Set<Biome> matchBiomes = new HashSet<>(biomes);
|
int rangeX = maxX - minX + 1;
|
||||||
SearchContext search = new SearchContext();
|
int rangeZ = maxZ - minZ + 1;
|
||||||
context.heightmap.visit(minX, minZ, maxX, maxZ, (cell, x, z) -> {
|
int y = centerY >> 2;
|
||||||
Biome biome = getBiome(cell, minX + x, minZ + z);
|
BlockPos blockpos = null;
|
||||||
if (matchBiomes.contains(biome)) {
|
int attempts = 0;
|
||||||
if (search.first || random.nextInt(search.count + 1) == 0) {
|
|
||||||
search.first = false;
|
Cell<Terrain> cell = new Cell<>();
|
||||||
search.pos.setPos(minX + x, 0, minZ + z);
|
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);
|
||||||
}
|
}
|
||||||
++search.count;
|
++attempts;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
return search.pos;
|
}
|
||||||
|
return blockpos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
package com.terraforged.mod.chunk;
|
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.Name;
|
||||||
import com.terraforged.mod.util.annotation.Ref;
|
import com.terraforged.mod.util.annotation.Ref;
|
||||||
import net.minecraft.entity.EntityClassification;
|
import net.minecraft.entity.EntityClassification;
|
||||||
@ -106,15 +107,10 @@ public abstract class ObfHelperChunkGenerator<T extends GenerationSettings> exte
|
|||||||
return super.getPossibleCreatures(type, pos);
|
return super.getPossibleCreatures(type, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
@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);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void spawnMobs(WorldGenRegion region) {
|
public final void spawnMobs(WorldGenRegion region) {
|
||||||
|
// vanilla does NOT check the mobSpawning gamerule before calling this
|
||||||
|
if (SpawnFix.canSpawnMobs()) {
|
||||||
int chunkX = region.getMainChunkX();
|
int chunkX = region.getMainChunkX();
|
||||||
int chunkZ = region.getMainChunkZ();
|
int chunkZ = region.getMainChunkZ();
|
||||||
Biome biome = region.getChunk(chunkX, chunkZ).getBiomes().getNoiseBiome(0, 0, 0);
|
Biome biome = region.getChunk(chunkX, chunkZ).getBiomes().getNoiseBiome(0, 0, 0);
|
||||||
@ -122,6 +118,15 @@ public abstract class ObfHelperChunkGenerator<T extends GenerationSettings> exte
|
|||||||
sharedseedrandom.setDecorationSeed(region.getSeed(), chunkX << 4, chunkZ << 4);
|
sharedseedrandom.setDecorationSeed(region.getSeed(), chunkX << 4, chunkZ << 4);
|
||||||
WorldEntitySpawner.performWorldGenSpawning(region, biome, chunkX, chunkZ, sharedseedrandom);
|
WorldEntitySpawner.performWorldGenSpawning(region, biome, chunkX, chunkZ, sharedseedrandom);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
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
|
@Override
|
||||||
@Name("getSurfaceLevel")
|
@Name("getSurfaceLevel")
|
||||||
|
@ -34,6 +34,7 @@ public class TerraGenSettings extends OverworldGenSettings {
|
|||||||
super.villageDistance *= settings.villageDistance;
|
super.villageDistance *= settings.villageDistance;
|
||||||
super.mansionDistance *= settings.mansionDistance;
|
super.mansionDistance *= settings.mansionDistance;
|
||||||
super.strongholdDistance *= settings.strongholdDistance;
|
super.strongholdDistance *= settings.strongholdDistance;
|
||||||
|
super.strongholdSpread *= settings.strongholdSpread;
|
||||||
super.biomeFeatureDistance *= settings.biomeStructureDistance;
|
super.biomeFeatureDistance *= settings.biomeStructureDistance;
|
||||||
super.oceanMonumentSpacing *= settings.oceanMonumentSpacing;
|
super.oceanMonumentSpacing *= settings.oceanMonumentSpacing;
|
||||||
super.oceanMonumentSeparation *= settings.oceanMonumentSeparation;
|
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)
|
@Range(min = 1, max = 10)
|
||||||
@Comment("Controls the distance between villages")
|
@Comment("Controls the distance between villages")
|
||||||
public int villageDistance = 4;
|
public int villageDistance = 2;
|
||||||
|
|
||||||
@Range(min = 1, max = 10)
|
@Range(min = 1, max = 10)
|
||||||
@Comment("Controls the distance between mansions")
|
@Comment("Controls the distance between mansions")
|
||||||
public int mansionDistance = 4;
|
public int mansionDistance = 2;
|
||||||
|
|
||||||
@Range(min = 1, max = 10)
|
@Range(min = 1, max = 10)
|
||||||
@Comment("Controls the distance between strongholds")
|
@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)
|
@Range(min = 1, max = 10)
|
||||||
@Comment("Controls the distance between biome structures")
|
@Comment("Controls the distance between biome structures")
|
||||||
@ -50,9 +54,9 @@ public class StructureSettings {
|
|||||||
|
|
||||||
@Range(min = 1, max = 10)
|
@Range(min = 1, max = 10)
|
||||||
@Comment("Controls the distance between ocean monuments")
|
@Comment("Controls the distance between ocean monuments")
|
||||||
public int oceanMonumentSpacing = 4;
|
public int oceanMonumentSpacing = 2;
|
||||||
|
|
||||||
@Range(min = 1, max = 10)
|
@Range(min = 1, max = 10)
|
||||||
@Comment("Controls the separation between ocean monuments")
|
@Comment("Controls the separation between ocean monuments")
|
||||||
public int oceanMonumentSeparation = 4;
|
public int oceanMonumentSeparation = 2;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user