Files
src
build.gradle
gradle.properties
settings.gradle
Code
6 137
src/main/java/com/kodari/farlands/mixin/NoiseChunkGeneratorMixin.java
package com.kodari.farlands.mixin;
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.registry.RegistryKey;
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
import net.minecraft.world.gen.chunk.ChunkNoiseSampler;
import net.minecraft.world.gen.chunk.NoiseChunkGenerator;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
@Mixin(NoiseChunkGenerator.class)
public abstract class NoiseChunkGeneratorMixin {
private static final int START = 12_550_824;
private static final int STAGE_LENGTH = 32_000;
@Shadow
public abstract boolean matchesSettings(RegistryKey<ChunkGeneratorSettings> settings);
@ModifyReturnValue(method = "getBlockState", at = @At("RETURN"))
private BlockState farlands_beyond$terrain(BlockState original, ChunkNoiseSampler sampler,
int x, int y, int z, BlockState state) {
if (!this.matchesSettings(ChunkGeneratorSettings.OVERWORLD)) {
return original;
}
int distance = Math.max(Math.abs(x), Math.abs(z));
if (distance < START) {
return original;
}
int stage = (distance - START) / STAGE_LENGTH;
if (stage >= 4) {
return Blocks.AIR.getDefaultState();
}
double density;
if (stage == 0) {
double walls = Math.sin(x * 0.017) + Math.sin(z * 0.017)
+ 0.55 * Math.sin(x * 0.043 + z * 0.031);
density = walls + Math.sin(y * 0.041 + x * 0.006) * 0.45 - (y - 90) / 115.0;
} else if (stage == 1) {
double lattice = Math.cos(x * Math.PI / 32.0) + Math.cos(z * Math.PI / 32.0);
density = lattice + Math.cos(y * Math.PI / 32.0) * 0.85 - 0.7;
} else if (stage == 2) {
double ridges = Math.cos((x + z) * Math.PI / 48.0)
+ Math.cos((x - z) * Math.PI / 48.0);
density = ridges + Math.cos(y * Math.PI / 24.0) * 0.65 - 0.95;
} else {
double islands = Math.cos(x * Math.PI / 64.0) + Math.cos(z * Math.PI / 64.0)
+ Math.cos((x + z) * Math.PI / 96.0) * 0.45;
density = islands - Math.abs(y - 100) / 32.0 - 1.25;
}
if (density <= 0.0) {
return Blocks.AIR.getDefaultState();
}
return Blocks.STONE.getDefaultState();
}
}