mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
Add value types for settings (BlockSpec, NoiseStyle, StyledRange, Range, BlockPosition, Object as any JSON), host-built noise through PackResources.noise(), and VanillaStructureHook for the platform's own structures
This commit is contained in:
1 parent
ef4b640867
commit
84969c74bd
28 files changed
+1012
-39
No files matched your search
@@ -0,0 +1,68 @@
|
||||
package com.volmit.config;
|
||||
|
||||
import com.volmit.random.WorldRandom;
|
||||
import java.util.Objects;
|
||||
|
||||
/** A span of numbers from {@code min} to {@code max}, both included, as packs write it: {@code {"min": 0, "max": 15}},
|
||||
* or a snippet under {@code snippet/range/}. An omitted bound keeps its default, so give a settings field its own
|
||||
* default with {@link #of}. A value the host creates with the no-argument constructor and reads the JSON into.
|
||||
*/
|
||||
@Snippet("range")
|
||||
@Desc("Represents a range")
|
||||
public final class Range {
|
||||
@Desc("The minimum value")
|
||||
private double min = 16;
|
||||
|
||||
@Desc("The maximum value")
|
||||
private double max = 32;
|
||||
|
||||
private Range() {
|
||||
}
|
||||
|
||||
private Range(double min, double max) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
public static Range of(double min, double max) {
|
||||
return new Range(min, max);
|
||||
}
|
||||
|
||||
public double min() {
|
||||
return min;
|
||||
}
|
||||
|
||||
public double max() {
|
||||
return max;
|
||||
}
|
||||
|
||||
/** Whether {@code value} lies between the bounds, both included. */
|
||||
public boolean contains(double value) {
|
||||
return value >= min && value <= max;
|
||||
}
|
||||
|
||||
/** A number between the bounds drawn from {@code random}: {@code min + nextDouble() * (max - min)}, one draw,
|
||||
* or {@code min} without a draw when the bounds are equal.
|
||||
*/
|
||||
public double pick(WorldRandom random) {
|
||||
if (min == max) {
|
||||
return min;
|
||||
}
|
||||
return min + random.nextDouble() * (max - min);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
return other instanceof Range that && Double.compare(min, that.min) == 0 && Double.compare(max, that.max) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(min, max);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Range[" + min + ".." + max + "]";
|
||||
}
|
||||
}
|
||||
@@ -25,5 +25,11 @@ public enum Reference {
|
||||
/** A region of the pack. */
|
||||
PACK_REGION,
|
||||
/** An object of the pack. */
|
||||
PACK_OBJECT
|
||||
PACK_OBJECT,
|
||||
/** One of the host's noise styles, such as {@code SIMPLEX}; see {@link com.volmit.noise.NoiseStyle}. */
|
||||
NOISE_STYLE,
|
||||
/** An expression of the pack. */
|
||||
PACK_EXPRESSION,
|
||||
/** An image map of the pack. */
|
||||
PACK_IMAGE_MAP
|
||||
}
|
||||
Reference in new issue
Block a user