Carvers

Generate Minecraft worlds by map images!

  1. Noise Carver
  2. Registering Carver Types

Carvers ‘carve’ blocks out, so Caves result.

Noise Carver

Places a Block by checking a defined noise and it’s thresholds. A block will be placed if the calculated noise value is lower than the threshold value.

{
  "type": "ctgen:noise_carver",
  "noise": {
    "octaves": [
      {
        "frequency": 1,
        "amplitude": 1
      },
      {
        "frequency": 0.5,
        "amplitude": 2
      }
    ],
    "persistence": 2,
    "stretch": 63,
    "stretch_y": 47
  },
  "threshold": 0.55
}
  • noise - a noise codec
    • octaves - the octaves for the SimplexNoise. Will be applied in the specified order
    • persistence - multiplies the amplitude for each octave
    • stretch - stretch the noise in x and z direction
    • stretch_y - stretch the noise in y direction
  • threshold - the threshold that must be exceeded by the noise value

Or in Java:

TerrainHeight terrainHeight = new NoiseCarver(new Noise(List.of(1F, 0.5F), 2, 63, 47), 0.55F);

Registering Carver Types

You can also register a custom carver using code similar to this one:

public class NoiseCarver extends Carver {
    public static final NoiseCarver DEFAULT = new NoiseCarver(new Noise(List.of(1F, 0.5F), 2, 63, 47), 0.55F);

    public static final Codec<NoiseCarver> CODEC = RecordCodecBuilder.create(instance -> instance.group(
            Noise.CODEC.optionalFieldOf("noise", DEFAULT.noise).forGetter(o -> o.noise),
            Codec.DOUBLE.optionalFieldOf("threshold", DEFAULT.threshold).forGetter(o -> o.threshold)
    ).apply(instance, NoiseCarver::new));
    public static final ResourceLocation ID = new ResourceLocation(YourMod.MODID, "noise_carver");

    private final Noise noise;
    private final double threshold;

    public NoiseCarver(Noise noise, double threshold) {
        this.noise = noise;
        this.threshold = threshold;
    }


    @Override
    public boolean canSetBlock(SimplexNoise noise, @NotNull BlockPos pos, double surfaceHeight, int minHeight, double carverModifier) {
        double height = (double) (pos.getY() - minHeight) / (surfaceHeight - minHeight) - 0.5;
        double addThreshold = height * height * height * height * carverModifier;

        double perlin = this.noise.getPerlin(noise, pos.getX(), pos.getY(), pos.getZ());

        double threshold = this.threshold + addThreshold;
        return !(perlin > threshold);
    }

    @Override
    protected Codec<NoiseCarver> codec() {
        return CODEC;
    }
}

To register the layer, just use this snippet:

CTRegistries.CARVER.register(NoiseCarver.ID, NoiseCarver.CODEC);

Continue with Layers