Skip to content

Commit

Permalink
Almost forgot to pluralize the API enums.
Browse files Browse the repository at this point in the history
* Yes I am aware some folks prefer singular; Biolith is my project, so I can do what I like.
  • Loading branch information
gniftygnome committed Jun 24, 2024
1 parent 5f2d351 commit 9f09191
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import net.minecraft.world.biome.source.util.MultiNoiseUtil;

/**
* Available noise values in the {@link BiomeParameterTarget} enum:
* Available noise values in the {@link BiomeParameterTargets} enum:
* <ul>
* <li>CONTINENTALNESS</li>
* <li>DEPTH</li>
Expand All @@ -17,7 +17,7 @@
* <li>WEIRDNESS</li>
* </ul>
*/
public enum BiomeParameterTarget implements StringIdentifiable {
public enum BiomeParameterTargets implements StringIdentifiable {
/*
* Do not add before or modify the order of the first six names;
* they must be in the same order as Mojang's parameter arrays.
Expand All @@ -31,10 +31,10 @@ public enum BiomeParameterTarget implements StringIdentifiable {
WEIRDNESS("weirdness"),
PEAKS_VALLEYS("peaks_valleys");

public static final Codec<BiomeParameterTarget> CODEC = StringIdentifiable.createCodec(BiomeParameterTarget::values);
public static final Codec<BiomeParameterTargets> CODEC = StringIdentifiable.createCodec(BiomeParameterTargets::values);
private final String name;

BiomeParameterTarget(String name) {
BiomeParameterTargets(String name) {
this.name = name;
}

Expand All @@ -51,7 +51,7 @@ public long getNoiseValue(MultiNoiseUtil.NoiseValuePoint noisePoint) {
case EROSION -> noisePoint.erosionNoise();
case DEPTH -> noisePoint.depth();
case WEIRDNESS -> noisePoint.weirdnessNoise();
case PEAKS_VALLEYS -> BiomeParameterTarget.getPeaksValleysNoiseLong(noisePoint.weirdnessNoise());
case PEAKS_VALLEYS -> BiomeParameterTargets.getPeaksValleysNoiseLong(noisePoint.weirdnessNoise());
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
*/
@SuppressWarnings("unused")
public class CriterionBuilder {
public static final Criterion NEAR_BORDER = ratioMax(RatioTarget.EDGE, 0.2f);
public static final Criterion NEAR_INTERIOR = ratioMax(RatioTarget.CENTER, 0.2f);
public static final Criterion NEAR_BORDER = ratioMax(RatioTargets.EDGE, 0.2f);
public static final Criterion NEAR_INTERIOR = ratioMax(RatioTargets.CENTER, 0.2f);

public static final Criterion BEACHSIDE = allOf(NEAR_BORDER, neighbor(BiomeTags.IS_BEACH));
public static final Criterion OCEANSIDE = allOf(NEAR_BORDER, neighbor(BiomeTags.IS_OCEAN));
Expand Down Expand Up @@ -87,15 +87,15 @@ public static Criterion anyOf(Criterion... criteria) {
* Creates a numerical {@link Criterion} used to evaluate whether the raw noise value of the
* {@link MultiNoiseUtil.NoiseValuePoint} being evaluated is within the provided range.
* </p><p>
* The available noise values are detailed in {@link BiomeParameterTarget}.
* The available noise values are detailed in {@link BiomeParameterTargets}.
* </p>
*
* @param parameter {@link BiomeParameterTarget target} to evaluate
* @param parameter {@link BiomeParameterTargets target} to evaluate
* @param min The minimum matching value of the validity range
* @param max The maximum matching value of the validity range
* @return The created {@link ValueCriterion}
*/
public static Criterion value(BiomeParameterTarget parameter, float min, float max) {
public static Criterion value(BiomeParameterTargets parameter, float min, float max) {
return new ValueCriterion(parameter, min, max);
}

Expand All @@ -104,14 +104,14 @@ public static Criterion value(BiomeParameterTarget parameter, float min, float m
* Creates a numerical {@link Criterion} used to evaluate whether the raw noise value of the
* {@link MultiNoiseUtil.NoiseValuePoint} being evaluated is at least the provided minimum.
* </p><p>
* The available noise values are detailed in {@link BiomeParameterTarget}.
* The available noise values are detailed in {@link BiomeParameterTargets}.
* </p>
*
* @param parameter {@link BiomeParameterTarget target} to evaluate
* @param parameter {@link BiomeParameterTargets target} to evaluate
* @param min The minimum matching value of the validity range
* @return The created {@link ValueCriterion}
*/
public static Criterion valueMin(BiomeParameterTarget parameter, float min) {
public static Criterion valueMin(BiomeParameterTargets parameter, float min) {
return value(parameter, min, Float.POSITIVE_INFINITY);
}

Expand All @@ -120,14 +120,14 @@ public static Criterion valueMin(BiomeParameterTarget parameter, float min) {
* Creates a numerical {@link Criterion} used to evaluate whether the raw noise value of the
* {@link MultiNoiseUtil.NoiseValuePoint} being evaluated is no more than the provided maximum.
* </p><p>
* The available noise values are detailed in {@link BiomeParameterTarget}.
* The available noise values are detailed in {@link BiomeParameterTargets}.
* </p>
*
* @param parameter {@link BiomeParameterTarget target} to evaluate
* @param parameter {@link BiomeParameterTargets target} to evaluate
* @param max The maximum matching value of the validity range
* @return The created {@link ValueCriterion}
*/
public static Criterion valueMax(BiomeParameterTarget parameter, float max) {
public static Criterion valueMax(BiomeParameterTargets parameter, float max) {
return value(parameter, Float.NEGATIVE_INFINITY, max);
}

Expand All @@ -137,15 +137,15 @@ public static Criterion valueMax(BiomeParameterTarget parameter, float max) {
* selected biome's {@link MultiNoiseUtil.ParameterRange} to a selected noise value of the
* {@link MultiNoiseUtil.NoiseValuePoint} being evaluated is within the provided range.
* </p><p>
* The available noise values are detailed in {@link BiomeParameterTarget}.
* The available noise values are detailed in {@link BiomeParameterTargets}.
* </p>
*
* @param parameter {@link BiomeParameterTarget target} to evaluate
* @param parameter {@link BiomeParameterTargets target} to evaluate
* @param min The minimum matching value of the validity range
* @param max The maximum matching value of the validity range
* @return The created {@link DeviationCriterion}
*/
public static Criterion deviation(BiomeParameterTarget parameter, float min, float max) {
public static Criterion deviation(BiomeParameterTargets parameter, float min, float max) {
return new DeviationCriterion(parameter, min, max);
}

Expand All @@ -155,14 +155,14 @@ public static Criterion deviation(BiomeParameterTarget parameter, float min, flo
* selected biome's {@link MultiNoiseUtil.ParameterRange} to a selected noise value of the
* {@link MultiNoiseUtil.NoiseValuePoint} being evaluated is at least the provided minimum.
* </p><p>
* The available noise values are detailed in {@link BiomeParameterTarget}.
* The available noise values are detailed in {@link BiomeParameterTargets}.
* </p>
*
* @param parameter {@link BiomeParameterTarget target} to evaluate
* @param parameter {@link BiomeParameterTargets target} to evaluate
* @param min The minimum matching value of the validity range
* @return The created {@link DeviationCriterion}
*/
public static Criterion deviationMin(BiomeParameterTarget parameter, float min) {
public static Criterion deviationMin(BiomeParameterTargets parameter, float min) {
return deviation(parameter, min, Float.POSITIVE_INFINITY);
}

Expand All @@ -172,14 +172,14 @@ public static Criterion deviationMin(BiomeParameterTarget parameter, float min)
* selected biome's {@link MultiNoiseUtil.ParameterRange} to a selected noise value of the
* {@link MultiNoiseUtil.NoiseValuePoint} being evaluated is no more than the provided maximum.
* </p><p>
* The available noise values are detailed in {@link BiomeParameterTarget}.
* The available noise values are detailed in {@link BiomeParameterTargets}.
* </p>
*
* @param parameter {@link BiomeParameterTarget target} to evaluate
* @param parameter {@link BiomeParameterTargets target} to evaluate
* @param max The maximum matching value of the validity range
* @return The created {@link DeviationCriterion}
*/
public static Criterion deviationMax(BiomeParameterTarget parameter, float max) {
public static Criterion deviationMax(BiomeParameterTargets parameter, float max) {
return deviation(parameter, Float.NEGATIVE_INFINITY, max);
}

Expand All @@ -189,15 +189,15 @@ public static Criterion deviationMax(BiomeParameterTarget parameter, float max)
* used to evaluate roughly how close the point being evaluated is to the noise center or edge of the of the
* selected noise or replacement biome.
* </p><p>
* The available noise values are detailed in {@link RatioTarget}.
* The available noise values are detailed in {@link RatioTargets}.
* </p>
*
* @param target {@link RatioTarget target} to evaluate
* @param target {@link RatioTargets target} to evaluate
* @param min The minimum matching value of the validity range
* @param max The maximum matching value of the validity range
* @return The created {@link RatioCriterion}
*/
public static Criterion ratio(RatioTarget target, float min, float max) {
public static Criterion ratio(RatioTargets target, float min, float max) {
return new RatioCriterion(target, min, max);
}

Expand All @@ -207,14 +207,14 @@ public static Criterion ratio(RatioTarget target, float min, float max) {
* used to evaluate roughly how close the point being evaluated is to the noise center or edge of the of the
* selected noise or replacement biome.
* </p><p>
* The available noise values are detailed in {@link RatioTarget}.
* The available noise values are detailed in {@link RatioTargets}.
* </p>
*
* @param target {@link RatioTarget target} to evaluate
* @param target {@link RatioTargets target} to evaluate
* @param min The minimum matching value of the validity range
* @return The created {@link RatioCriterion}
*/
public static Criterion ratioMin(RatioTarget target, float min) {
public static Criterion ratioMin(RatioTargets target, float min) {
return ratio(target, min, Float.POSITIVE_INFINITY);
}

Expand All @@ -224,14 +224,14 @@ public static Criterion ratioMin(RatioTarget target, float min) {
* used to evaluate roughly how close the point being evaluated is to the noise center or edge of the of the
* selected noise or replacement biome.
* </p><p>
* The available noise values are detailed in {@link RatioTarget}.
* The available noise values are detailed in {@link RatioTargets}.
* </p>
*
* @param target {@link RatioTarget target} to evaluate
* @param target {@link RatioTargets target} to evaluate
* @param max The maximum matching value of the validity range
* @return The created {@link RatioCriterion}
*/
public static Criterion ratioMax(RatioTarget target, float max) {
public static Criterion ratioMax(RatioTargets target, float max) {
return ratio(target, Float.NEGATIVE_INFINITY, max);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
import net.minecraft.util.StringIdentifiable;

/**
* Available computed ratios in the {@link RatioTarget} enum:
* Available computed ratios in the {@link RatioTargets} enum:
* <ul>
* <li>CENTER</li>
* <li>EDGE</li>
* </ul>
*/
public enum RatioTarget implements StringIdentifiable {
public enum RatioTargets implements StringIdentifiable {
CENTER("center"),
EDGE("edge");

public static final Codec<RatioTarget> CODEC = StringIdentifiable.createCodec(RatioTarget::values);
public static final Codec<RatioTargets> CODEC = StringIdentifiable.createCodec(RatioTargets::values);
private final String name;

RatioTarget(String name) {
RatioTargets(String name) {
this.name = name;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import com.terraformersmc.biolith.api.biome.sub.BiomeParameterTarget;
import com.terraformersmc.biolith.api.biome.sub.BiomeParameterTargets;
import com.terraformersmc.biolith.api.biome.sub.Criterion;
import net.minecraft.util.dynamic.Range;

public abstract class AbstractParameterCriterion implements Criterion {
protected final BiomeParameterTarget parameter;
protected final BiomeParameterTargets parameter;
protected Range<Float> allowedValues;

public AbstractParameterCriterion(BiomeParameterTarget parameter, float min, float max) {
public AbstractParameterCriterion(BiomeParameterTargets parameter, float min, float max) {
this.parameter = parameter;
this.allowedValues = new Range<>(min, max);
}

protected static <T extends AbstractParameterCriterion> MapCodec<T> buildCodec(Function3<BiomeParameterTarget, Float, Float, T> function) {
protected static <T extends AbstractParameterCriterion> MapCodec<T> buildCodec(Function3<BiomeParameterTargets, Float, Float, T> function) {
return RecordCodecBuilder.mapCodec(
(instance) -> instance.group(
BiomeParameterTarget.CODEC.fieldOf("parameter")
BiomeParameterTargets.CODEC.fieldOf("parameter")
.forGetter(AbstractParameterCriterion::parameter),
Codec.FLOAT.optionalFieldOf("min", Float.NEGATIVE_INFINITY)
.forGetter(AbstractParameterCriterion::min),
Expand All @@ -30,7 +30,7 @@ protected static <T extends AbstractParameterCriterion> MapCodec<T> buildCodec(F
.apply(instance, function));
}

public BiomeParameterTarget parameter() {
public BiomeParameterTargets parameter() {
return parameter;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.terraformersmc.biolith.impl.biome.sub;

import com.mojang.serialization.MapCodec;
import com.terraformersmc.biolith.api.biome.sub.BiomeParameterTarget;
import com.terraformersmc.biolith.api.biome.sub.BiomeParameterTargets;
import com.terraformersmc.biolith.api.biome.sub.CriterionType;
import com.terraformersmc.biolith.api.biome.BiolithFittestNodes;
import com.terraformersmc.biolith.impl.biome.DimensionBiomePlacement;
Expand All @@ -14,7 +14,7 @@
public class DeviationCriterion extends AbstractParameterCriterion {
public static final MapCodec<DeviationCriterion> CODEC = buildCodec(DeviationCriterion::new);

public DeviationCriterion(BiomeParameterTarget parameter, float min, float max) {
public DeviationCriterion(BiomeParameterTargets parameter, float min, float max) {
super(parameter, min, max);
}

Expand All @@ -31,18 +31,18 @@ public MapCodec<DeviationCriterion> getCodec() {
@Override
public boolean matches(BiolithFittestNodes<RegistryEntry<Biome>> fittestNodes, DimensionBiomePlacement biomePlacement, MultiNoiseUtil.NoiseValuePoint noisePoint, @Nullable Range<Float> replacementRange, float replacementNoise) {
long value = parameter.getNoiseValue(noisePoint);
long parameterCenter = BiomeParameterTarget.parameterCenter(getParameterRange(fittestNodes.ultimate().parameters));
long parameterCenter = BiomeParameterTargets.parameterCenter(getParameterRange(fittestNodes.ultimate().parameters));

return allowedValues.contains(MultiNoiseUtil.toFloat(value - parameterCenter));
}

private MultiNoiseUtil.ParameterRange getParameterRange(MultiNoiseUtil.ParameterRange[] parameters) {
if (parameter == BiomeParameterTarget.PEAKS_VALLEYS) {
if (parameter == BiomeParameterTargets.PEAKS_VALLEYS) {
// PV is a calculated noise based on folding weirdness twice
long weirdnessMin = parameters[BiomeParameterTarget.WEIRDNESS.ordinal()].min();
long weirdnessMax = parameters[BiomeParameterTarget.WEIRDNESS.ordinal()].max();
long point1 = BiomeParameterTarget.getPeaksValleysNoiseLong(weirdnessMin);
long point2 = BiomeParameterTarget.getPeaksValleysNoiseLong(weirdnessMax);
long weirdnessMin = parameters[BiomeParameterTargets.WEIRDNESS.ordinal()].min();
long weirdnessMax = parameters[BiomeParameterTargets.WEIRDNESS.ordinal()].max();
long point1 = BiomeParameterTargets.getPeaksValleysNoiseLong(weirdnessMin);
long point2 = BiomeParameterTargets.getPeaksValleysNoiseLong(weirdnessMax);
long pvMin;
long pvMax;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import com.terraformersmc.biolith.api.biome.sub.BiomeParameterTarget;
import com.terraformersmc.biolith.api.biome.sub.BiomeParameterTargets;
import com.terraformersmc.biolith.api.biome.sub.Criterion;
import com.terraformersmc.biolith.api.biome.sub.CriterionType;
import com.terraformersmc.biolith.api.biome.BiolithFittestNodes;
import com.terraformersmc.biolith.api.biome.sub.RatioTarget;
import com.terraformersmc.biolith.api.biome.sub.RatioTargets;
import com.terraformersmc.biolith.impl.biome.DimensionBiomePlacement;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.util.dynamic.Range;
Expand All @@ -16,10 +16,10 @@
import net.minecraft.world.biome.source.util.MultiNoiseUtil;
import org.jetbrains.annotations.Nullable;

public record RatioCriterion(RatioTarget target, Range<Float> allowedValues) implements Criterion {
public record RatioCriterion(RatioTargets target, Range<Float> allowedValues) implements Criterion {
public static final MapCodec<RatioCriterion> CODEC = RecordCodecBuilder.mapCodec(
(instance) -> instance.group(
RatioTarget.CODEC.fieldOf("target")
RatioTargets.CODEC.fieldOf("target")
.forGetter(RatioCriterion::target),
Codec.FLOAT.optionalFieldOf("min", Float.NEGATIVE_INFINITY)
.forGetter(RatioCriterion::min),
Expand All @@ -28,7 +28,7 @@ public record RatioCriterion(RatioTarget target, Range<Float> allowedValues) imp
)
.apply(instance, RatioCriterion::new));

public RatioCriterion(RatioTarget target, float min, float max) {
public RatioCriterion(RatioTargets target, float min, float max) {
this(target, new Range<>(min, max));
}

Expand All @@ -53,10 +53,10 @@ public MapCodec<? extends Criterion> getCodec() {
public boolean matches(BiolithFittestNodes<RegistryEntry<Biome>> fittestNodes, DimensionBiomePlacement biomePlacement, MultiNoiseUtil.NoiseValuePoint noisePoint, @Nullable Range<Float> replacementRange, float replacementNoise) {
float comparable;

if (target == RatioTarget.CENTER) {
if (target == RatioTargets.CENTER) {
// Vanilla biomes pre-Biolith replacement; /10k is analogous to MultiNoiseUtil.toFloat(); param 6 is offset
comparable = MathHelper.sqrt((float) BiomeParameterTarget.getSquaredDistance(
BiomeParameterTarget.parametersCenterPoint(fittestNodes.ultimate().parameters),
comparable = MathHelper.sqrt((float) BiomeParameterTargets.getSquaredDistance(
BiomeParameterTargets.parametersCenterPoint(fittestNodes.ultimate().parameters),
noisePoint, fittestNodes.ultimate().parameters[6].min())) / 10000f;
// Post-replacement we need to add in the replacement noise restriction
if (replacementRange != null) {
Expand All @@ -72,7 +72,7 @@ public boolean matches(BiolithFittestNodes<RegistryEntry<Biome>> fittestNodes, D
(replacementRange.minInclusive() + replacementRange.maxInclusive()) / 2f), comparable);
}
}
} else if (target == RatioTarget.EDGE) {
} else if (target == RatioTargets.EDGE) {
// Vanilla biomes pre-Biolith replacement
if (fittestNodes.penultimate() == null) {
comparable = 1f;
Expand Down
Loading

0 comments on commit 9f09191

Please sign in to comment.