Prevent meteorites from generating in the end or nether.

This commit is contained in:
Sebastian Hartte
2020-06-21 17:18:14 +02:00
parent 25413c58f6
commit 2ed64f4944
3 changed files with 59 additions and 38 deletions
+22 -10
View File
@@ -637,8 +637,6 @@ final class Registration {
// StorageWorldProvider.class ); // StorageWorldProvider.class );
registries.worldgen().disableWorldGenForDimension(type, DimensionType.THE_NETHER.getRegistryName()); registries.worldgen().disableWorldGenForDimension(type, DimensionType.THE_NETHER.getRegistryName());
registries.worldgen().disableWorldGenForDimension(type, DimensionType.THE_NETHER.getRegistryName());
} }
// whitelist from config // whitelist from config
@@ -648,18 +646,35 @@ final class Registration {
} }
ForgeRegistries.BIOMES.forEach(b -> { ForgeRegistries.BIOMES.forEach(b -> {
// b.addFeature(GenerationStage.Decoration.TOP_LAYER_MODIFICATION, addMeteoriteWorldGen(b);
// new ConfiguredFeature<NoFeatureConfig, Feature<NoFeatureConfig>>(MeteoriteWorldGen.INSTANCE, addQuartzWorldGen(b);
// IFeatureConfig.NO_FEATURE_CONFIG)); });
}
private static void addMeteoriteWorldGen(Biome b) {
if (!AEConfig.instance().isFeatureEnabled(AEFeature.METEORITE_WORLD_GEN)) {
return;
}
if (b.getCategory() == Biome.Category.THEEND || b.getCategory() == Biome.Category.NETHER) {
return;
}
b.addStructure(MeteoriteStructure.INSTANCE.withConfiguration(IFeatureConfig.NO_FEATURE_CONFIG)); b.addStructure(MeteoriteStructure.INSTANCE.withConfiguration(IFeatureConfig.NO_FEATURE_CONFIG));
b.addFeature(GenerationStage.Decoration.TOP_LAYER_MODIFICATION, b.addFeature(GenerationStage.Decoration.TOP_LAYER_MODIFICATION,
MeteoriteStructure.INSTANCE.withConfiguration(IFeatureConfig.NO_FEATURE_CONFIG) MeteoriteStructure.INSTANCE.withConfiguration(IFeatureConfig.NO_FEATURE_CONFIG)
.withPlacement(Placement.NOPE.configure(IPlacementConfig.NO_PLACEMENT_CONFIG))); .withPlacement(Placement.NOPE.configure(IPlacementConfig.NO_PLACEMENT_CONFIG)));
}
private static void addQuartzWorldGen(Biome b) {
if (!AEConfig.instance().isFeatureEnabled(AEFeature.CERTUS_QUARTZ_WORLD_GEN)) {
return;
}
if (AEConfig.instance().isFeatureEnabled(AEFeature.CERTUS_QUARTZ_WORLD_GEN)) {
BlockState quartzOre = AEApi.instance().definitions().blocks().quartzOre().block().getDefaultState(); BlockState quartzOre = AEApi.instance().definitions().blocks().quartzOre().block().getDefaultState();
b.addFeature(GenerationStage.Decoration.UNDERGROUND_ORES, Feature.ORE b.addFeature(GenerationStage.Decoration.UNDERGROUND_ORES,
Feature.ORE
.withConfiguration(new OreFeatureConfig(OreFeatureConfig.FillerBlockType.NATURAL_STONE, .withConfiguration(new OreFeatureConfig(OreFeatureConfig.FillerBlockType.NATURAL_STONE,
quartzOre, AEConfig.instance().getQuartzOresPerCluster())) quartzOre, AEConfig.instance().getQuartzOresPerCluster()))
.withPlacement(Placement.COUNT_RANGE.configure( .withPlacement(Placement.COUNT_RANGE.configure(
@@ -677,9 +692,6 @@ final class Registration {
} }
} }
});
}
public void registerWorldGen(RegistryEvent.Register<Feature<?>> evt) { public void registerWorldGen(RegistryEvent.Register<Feature<?>> evt) {
IForgeRegistry<Feature<?>> r = evt.getRegistry(); IForgeRegistry<Feature<?>> r = evt.getRegistry();
@@ -46,8 +46,10 @@ public class MeteoriteSpawner {
int minY = 10 + stepSize; int minY = 10 + stepSize;
BlockPos.Mutable mutablePos = new BlockPos.Mutable(startPos); BlockPos.Mutable mutablePos = new BlockPos.Mutable(startPos);
// Place the center on the first solid ground block // Place the center on the first solid ground block, but move it down a little
int startY = world.getHeight(Heightmap.Type.WORLD_SURFACE_WG, startPos).getY(); // to embed the meteorite more
// in the ground
int startY = world.getHeight(Heightmap.Type.WORLD_SURFACE_WG, startPos).getY() - stepSize / 2;
mutablePos.setY(startY); mutablePos.setY(startY);
while (mutablePos.getY() > minY) { while (mutablePos.getY() > minY) {
@@ -1,26 +1,25 @@
package appeng.worldgen; package appeng.worldgen;
import java.util.Iterator;
import java.util.Random; import java.util.Random;
import java.util.function.Function; import java.util.function.Function;
import com.mojang.datafixers.Dynamic; import com.mojang.datafixers.Dynamic;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.MutableBoundingBox; import net.minecraft.util.math.MutableBoundingBox;
import net.minecraft.world.IWorld;
import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.BiomeManager; import net.minecraft.world.biome.BiomeManager;
import net.minecraft.world.gen.ChunkGenerator; import net.minecraft.world.gen.ChunkGenerator;
import net.minecraft.world.gen.GenerationSettings; import net.minecraft.world.gen.EndChunkGenerator;
import net.minecraft.world.gen.Heightmap; import net.minecraft.world.gen.NetherChunkGenerator;
import net.minecraft.world.gen.feature.NoFeatureConfig; import net.minecraft.world.gen.feature.NoFeatureConfig;
import net.minecraft.world.gen.feature.structure.*; import net.minecraft.world.gen.feature.structure.ScatteredStructure;
import net.minecraft.world.gen.feature.structure.Structure;
import net.minecraft.world.gen.feature.structure.StructureStart;
import net.minecraft.world.gen.feature.template.TemplateManager; import net.minecraft.world.gen.feature.template.TemplateManager;
import appeng.core.AEConfig; import appeng.core.AEConfig;
import appeng.core.AELog;
import appeng.core.AppEng; import appeng.core.AppEng;
public class MeteoriteStructure extends ScatteredStructure<NoFeatureConfig> { public class MeteoriteStructure extends ScatteredStructure<NoFeatureConfig> {
@@ -36,12 +35,21 @@ public class MeteoriteStructure extends ScatteredStructure<NoFeatureConfig> {
} }
@Override @Override
public boolean canBeGenerated(BiomeManager biomeManagerIn, ChunkGenerator<?> generatorIn, Random randIn, int chunkX, public boolean canBeGenerated(BiomeManager biomeManagerIn, ChunkGenerator<?> generator, Random randIn, int chunkX,
int chunkZ, Biome biomeIn) { int chunkZ, Biome biomeIn) {
if (super.canBeGenerated(biomeManagerIn, generatorIn, randIn, chunkX, chunkZ, biomeIn)) { if (super.canBeGenerated(biomeManagerIn, generator, randIn, chunkX, chunkZ, biomeIn)) {
// In case the biome blacklist fails, we still double-check here that we're not
// generating chunks for
// the nether or end.
if (generator.getClass().equals(EndChunkGenerator.class)
|| generator.getClass().equals(NetherChunkGenerator.class)) {
AELog.warn("ignoring attempt to generate meteorite in nether/end.");
return false;
}
int i = chunkX >> 4; int i = chunkX >> 4;
int j = chunkZ >> 4; int j = chunkZ >> 4;
randIn.setSeed((long) (i ^ j << 4) ^ generatorIn.getSeed()); randIn.setSeed((long) (i ^ j << 4) ^ generator.getSeed());
randIn.nextInt(); randIn.nextInt();
return randIn.nextBoolean(); return randIn.nextBoolean();
} }
@@ -75,8 +83,7 @@ public class MeteoriteStructure extends ScatteredStructure<NoFeatureConfig> {
} }
public void init(ChunkGenerator<?> generator, TemplateManager templateManagerIn, int chunkX, int chunkZ, public void init(ChunkGenerator<?> generator, TemplateManager templateManagerIn, int chunkX, int chunkZ,
Biome biomeIn) { Biome biome) {
float meteoriteSize = (this.rand.nextFloat() * 6.0f) + 2; float meteoriteSize = (this.rand.nextFloat() * 6.0f) + 2;
int centerX = chunkX * 16 + rand.nextInt(16); int centerX = chunkX * 16 + rand.nextInt(16);