Skip to content

Commit 5848a5f

Browse files
authored
Merge pull request #177 from Chainmail-Studios/development
Merge fixes.
2 parents 60ddf8a + 3d061a3 commit 5848a5f

38 files changed

+437
-30
lines changed

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ api_version = 0.15.1+build.380-1.16.1
1111

1212
# Mod
1313
mod_name = astromine
14-
mod_version = 1.3.4
14+
mod_version = 1.3.5
1515
mod_group = com.github.chainmailstudios
1616
version_meta = fabric-1.16.1
1717

1818
# Dependencies
1919
cardinal_components_version = 2.4.2
20-
spinnery_version = 3.1.12+fabric-1.16.x
20+
spinnery_version = 3.1.14+fabric-1.16.x
2121
shapes_version = 2.0.0+build.10
2222
patchouli_version = 1.16-37.21-FABRIC
2323
lba_version = 0.7.1-pre.4

src/main/java/com/github/chainmailstudios/astromine/common/block/entity/VentBlockEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void tick() {
8181

8282
BlockPos output = position.offset(direction);
8383

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

8787
WorldAtmosphereComponent atmosphereComponent = componentProvider.getComponent(AstromineComponentTypes.WORLD_ATMOSPHERE_COMPONENT);

src/main/java/com/github/chainmailstudios/astromine/common/world/MoonBiome.java renamed to src/main/java/com/github/chainmailstudios/astromine/common/world/biome/DepthScaleBiome.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24-
package com.github.chainmailstudios.astromine.common.world;
24+
package com.github.chainmailstudios.astromine.common.world.biome;
2525

2626

2727
import net.minecraft.sound.BiomeMoodSound;
2828
import net.minecraft.world.biome.Biome;
2929
import net.minecraft.world.biome.BiomeEffects;
3030
import net.minecraft.world.gen.surfacebuilder.SurfaceBuilder;
3131

32-
public class MoonBiome extends Biome {
33-
public MoonBiome(float baseHeight, float variation) {
32+
public class DepthScaleBiome extends Biome {
33+
public DepthScaleBiome(float baseHeight, float variation) {
3434
super(new Settings().configureSurfaceBuilder(SurfaceBuilder.NOPE, SurfaceBuilder.STONE_CONFIG)
3535
.precipitation(Precipitation.NONE)
3636
.category(Category.NONE)

src/main/java/com/github/chainmailstudios/astromine/common/world/EarthSpaceBiome.java renamed to src/main/java/com/github/chainmailstudios/astromine/common/world/biome/EarthSpaceBiome.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24-
package com.github.chainmailstudios.astromine.common.world;
24+
package com.github.chainmailstudios.astromine.common.world.biome;
2525

2626
import com.github.chainmailstudios.astromine.registry.AstromineEntityTypes;
2727
import com.github.chainmailstudios.astromine.registry.AstromineFeatures;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.github.chainmailstudios.astromine.common.world.biome;
2+
3+
import com.github.chainmailstudios.astromine.registry.AstromineFeatures;
4+
5+
import net.minecraft.world.gen.GenerationStep;
6+
import net.minecraft.world.gen.decorator.CountDecoratorConfig;
7+
import net.minecraft.world.gen.decorator.Decorator;
8+
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
9+
10+
public class MoonBiome extends DepthScaleBiome {
11+
public MoonBiome(float baseHeight, float variation) {
12+
super(baseHeight, variation);
13+
this.addFeature(GenerationStep.Feature.RAW_GENERATION, AstromineFeatures.MOON_CRATER.configure(DefaultFeatureConfig.INSTANCE).createDecoratedFeature(Decorator.COUNT_HEIGHTMAP.configure(new CountDecoratorConfig(2))));
14+
}
15+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package com.github.chainmailstudios.astromine.common.world.feature;
2+
3+
import java.util.Random;
4+
5+
import com.github.chainmailstudios.astromine.common.noise.OpenSimplexNoise;
6+
import com.mojang.serialization.Codec;
7+
8+
import net.minecraft.block.Blocks;
9+
import net.minecraft.util.math.BlockPos;
10+
import net.minecraft.world.ServerWorldAccess;
11+
import net.minecraft.world.gen.StructureAccessor;
12+
import net.minecraft.world.gen.chunk.ChunkGenerator;
13+
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
14+
import net.minecraft.world.gen.feature.Feature;
15+
16+
public class MoonCraterFeature extends Feature<DefaultFeatureConfig> {
17+
private static final double SCALE = 1 / 19.42;
18+
private long seed = 0;
19+
private OpenSimplexNoise noise = new OpenSimplexNoise(0);
20+
21+
public MoonCraterFeature(Codec<DefaultFeatureConfig> configCodec) {
22+
super(configCodec);
23+
}
24+
25+
@Override
26+
public boolean generate(ServerWorldAccess world, StructureAccessor structureAccessor, ChunkGenerator generator, Random random, BlockPos pos, DefaultFeatureConfig config) {
27+
if (this.seed != world.getSeed()) {
28+
this.noise = new OpenSimplexNoise(world.getSeed());
29+
this.seed = world.getSeed();
30+
}
31+
32+
int radius = random.nextInt(7) + 4;
33+
34+
int radiusSquared = radius * radius;
35+
36+
for (int x = -radius; x <= radius; x++) {
37+
for (int z = -radius; z <= radius; z++) {
38+
39+
for (int y = -radius; y <= radius; y++) {
40+
int squareDistance = (x * x) + (y * y) + (z * z);
41+
42+
if (squareDistance <= radiusSquared) {
43+
BlockPos local = pos.add(x, y, z);
44+
45+
double noiseX = local.getX() * SCALE;
46+
double noiseY = local.getY() * SCALE;
47+
double noiseZ = local.getZ() * SCALE;
48+
49+
double noise = this.noise.sample(noiseX, noiseY, noiseZ);
50+
noise += computeNoiseFalloff(y, radius);
51+
52+
if (noise > 0 && !world.getBlockState(local).isAir()) {
53+
world.setBlockState(local, Blocks.AIR.getDefaultState(), 3);
54+
}
55+
}
56+
}
57+
}
58+
}
59+
60+
return true;
61+
}
62+
63+
private double computeNoiseFalloff(int y, int radius) {
64+
return -(2.0 / (y + radius + 0.5));
65+
}
66+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package com.github.chainmailstudios.astromine.common.world.generation.mars;
2+
3+
import java.util.function.LongFunction;
4+
5+
import com.github.chainmailstudios.astromine.common.world.layer.mars.MarsBiomeLayer;
6+
import com.github.chainmailstudios.astromine.common.world.layer.mars.MarsRiverLayer;
7+
import com.github.chainmailstudios.astromine.common.world.layer.util.PlainsOnlyLayer;
8+
import com.google.common.collect.ImmutableList;
9+
import com.mojang.serialization.Codec;
10+
11+
import net.minecraft.world.biome.Biome;
12+
import net.minecraft.world.biome.layer.ScaleLayer;
13+
import net.minecraft.world.biome.layer.SimpleLandNoiseLayer;
14+
import net.minecraft.world.biome.layer.util.CachingLayerContext;
15+
import net.minecraft.world.biome.layer.util.LayerFactory;
16+
import net.minecraft.world.biome.layer.util.LayerSampleContext;
17+
import net.minecraft.world.biome.layer.util.LayerSampler;
18+
import net.minecraft.world.biome.source.BiomeLayerSampler;
19+
import net.minecraft.world.biome.source.BiomeSource;
20+
21+
public class MarsBiomeSource extends BiomeSource {
22+
public static Codec<MarsBiomeSource> CODEC = Codec.LONG.fieldOf("seed").xmap(MarsBiomeSource::new, (source) -> source.seed).stable().codec();
23+
private final long seed;
24+
private final BiomeLayerSampler sampler;
25+
26+
public MarsBiomeSource(long seed) {
27+
super(ImmutableList.of());
28+
this.seed = seed;
29+
this.sampler = build(seed);
30+
}
31+
32+
@Override
33+
protected Codec<? extends BiomeSource> method_28442() {
34+
return CODEC;
35+
}
36+
37+
@Override
38+
public BiomeSource withSeed(long seed) {
39+
return new MarsBiomeSource(seed);
40+
}
41+
42+
@Override
43+
public Biome getBiomeForNoiseGen(int biomeX, int biomeY, int biomeZ) {
44+
return sampler.sample(biomeX, biomeZ);
45+
}
46+
47+
public static BiomeLayerSampler build(long seed) {
48+
return new BiomeLayerSampler(build((salt) -> new CachingLayerContext(25, seed, salt)));
49+
}
50+
51+
private static <T extends LayerSampler, C extends LayerSampleContext<T>> LayerFactory<T> build(LongFunction<C> contextProvider) {
52+
LayerFactory<T> mainLayer = SimpleLandNoiseLayer.INSTANCE.create(contextProvider.apply(432L), PlainsOnlyLayer.INSTANCE.create(contextProvider.apply(543L)));
53+
for (int i = 0; i < 7; i++) {
54+
mainLayer = ScaleLayer.NORMAL.create(contextProvider.apply(43 + i), mainLayer);
55+
}
56+
57+
mainLayer = MarsRiverLayer.INSTANCE.create(contextProvider.apply(56L), mainLayer);
58+
for (int i = 0; i < 2; i++) {
59+
mainLayer = ScaleLayer.NORMAL.create(contextProvider.apply(473 + i), mainLayer);
60+
}
61+
62+
mainLayer = MarsBiomeLayer.INSTANCE.create(contextProvider.apply(721), mainLayer);
63+
64+
return mainLayer;
65+
}
66+
}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
package com.github.chainmailstudios.astromine.common.world.generation.mars;
2+
3+
import java.util.Arrays;
4+
import java.util.Random;
5+
6+
import com.github.chainmailstudios.astromine.common.miscellaneous.BiomeGenCache;
7+
import com.github.chainmailstudios.astromine.common.noise.OctaveNoiseSampler;
8+
import com.github.chainmailstudios.astromine.common.noise.OpenSimplexNoise;
9+
import com.github.chainmailstudios.astromine.common.world.generation.moon.MoonBiomeSource;
10+
import com.github.chainmailstudios.astromine.registry.AstromineBlocks;
11+
import com.mojang.serialization.Codec;
12+
import com.mojang.serialization.codecs.RecordCodecBuilder;
13+
14+
import net.minecraft.block.BlockState;
15+
import net.minecraft.block.Blocks;
16+
import net.minecraft.util.math.BlockPos;
17+
import net.minecraft.util.math.MathHelper;
18+
import net.minecraft.world.BlockView;
19+
import net.minecraft.world.ChunkRegion;
20+
import net.minecraft.world.Heightmap;
21+
import net.minecraft.world.WorldAccess;
22+
import net.minecraft.world.biome.Biome;
23+
import net.minecraft.world.biome.source.BiomeSource;
24+
import net.minecraft.world.chunk.Chunk;
25+
import net.minecraft.world.gen.ChunkRandom;
26+
import net.minecraft.world.gen.StructureAccessor;
27+
import net.minecraft.world.gen.chunk.ChunkGenerator;
28+
import net.minecraft.world.gen.chunk.StructuresConfig;
29+
import net.minecraft.world.gen.chunk.VerticalBlockSample;
30+
31+
public class MarsChunkGenerator extends ChunkGenerator {
32+
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))
33+
.apply(instance, MarsChunkGenerator::new));
34+
35+
private final BiomeSource biomeSource;
36+
private final long seed;
37+
private final OctaveNoiseSampler<OpenSimplexNoise> lowerInterpolatedNoise;
38+
private final OctaveNoiseSampler<OpenSimplexNoise> upperInterpolatedNoise;
39+
private final OctaveNoiseSampler<OpenSimplexNoise> interpolationNoise;
40+
private final ThreadLocal<BiomeGenCache> cache;
41+
public MarsChunkGenerator(BiomeSource biomeSource, long seed) {
42+
super(biomeSource, new StructuresConfig(false));
43+
this.biomeSource = biomeSource;
44+
this.seed = seed;
45+
Random random = new Random(seed);
46+
lowerInterpolatedNoise = new OctaveNoiseSampler<>(OpenSimplexNoise.class, random, 5, 140.43, 45, 10);
47+
upperInterpolatedNoise = new OctaveNoiseSampler<>(OpenSimplexNoise.class, random, 5, 140.43, 45, 10);
48+
interpolationNoise = new OctaveNoiseSampler<>(OpenSimplexNoise.class, random, 3, 80.32, 3, 3);
49+
this.cache = ThreadLocal.withInitial(() -> new BiomeGenCache(biomeSource));
50+
}
51+
52+
@Override
53+
protected Codec<? extends ChunkGenerator> method_28506() {
54+
return CODEC;
55+
}
56+
57+
@Override
58+
public ChunkGenerator withSeed(long seed) {
59+
return new MarsChunkGenerator(new MoonBiomeSource(seed), seed);
60+
}
61+
62+
@Override
63+
public void buildSurface(ChunkRegion region, Chunk chunk) {
64+
// Unused.
65+
}
66+
67+
@Override
68+
public void populateNoise(WorldAccess world, StructureAccessor accessor, Chunk chunk) {
69+
int x1 = chunk.getPos().getStartX();
70+
int z1 = chunk.getPos().getStartZ();
71+
72+
int x2 = chunk.getPos().getEndX();
73+
int z2 = chunk.getPos().getEndZ();
74+
75+
ChunkRandom chunkRandom = new ChunkRandom();
76+
chunkRandom.setTerrainSeed(chunk.getPos().x, chunk.getPos().z);
77+
78+
for (int x = x1; x <= x2; ++x) {
79+
for (int z = z1; z <= z2; ++z) {
80+
float depth = 0;
81+
float scale = 0;
82+
int i = 0;
83+
84+
// Biome lerp
85+
for (int x0 = -5; x0 <= 5; x0++) {
86+
for (int z0 = -5; z0 <= 5; z0++) {
87+
Biome biome = this.cache.get().getBiome((x + x0) >> 2, (z + z0) >> 2);
88+
89+
i++;
90+
depth += biome.getDepth();
91+
scale += biome.getScale();
92+
}
93+
}
94+
95+
depth /= i;
96+
scale /= i;
97+
98+
// Noise calculation
99+
double noise = interpolationNoise.sample(x, z);
100+
if (noise >= 1) {
101+
noise = upperInterpolatedNoise.sample(x, z);
102+
} else if (noise <= -1) {
103+
noise = lowerInterpolatedNoise.sample(x, z);
104+
} else {
105+
noise = MathHelper.clampedLerp(lowerInterpolatedNoise.sample(x, z), upperInterpolatedNoise.sample(x, z), noise);
106+
}
107+
108+
int height = (int) (depth + (noise * scale));
109+
for (int y = 0; y <= height; ++y) {
110+
chunk.setBlockState(new BlockPos(x, y, z), AstromineBlocks.MARS_SOIL.getDefaultState(), false);
111+
if (y <= 5) {
112+
if (chunkRandom.nextInt(y + 1) == 0) {
113+
chunk.setBlockState(new BlockPos(x, y, z), Blocks.BEDROCK.getDefaultState(), false);
114+
}
115+
}
116+
}
117+
}
118+
}
119+
}
120+
121+
@Override
122+
public int getHeight(int x, int z, Heightmap.Type heightmapType) {
123+
return 0;
124+
}
125+
126+
@Override
127+
public BlockView getColumnSample(int x, int z) {
128+
BlockState[] states = new BlockState[256];
129+
Arrays.fill(states, Blocks.AIR.getDefaultState());
130+
return new VerticalBlockSample(states);
131+
}
132+
}

src/main/java/com/github/chainmailstudios/astromine/common/world/generation/MoonBiomeSource.java renamed to src/main/java/com/github/chainmailstudios/astromine/common/world/generation/moon/MoonBiomeSource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24-
package com.github.chainmailstudios.astromine.common.world.generation;
24+
package com.github.chainmailstudios.astromine.common.world.generation.moon;
2525

2626
import java.util.function.LongFunction;
2727

28-
import com.github.chainmailstudios.astromine.common.world.layer.MoonBiomeLayer;
28+
import com.github.chainmailstudios.astromine.common.world.layer.moon.MoonBiomeLayer;
2929
import com.google.common.collect.ImmutableList;
3030
import com.mojang.serialization.Codec;
3131

src/main/java/com/github/chainmailstudios/astromine/common/world/generation/MoonChunkGenerator.java renamed to src/main/java/com/github/chainmailstudios/astromine/common/world/generation/moon/MoonChunkGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24-
package com.github.chainmailstudios.astromine.common.world.generation;
24+
package com.github.chainmailstudios.astromine.common.world.generation.moon;
2525

2626
import java.util.Arrays;
2727

0 commit comments

Comments
 (0)