Skip to content

Commit

Permalink
Merge pull request #177 from Chainmail-Studios/development
Browse files Browse the repository at this point in the history
Merge fixes.
  • Loading branch information
Shnupbups authored Jul 24, 2020
2 parents 60ddf8a + 3d061a3 commit 5848a5f
Show file tree
Hide file tree
Showing 38 changed files with 437 additions and 30 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ api_version = 0.15.1+build.380-1.16.1

# Mod
mod_name = astromine
mod_version = 1.3.4
mod_version = 1.3.5
mod_group = com.github.chainmailstudios
version_meta = fabric-1.16.1

# Dependencies
cardinal_components_version = 2.4.2
spinnery_version = 3.1.12+fabric-1.16.x
spinnery_version = 3.1.14+fabric-1.16.x
shapes_version = 2.0.0+build.10
patchouli_version = 1.16-37.21-FABRIC
lba_version = 0.7.1-pre.4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void tick() {

BlockPos output = position.offset(direction);

if (asEnergy().use(50) && world.getBlockState(output).getBlock() instanceof AirBlock) {
if (asEnergy().use(AstromineConfig.get().ventEnergyConsumed) && world.getBlockState(output).getBlock() instanceof AirBlock) {
ComponentProvider componentProvider = ComponentProvider.fromWorld(world);

WorldAtmosphereComponent atmosphereComponent = componentProvider.getComponent(AstromineComponentTypes.WORLD_ATMOSPHERE_COMPONENT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.chainmailstudios.astromine.common.world;
package com.github.chainmailstudios.astromine.common.world.biome;


import net.minecraft.sound.BiomeMoodSound;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.BiomeEffects;
import net.minecraft.world.gen.surfacebuilder.SurfaceBuilder;

public class MoonBiome extends Biome {
public MoonBiome(float baseHeight, float variation) {
public class DepthScaleBiome extends Biome {
public DepthScaleBiome(float baseHeight, float variation) {
super(new Settings().configureSurfaceBuilder(SurfaceBuilder.NOPE, SurfaceBuilder.STONE_CONFIG)
.precipitation(Precipitation.NONE)
.category(Category.NONE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.chainmailstudios.astromine.common.world;
package com.github.chainmailstudios.astromine.common.world.biome;

import com.github.chainmailstudios.astromine.registry.AstromineEntityTypes;
import com.github.chainmailstudios.astromine.registry.AstromineFeatures;
Expand Down
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))));
}
}
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));
}
}
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;
}
}
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.chainmailstudios.astromine.common.world.generation;
package com.github.chainmailstudios.astromine.common.world.generation.moon;

import java.util.function.LongFunction;

import com.github.chainmailstudios.astromine.common.world.layer.MoonBiomeLayer;
import com.github.chainmailstudios.astromine.common.world.layer.moon.MoonBiomeLayer;
import com.google.common.collect.ImmutableList;
import com.mojang.serialization.Codec;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.chainmailstudios.astromine.common.world.generation;
package com.github.chainmailstudios.astromine.common.world.generation.moon;

import java.util.Arrays;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.chainmailstudios.astromine.common.world.generation;
package com.github.chainmailstudios.astromine.common.world.generation.space;

import com.github.chainmailstudios.astromine.registry.AstromineBiomes;
import com.google.common.collect.ImmutableList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.chainmailstudios.astromine.common.world.generation;
package com.github.chainmailstudios.astromine.common.world.generation.space;

import com.github.chainmailstudios.astromine.common.noise.OctaveNoiseSampler;
import com.github.chainmailstudios.astromine.common.noise.OpenSimplexNoise;
Expand Down
Loading

0 comments on commit 5848a5f

Please sign in to comment.