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
@@ -46,8 +46,10 @@ public class MeteoriteSpawner {
int minY = 10 + stepSize;
BlockPos.Mutable mutablePos = new BlockPos.Mutable(startPos);
// Place the center on the first solid ground block
int startY = world.getHeight(Heightmap.Type.WORLD_SURFACE_WG, startPos).getY();
// Place the center on the first solid ground block, but move it down a little
// to embed the meteorite more
// in the ground
int startY = world.getHeight(Heightmap.Type.WORLD_SURFACE_WG, startPos).getY() - stepSize / 2;
mutablePos.setY(startY);
while (mutablePos.getY() > minY) {
@@ -1,26 +1,25 @@
package appeng.worldgen;
import java.util.Iterator;
import java.util.Random;
import java.util.function.Function;
import com.mojang.datafixers.Dynamic;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.MutableBoundingBox;
import net.minecraft.world.IWorld;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.BiomeManager;
import net.minecraft.world.gen.ChunkGenerator;
import net.minecraft.world.gen.GenerationSettings;
import net.minecraft.world.gen.Heightmap;
import net.minecraft.world.gen.EndChunkGenerator;
import net.minecraft.world.gen.NetherChunkGenerator;
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 appeng.core.AEConfig;
import appeng.core.AELog;
import appeng.core.AppEng;
public class MeteoriteStructure extends ScatteredStructure<NoFeatureConfig> {
@@ -36,12 +35,21 @@ public class MeteoriteStructure extends ScatteredStructure<NoFeatureConfig> {
}
@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) {
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 j = chunkZ >> 4;
randIn.setSeed((long) (i ^ j << 4) ^ generatorIn.getSeed());
randIn.setSeed((long) (i ^ j << 4) ^ generator.getSeed());
randIn.nextInt();
return randIn.nextBoolean();
}
@@ -75,8 +83,7 @@ public class MeteoriteStructure extends ScatteredStructure<NoFeatureConfig> {
}
public void init(ChunkGenerator<?> generator, TemplateManager templateManagerIn, int chunkX, int chunkZ,
Biome biomeIn) {
Biome biome) {
float meteoriteSize = (this.rand.nextFloat() * 6.0f) + 2;
int centerX = chunkX * 16 + rand.nextInt(16);