-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #177 from Chainmail-Studios/development
Merge fixes.
- Loading branch information
Showing
38 changed files
with
437 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/com/github/chainmailstudios/astromine/common/world/biome/MoonBiome.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.github.chainmailstudios.astromine.common.world.biome; | ||
|
||
import com.github.chainmailstudios.astromine.registry.AstromineFeatures; | ||
|
||
import net.minecraft.world.gen.GenerationStep; | ||
import net.minecraft.world.gen.decorator.CountDecoratorConfig; | ||
import net.minecraft.world.gen.decorator.Decorator; | ||
import net.minecraft.world.gen.feature.DefaultFeatureConfig; | ||
|
||
public class MoonBiome extends DepthScaleBiome { | ||
public MoonBiome(float baseHeight, float variation) { | ||
super(baseHeight, variation); | ||
this.addFeature(GenerationStep.Feature.RAW_GENERATION, AstromineFeatures.MOON_CRATER.configure(DefaultFeatureConfig.INSTANCE).createDecoratedFeature(Decorator.COUNT_HEIGHTMAP.configure(new CountDecoratorConfig(2)))); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...in/java/com/github/chainmailstudios/astromine/common/world/feature/MoonCraterFeature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.github.chainmailstudios.astromine.common.world.feature; | ||
|
||
import java.util.Random; | ||
|
||
import com.github.chainmailstudios.astromine.common.noise.OpenSimplexNoise; | ||
import com.mojang.serialization.Codec; | ||
|
||
import net.minecraft.block.Blocks; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.ServerWorldAccess; | ||
import net.minecraft.world.gen.StructureAccessor; | ||
import net.minecraft.world.gen.chunk.ChunkGenerator; | ||
import net.minecraft.world.gen.feature.DefaultFeatureConfig; | ||
import net.minecraft.world.gen.feature.Feature; | ||
|
||
public class MoonCraterFeature extends Feature<DefaultFeatureConfig> { | ||
private static final double SCALE = 1 / 19.42; | ||
private long seed = 0; | ||
private OpenSimplexNoise noise = new OpenSimplexNoise(0); | ||
|
||
public MoonCraterFeature(Codec<DefaultFeatureConfig> configCodec) { | ||
super(configCodec); | ||
} | ||
|
||
@Override | ||
public boolean generate(ServerWorldAccess world, StructureAccessor structureAccessor, ChunkGenerator generator, Random random, BlockPos pos, DefaultFeatureConfig config) { | ||
if (this.seed != world.getSeed()) { | ||
this.noise = new OpenSimplexNoise(world.getSeed()); | ||
this.seed = world.getSeed(); | ||
} | ||
|
||
int radius = random.nextInt(7) + 4; | ||
|
||
int radiusSquared = radius * radius; | ||
|
||
for (int x = -radius; x <= radius; x++) { | ||
for (int z = -radius; z <= radius; z++) { | ||
|
||
for (int y = -radius; y <= radius; y++) { | ||
int squareDistance = (x * x) + (y * y) + (z * z); | ||
|
||
if (squareDistance <= radiusSquared) { | ||
BlockPos local = pos.add(x, y, z); | ||
|
||
double noiseX = local.getX() * SCALE; | ||
double noiseY = local.getY() * SCALE; | ||
double noiseZ = local.getZ() * SCALE; | ||
|
||
double noise = this.noise.sample(noiseX, noiseY, noiseZ); | ||
noise += computeNoiseFalloff(y, radius); | ||
|
||
if (noise > 0 && !world.getBlockState(local).isAir()) { | ||
world.setBlockState(local, Blocks.AIR.getDefaultState(), 3); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
private double computeNoiseFalloff(int y, int radius) { | ||
return -(2.0 / (y + radius + 0.5)); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...a/com/github/chainmailstudios/astromine/common/world/generation/mars/MarsBiomeSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.github.chainmailstudios.astromine.common.world.generation.mars; | ||
|
||
import java.util.function.LongFunction; | ||
|
||
import com.github.chainmailstudios.astromine.common.world.layer.mars.MarsBiomeLayer; | ||
import com.github.chainmailstudios.astromine.common.world.layer.mars.MarsRiverLayer; | ||
import com.github.chainmailstudios.astromine.common.world.layer.util.PlainsOnlyLayer; | ||
import com.google.common.collect.ImmutableList; | ||
import com.mojang.serialization.Codec; | ||
|
||
import net.minecraft.world.biome.Biome; | ||
import net.minecraft.world.biome.layer.ScaleLayer; | ||
import net.minecraft.world.biome.layer.SimpleLandNoiseLayer; | ||
import net.minecraft.world.biome.layer.util.CachingLayerContext; | ||
import net.minecraft.world.biome.layer.util.LayerFactory; | ||
import net.minecraft.world.biome.layer.util.LayerSampleContext; | ||
import net.minecraft.world.biome.layer.util.LayerSampler; | ||
import net.minecraft.world.biome.source.BiomeLayerSampler; | ||
import net.minecraft.world.biome.source.BiomeSource; | ||
|
||
public class MarsBiomeSource extends BiomeSource { | ||
public static Codec<MarsBiomeSource> CODEC = Codec.LONG.fieldOf("seed").xmap(MarsBiomeSource::new, (source) -> source.seed).stable().codec(); | ||
private final long seed; | ||
private final BiomeLayerSampler sampler; | ||
|
||
public MarsBiomeSource(long seed) { | ||
super(ImmutableList.of()); | ||
this.seed = seed; | ||
this.sampler = build(seed); | ||
} | ||
|
||
@Override | ||
protected Codec<? extends BiomeSource> method_28442() { | ||
return CODEC; | ||
} | ||
|
||
@Override | ||
public BiomeSource withSeed(long seed) { | ||
return new MarsBiomeSource(seed); | ||
} | ||
|
||
@Override | ||
public Biome getBiomeForNoiseGen(int biomeX, int biomeY, int biomeZ) { | ||
return sampler.sample(biomeX, biomeZ); | ||
} | ||
|
||
public static BiomeLayerSampler build(long seed) { | ||
return new BiomeLayerSampler(build((salt) -> new CachingLayerContext(25, seed, salt))); | ||
} | ||
|
||
private static <T extends LayerSampler, C extends LayerSampleContext<T>> LayerFactory<T> build(LongFunction<C> contextProvider) { | ||
LayerFactory<T> mainLayer = SimpleLandNoiseLayer.INSTANCE.create(contextProvider.apply(432L), PlainsOnlyLayer.INSTANCE.create(contextProvider.apply(543L))); | ||
for (int i = 0; i < 7; i++) { | ||
mainLayer = ScaleLayer.NORMAL.create(contextProvider.apply(43 + i), mainLayer); | ||
} | ||
|
||
mainLayer = MarsRiverLayer.INSTANCE.create(contextProvider.apply(56L), mainLayer); | ||
for (int i = 0; i < 2; i++) { | ||
mainLayer = ScaleLayer.NORMAL.create(contextProvider.apply(473 + i), mainLayer); | ||
} | ||
|
||
mainLayer = MarsBiomeLayer.INSTANCE.create(contextProvider.apply(721), mainLayer); | ||
|
||
return mainLayer; | ||
} | ||
} |
132 changes: 132 additions & 0 deletions
132
...om/github/chainmailstudios/astromine/common/world/generation/mars/MarsChunkGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
package com.github.chainmailstudios.astromine.common.world.generation.mars; | ||
|
||
import java.util.Arrays; | ||
import java.util.Random; | ||
|
||
import com.github.chainmailstudios.astromine.common.miscellaneous.BiomeGenCache; | ||
import com.github.chainmailstudios.astromine.common.noise.OctaveNoiseSampler; | ||
import com.github.chainmailstudios.astromine.common.noise.OpenSimplexNoise; | ||
import com.github.chainmailstudios.astromine.common.world.generation.moon.MoonBiomeSource; | ||
import com.github.chainmailstudios.astromine.registry.AstromineBlocks; | ||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
|
||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.Blocks; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.MathHelper; | ||
import net.minecraft.world.BlockView; | ||
import net.minecraft.world.ChunkRegion; | ||
import net.minecraft.world.Heightmap; | ||
import net.minecraft.world.WorldAccess; | ||
import net.minecraft.world.biome.Biome; | ||
import net.minecraft.world.biome.source.BiomeSource; | ||
import net.minecraft.world.chunk.Chunk; | ||
import net.minecraft.world.gen.ChunkRandom; | ||
import net.minecraft.world.gen.StructureAccessor; | ||
import net.minecraft.world.gen.chunk.ChunkGenerator; | ||
import net.minecraft.world.gen.chunk.StructuresConfig; | ||
import net.minecraft.world.gen.chunk.VerticalBlockSample; | ||
|
||
public class MarsChunkGenerator extends ChunkGenerator { | ||
public static Codec<MarsChunkGenerator> CODEC = RecordCodecBuilder.create(instance -> instance.group(BiomeSource.field_24713.fieldOf("biome_source").forGetter(gen -> gen.biomeSource), Codec.LONG.fieldOf("seed").forGetter(gen -> gen.seed)) | ||
.apply(instance, MarsChunkGenerator::new)); | ||
|
||
private final BiomeSource biomeSource; | ||
private final long seed; | ||
private final OctaveNoiseSampler<OpenSimplexNoise> lowerInterpolatedNoise; | ||
private final OctaveNoiseSampler<OpenSimplexNoise> upperInterpolatedNoise; | ||
private final OctaveNoiseSampler<OpenSimplexNoise> interpolationNoise; | ||
private final ThreadLocal<BiomeGenCache> cache; | ||
public MarsChunkGenerator(BiomeSource biomeSource, long seed) { | ||
super(biomeSource, new StructuresConfig(false)); | ||
this.biomeSource = biomeSource; | ||
this.seed = seed; | ||
Random random = new Random(seed); | ||
lowerInterpolatedNoise = new OctaveNoiseSampler<>(OpenSimplexNoise.class, random, 5, 140.43, 45, 10); | ||
upperInterpolatedNoise = new OctaveNoiseSampler<>(OpenSimplexNoise.class, random, 5, 140.43, 45, 10); | ||
interpolationNoise = new OctaveNoiseSampler<>(OpenSimplexNoise.class, random, 3, 80.32, 3, 3); | ||
this.cache = ThreadLocal.withInitial(() -> new BiomeGenCache(biomeSource)); | ||
} | ||
|
||
@Override | ||
protected Codec<? extends ChunkGenerator> method_28506() { | ||
return CODEC; | ||
} | ||
|
||
@Override | ||
public ChunkGenerator withSeed(long seed) { | ||
return new MarsChunkGenerator(new MoonBiomeSource(seed), seed); | ||
} | ||
|
||
@Override | ||
public void buildSurface(ChunkRegion region, Chunk chunk) { | ||
// Unused. | ||
} | ||
|
||
@Override | ||
public void populateNoise(WorldAccess world, StructureAccessor accessor, Chunk chunk) { | ||
int x1 = chunk.getPos().getStartX(); | ||
int z1 = chunk.getPos().getStartZ(); | ||
|
||
int x2 = chunk.getPos().getEndX(); | ||
int z2 = chunk.getPos().getEndZ(); | ||
|
||
ChunkRandom chunkRandom = new ChunkRandom(); | ||
chunkRandom.setTerrainSeed(chunk.getPos().x, chunk.getPos().z); | ||
|
||
for (int x = x1; x <= x2; ++x) { | ||
for (int z = z1; z <= z2; ++z) { | ||
float depth = 0; | ||
float scale = 0; | ||
int i = 0; | ||
|
||
// Biome lerp | ||
for (int x0 = -5; x0 <= 5; x0++) { | ||
for (int z0 = -5; z0 <= 5; z0++) { | ||
Biome biome = this.cache.get().getBiome((x + x0) >> 2, (z + z0) >> 2); | ||
|
||
i++; | ||
depth += biome.getDepth(); | ||
scale += biome.getScale(); | ||
} | ||
} | ||
|
||
depth /= i; | ||
scale /= i; | ||
|
||
// Noise calculation | ||
double noise = interpolationNoise.sample(x, z); | ||
if (noise >= 1) { | ||
noise = upperInterpolatedNoise.sample(x, z); | ||
} else if (noise <= -1) { | ||
noise = lowerInterpolatedNoise.sample(x, z); | ||
} else { | ||
noise = MathHelper.clampedLerp(lowerInterpolatedNoise.sample(x, z), upperInterpolatedNoise.sample(x, z), noise); | ||
} | ||
|
||
int height = (int) (depth + (noise * scale)); | ||
for (int y = 0; y <= height; ++y) { | ||
chunk.setBlockState(new BlockPos(x, y, z), AstromineBlocks.MARS_SOIL.getDefaultState(), false); | ||
if (y <= 5) { | ||
if (chunkRandom.nextInt(y + 1) == 0) { | ||
chunk.setBlockState(new BlockPos(x, y, z), Blocks.BEDROCK.getDefaultState(), false); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public int getHeight(int x, int z, Heightmap.Type heightmapType) { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public BlockView getColumnSample(int x, int z) { | ||
BlockState[] states = new BlockState[256]; | ||
Arrays.fill(states, Blocks.AIR.getDefaultState()); | ||
return new VerticalBlockSample(states); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.