| 1 | package net.minecraft.world.level.levelgen.densityfunction;
|
| 2 |
|
| 3 | import com.mojang.serialization.Codec;
|
| 4 | import com.mojang.serialization.MapCodec;
|
| 5 | import java.lang.annotation.ElementType;
|
| 6 | import java.lang.annotation.Retention;
|
| 7 | import java.lang.annotation.RetentionPolicy;
|
| 8 | import java.lang.annotation.Target;
|
| 9 | import net.minecraft.core.Direction;
|
| 10 | import net.minecraft.core.Holder;
|
| 11 | import net.minecraft.core.registries.Registries;
|
| 12 | import net.minecraft.core.registries.codec.RegistryCodecs;
|
| 13 | import net.minecraft.resources.Identifier;
|
| 14 | import net.minecraft.util.Interval;
|
| 15 | import net.minecraft.util.RandomSource;
|
| 16 | import net.minecraft.world.level.levelgen.synth.Noise;
|
| 17 | import net.minecraft.world.level.levelgen.synth.NormalNoise;
|
| 18 |
|
| 19 | public interface DensityFunction {
|
| 20 | Codec<Holder<DensityFunction>> REFERENCE_CODEC = RegistryCodecs.holder(Registries.DENSITY_FUNCTION);
|
| 21 | Codec<DensityFunction> CODEC = RegistryCodecs.holder(Registries.DENSITY_FUNCTION, DensityFunctions.DIRECT_CODEC).xmap(holder -> {
|
| 22 | return switch (holder) {
|
| 23 | case Holder.Direct<DensityFunction> direct -> (DensityFunction)direct.value();
|
| 24 | case Holder.Reference<DensityFunction> reference -> new DensityFunctions.HolderHolder(reference);
|
| 25 | default -> throw new MatchException(null, null);
|
| 26 | };
|
| 27 | }, value -> {
|
| 28 | return switch (value) {
|
| 29 | case DensityFunctions.HolderHolder(Holder<DensityFunction> function) -> function;
|
| 30 | default -> Holder.direct(value);
|
| 31 | };
|
| 32 | });
|
| 33 | int AXIS_X = 1;
|
| 34 | int AXIS_Y = 2;
|
| 35 | int AXIS_Z = 4;
|
| 36 | @DensityFunction.Axes int NO_AXES = 0;
|
| 37 | @DensityFunction.Axes int ALL_AXES = 7;
|
| 38 |
|
| 39 | static @DensityFunction.Axes int axesFrom(final Direction.Axis axis) {
|
| 40 | return switch (axis) {
|
| 41 | case X -> 1;
|
| 42 | case Y -> 2;
|
| 43 | case Z -> 4;
|
| 44 | };
|
| 45 | }
|
| 46 |
|
| 47 | DensitySampler compileSampler(DensityFunction.CompileContext context);
|
| 48 |
|
| 49 | DensityFunction rewriteChildren(DfRewriteRule rule);
|
| 50 |
|
| 51 | Interval range();
|
| 52 |
|
| 53 | @DensityFunction.Axes int domainAxes();
|
| 54 |
|
| 55 | MapCodec<? extends DensityFunction> codec();
|
| 56 |
|
| 57 | default DensityFunction clamp(final float min, final float max) {
|
| 58 | return DensityFunctions.clamp(this, min, max);
|
| 59 | }
|
| 60 |
|
| 61 | default DensityFunction abs() {
|
| 62 | return DensityFunctions.abs(this);
|
| 63 | }
|
| 64 |
|
| 65 | default DensityFunction square() {
|
| 66 | return DensityFunctions.square(this);
|
| 67 | }
|
| 68 |
|
| 69 | default DensityFunction cube() {
|
| 70 | return DensityFunctions.cube(this);
|
| 71 | }
|
| 72 |
|
| 73 | default DensityFunction sqrt() {
|
| 74 | return DensityFunctions.sqrt(this);
|
| 75 | }
|
| 76 |
|
| 77 | default DensityFunction halfNegative() {
|
| 78 | return DensityFunctions.halfNegative(this);
|
| 79 | }
|
| 80 |
|
| 81 | default DensityFunction quarterNegative() {
|
| 82 | return DensityFunctions.quarterNegative(this);
|
| 83 | }
|
| 84 |
|
| 85 | default DensityFunction reciprocal() {
|
| 86 | return DensityFunctions.reciprocal(this);
|
| 87 | }
|
| 88 |
|
| 89 | default DensityFunction negate() {
|
| 90 | return DensityFunctions.negate(this);
|
| 91 | }
|
| 92 |
|
| 93 | default DensityFunction squeeze() {
|
| 94 | return DensityFunctions.squeeze(this);
|
| 95 | }
|
| 96 |
|
| 97 | default DensityFunction log() {
|
| 98 | return DensityFunctions.log(this);
|
| 99 | }
|
| 100 |
|
| 101 | default DensityFunction sign() {
|
| 102 | return DensityFunctions.sign(this);
|
| 103 | }
|
| 104 |
|
| 105 | default DensityFunction add(final DensityFunction right) {
|
| 106 | return DensityFunctions.add(this, right);
|
| 107 | }
|
| 108 |
|
| 109 | default DensityFunction add(final float right) {
|
| 110 | return DensityFunctions.add(this, DensityFunctions.constant(right));
|
| 111 | }
|
| 112 |
|
| 113 | default DensityFunction sub(final DensityFunction right) {
|
| 114 | return DensityFunctions.sub(this, right);
|
| 115 | }
|
| 116 |
|
| 117 | default DensityFunction sub(final float right) {
|
| 118 | return DensityFunctions.sub(this, DensityFunctions.constant(right));
|
| 119 | }
|
| 120 |
|
| 121 | default DensityFunction mul(final DensityFunction right) {
|
| 122 | return DensityFunctions.mul(this, right);
|
| 123 | }
|
| 124 |
|
| 125 | default DensityFunction mul(final float right) {
|
| 126 | return DensityFunctions.mul(this, DensityFunctions.constant(right));
|
| 127 | }
|
| 128 |
|
| 129 | default DensityFunction div(final DensityFunction right) {
|
| 130 | return DensityFunctions.div(this, right);
|
| 131 | }
|
| 132 |
|
| 133 | default DensityFunction div(final float right) {
|
| 134 | return DensityFunctions.div(this, DensityFunctions.constant(right));
|
| 135 | }
|
| 136 |
|
| 137 | default DensityFunction pow(final DensityFunction exponent) {
|
| 138 | return DensityFunctions.pow(this, exponent);
|
| 139 | }
|
| 140 |
|
| 141 | default DensityFunction pow(final float exponent) {
|
| 142 | if (exponent == 0.5F) {
|
| 143 | return this.sqrt();
|
| 144 | } else if (exponent == 2.0F) {
|
| 145 | return this.square();
|
| 146 | } else {
|
| 147 | return exponent == 3.0F ? this.cube() : DensityFunctions.pow(this, DensityFunctions.constant(exponent));
|
| 148 | }
|
| 149 | }
|
| 150 |
|
| 151 | @Retention(RetentionPolicy.CLASS)
|
| 152 | @Target(ElementType.TYPE_USE)
|
| 153 | @interface Axes {
|
| 154 | }
|
| 155 |
|
| 156 | interface CompileContext {
|
| 157 | Noise createNoiseSampler(Holder<NormalNoise> parameters);
|
| 158 |
|
| 159 | RandomSource createRandom(Identifier seed);
|
| 160 |
|
| 161 | @Deprecated
|
| 162 | RandomSource createEndIslandRandom();
|
| 163 | }
|
| 164 | }
|
| 165 |
|