mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
Port v3e's parts-based procedural objects
The 37 part classes from v3e (dev) now live in engine/procedural, outside the host's own type package, so the built-ins jar may register them as a resource kind. ProceduralObjectCatalog reads iris:objects/procedural definitions from the pack's procedural/ folder and bakes their variants per world (or detached, for reach); ObjectPool places procedural/<path> and procedural/<path>#<n> keys like any object and warms them, and ObjectChunk keeps their baked leaves. ProceduralValue reads its forms (number, range, keyframes, curve shape) through IrisApi's @JsonForms codec instead of Gson. Trees: procedural/trees/ counts as a tree folder and TreeGrowing reports every variant it places as a tree. The v4-era kinds (tree, ruin, formation, coral, fungi, crystal), ProceduralPlacement, ProceduralObjectSettings and PlacementSource are removed; ObjectPlacement is the one placement.
This commit is contained in:
1 parent
501862b9ea
commit
d2ce5f4a05
126 files changed
+4031
-9036
No files matched your search
@@ -67,8 +67,9 @@ placement itself, read by the module decoder like any settings class, and the on
|
||||
stages into the chunk's mantle (on the surface, in a cave inside the cave's bounds, or hung from the terrain above), reading the
|
||||
carved space the cave carver planned, and the loot an object placed at a block defines; the layout, the settings of a column and
|
||||
the upper dimension's objects come from IrisApi (`TerrainSampler`, `FeatureSettings`, `UpperDimension`). `ObjectPlacing` and its helpers (`ChunkObjectPlacing`,
|
||||
`CaveAnchors`, `PlacementReach`) decide what to place and where. The procedural generators (`engine/object/procedural`) stay
|
||||
compiled in, behind `ProceduralPlacement`, until they build `GeneratedObject`s instead of Iris objects.
|
||||
`CaveAnchors`, `PlacementReach`) decide what to place and where. Procedural objects (`engine/procedural`, resource kind
|
||||
`iris:objects/procedural`, folder `procedural`) are definitions of parts that bake into variants; a placement names them as
|
||||
`procedural/<path>`, or `procedural/<path>#<index>` for one variant, like any object.
|
||||
`iris:loot` owns the loot table resource kind (`LootResources`, folder `loot`), checks the tables and the references to
|
||||
them (`LootValidator`), and provides `Loot` (`LootGiving`: which tables a container draws from and the `ItemDrop`s a
|
||||
table gives) and `BlockDrops` (`BlockDropping`). `iris:spawn` owns spawners, entities and markers (`SpawnResources`,
|
||||
|
||||
+1
-1
@@ -88,7 +88,7 @@ include art/arcane/iris/engine/mantle/components/ObjectLocating*.class
|
||||
include art/arcane/iris/engine/mantle/components/TreeGrowing*.class
|
||||
include art/arcane/iris/engine/mantle/components/ObjectChunk*.class
|
||||
include art/arcane/iris/engine/mantle/components/GoldenDebugTerrain*.class
|
||||
include art/arcane/iris/engine/object/procedural/**
|
||||
include art/arcane/iris/engine/procedural/**
|
||||
module art.arcane.iris.engine.modifier.FloatingModule
|
||||
include art/arcane/iris/engine/modifier/FloatingIslands*.class
|
||||
include art/arcane/iris/engine/object/terrain/floating/**
|
||||
|
||||
@@ -70,7 +70,7 @@ import java.util.TreeSet;
|
||||
@Snippet("iris/objects/object-placer")
|
||||
@Desc("Represents an iris object placer. It places objects.")
|
||||
@JsonAdapter(ObjectPlacement.KeepingItsJson.class)
|
||||
public final class ObjectPlacement implements PlacementSource {
|
||||
public final class ObjectPlacement {
|
||||
private static final int DEFAULT_SURFACE_SUPPORT_BUFFER = 2;
|
||||
private static final int DEFAULT_SURFACE_SUPPORT_DEPTH = 2;
|
||||
|
||||
@@ -273,7 +273,6 @@ public final class ObjectPlacement implements PlacementSource {
|
||||
return snow;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDolphinTarget() {
|
||||
return isDolphinTarget;
|
||||
}
|
||||
@@ -286,7 +285,6 @@ public final class ObjectPlacement implements PlacementSource {
|
||||
return rotateTowardsSlope;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double chance() {
|
||||
return chance;
|
||||
}
|
||||
@@ -342,17 +340,14 @@ public final class ObjectPlacement implements PlacementSource {
|
||||
return boreExtendMinY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean underwater() {
|
||||
return underwater;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CarvingMode carvingSupport() {
|
||||
return carvingSupport;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int surfaceSupportBuffer() {
|
||||
return surfaceSupportBuffer;
|
||||
}
|
||||
@@ -361,12 +356,10 @@ public final class ObjectPlacement implements PlacementSource {
|
||||
return surfaceSupportDepth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requireSurfaceSupport() {
|
||||
return requireSurfaceSupport;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CaveAnchorMode caveAnchorMode() {
|
||||
return caveAnchorMode;
|
||||
}
|
||||
@@ -408,7 +401,6 @@ public final class ObjectPlacement implements PlacementSource {
|
||||
return warp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectPlaceMode mode() {
|
||||
return mode;
|
||||
}
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.builtin.objects;
|
||||
|
||||
import art.arcane.iris.builtin.anchor.ObjectPlaceMode;
|
||||
import art.arcane.iris.builtin.carve.CarvingMode;
|
||||
import art.arcane.iris.builtin.carve.CaveAnchorMode;
|
||||
|
||||
/** What a placement is read from: an object placement of a biome or region, or a procedural object. */
|
||||
public interface PlacementSource {
|
||||
double chance();
|
||||
|
||||
ObjectPlaceMode mode();
|
||||
|
||||
CarvingMode carvingSupport();
|
||||
|
||||
CaveAnchorMode caveAnchorMode();
|
||||
|
||||
boolean underwater();
|
||||
|
||||
boolean requireSurfaceSupport();
|
||||
|
||||
int surfaceSupportBuffer();
|
||||
|
||||
boolean isDolphinTarget();
|
||||
}
|
||||
@@ -21,7 +21,7 @@ package art.arcane.iris.engine.mantle.components;
|
||||
import art.arcane.iris.builtin.anchor.PlaceTrait;
|
||||
import art.arcane.iris.builtin.carve.CaveAnchorMode;
|
||||
import art.arcane.iris.modules.carve.CaveProfile;
|
||||
import art.arcane.iris.builtin.objects.PlacementSource;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
|
||||
/** What a cave object placement takes from the cave profile that applies to it. */
|
||||
final class CaveSettings {
|
||||
@@ -51,7 +51,7 @@ final class CaveSettings {
|
||||
}
|
||||
|
||||
/** How the placement looks for its anchor in caves: its own mode, else the profile's, else the floor; turned upside down, the ceiling. */
|
||||
CaveAnchors.Search searchFor(PlacementSource placement, CaveProfile profile) {
|
||||
CaveAnchors.Search searchFor(ObjectPlacement placement, CaveProfile profile) {
|
||||
CaveAnchorMode mode = anchorMode(placement, profile);
|
||||
if (placement.mode().placeMode().has(PlaceTrait.UPSIDE_DOWN)) {
|
||||
mode = CaveAnchorMode.CEILING;
|
||||
@@ -59,7 +59,7 @@ final class CaveSettings {
|
||||
return new CaveAnchors.Search(mode, scanStep(profile), minDepthBelowSurface(profile), searchAttempts(profile));
|
||||
}
|
||||
|
||||
private static CaveAnchorMode anchorMode(PlacementSource placement, CaveProfile profile) {
|
||||
private static CaveAnchorMode anchorMode(ObjectPlacement placement, CaveProfile profile) {
|
||||
CaveAnchorMode placementMode = placement.caveAnchorMode();
|
||||
if (placementMode != null && !placementMode.equals(CaveAnchorMode.PROFILE_DEFAULT)) {
|
||||
return placementMode;
|
||||
|
||||
@@ -24,21 +24,17 @@ import art.arcane.iris.builtin.carve.CaveLavaHeightSettings;
|
||||
import art.arcane.iris.modules.carve.CaveProfile;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.ObjectSettings;
|
||||
import art.arcane.iris.builtin.objects.PlacementSource;
|
||||
import art.arcane.iris.modules.objects.ProceduralObjectSettings;
|
||||
import art.arcane.iris.builtin.objects.RequireSurfaceSupportSettings;
|
||||
import art.arcane.iris.builtin.objects.SurfaceSupportBufferSettings;
|
||||
import art.arcane.iris.builtin.objects.UpperObjectsForceSettings;
|
||||
import art.arcane.iris.builtin.objects.UpperObjectsSettings;
|
||||
import art.arcane.iris.engine.object.procedural.ResolvedProceduralObjects;
|
||||
import art.arcane.iris.engine.procedural.ProceduralObjectCatalog;
|
||||
import art.arcane.iris.modules.objects.CavePlacement;
|
||||
import art.arcane.iris.modules.objects.TerrainTransaction;
|
||||
import art.arcane.iris.modules.objects.EffectiveSettings;
|
||||
import art.arcane.iris.modules.objects.ObjectPool;
|
||||
import art.arcane.iris.modules.objects.ObjectSeparation;
|
||||
import art.arcane.iris.modules.objects.PlacementChanges;
|
||||
import art.arcane.iris.modules.objects.PlacementTags;
|
||||
import art.arcane.iris.modules.objects.ProceduralPlacement;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.ModuleLog;
|
||||
@@ -56,8 +52,8 @@ import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
/**
|
||||
* Places what the objects of one chunk's region and biomes say: the objects of its surface, caves and the terrain stacked above,
|
||||
* and its procedural objects, in that order, all drawing from the one random of the chunk.
|
||||
* Places what the objects of one chunk's region and biomes say: the objects of its surface, caves and the terrain stacked
|
||||
* above, in that order, all drawing from the one random of the chunk.
|
||||
*/
|
||||
final class ChunkObjectPlacing {
|
||||
/** Objects read their chunk's settings at local 8, 8 as Iris always did, not at the API's centre column (local 7, 7): moving it would move objects. */
|
||||
@@ -91,12 +87,12 @@ final class ChunkObjectPlacing {
|
||||
private final int worldHeight;
|
||||
private final int caveLavaHeight;
|
||||
|
||||
ChunkObjectPlacing(ObjectPool objects, EffectiveSettings settings, ModuleLog log, MantleStageContext context) {
|
||||
ChunkObjectPlacing(ObjectPool objects, ModuleLog log, MantleStageContext context) {
|
||||
this.objects = objects;
|
||||
this.separation = ObjectSeparation.of(context.world());
|
||||
this.log = log;
|
||||
this.context = context;
|
||||
this.chunk = new ObjectChunk(context, settings, log);
|
||||
this.chunk = new ObjectChunk(context, log);
|
||||
this.terrain = context.terrain();
|
||||
this.chunkX = context.chunkX();
|
||||
this.chunkZ = context.chunkZ();
|
||||
@@ -121,7 +117,6 @@ final class ChunkObjectPlacing {
|
||||
logLayerStart(column);
|
||||
}
|
||||
Tally tally = placeObjects(column);
|
||||
placeProceduralObjects(column);
|
||||
if (upperObjectsEnabled()) {
|
||||
placeUpperObjects(column);
|
||||
}
|
||||
@@ -136,8 +131,7 @@ final class ChunkObjectPlacing {
|
||||
ResourceId surface = terrain.surfaceBiome(centerX, centerZ);
|
||||
int surfaceY = terrain.surfaceHeight(centerX, centerZ);
|
||||
ResourceId cave = resolveCaveObjectBiome(surfaceY, surface);
|
||||
return new Column(region, surface, cave, surfaceY, objectsOf(cave, region, surface), proceduralOf(cave, region, surface),
|
||||
profilesOf(cave, region, surface));
|
||||
return new Column(region, surface, cave, surfaceY, objectsOf(cave, region, surface), profilesOf(cave, region, surface));
|
||||
}
|
||||
|
||||
private ResourceId resolveCaveObjectBiome(int surfaceY, ResourceId surfaceBiome) {
|
||||
@@ -169,12 +163,6 @@ final class ChunkObjectPlacing {
|
||||
levelValue(declared, Level.REGION));
|
||||
}
|
||||
|
||||
private ColumnProcedural proceduralOf(ResourceId cave, ResourceId region, ResourceId surface) {
|
||||
SettingsStack<ProceduralObjectSettings> declared = context.settings().at(ProceduralObjectSettings.class, centerX, centerZ);
|
||||
return new ColumnProcedural(levelValue(declared, Level.BIOME),
|
||||
caveSettings(cave, surface, declared, ProceduralObjectSettings.class), levelValue(declared, Level.REGION));
|
||||
}
|
||||
|
||||
private ColumnProfiles profilesOf(ResourceId cave, ResourceId region, ResourceId surface) {
|
||||
SettingsStack<CaveProfile> declared = context.settings().at(CaveProfile.class, centerX, centerZ);
|
||||
return new ColumnProfiles(levelValue(declared, Level.BIOME), caveSettings(cave, surface, declared, CaveProfile.class),
|
||||
@@ -415,115 +403,6 @@ final class ChunkObjectPlacing {
|
||||
return contained.commit() == TerrainTransaction.Commit.REJECTED ? "CONTAINMENT" : "NO_WRITES";
|
||||
}
|
||||
|
||||
private void placeProceduralObjects(Column column) {
|
||||
List<ProceduralPlacement> surface = proceduralPlacements(column.procedural().surface());
|
||||
List<ProceduralPlacement> region = proceduralPlacements(column.procedural().region());
|
||||
CaveProfile surfaceProfile = caves.resolve(column.profiles().surface(), column.profiles().region());
|
||||
CaveProfile regionProfile = caves.resolve(column.profiles().region(), column.profiles().cave());
|
||||
placeProceduralFrom(surface, column.surface().toString(), surfaceProfile, column.surface());
|
||||
placeProceduralFrom(region, column.region().toString(), regionProfile, null);
|
||||
if (!column.cave().equals(column.surface())) {
|
||||
CaveProfile caveProfile = caves.resolve(column.profiles().cave(), column.profiles().region());
|
||||
placeProceduralFrom(proceduralPlacements(column.procedural().cave()), column.cave().toString(), caveProfile, column.cave());
|
||||
}
|
||||
}
|
||||
|
||||
private List<ProceduralPlacement> proceduralPlacements(ProceduralObjectSettings settings) {
|
||||
return settings == null ? List.of() : ResolvedProceduralObjects.of(context.world(), settings);
|
||||
}
|
||||
|
||||
private void placeProceduralFrom(List<ProceduralPlacement> placements, String scope, CaveProfile caveProfile, ResourceId expectedCaveBiome) {
|
||||
if (placements.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
int blockX = context.originX();
|
||||
int blockZ = context.originZ();
|
||||
CaveAnchors anchors = newAnchors();
|
||||
for (ProceduralPlacement placement : placements) {
|
||||
boolean chancePassed = passesProceduralChance(rng, placement.chance());
|
||||
if (golden) {
|
||||
log.debug("Goldendebug procedural chance: chunk=" + chunkX + "," + chunkZ + " scope=" + scope + " placement=" + placement.name() + " passed=" + chancePassed);
|
||||
}
|
||||
if (!chancePassed) {
|
||||
continue;
|
||||
}
|
||||
placeProcedural(placement, scope, caveProfile, expectedCaveBiome, anchors, blockX, blockZ);
|
||||
}
|
||||
}
|
||||
|
||||
private void placeProcedural(ProceduralPlacement placement, String scope, CaveProfile caveProfile, ResourceId expectedCaveBiome,
|
||||
CaveAnchors anchors, int blockX, int blockZ) {
|
||||
boolean carving = placement.carvingSupport() == CarvingMode.CARVING_ONLY;
|
||||
CaveAnchors.Search search = caves.searchFor(placement, caveProfile);
|
||||
int density = Math.max(1, placement.density());
|
||||
for (int i = 0; i < density; i++) {
|
||||
Optional<PlaceableObject> picked = placement.variant(rng);
|
||||
if (picked.isEmpty()) {
|
||||
if (golden) {
|
||||
log.debug("Goldendebug procedural pick: chunk=" + chunkX + "," + chunkZ + " placement=" + placement.name() + " densityIndex=" + i + " variant=null");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
PlaceableObject variant = picked.get();
|
||||
CaveAnchors.Anchor anchor = carving ? anchors.find(rng, blockX, blockZ, search, expectedCaveBiome, placement.underwater()) : null;
|
||||
if (carving && anchor == null) {
|
||||
if (golden) {
|
||||
log.debug("Goldendebug procedural cave anchor rejected: chunk=" + chunkX + "," + chunkZ + " placement=" + placement.name()
|
||||
+ " minDepthBelowSurface=" + search.minDepthBelowSurface());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
int x = anchor == null ? rng.i(blockX, blockX + CHUNK_WIDTH_BLOCKS) : anchor.x();
|
||||
int z = anchor == null ? rng.i(blockZ, blockZ + CHUNK_WIDTH_BLOCKS) : anchor.z();
|
||||
int id = rng.i(0, Integer.MAX_VALUE);
|
||||
if (golden) {
|
||||
logProceduralPick(placement, variant, i, x, z, carving);
|
||||
}
|
||||
try {
|
||||
placeProceduralVariant(placement, variant, scope, caveProfile, search, anchor, x, z, id);
|
||||
} catch (Throwable failure) {
|
||||
log.error("Failed to place procedural object '" + placement.name() + "' in " + scope, failure);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void placeProceduralVariant(ProceduralPlacement placement, PlaceableObject variant, String scope, CaveProfile caveProfile,
|
||||
CaveAnchors.Search search, CaveAnchors.Anchor anchor, int x, int z, int id) {
|
||||
String goldenTag = golden ? scope + "/" + placement.name() : null;
|
||||
PlacementTags tags = tags(variant, id, "procedural", placement.tree(), false);
|
||||
int resultY;
|
||||
String commit = "n/a";
|
||||
if (anchor != null) {
|
||||
PlacementChanges changes = effective.forCave(placement, variant, caveProfile);
|
||||
CavePlacement contained = chunk.placeInCave(variant, x, anchor.y(), z, placement, changes, search.minDepthBelowSurface(), tags, goldenTag);
|
||||
resultY = contained.resultY();
|
||||
commit = contained.commit().toString();
|
||||
} else {
|
||||
resultY = chunk.placeOnSurface(variant, x, z, placement, PlacementChanges.NONE, tags, goldenTag);
|
||||
}
|
||||
if (golden) {
|
||||
log.debug("Goldendebug procedural result: chunk=" + chunkX + "," + chunkZ + " placement=" + placement.name()
|
||||
+ " variant=" + variant.name() + " xx=" + x + " zz=" + z + " resultY=" + resultY + " commit=" + commit);
|
||||
}
|
||||
}
|
||||
|
||||
private void logProceduralPick(ProceduralPlacement placement, PlaceableObject variant, int index, int x, int z, boolean carving) {
|
||||
List<PlaceableObject> pool = placement.variants();
|
||||
log.debug("Goldendebug procedural pick: chunk=" + chunkX + "," + chunkZ + " placement=" + placement.name() + " densityIndex=" + index
|
||||
+ " variant=" + variant.name() + " variantIndex=" + pool.indexOf(variant) + "/" + pool.size() + " xx=" + x + " zz=" + z
|
||||
+ " mode=" + placement.mode() + " carving=" + carving);
|
||||
}
|
||||
|
||||
static boolean passesProceduralChance(RNG rng, double chance) {
|
||||
if (chance <= 0.0) {
|
||||
return false;
|
||||
}
|
||||
if (chance >= 1.0) {
|
||||
return true;
|
||||
}
|
||||
return rng.chance(Math.max(0.0, Math.min(1.0, chance + rng.d(-CHANCE_JITTER, CHANCE_JITTER))));
|
||||
}
|
||||
|
||||
private void placeUpperObjects(Column column) {
|
||||
SettingsStack<ObjectSettings> upper = terrain.upperDimension()
|
||||
.map(dimension -> dimension.settings().at(ObjectSettings.class, centerX, centerZ))
|
||||
@@ -593,11 +472,8 @@ final class ChunkObjectPlacing {
|
||||
}
|
||||
}
|
||||
|
||||
private PlacementTags tags(PlaceableObject object, int id, String context, boolean treePlacement, PlacementSource placement) {
|
||||
return tags(object, id, context, treePlacement, placement.isDolphinTarget() && placement.underwater());
|
||||
}
|
||||
|
||||
private PlacementTags tags(PlaceableObject object, int id, String context, boolean treePlacement, boolean buriedTreasure) {
|
||||
private PlacementTags tags(PlaceableObject object, int id, String context, boolean treePlacement, ObjectPlacement placement) {
|
||||
boolean buriedTreasure = placement.isDolphinTarget() && placement.underwater();
|
||||
return new PlacementTags(placementMarker(object, id, context), treePlacement, buriedTreasure);
|
||||
}
|
||||
|
||||
@@ -612,8 +488,12 @@ final class ChunkObjectPlacing {
|
||||
return PlacementRecord.of(this.context.world().resources().idOf(key), id);
|
||||
}
|
||||
|
||||
/** Objects in {@code trees/} are trees, procedural ones in {@code procedural/trees/} too, and so is anything a placement grows from saplings. */
|
||||
private static boolean isTreePlacement(PlaceableObject object, ObjectPlacement placement) {
|
||||
String key = object == null ? null : object.name();
|
||||
if (key != null && ProceduralObjectCatalog.isProceduralKey(key)) {
|
||||
key = key.substring(ProceduralObjectCatalog.KEY_PREFIX.length());
|
||||
}
|
||||
return (key != null && key.startsWith(TREE_FOLDER)) || (placement != null && !placement.trees().isEmpty());
|
||||
}
|
||||
|
||||
@@ -674,15 +554,12 @@ final class ChunkObjectPlacing {
|
||||
}
|
||||
|
||||
private record Column(ResourceId region, ResourceId surface, ResourceId cave, int surfaceY, ColumnObjects objects,
|
||||
ColumnProcedural procedural, ColumnProfiles profiles) {
|
||||
ColumnProfiles profiles) {
|
||||
}
|
||||
|
||||
private record ColumnObjects(ObjectSettings surface, ObjectSettings cave, ObjectSettings region) {
|
||||
}
|
||||
|
||||
private record ColumnProcedural(ProceduralObjectSettings surface, ProceduralObjectSettings cave, ProceduralObjectSettings region) {
|
||||
}
|
||||
|
||||
private record ColumnProfiles(CaveProfile surface, CaveProfile cave, CaveProfile region) {
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ package art.arcane.iris.engine.mantle.components;
|
||||
import art.arcane.iris.builtin.anchor.ObjectPlaceMode;
|
||||
import art.arcane.iris.builtin.anchor.PlaceTrait;
|
||||
import art.arcane.iris.modules.carve.CaveProfile;
|
||||
import art.arcane.iris.builtin.objects.PlacementSource;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.modules.objects.PlacementChanges;
|
||||
import com.volmit.object.PlaceableObject;
|
||||
|
||||
@@ -41,12 +41,12 @@ final class EffectivePlacements {
|
||||
}
|
||||
|
||||
/** The changes to make to {@code placement} to place {@code object} on the surface. */
|
||||
PlacementChanges forSurface(PlacementSource placement, PlaceableObject object) {
|
||||
PlacementChanges forSurface(ObjectPlacement placement, PlaceableObject object) {
|
||||
return withDimensionSurfaceSupport(placement, withImportedMode(placement, object, PlacementChanges.NONE));
|
||||
}
|
||||
|
||||
/** The changes to make to {@code placement} to place {@code object} in a cave with the cave profile {@code caveProfile}. */
|
||||
PlacementChanges forCave(PlacementSource placement, PlaceableObject object, CaveProfile caveProfile) {
|
||||
PlacementChanges forCave(ObjectPlacement placement, PlaceableObject object, CaveProfile caveProfile) {
|
||||
PlacementChanges changes = forSurface(placement, object);
|
||||
ObjectPlaceMode mode = changes.mode() != null ? changes.mode() : placement.mode();
|
||||
if (mode != ObjectPlaceMode.CENTER_HEIGHT || caveProfile == null) {
|
||||
@@ -62,7 +62,7 @@ final class EffectivePlacements {
|
||||
}
|
||||
|
||||
/** Imported objects are placed with the fast minimal stilt unless their mode finds its own height. */
|
||||
private static PlacementChanges withImportedMode(PlacementSource placement, PlaceableObject object, PlacementChanges changes) {
|
||||
private static PlacementChanges withImportedMode(ObjectPlacement placement, PlaceableObject object, PlacementChanges changes) {
|
||||
String key = object.name();
|
||||
if (key == null || key.isBlank() || !isImported(key)) {
|
||||
return changes;
|
||||
@@ -79,7 +79,7 @@ final class EffectivePlacements {
|
||||
}
|
||||
|
||||
/** The dimension widens the buffer of a placement, never narrows it, and its support requirement applies on top of the placement's own: both have to want it. */
|
||||
private PlacementChanges withDimensionSurfaceSupport(PlacementSource placement, PlacementChanges changes) {
|
||||
private PlacementChanges withDimensionSurfaceSupport(ObjectPlacement placement, PlacementChanges changes) {
|
||||
boolean require = placement.requireSurfaceSupport() && dimensionRequiresSurfaceSupport;
|
||||
int buffer = Math.max(placement.surfaceSupportBuffer(), dimensionSurfaceSupportBuffer);
|
||||
if (require == placement.requireSurfaceSupport() && buffer == placement.surfaceSupportBuffer()) {
|
||||
|
||||
@@ -24,6 +24,7 @@ import art.arcane.iris.modules.floating.FloatingChildSettings;
|
||||
import art.arcane.iris.modules.floating.IslandFootprint;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.ObjectSettings;
|
||||
import art.arcane.iris.engine.procedural.ProceduralObjectCatalog;
|
||||
import art.arcane.iris.modules.objects.ObjectPool;
|
||||
import art.arcane.iris.modules.objects.ObjectSize;
|
||||
import com.volmit.object.PlaceableObject;
|
||||
@@ -426,6 +427,7 @@ public final class FloatingObjectPlacing {
|
||||
/** The reach of floating children's objects, each object sized once. */
|
||||
private static final class Reach {
|
||||
private final PackResources resources;
|
||||
private final ProceduralObjectCatalog procedural;
|
||||
private final Map<ResourceId, ObjectSettings> biomeObjects;
|
||||
private final ModuleLog log;
|
||||
private final Map<String, Optional<ObjectSize>> sizes = new HashMap<>();
|
||||
@@ -433,6 +435,7 @@ public final class FloatingObjectPlacing {
|
||||
|
||||
private Reach(PackResources resources, Map<ResourceId, ObjectSettings> biomeObjects, ModuleLog log) {
|
||||
this.resources = resources;
|
||||
this.procedural = ProceduralObjectCatalog.detached(resources, log);
|
||||
this.biomeObjects = biomeObjects;
|
||||
this.log = log;
|
||||
}
|
||||
@@ -479,7 +482,7 @@ public final class FloatingObjectPlacing {
|
||||
|
||||
private int objectReach(String objectKey, ObjectPlacement placement) {
|
||||
try {
|
||||
Optional<ObjectSize> size = sizes.computeIfAbsent(objectKey, key -> PlacementReach.sizeOf(resources, key));
|
||||
Optional<ObjectSize> size = sizes.computeIfAbsent(objectKey, key -> PlacementReach.sizeOf(resources, procedural, key));
|
||||
if (size.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -23,15 +23,14 @@ import art.arcane.iris.builtin.anchor.PlaceTrait;
|
||||
import art.arcane.iris.builtin.blocks.ObjectMarkers;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.ObjectRun;
|
||||
import art.arcane.iris.builtin.objects.PlacementSource;
|
||||
import art.arcane.iris.modules.objects.CarvedSpace;
|
||||
import art.arcane.iris.modules.objects.CavePlacement;
|
||||
import art.arcane.iris.modules.objects.CaveTransaction;
|
||||
import art.arcane.iris.modules.objects.EffectiveSettings;
|
||||
import art.arcane.iris.modules.objects.ForwardingTerrain;
|
||||
import art.arcane.iris.modules.objects.PlacementChanges;
|
||||
import art.arcane.iris.engine.procedural.ProceduralObjectCatalog;
|
||||
import art.arcane.iris.modules.objects.PlacementTags;
|
||||
import art.arcane.iris.modules.objects.ProceduralPlacement;
|
||||
import art.arcane.iris.modules.objects.TerrainTransaction;
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.block.BlockRegistry;
|
||||
@@ -55,17 +54,15 @@ final class ObjectChunk {
|
||||
private final PackWorld world;
|
||||
private final PlacementTerrain terrain;
|
||||
private final CarvedSpace carved;
|
||||
private final EffectiveSettings settings;
|
||||
private final BlockRegistry blocks;
|
||||
private final ModuleLog log;
|
||||
private final int worldHeight;
|
||||
|
||||
ObjectChunk(MantleStageContext context, EffectiveSettings settings, ModuleLog log) {
|
||||
ObjectChunk(MantleStageContext context, ModuleLog log) {
|
||||
this.world = context.world();
|
||||
this.terrain = context.placementTerrain();
|
||||
this.worldHeight = context.terrain().bounds().maxY();
|
||||
this.carved = new CarvedSpace(context.extension(MatterMantle.class).orElseThrow(), worldHeight);
|
||||
this.settings = settings;
|
||||
this.blocks = world.resources().blocks();
|
||||
this.log = log;
|
||||
}
|
||||
@@ -86,10 +83,10 @@ final class ObjectChunk {
|
||||
* @param goldenTag logs the placement's questions under this tag, or null to leave them
|
||||
* @return the height the object was placed at, negative when the placement rejected it
|
||||
*/
|
||||
int placeOnSurface(PlaceableObject object, int x, int z, PlacementSource placement, PlacementChanges changes,
|
||||
int placeOnSurface(PlaceableObject object, int x, int z, ObjectPlacement placement, PlacementChanges changes,
|
||||
PlacementTags tags, String goldenTag) {
|
||||
PlacementTerrain placer = proceduralTerrain(terrain, placement, goldenTag);
|
||||
return place(ObjectRun.of(object, settings.of(placement, changes), x, SAMPLED_HEIGHT, z), placer, tags);
|
||||
PlacementTerrain placer = proceduralTerrain(terrain, object, goldenTag);
|
||||
return place(ObjectRun.of(object, EffectiveSettings.withChanges(placement, changes), x, SAMPLED_HEIGHT, z), placer, tags);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,10 +95,10 @@ final class ObjectChunk {
|
||||
*
|
||||
* @param goldenTag logs the placement's questions under this tag, or null to leave them
|
||||
*/
|
||||
CavePlacement placeInCave(PlaceableObject object, int x, int anchorY, int z, PlacementSource placement, PlacementChanges changes,
|
||||
CavePlacement placeInCave(PlaceableObject object, int x, int anchorY, int z, ObjectPlacement placement, PlacementChanges changes,
|
||||
int minDepthBelowSurface, PlacementTags tags, String goldenTag) {
|
||||
ObjectPlacement effective = settings.of(placement, changes);
|
||||
CaveTransaction transaction = new CaveTransaction(proceduralTerrain(terrain, placement, goldenTag), worldHeight, anchorY,
|
||||
ObjectPlacement effective = EffectiveSettings.withChanges(placement, changes);
|
||||
CaveTransaction transaction = new CaveTransaction(proceduralTerrain(terrain, object, goldenTag), worldHeight, anchorY,
|
||||
minDepthBelowSurface);
|
||||
int placeY = anchorY;
|
||||
if (effective.mode().placeMode().has(PlaceTrait.UPSIDE_DOWN)) {
|
||||
@@ -131,15 +128,15 @@ final class ObjectChunk {
|
||||
}
|
||||
|
||||
/**
|
||||
* A procedural object's terrain: its leaves decay when it is meant to look real, and the golden-debug switch logs
|
||||
* its questions. Object placements use the chunk's terrain as it is.
|
||||
* A procedural variant's terrain: it keeps the leaf states the variant baked, persistent or decaying, and the
|
||||
* golden-debug switch logs its questions. Pack objects use the chunk's terrain as it is.
|
||||
*/
|
||||
private PlacementTerrain proceduralTerrain(PlacementTerrain base, PlacementSource placement, String goldenTag) {
|
||||
if (!(placement instanceof ProceduralPlacement procedural)) {
|
||||
private PlacementTerrain proceduralTerrain(PlacementTerrain base, PlaceableObject object, String goldenTag) {
|
||||
if (!ProceduralObjectCatalog.isProceduralKey(object.name())) {
|
||||
return base;
|
||||
}
|
||||
PlacementTerrain decaying = procedural.plausible() ? new DecayingTerrain(base) : base;
|
||||
return goldenTag == null ? decaying : new GoldenDebugTerrain(decaying, goldenTag, log);
|
||||
PlacementTerrain keepingBakedLeaves = new DecayingTerrain(base);
|
||||
return goldenTag == null ? keepingBakedLeaves : new GoldenDebugTerrain(keepingBakedLeaves, goldenTag, log);
|
||||
}
|
||||
|
||||
/** Writes the tags beside each of the object's own blocks. */
|
||||
@@ -157,7 +154,7 @@ final class ObjectChunk {
|
||||
}
|
||||
}
|
||||
|
||||
/** A terrain whose leaves decay, for procedural objects meant to look like the real thing. */
|
||||
/** A terrain that leaves non-persistent leaves as they are, so they decay like the real thing. */
|
||||
private static final class DecayingTerrain extends ForwardingTerrain {
|
||||
private DecayingTerrain(PlacementTerrain delegate) {
|
||||
super(delegate);
|
||||
|
||||
@@ -21,7 +21,7 @@ package art.arcane.iris.engine.mantle.components;
|
||||
import art.arcane.iris.builtin.IrisStages;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.ObjectSettings;
|
||||
import art.arcane.iris.modules.objects.ProceduralObjectSettings;
|
||||
import art.arcane.iris.engine.procedural.ProceduralObjectCatalog;
|
||||
import art.arcane.iris.builtin.objects.RequireSurfaceSupportSettings;
|
||||
import art.arcane.iris.builtin.objects.SurfaceSupportBufferSettings;
|
||||
import art.arcane.iris.modules.objects.TreeGrowthSettings;
|
||||
@@ -41,8 +41,9 @@ import com.volmit.world.PackWorld;
|
||||
/**
|
||||
* Module {@code iris:objects}: the objects the dimension's regions and biomes place, written into the mantle
|
||||
* once the caves they may anchor in are planned. A port of what was Iris's object mantle component, its work
|
||||
* done by {@link ObjectPlacing}, one per engine runtime, with the noise of its placements and the variants of its procedural
|
||||
* objects built ahead of generation ({@link #warmUp}). Its reach is the pack's largest object placement. It tells
|
||||
* done by {@link ObjectPlacing}, one per engine runtime, with the noise of its placements and the variants of the
|
||||
* procedural objects they place ({@link ProceduralObjectCatalog}) built ahead of generation ({@link #warmUp}). Its
|
||||
* reach is the pack's largest object placement. It tells
|
||||
* Iris which objects a chunk would get and which biomes and regions place an object ({@link ObjectLocating}), for the
|
||||
* object search and studio tools, and grows the trees of saplings ({@link TreeGrowing}).
|
||||
*/
|
||||
@@ -63,9 +64,9 @@ public final class ObjectModule implements IrisModule, ModuleLifecycle {
|
||||
var registry = setup.registry();
|
||||
registry.registerService(ObjectsAt.class, new ObjectLocating());
|
||||
registry.registerService(SaplingGrowth.class, new TreeGrowing());
|
||||
registry.registerSettings(ObjectSettings.class, ProceduralObjectSettings.class, TreeGrowthSettings.class,
|
||||
RequireSurfaceSupportSettings.class, SurfaceSupportBufferSettings.class, UpperObjectsSettings.class,
|
||||
UpperObjectsForceSettings.class);
|
||||
registry.registerSettings(ObjectSettings.class, TreeGrowthSettings.class, RequireSurfaceSupportSettings.class,
|
||||
SurfaceSupportBufferSettings.class, UpperObjectsSettings.class, UpperObjectsForceSettings.class);
|
||||
registry.registerResourceKind(ProceduralObjectCatalog.DEFINITIONS);
|
||||
registry.registerPlacementType(ObjectPlacement.class, ObjectPlacement.jsonFields());
|
||||
registry.registerLifecycle(this);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.ObjectSettings;
|
||||
import art.arcane.iris.modules.objects.EffectiveSettings;
|
||||
import art.arcane.iris.modules.objects.ObjectPool;
|
||||
import art.arcane.iris.modules.objects.ObjectSeparation;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
@@ -50,7 +49,6 @@ public final class ObjectPlacing {
|
||||
private final PackWorld world;
|
||||
private final ObjectPool objects;
|
||||
private final ObjectSeparation separation;
|
||||
private final EffectiveSettings settings = new EffectiveSettings();
|
||||
private final ModuleLog log;
|
||||
|
||||
private ObjectPlacing(PackWorld world) {
|
||||
@@ -67,7 +65,7 @@ public final class ObjectPlacing {
|
||||
|
||||
/** Places what originates in the chunk {@code context} generates. */
|
||||
void place(MantleStageContext context) {
|
||||
new ChunkObjectPlacing(objects, settings, log, context).place();
|
||||
new ChunkObjectPlacing(objects, log, context).place();
|
||||
}
|
||||
|
||||
/** The keys of the objects the chunk would get, as far as the chunk's surface objects go. */
|
||||
|
||||
@@ -21,11 +21,8 @@ package art.arcane.iris.engine.mantle.components;
|
||||
import art.arcane.iris.builtin.IrisSeedPurposes;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.ObjectSettings;
|
||||
import art.arcane.iris.modules.objects.ProceduralObjectSettings;
|
||||
import art.arcane.iris.engine.object.procedural.ResolvedProceduralObjects;
|
||||
import art.arcane.iris.modules.objects.Declaration;
|
||||
import art.arcane.iris.modules.objects.ObjectPool;
|
||||
import art.arcane.iris.modules.objects.ProceduralPlacement;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.config.Level;
|
||||
import com.volmit.world.PackWorld;
|
||||
@@ -55,18 +52,12 @@ final class ObjectWarmUp {
|
||||
|
||||
void warm() {
|
||||
List<Declaration<ObjectSettings>> placements = byKey(Declaration.allOf(world, ObjectSettings.class));
|
||||
List<Declaration<ProceduralObjectSettings>> procedural = byKey(Declaration.allOf(world, ProceduralObjectSettings.class));
|
||||
for (Level level : WARMED_LEVELS) {
|
||||
for (Declaration<ObjectSettings> declaration : placements) {
|
||||
if (declaration.level() == level) {
|
||||
warmPlacements(declaration.settings().objects());
|
||||
}
|
||||
}
|
||||
for (Declaration<ProceduralObjectSettings> declaration : procedural) {
|
||||
if (declaration.level() == level) {
|
||||
warmProcedural(declaration.settings());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,10 +72,4 @@ final class ObjectWarmUp {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void warmProcedural(ProceduralObjectSettings settings) {
|
||||
for (ProceduralPlacement placement : ResolvedProceduralObjects.of(world, settings)) {
|
||||
placement.variant(root.nextParallelRNG(warmed++));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,19 +21,17 @@ package art.arcane.iris.engine.mantle.components;
|
||||
import art.arcane.iris.builtin.anchor.PlaceMode;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.ObjectSettings;
|
||||
import art.arcane.iris.modules.objects.ProceduralObjectSettings;
|
||||
import art.arcane.iris.builtin.prepare.AxisRotationClamp;
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
import art.arcane.iris.builtin.prepare.ObjectTranslate;
|
||||
import art.arcane.iris.builtin.vacuum.VacuumSettings;
|
||||
import art.arcane.iris.engine.object.procedural.ResolvedProceduralObjects;
|
||||
import art.arcane.iris.engine.procedural.ProceduralObjectCatalog;
|
||||
import art.arcane.iris.engine.procedural.ProceduralVariants;
|
||||
import art.arcane.iris.modules.objects.ObjectSize;
|
||||
import art.arcane.iris.modules.objects.ProceduralPlacement;
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.config.FeatureSettings.Entry;
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.geometry.BlockBox;
|
||||
import com.volmit.object.PlaceableObject;
|
||||
import com.volmit.resource.PackResources;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -50,24 +48,23 @@ final class PlacementReach {
|
||||
private static final double SCALE_PADDING_FACTOR = 2D;
|
||||
|
||||
private final PackResources resources;
|
||||
private final ProceduralObjectCatalog procedural;
|
||||
private final ModuleLog log;
|
||||
private final Map<String, Optional<ObjectSize>> sizes = new HashMap<>();
|
||||
private final Set<String> warnedLargeObjects = new HashSet<>();
|
||||
|
||||
PlacementReach(PackResources resources, ModuleLog log) {
|
||||
this.resources = resources;
|
||||
this.procedural = ProceduralObjectCatalog.detached(resources, log);
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
/** The largest reach of any object placement or procedural object the pack's regions and biomes declare. */
|
||||
/** The largest reach of any object placement the pack's regions and biomes declare. */
|
||||
int ofPack(PackSettings settings) {
|
||||
int radius = 0;
|
||||
for (Entry<ObjectSettings> entry : settings.declared(ObjectSettings.class)) {
|
||||
radius = Math.max(radius, ofPlacements(entry.value().objects()));
|
||||
}
|
||||
for (Entry<ProceduralObjectSettings> entry : settings.declared(ProceduralObjectSettings.class)) {
|
||||
radius = Math.max(radius, ofProcedural(entry.value()));
|
||||
}
|
||||
return radius;
|
||||
}
|
||||
|
||||
@@ -86,7 +83,7 @@ final class PlacementReach {
|
||||
|
||||
private int ofObject(ObjectPlacement placement, String objectKey) {
|
||||
try {
|
||||
Optional<ObjectSize> size = sizes.computeIfAbsent(objectKey, key -> sizeOf(resources, key));
|
||||
Optional<ObjectSize> size = sizes.computeIfAbsent(objectKey, key -> sizeOf(resources, procedural, key));
|
||||
if (size.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
@@ -101,8 +98,11 @@ final class PlacementReach {
|
||||
}
|
||||
}
|
||||
|
||||
/** The size of the pack object {@code objectKey} names; empty when the pack has none. */
|
||||
static Optional<ObjectSize> sizeOf(PackResources resources, String objectKey) {
|
||||
/** The size of the object {@code objectKey} names, for a procedural pool its largest variant; empty when the pack has none. */
|
||||
static Optional<ObjectSize> sizeOf(PackResources resources, ProceduralObjectCatalog procedural, String objectKey) {
|
||||
if (ProceduralObjectCatalog.isProceduralKey(objectKey)) {
|
||||
return procedural.variants(objectKey).map(ProceduralVariants::largestSize);
|
||||
}
|
||||
return resources.objects().sizeOf(resources.idOf(objectKey)).map(PlacementReach::sizeOf);
|
||||
}
|
||||
|
||||
@@ -110,22 +110,6 @@ final class PlacementReach {
|
||||
return new ObjectSize(box.maxX() - box.minX(), box.maxY() - box.minY(), box.maxZ() - box.minZ());
|
||||
}
|
||||
|
||||
private int ofProcedural(ProceduralObjectSettings settings) {
|
||||
int radius = 0;
|
||||
for (ProceduralPlacement placement : ResolvedProceduralObjects.resolve(settings, resources)) {
|
||||
for (PlaceableObject variant : placement.variants()) {
|
||||
radius = Math.max(radius, of(new ObjectSize(variant.width(), variant.height(), variant.depth()), placement));
|
||||
}
|
||||
}
|
||||
return radius;
|
||||
}
|
||||
|
||||
/** The reach of an object of {@code size} placed with the options a procedural object has. */
|
||||
static int of(ObjectSize size, ProceduralPlacement placement) {
|
||||
return of(size, placement.mode().placeMode(), null, placement.rotation(), placement.translate(), null,
|
||||
placement.vacuumSettings().orElse(null));
|
||||
}
|
||||
|
||||
static int of(ObjectSize size, ObjectPlacement placement) {
|
||||
return of(size, placement.mode().placeMode(), placement.scale().maxScale(), placement.rotation(), placement.translate(),
|
||||
placement.warp() == null || placement.warp().isFlat() ? 0 : placement.warp().multiplier(),
|
||||
|
||||
@@ -21,10 +21,9 @@ package art.arcane.iris.engine.mantle.components;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.ObjectRun;
|
||||
import art.arcane.iris.builtin.objects.ObjectSettings;
|
||||
import art.arcane.iris.modules.objects.ProceduralObjectSettings;
|
||||
import art.arcane.iris.engine.procedural.ProceduralObjectCatalog;
|
||||
import art.arcane.iris.modules.objects.TreeGrowthSettings;
|
||||
import art.arcane.iris.modules.objects.TreeMode;
|
||||
import art.arcane.iris.modules.objects.tree.Tree;
|
||||
import art.arcane.iris.engine.loot.BlockBiomes;
|
||||
import art.arcane.iris.modules.objects.Declaration;
|
||||
import art.arcane.iris.modules.objects.ObjectPool;
|
||||
@@ -61,6 +60,7 @@ import java.util.stream.Collectors;
|
||||
public final class TreeGrowing implements SaplingGrowth {
|
||||
private static final int SAPLING_WIDTH = 1;
|
||||
private static final int SAPLING_DEPTH = 1;
|
||||
private static final String PROCEDURAL_TREE_FOLDER = ProceduralObjectCatalog.KEY_PREFIX + "trees/";
|
||||
|
||||
@Override
|
||||
public Optional<Growth> grow(PackWorld world, Sapling sapling, Surroundings surroundings) {
|
||||
@@ -75,7 +75,7 @@ public final class TreeGrowing implements SaplingGrowth {
|
||||
return Optional.empty();
|
||||
}
|
||||
List<String> keys = placement.get().place();
|
||||
Optional<PlaceableObject> tree = ObjectPool.of(world).object(keys.get(RNG.r.i(keys.size())));
|
||||
Optional<PlaceableObject> tree = ObjectPool.of(world).object(keys.get(RNG.r.i(keys.size())), RNG.r);
|
||||
if (tree.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
@@ -90,14 +90,24 @@ public final class TreeGrowing implements SaplingGrowth {
|
||||
@Override
|
||||
public TreeObjects treeObjects(PackWorld world) {
|
||||
Set<String> objects = new HashSet<>();
|
||||
Set<String> procedural = new HashSet<>();
|
||||
for (Declaration<ObjectSettings> declaration : Declaration.allOf(world, ObjectSettings.class)) {
|
||||
collectPlacements(declaration.settings().objects(), objects);
|
||||
}
|
||||
for (Declaration<ProceduralObjectSettings> declaration : Declaration.allOf(world, ProceduralObjectSettings.class)) {
|
||||
collectProceduralTrees(declaration.settings().trees(), procedural);
|
||||
return new TreeObjects(idsOf(world, placedNames(world, objects)));
|
||||
}
|
||||
|
||||
/** The names objects are placed under: a procedural pool's are its variants' own. */
|
||||
private static Set<String> placedNames(PackWorld world, Set<String> objectKeys) {
|
||||
ProceduralObjectCatalog procedural = ProceduralObjectCatalog.of(world);
|
||||
Set<String> names = new HashSet<>();
|
||||
for (String key : objectKeys) {
|
||||
if (ProceduralObjectCatalog.isProceduralKey(key)) {
|
||||
procedural.placeable(key).forEach(variant -> names.add(variant.name()));
|
||||
} else {
|
||||
names.add(key);
|
||||
}
|
||||
}
|
||||
return new TreeObjects(idsOf(world, objects), idsOf(world, procedural));
|
||||
return names;
|
||||
}
|
||||
|
||||
private static Set<ResourceId> idsOf(PackWorld world, Set<String> keys) {
|
||||
@@ -134,29 +144,22 @@ public final class TreeGrowing implements SaplingGrowth {
|
||||
return matches;
|
||||
}
|
||||
|
||||
/** The objects of tree placements, and procedural objects in {@code procedural/trees/} wherever they are placed. */
|
||||
private static void collectPlacements(List<ObjectPlacement> placements, Set<String> objectKeys) {
|
||||
for (ObjectPlacement placement : placements) {
|
||||
if (placement == null || placement.trees().isEmpty()) {
|
||||
if (placement == null) {
|
||||
continue;
|
||||
}
|
||||
for (String objectKey : placement.place()) {
|
||||
if (objectKey != null && !objectKey.isBlank()) {
|
||||
if (objectKey != null && !objectKey.isBlank() && (!placement.trees().isEmpty() || isProceduralTree(objectKey))) {
|
||||
objectKeys.add(objectKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void collectProceduralTrees(List<Tree> trees, Set<String> objectKeys) {
|
||||
for (Tree tree : trees) {
|
||||
if (tree == null || tree.name() == null || tree.name().isBlank()) {
|
||||
continue;
|
||||
}
|
||||
int variants = Math.max(1, tree.variants());
|
||||
for (int index = 0; index < variants; index++) {
|
||||
objectKeys.add(Tree.variantLoadKey(tree.name(), index));
|
||||
}
|
||||
}
|
||||
private static boolean isProceduralTree(String objectKey) {
|
||||
return objectKey.startsWith(PROCEDURAL_TREE_FOLDER);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,134 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural;
|
||||
|
||||
import art.arcane.iris.modules.objects.ObjectBuilder;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.block.PaletteSpec;
|
||||
import com.volmit.object.ObjectBlock;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Shared low-level helpers for building procedural objects in memory: resolving a single block id or a noise palette
|
||||
* into a block state, and assembling a raw block map into a centered object shape anchored so its y=0 layer sits one
|
||||
* block above the terrain surface (same convention the tree generator uses).
|
||||
*/
|
||||
public final class IrisProceduralBlocks {
|
||||
public static final String[] FACE_PROPERTIES = {"north", "east", "south", "west", "up", "down"};
|
||||
|
||||
private IrisProceduralBlocks() {
|
||||
}
|
||||
|
||||
public static int[] faceOffset(String face) {
|
||||
return switch (face) {
|
||||
case "north" -> new int[]{0, 0, -1};
|
||||
case "south" -> new int[]{0, 0, 1};
|
||||
case "east" -> new int[]{1, 0, 0};
|
||||
case "west" -> new int[]{-1, 0, 0};
|
||||
case "up" -> new int[]{0, 1, 0};
|
||||
default -> new int[]{0, -1, 0};
|
||||
};
|
||||
}
|
||||
|
||||
public static boolean paletteSet(PaletteSpec palette) {
|
||||
return palette != null && !palette.palette().isEmpty();
|
||||
}
|
||||
|
||||
public static boolean paletteSet(Optional<PaletteSpec> palette) {
|
||||
return palette.filter(IrisProceduralBlocks::paletteSet).isPresent();
|
||||
}
|
||||
|
||||
public static BlockState resolve(String block, Optional<PaletteSpec> palette, ObjectBuilder blocks, int x, int y, int z, RNG paletteRng) {
|
||||
return resolve(block, palette.orElse(null), blocks, x, y, z, paletteRng);
|
||||
}
|
||||
|
||||
public static BlockState resolve(Optional<String> block, Optional<PaletteSpec> palette, ObjectBuilder blocks, int x, int y, int z, RNG paletteRng) {
|
||||
return resolve(block.orElse(null), palette.orElse(null), blocks, x, y, z, paletteRng);
|
||||
}
|
||||
|
||||
/** The block of {@code palette} at the position, picked with the seed of {@code paletteRng} as the palette's old class did; else {@code block}. */
|
||||
public static BlockState resolve(String block, PaletteSpec palette, ObjectBuilder blocks, int x, int y, int z, RNG paletteRng) {
|
||||
if (paletteSet(palette)) {
|
||||
return blocks.pick(palette, paletteRng.getSeed(), x, y, z);
|
||||
}
|
||||
if (block != null && !block.isEmpty()) {
|
||||
return blocks.block(block);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean hasProperty(BlockState state, String property) {
|
||||
return state.properties().containsKey(property);
|
||||
}
|
||||
|
||||
public static String materialKey(BlockState state) {
|
||||
return state.material().toString();
|
||||
}
|
||||
|
||||
public static String propertyValue(BlockState state, String property) {
|
||||
return state.properties().get(property);
|
||||
}
|
||||
|
||||
/** The blocks centered on x and z, with their lowest layer one block above the anchor; null when there are none. */
|
||||
public static ProceduralShape assemble(Map<Vector3i, BlockState> blocks) {
|
||||
if (blocks == null || blocks.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int minX = Integer.MAX_VALUE;
|
||||
int minY = Integer.MAX_VALUE;
|
||||
int minZ = Integer.MAX_VALUE;
|
||||
int maxX = Integer.MIN_VALUE;
|
||||
int maxY = Integer.MIN_VALUE;
|
||||
int maxZ = Integer.MIN_VALUE;
|
||||
for (Vector3i v : blocks.keySet()) {
|
||||
minX = Math.min(minX, v.getBlockX());
|
||||
minY = Math.min(minY, v.getBlockY());
|
||||
minZ = Math.min(minZ, v.getBlockZ());
|
||||
maxX = Math.max(maxX, v.getBlockX());
|
||||
maxY = Math.max(maxY, v.getBlockY());
|
||||
maxZ = Math.max(maxZ, v.getBlockZ());
|
||||
}
|
||||
|
||||
int w = maxX - minX + 1;
|
||||
int h = maxY - minY + 1;
|
||||
int d = maxZ - minZ + 1;
|
||||
int cx = w / 2;
|
||||
int cy = h / 2;
|
||||
int cz = d / 2;
|
||||
|
||||
List<ObjectBlock> placed = new ArrayList<>(blocks.size());
|
||||
for (Map.Entry<Vector3i, BlockState> entry : blocks.entrySet()) {
|
||||
Vector3i v = entry.getKey();
|
||||
int nx = v.getBlockX() - minX - cx;
|
||||
int ny = v.getBlockY() - cy + 1;
|
||||
int nz = v.getBlockZ() - minZ - cz;
|
||||
placed.add(new ObjectBlock(new BlockPosition(nx, ny, nz), entry.getValue()));
|
||||
}
|
||||
|
||||
return new ProceduralShape(w, h, d, placed);
|
||||
}
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural;
|
||||
|
||||
import art.arcane.iris.modules.objects.ProceduralObjectSettings;
|
||||
import art.arcane.iris.modules.objects.tree.Tree;
|
||||
import art.arcane.iris.engine.object.procedural.coral.ResolvedCoral;
|
||||
import art.arcane.iris.engine.object.procedural.crystal.ResolvedCrystal;
|
||||
import art.arcane.iris.engine.object.procedural.formation.ResolvedFormation;
|
||||
import art.arcane.iris.engine.object.procedural.fungi.ResolvedFungus;
|
||||
import art.arcane.iris.engine.object.procedural.ruin.ResolvedRuin;
|
||||
import art.arcane.iris.engine.object.procedural.tree.ResolvedTree;
|
||||
import art.arcane.iris.modules.objects.ProceduralPlacement;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.world.PackWorld;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
/** The procedural objects a region or biome declares, each made placeable once per world, in the order the settings list them. */
|
||||
public final class ResolvedProceduralObjects {
|
||||
private ResolvedProceduralObjects() {
|
||||
}
|
||||
|
||||
/** The placements {@code settings} declare in {@code world}, resolved the first time the world asks. */
|
||||
public static List<ProceduralPlacement> of(PackWorld world, ProceduralObjectSettings settings) {
|
||||
PackResources resources = world.resources();
|
||||
return world.state(ResolvedByDeclaration.class, ignored -> new ResolvedByDeclaration()).placements
|
||||
.computeIfAbsent(settings, declared -> resolve(declared, resources));
|
||||
}
|
||||
|
||||
/** The placements {@code settings} declare, resolved anew, for work outside any world such as working out the pack's reach. */
|
||||
public static List<ProceduralPlacement> resolve(ProceduralObjectSettings settings, PackResources resources) {
|
||||
List<ProceduralPlacement> all = new ArrayList<>();
|
||||
for (Tree tree : settings.trees()) {
|
||||
all.add(new ResolvedTree(tree, resources));
|
||||
}
|
||||
addAll(all, settings.ruins(), resources, ResolvedRuin::new);
|
||||
addAll(all, settings.formations(), resources, ResolvedFormation::new);
|
||||
addAll(all, settings.coral(), resources, ResolvedCoral::new);
|
||||
addAll(all, settings.fungi(), resources, ResolvedFungus::new);
|
||||
addAll(all, settings.crystals(), resources, ResolvedCrystal::new);
|
||||
return List.copyOf(all);
|
||||
}
|
||||
|
||||
private static <S> void addAll(List<ProceduralPlacement> all, List<S> settings, PackResources resources,
|
||||
BiFunction<S, PackResources, ResolvedProceduralPlacement> resolve) {
|
||||
for (S entry : settings) {
|
||||
all.add(resolve.apply(entry, resources));
|
||||
}
|
||||
}
|
||||
|
||||
/** A world's resolved placements, by the settings that declare them. */
|
||||
private static final class ResolvedByDeclaration {
|
||||
private final Map<ProceduralObjectSettings, List<ProceduralPlacement>> placements = new ConcurrentHashMap<>();
|
||||
}
|
||||
}
|
||||
-181
@@ -1,181 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural;
|
||||
|
||||
import art.arcane.iris.builtin.anchor.ObjectPlaceMode;
|
||||
import art.arcane.iris.builtin.carve.CarvingMode;
|
||||
import art.arcane.iris.builtin.carve.CaveAnchorMode;
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
import art.arcane.iris.builtin.prepare.ObjectTranslate;
|
||||
import art.arcane.iris.builtin.stilt.StiltSettings;
|
||||
import art.arcane.iris.builtin.vacuum.VacuumSettings;
|
||||
import art.arcane.iris.builtin.validate.ObjectLimit;
|
||||
import art.arcane.iris.modules.objects.ObjectBuilder;
|
||||
import art.arcane.iris.modules.objects.ProceduralPlacement;
|
||||
import art.arcane.volmlib.util.cache.AtomicCache;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.object.PlaceableObject;
|
||||
import com.volmit.resource.PackResources;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* A procedural object's settings made placeable: bakes a deterministic pool of variants from them, once, through the
|
||||
* pack's objects ({@link ObjectBuilder}), and hands the placement options to {@code iris:objects}.
|
||||
*/
|
||||
public abstract class ResolvedProceduralPlacement implements ProceduralPlacement {
|
||||
private static final long VARIANT_SEED_STRIDE = 7919L;
|
||||
|
||||
/** The options every procedural placement shares with an object placement. */
|
||||
public record Shape(String name, double chance, int density, long seed, int variants, ObjectPlaceMode mode,
|
||||
ObjectRotation rotation, ObjectLimit clamp, CarvingMode carvingSupport, boolean underwater,
|
||||
ObjectTranslate translate, StiltSettings stiltSettings, VacuumSettings vacuumSettings) {
|
||||
}
|
||||
|
||||
private final Shape shape;
|
||||
private final PackResources resources;
|
||||
private final AtomicCache<List<PlaceableObject>> variantCache = new AtomicCache<>();
|
||||
|
||||
protected ResolvedProceduralPlacement(Shape shape, PackResources resources) {
|
||||
this.shape = shape;
|
||||
this.resources = resources;
|
||||
}
|
||||
|
||||
/** The shape variant {@code index} is baked as, from its own seeded stream; null when it has no blocks. */
|
||||
protected abstract ProceduralShape generate(int index, RNG rng, ObjectBuilder blocks);
|
||||
|
||||
/** The number of variants to bake; the settings' count, at least one. */
|
||||
protected int variantCount() {
|
||||
return Math.max(1, shape.variants());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return shape.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double chance() {
|
||||
return shape.chance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int density() {
|
||||
return shape.density();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean plausible() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tree() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectPlaceMode mode() {
|
||||
return shape.mode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CarvingMode carvingSupport() {
|
||||
return shape.carvingSupport();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CaveAnchorMode caveAnchorMode() {
|
||||
return CaveAnchorMode.PROFILE_DEFAULT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean underwater() {
|
||||
return shape.underwater();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectRotation rotation() {
|
||||
return shape.rotation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectTranslate translate() {
|
||||
return shape.translate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<VacuumSettings> vacuumSettings() {
|
||||
return Optional.ofNullable(shape.vacuumSettings());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectLimit clamp() {
|
||||
return shape.clamp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<StiltSettings> stiltSettings() {
|
||||
return Optional.ofNullable(shape.stiltSettings());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PlaceableObject> variants() {
|
||||
return variantCache.aquire(() -> bake(new ObjectBuilder(resources)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<PlaceableObject> variant(RNG rng) {
|
||||
List<PlaceableObject> baked = variants();
|
||||
if (baked == null || baked.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(baked.get(rng.i(baked.size())));
|
||||
}
|
||||
|
||||
/** Bakes every variant; the default draws variant {@code i} from {@code seed + i * stride}. */
|
||||
protected List<PlaceableObject> bake(ObjectBuilder blocks) {
|
||||
List<PlaceableObject> baked = new ArrayList<>();
|
||||
int count = variantCount();
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
ProceduralShape generated = generate(i, variantRng(i), blocks);
|
||||
if (generated == null || generated.blocks().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
baked.add(build(blocks, "procedural/" + shape.name() + "#" + i, generated));
|
||||
}
|
||||
|
||||
return baked;
|
||||
}
|
||||
|
||||
protected static PlaceableObject build(ObjectBuilder blocks, String loadKey, ProceduralShape generated) {
|
||||
return blocks.build(loadKey, generated.width(), generated.height(), generated.depth(), generated.blocks());
|
||||
}
|
||||
|
||||
protected final RNG variantRng(int index) {
|
||||
return new RNG(shape.seed() + (index * VARIANT_SEED_STRIDE));
|
||||
}
|
||||
|
||||
protected final long seed() {
|
||||
return shape.seed();
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.coral;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class CoralCanvas {
|
||||
public enum Role {
|
||||
STRUCTURE,
|
||||
TIP
|
||||
}
|
||||
|
||||
private static final long BIAS = 1L << 20;
|
||||
private static final long MASK = (1L << 21) - 1L;
|
||||
|
||||
private final Map<Long, Role> cells = new HashMap<>();
|
||||
|
||||
public void set(int x, int y, int z, Role role) {
|
||||
if (y < 0) {
|
||||
return;
|
||||
}
|
||||
long key = encode(x, y, z);
|
||||
Role existing = cells.get(key);
|
||||
if (existing == Role.TIP && role == Role.STRUCTURE) {
|
||||
return;
|
||||
}
|
||||
cells.put(key, role);
|
||||
}
|
||||
|
||||
public Map<Long, Role> getCells() {
|
||||
return cells;
|
||||
}
|
||||
|
||||
public static long encode(int x, int y, int z) {
|
||||
long ex = (x + BIAS) & MASK;
|
||||
long ey = (y + BIAS) & MASK;
|
||||
long ez = (z + BIAS) & MASK;
|
||||
return (ex << 42) | (ey << 21) | ez;
|
||||
}
|
||||
|
||||
public static int[] decode(long key) {
|
||||
int ez = (int) ((key & MASK) - BIAS);
|
||||
int ey = (int) (((key >> 21) & MASK) - BIAS);
|
||||
int ex = (int) (((key >> 42) & MASK) - BIAS);
|
||||
return new int[]{ex, ey, ez};
|
||||
}
|
||||
}
|
||||
@@ -1,263 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.coral;
|
||||
|
||||
import art.arcane.iris.modules.objects.coral.Coral;
|
||||
import art.arcane.iris.modules.objects.ObjectBuilder;
|
||||
import art.arcane.iris.engine.object.procedural.ProceduralShape;
|
||||
import art.arcane.iris.engine.object.procedural.IrisProceduralBlocks;
|
||||
import art.arcane.iris.engine.object.procedural.tree.TreeFunctions;
|
||||
import com.volmit.block.BlockState;
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class CoralGenerator {
|
||||
private static final double GOLDEN_ANGLE = 137.50776405003785;
|
||||
|
||||
private CoralGenerator() {
|
||||
}
|
||||
|
||||
public static ProceduralShape generate(Coral coral, int variantIndex, RNG rng, ObjectBuilder blocks) {
|
||||
int lo = Math.min(coral.heightMin(), coral.heightMax());
|
||||
int hi = Math.max(coral.heightMin(), coral.heightMax());
|
||||
int height = Math.max(2, rng.i(lo, hi + 1));
|
||||
long shapeSeed = rng.getSeed() + variantIndex * 31L;
|
||||
|
||||
CoralCanvas canvas = new CoralCanvas();
|
||||
switch (coral.form()) {
|
||||
case BRANCHING -> buildBranching(canvas, coral, height, shapeSeed, rng);
|
||||
case FAN -> buildFan(canvas, coral, height, shapeSeed);
|
||||
case BRAIN -> buildBrain(canvas, coral, height, shapeSeed);
|
||||
case PILLAR -> buildPillar(canvas, coral, height, shapeSeed);
|
||||
case TENDRIL -> buildTendril(canvas, coral, height, shapeSeed, rng);
|
||||
}
|
||||
|
||||
Map<Vector3i, BlockState> resolved = resolve(canvas, coral, blocks);
|
||||
return IrisProceduralBlocks.assemble(resolved);
|
||||
}
|
||||
|
||||
private static void buildBranching(CoralCanvas canvas, Coral coral, int height, long seed, RNG rng) {
|
||||
int stalkTop = Math.max(1, (int) Math.round(height * 0.5));
|
||||
for (int y = 0; y < stalkTop; y++) {
|
||||
placeWavy(canvas, coral, 0, y, 0, y, seed, CoralCanvas.Role.STRUCTURE);
|
||||
}
|
||||
|
||||
int count = Math.max(1, coral.branchCount());
|
||||
for (int b = 0; b < count; b++) {
|
||||
double az = branchAzimuth(coral, b, count, rng);
|
||||
int startY = stalkTop - 1 + (int) Math.round((b % 2) * 1.0);
|
||||
double[] tip = rasterizeArm(canvas, coral, 0, startY, 0, az,
|
||||
coral.branchElevation(), coral.branchLength(), seed + b * 131L);
|
||||
|
||||
placeTipCluster(canvas, coral, (int) Math.round(tip[0]), (int) Math.round(tip[1]), (int) Math.round(tip[2]),
|
||||
coral.tipClusterRadius(), seed + b * 977L);
|
||||
|
||||
if (coral.subBranches()) {
|
||||
int subCount = Math.max(1, coral.subBranchCount());
|
||||
for (int s = 0; s < subCount; s++) {
|
||||
double subAz = az + (s - (subCount - 1) / 2.0) * 35.0;
|
||||
double subLen = coral.branchLength() * coral.subBranchScale();
|
||||
double[] subTip = rasterizeArm(canvas, coral,
|
||||
(int) Math.round(tip[0]), (int) Math.round(tip[1]), (int) Math.round(tip[2]),
|
||||
subAz, coral.branchElevation() + 10.0, subLen, seed + b * 131L + s * 17L + 5000L);
|
||||
placeTipCluster(canvas, coral, (int) Math.round(subTip[0]), (int) Math.round(subTip[1]), (int) Math.round(subTip[2]),
|
||||
Math.max(0, coral.tipClusterRadius() - 1), seed + b * 977L + s * 53L);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void buildFan(CoralCanvas canvas, Coral coral, int height, long seed) {
|
||||
int half = Math.max(1, coral.fanWidth());
|
||||
for (int y = 0; y < height; y++) {
|
||||
double t = y / (double) Math.max(1, height - 1);
|
||||
double profile = Math.sin(Math.PI * t);
|
||||
int w = (int) Math.round(half * profile);
|
||||
for (int dx = -w; dx <= w; dx++) {
|
||||
canvas.set(dx, y, 0, CoralCanvas.Role.STRUCTURE);
|
||||
}
|
||||
}
|
||||
for (int dx = -half; dx <= half; dx++) {
|
||||
placeTip(canvas, coral, dx, height - 1, 0, seed + dx);
|
||||
}
|
||||
}
|
||||
|
||||
private static void buildBrain(CoralCanvas canvas, Coral coral, int height, long seed) {
|
||||
int r = Math.max(1, coral.brainRadius());
|
||||
int ry = Math.max(1, Math.min(r, (int) Math.round(height * 0.6)));
|
||||
double rough = coral.brainRoughness();
|
||||
for (int dx = -r; dx <= r; dx++) {
|
||||
for (int dz = -r; dz <= r; dz++) {
|
||||
for (int dy = 0; dy <= ry * 2; dy++) {
|
||||
double nx = dx / (double) r;
|
||||
double ny = (dy - ry) / (double) ry;
|
||||
double nz = dz / (double) r;
|
||||
double d = nx * nx + ny * ny + nz * nz;
|
||||
double wobble = (TreeFunctions.valueNoise3D(dx, dy, dz, seed) - 0.5) * 2.0 * rough;
|
||||
if (d <= 1.0 + wobble) {
|
||||
canvas.set(dx, dy, dz, CoralCanvas.Role.STRUCTURE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void buildPillar(CoralCanvas canvas, Coral coral, int height, long seed) {
|
||||
int r = Math.max(1, coral.pillarRadius());
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int dx = -r; dx <= r; dx++) {
|
||||
for (int dz = -r; dz <= r; dz++) {
|
||||
if (dx * dx + dz * dz <= r * r) {
|
||||
canvas.set(dx, y, dz, CoralCanvas.Role.STRUCTURE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
placeTipCluster(canvas, coral, 0, height - 1, 0, coral.tipClusterRadius(), seed);
|
||||
}
|
||||
|
||||
private static void buildTendril(CoralCanvas canvas, Coral coral, int height, long seed, RNG rng) {
|
||||
int count = Math.max(1, coral.tendrilCount());
|
||||
double radius = Math.max(0.0, coral.spread());
|
||||
for (int c = 0; c < count; c++) {
|
||||
double az = Math.toRadians(c * (360.0 / count));
|
||||
double bx = Math.cos(az) * radius * 0.5;
|
||||
double bz = Math.sin(az) * radius * 0.5;
|
||||
int tx = (int) Math.round(bx);
|
||||
int tz = (int) Math.round(bz);
|
||||
int top = 0;
|
||||
for (int y = 0; y < height; y++) {
|
||||
placeWavy(canvas, coral, tx, y, tz, y * (c + 1), seed + c * 311L, CoralCanvas.Role.STRUCTURE);
|
||||
top = y;
|
||||
}
|
||||
placeTip(canvas, coral, tx, top, tz, seed + c * 311L);
|
||||
}
|
||||
}
|
||||
|
||||
private static double[] rasterizeArm(CoralCanvas canvas, Coral coral, int ox, int oy, int oz,
|
||||
double azimuthDeg, double elevationDeg, double length, long seed) {
|
||||
double azRad = Math.toRadians(azimuthDeg);
|
||||
double elRad = Math.toRadians(elevationDeg);
|
||||
double dx = length * Math.cos(elRad) * Math.sin(azRad);
|
||||
double dy = length * Math.sin(elRad);
|
||||
double dz = length * Math.cos(elRad) * Math.cos(azRad);
|
||||
int steps = Math.max(1, (int) Math.round(Math.max(Math.abs(dy), Math.max(Math.abs(dx), Math.abs(dz)))));
|
||||
|
||||
double[] tip = new double[]{ox, oy, oz};
|
||||
for (int i = 0; i <= steps; i++) {
|
||||
double t = i / (double) steps;
|
||||
double sway = swayOffset(coral, t * length, seed);
|
||||
int x = (int) Math.round(ox + dx * t + sway);
|
||||
int y = (int) Math.round(oy + dy * t);
|
||||
int z = (int) Math.round(oz + dz * t - sway);
|
||||
canvas.set(x, y, z, CoralCanvas.Role.STRUCTURE);
|
||||
tip = new double[]{x, y, z};
|
||||
}
|
||||
return tip;
|
||||
}
|
||||
|
||||
private static void placeWavy(CoralCanvas canvas, Coral coral, int x, int y, int z, double phase, long seed, CoralCanvas.Role role) {
|
||||
double sway = swayOffset(coral, phase, seed);
|
||||
int sx = (int) Math.round(sway);
|
||||
int sz = (int) Math.round(swayOffset(coral, phase + 53.0, seed + 7L));
|
||||
canvas.set(x + sx, y, z + sz, role);
|
||||
}
|
||||
|
||||
private static double swayOffset(Coral coral, double phase, long seed) {
|
||||
double amount = Math.max(0.0, Math.min(1.0, coral.sway()));
|
||||
if (amount <= 0.0) {
|
||||
return 0.0;
|
||||
}
|
||||
double n = TreeFunctions.valueNoise1D(phase * 0.35, seed) - 0.5;
|
||||
return n * 2.0 * amount * (1.0 + coral.spread() * 0.25);
|
||||
}
|
||||
|
||||
private static void placeTipCluster(CoralCanvas canvas, Coral coral, int cx, int cy, int cz, int radius, long seed) {
|
||||
if (radius <= 0) {
|
||||
placeTip(canvas, coral, cx, cy, cz, seed);
|
||||
return;
|
||||
}
|
||||
for (int dx = -radius; dx <= radius; dx++) {
|
||||
for (int dy = -radius; dy <= radius; dy++) {
|
||||
for (int dz = -radius; dz <= radius; dz++) {
|
||||
if (dx * dx + dy * dy + dz * dz <= radius * radius) {
|
||||
canvas.set(cx + dx, cy + dy, cz + dz, CoralCanvas.Role.STRUCTURE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
placeTip(canvas, coral, cx, cy + radius + 1, cz, seed);
|
||||
}
|
||||
|
||||
private static void placeTip(CoralCanvas canvas, Coral coral, int x, int y, int z, long seed) {
|
||||
if (!hasTip(coral)) {
|
||||
return;
|
||||
}
|
||||
if (TreeFunctions.valueNoise1D(x * 31.0 + y * 17.0 + z * 13.0, seed) <= coral.tipChance()) {
|
||||
canvas.set(x, y, z, CoralCanvas.Role.TIP);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean hasTip(Coral coral) {
|
||||
return IrisProceduralBlocks.paletteSet(coral.tipPalette())
|
||||
|| (coral.tipBlock() != null && !coral.tipBlock().isEmpty());
|
||||
}
|
||||
|
||||
private static double branchAzimuth(Coral coral, int index, int count, RNG rng) {
|
||||
return switch (coral.branchAzimuth()) {
|
||||
case GOLDEN_ANGLE -> index * GOLDEN_ANGLE;
|
||||
case EVEN -> index * (360.0 / count);
|
||||
case RANDOM -> rng.d(0.0, 360.0);
|
||||
};
|
||||
}
|
||||
|
||||
private static Map<Vector3i, BlockState> resolve(CoralCanvas canvas, Coral coral, ObjectBuilder blocks) {
|
||||
Map<Vector3i, BlockState> out = new HashMap<>();
|
||||
RNG paletteRng = new RNG(coral.seed());
|
||||
for (Map.Entry<Long, CoralCanvas.Role> entry : canvas.getCells().entrySet()) {
|
||||
int[] xyz = CoralCanvas.decode(entry.getKey());
|
||||
int x = xyz[0];
|
||||
int y = xyz[1];
|
||||
int z = xyz[2];
|
||||
BlockState state;
|
||||
if (entry.getValue() == CoralCanvas.Role.TIP) {
|
||||
state = IrisProceduralBlocks.resolve(coral.tipBlock(), coral.tipPalette(), blocks, x, y, z, paletteRng);
|
||||
if (state == null) {
|
||||
state = IrisProceduralBlocks.resolve(coral.block(), coral.blockPalette(), blocks, x, y, z, paletteRng);
|
||||
}
|
||||
} else {
|
||||
state = IrisProceduralBlocks.resolve(coral.block(), coral.blockPalette(), blocks, x, y, z, paletteRng);
|
||||
}
|
||||
if (state == null) {
|
||||
continue;
|
||||
}
|
||||
if (coral.waterlogged() && IrisProceduralBlocks.hasProperty(state, "waterlogged")) {
|
||||
try {
|
||||
state = blocks.withProperty(state, "waterlogged", "true");
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
}
|
||||
out.put(new Vector3i(x, y, z), state);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.coral;
|
||||
|
||||
import art.arcane.iris.modules.objects.coral.Coral;
|
||||
import art.arcane.iris.engine.object.procedural.ProceduralShape;
|
||||
import art.arcane.iris.engine.object.procedural.ResolvedProceduralPlacement;
|
||||
import art.arcane.iris.modules.objects.ObjectBuilder;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.resource.PackResources;
|
||||
|
||||
/** A coral reef made placeable: its variants are baked by {@link CoralGenerator}. */
|
||||
public final class ResolvedCoral extends ResolvedProceduralPlacement {
|
||||
private final Coral settings;
|
||||
|
||||
public ResolvedCoral(Coral settings, PackResources resources) {
|
||||
super(new Shape(settings.name(), settings.chance(), settings.density(), settings.seed(), settings.variants(), settings.mode(),
|
||||
settings.rotation(), settings.clamp(), settings.carvingSupport(), settings.underwater(), settings.translate(),
|
||||
settings.stiltSettings().orElse(null), settings.vacuumSettings().orElse(null)), resources);
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ProceduralShape generate(int index, RNG rng, ObjectBuilder blocks) {
|
||||
return CoralGenerator.generate(settings, index, rng, blocks);
|
||||
}
|
||||
}
|
||||
-49
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.crystal;
|
||||
|
||||
import art.arcane.iris.modules.objects.crystal.Crystal;
|
||||
import art.arcane.iris.engine.object.procedural.tree.TreeFunctions;
|
||||
|
||||
public final class CrystalBaseBuilder {
|
||||
private CrystalBaseBuilder() {
|
||||
}
|
||||
|
||||
public static void build(CrystalCanvas canvas, Crystal crystal, long seed) {
|
||||
double radius = crystal.baseRadius();
|
||||
if (radius <= 0.0) {
|
||||
canvas.set(0, 0, 0, CrystalRole.BASE);
|
||||
return;
|
||||
}
|
||||
|
||||
double noiseStrength = crystal.baseNoise();
|
||||
int reach = (int) Math.ceil(radius + 1.0);
|
||||
for (int x = -reach; x <= reach; x++) {
|
||||
for (int y = -reach; y <= reach; y++) {
|
||||
for (int z = -reach; z <= reach; z++) {
|
||||
double distance = Math.sqrt((double) x * x + (double) y * y + (double) z * z);
|
||||
double wobble = (TreeFunctions.valueNoise3D(x, y, z, seed) - 0.5) * 2.0 * noiseStrength * radius;
|
||||
if (distance <= radius + wobble) {
|
||||
canvas.set(x, y, z, CrystalRole.BASE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.crystal;
|
||||
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class CrystalCanvas {
|
||||
private final Map<Vector3i, CrystalRole> cells = new HashMap<>();
|
||||
|
||||
public void set(int x, int y, int z, CrystalRole role) {
|
||||
Vector3i key = new Vector3i(x, y, z);
|
||||
CrystalRole existing = cells.get(key);
|
||||
if (existing == null || rank(role) > rank(existing)) {
|
||||
cells.put(key, role);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean has(int x, int y, int z) {
|
||||
return cells.containsKey(new Vector3i(x, y, z));
|
||||
}
|
||||
|
||||
public Map<Vector3i, CrystalRole> getCells() {
|
||||
return cells;
|
||||
}
|
||||
|
||||
private static int rank(CrystalRole role) {
|
||||
return switch (role) {
|
||||
case BASE -> 0;
|
||||
case SHARD -> 1;
|
||||
case TIP -> 2;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,112 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.crystal;
|
||||
|
||||
import art.arcane.iris.modules.objects.crystal.Crystal;
|
||||
import com.volmit.block.PaletteSpec;
|
||||
import art.arcane.iris.modules.objects.ObjectBuilder;
|
||||
import art.arcane.iris.engine.object.procedural.ProceduralShape;
|
||||
import art.arcane.iris.engine.object.procedural.IrisProceduralBlocks;
|
||||
import com.volmit.block.BlockState;
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class CrystalGenerator {
|
||||
private CrystalGenerator() {
|
||||
}
|
||||
|
||||
public static ProceduralShape generate(Crystal crystal, int variantIndex, RNG rng, ObjectBuilder blocks) {
|
||||
CrystalCanvas canvas = new CrystalCanvas();
|
||||
long structureSeed = rng.getSeed();
|
||||
|
||||
CrystalBaseBuilder.build(canvas, crystal, structureSeed + 977L);
|
||||
CrystalShardBuilder.build(canvas, crystal, rng);
|
||||
|
||||
Map<Vector3i, BlockState> resolved = new HashMap<>();
|
||||
RNG paletteRng = new RNG(crystal.seed());
|
||||
RNG tipRng = new RNG(crystal.seed() + (variantIndex * 31337L) + 4099L);
|
||||
|
||||
for (Map.Entry<Vector3i, CrystalRole> entry : canvas.getCells().entrySet()) {
|
||||
Vector3i position = entry.getKey();
|
||||
int x = position.getBlockX();
|
||||
int y = position.getBlockY();
|
||||
int z = position.getBlockZ();
|
||||
BlockState blockData = resolveRole(crystal, entry.getValue(), blocks, x, y, z, paletteRng, tipRng);
|
||||
if (blockData == null) {
|
||||
continue;
|
||||
}
|
||||
resolved.put(position, blockData);
|
||||
}
|
||||
|
||||
return IrisProceduralBlocks.assemble(resolved);
|
||||
}
|
||||
|
||||
private static BlockState resolveRole(Crystal crystal, CrystalRole role, ObjectBuilder blocks, int x, int y, int z, RNG paletteRng, RNG tipRng) {
|
||||
return switch (role) {
|
||||
case BASE -> resolveBase(crystal, blocks, x, y, z, paletteRng);
|
||||
case SHARD -> resolveShard(crystal, blocks, x, y, z, paletteRng);
|
||||
case TIP -> resolveTip(crystal, blocks, x, y, z, paletteRng, tipRng);
|
||||
};
|
||||
}
|
||||
|
||||
private static BlockState resolveBase(Crystal crystal, ObjectBuilder blocks, int x, int y, int z, RNG paletteRng) {
|
||||
boolean hasBase = IrisProceduralBlocks.paletteSet(crystal.basePalette())
|
||||
|| (crystal.baseBlock() != null && !crystal.baseBlock().isEmpty());
|
||||
if (hasBase) {
|
||||
BlockState base = IrisProceduralBlocks.resolve(crystal.baseBlock(), crystal.basePalette(), blocks, x, y, z, paletteRng);
|
||||
if (base != null) {
|
||||
return base;
|
||||
}
|
||||
}
|
||||
return resolveShard(crystal, blocks, x, y, z, paletteRng);
|
||||
}
|
||||
|
||||
private static BlockState resolveShard(Crystal crystal, ObjectBuilder blocks, int x, int y, int z, RNG paletteRng) {
|
||||
return IrisProceduralBlocks.resolve(crystal.block(), crystal.blockPalette(), blocks, x, y, z, paletteRng);
|
||||
}
|
||||
|
||||
private static BlockState resolveTip(Crystal crystal, ObjectBuilder blocks, int x, int y, int z, RNG paletteRng, RNG tipRng) {
|
||||
boolean hasTip = IrisProceduralBlocks.paletteSet(crystal.tipPalette())
|
||||
|| (crystal.tipBlock() != null && !crystal.tipBlock().isEmpty());
|
||||
|
||||
if (hasTip) {
|
||||
if (tipRng.chance(crystal.tipChance())) {
|
||||
BlockState tip = IrisProceduralBlocks.resolve(crystal.tipBlock(), crystal.tipPalette(), blocks, x, y, z, paletteRng);
|
||||
if (tip != null) {
|
||||
return tip;
|
||||
}
|
||||
}
|
||||
return resolveShard(crystal, blocks, x, y, z, paletteRng);
|
||||
}
|
||||
|
||||
if (crystal.glow() && crystal.glowBlock() != null && !crystal.glowBlock().isEmpty()) {
|
||||
if (tipRng.chance(crystal.tipChance())) {
|
||||
BlockState glow = IrisProceduralBlocks.resolve(crystal.glowBlock(), (PaletteSpec) null, blocks, x, y, z, paletteRng);
|
||||
if (glow != null) {
|
||||
return glow;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resolveShard(crystal, blocks, x, y, z, paletteRng);
|
||||
}
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.crystal;
|
||||
|
||||
import art.arcane.iris.modules.objects.crystal.CrystalSurface;
|
||||
|
||||
|
||||
public final class CrystalGeometry {
|
||||
private CrystalGeometry() {
|
||||
}
|
||||
|
||||
public static double[] surfaceNormal(CrystalSurface surface) {
|
||||
return switch (surface) {
|
||||
case FLOOR -> new double[]{0.0, 1.0, 0.0};
|
||||
case CEILING -> new double[]{0.0, -1.0, 0.0};
|
||||
case WALL -> {
|
||||
double len = Math.sqrt(1.0 + 0.5 * 0.5);
|
||||
yield new double[]{1.0 / len, 0.5 / len, 0.0};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static double[] orthonormalBasisU(double[] normal) {
|
||||
double[] reference = Math.abs(normal[1]) > 0.99 ? new double[]{1.0, 0.0, 0.0} : new double[]{0.0, 1.0, 0.0};
|
||||
double[] u = cross(reference, normal);
|
||||
normalize(u);
|
||||
return u;
|
||||
}
|
||||
|
||||
public static double[] orthonormalBasisV(double[] normal, double[] u) {
|
||||
double[] v = cross(normal, u);
|
||||
normalize(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
public static double[] coneDirection(double[] normal, double[] u, double[] v, double coneAngleRadians, double azimuthRadians) {
|
||||
double sin = Math.sin(coneAngleRadians);
|
||||
double cos = Math.cos(coneAngleRadians);
|
||||
double ca = Math.cos(azimuthRadians);
|
||||
double sa = Math.sin(azimuthRadians);
|
||||
double[] dir = new double[3];
|
||||
for (int i = 0; i < 3; i++) {
|
||||
dir[i] = cos * normal[i] + sin * (ca * u[i] + sa * v[i]);
|
||||
}
|
||||
normalize(dir);
|
||||
return dir;
|
||||
}
|
||||
|
||||
public static double[] cross(double[] a, double[] b) {
|
||||
return new double[]{
|
||||
a[1] * b[2] - a[2] * b[1],
|
||||
a[2] * b[0] - a[0] * b[2],
|
||||
a[0] * b[1] - a[1] * b[0]
|
||||
};
|
||||
}
|
||||
|
||||
public static void normalize(double[] vec) {
|
||||
double len = Math.sqrt(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]);
|
||||
if (len < 1e-9) {
|
||||
vec[0] = 0.0;
|
||||
vec[1] = 1.0;
|
||||
vec[2] = 0.0;
|
||||
return;
|
||||
}
|
||||
vec[0] /= len;
|
||||
vec[1] /= len;
|
||||
vec[2] /= len;
|
||||
}
|
||||
}
|
||||
-125
@@ -1,125 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.crystal;
|
||||
|
||||
import art.arcane.iris.modules.objects.crystal.CrystalDistribution;
|
||||
import art.arcane.iris.modules.objects.crystal.Crystal;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
public final class CrystalShardBuilder {
|
||||
private static final double GOLDEN_ANGLE = 137.50776405003785;
|
||||
|
||||
private CrystalShardBuilder() {
|
||||
}
|
||||
|
||||
public static void build(CrystalCanvas canvas, Crystal crystal, RNG rng) {
|
||||
double[] normal = CrystalGeometry.surfaceNormal(crystal.growthSurface());
|
||||
double[] u = CrystalGeometry.orthonormalBasisU(normal);
|
||||
double[] v = CrystalGeometry.orthonormalBasisV(normal, u);
|
||||
|
||||
int countLo = Math.min(crystal.shardCountMin(), crystal.shardCountMax());
|
||||
int countHi = Math.max(crystal.shardCountMin(), crystal.shardCountMax());
|
||||
int shardCount = Math.max(1, rng.i(countLo, countHi + 1));
|
||||
|
||||
int lengthLo = Math.min(crystal.shardLengthMin(), crystal.shardLengthMax());
|
||||
int lengthHi = Math.max(crystal.shardLengthMin(), crystal.shardLengthMax());
|
||||
|
||||
double spreadRadians = Math.toRadians(Math.max(0.0, Math.min(90.0, crystal.spreadAngle())));
|
||||
double jitterAmount = Math.max(0.0, Math.min(1.0, crystal.jitter()));
|
||||
double emitRadius = Math.max(0.0, crystal.baseRadius() * 0.6);
|
||||
|
||||
for (int i = 0; i < shardCount; i++) {
|
||||
double azimuth = azimuth(crystal.distribution(), i, rng);
|
||||
azimuth += rng.d(-Math.PI, Math.PI) * jitterAmount * 0.5;
|
||||
|
||||
double cone = spreadRadians * fanFraction(shardCount, i, rng);
|
||||
cone += rng.d(-spreadRadians, spreadRadians) * jitterAmount * 0.5;
|
||||
cone = Math.max(0.0, Math.min(Math.PI / 2.0, cone));
|
||||
|
||||
double[] direction = CrystalGeometry.coneDirection(normal, u, v, cone, azimuth);
|
||||
|
||||
double ox = normal[0] * emitRadius + u[0] * Math.cos(azimuth) * emitRadius + v[0] * Math.sin(azimuth) * emitRadius;
|
||||
double oy = normal[1] * emitRadius + u[1] * Math.cos(azimuth) * emitRadius + v[1] * Math.sin(azimuth) * emitRadius;
|
||||
double oz = normal[2] * emitRadius + u[2] * Math.cos(azimuth) * emitRadius + v[2] * Math.sin(azimuth) * emitRadius;
|
||||
|
||||
int length = Math.max(1, rng.i(lengthLo, lengthHi + 1));
|
||||
rasterizeShard(canvas, crystal, ox, oy, oz, direction, length);
|
||||
}
|
||||
}
|
||||
|
||||
private static void rasterizeShard(CrystalCanvas canvas, Crystal crystal, double ox, double oy, double oz, double[] direction, int length) {
|
||||
double baseRadius = Math.max(0.5, crystal.shardBaseRadius());
|
||||
double taper = Math.max(0.0, Math.min(1.0, crystal.shardTaper()));
|
||||
|
||||
int samples = Math.max(1, length * 3);
|
||||
|
||||
for (int s = 0; s <= samples; s++) {
|
||||
double t = s / (double) samples;
|
||||
double cx = ox + direction[0] * length * t;
|
||||
double cy = oy + direction[1] * length * t;
|
||||
double cz = oz + direction[2] * length * t;
|
||||
|
||||
double radius = baseRadius * (1.0 - taper * t);
|
||||
if (t >= 1.0) {
|
||||
radius = 0.0;
|
||||
}
|
||||
radius = Math.max(0.0, radius);
|
||||
|
||||
int reach = (int) Math.floor(radius);
|
||||
int centerX = (int) Math.round(cx);
|
||||
int centerY = (int) Math.round(cy);
|
||||
int centerZ = (int) Math.round(cz);
|
||||
|
||||
if (reach <= 0) {
|
||||
canvas.set(centerX, centerY, centerZ, CrystalRole.SHARD);
|
||||
} else {
|
||||
for (int dx = -reach; dx <= reach; dx++) {
|
||||
for (int dy = -reach; dy <= reach; dy++) {
|
||||
for (int dz = -reach; dz <= reach; dz++) {
|
||||
double dist = Math.sqrt((double) dx * dx + (double) dy * dy + (double) dz * dz);
|
||||
if (dist <= radius) {
|
||||
canvas.set(centerX + dx, centerY + dy, centerZ + dz, CrystalRole.SHARD);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int tipX = (int) Math.round(ox + direction[0] * length);
|
||||
int tipY = (int) Math.round(oy + direction[1] * length);
|
||||
int tipZ = (int) Math.round(oz + direction[2] * length);
|
||||
canvas.set(tipX, tipY, tipZ, CrystalRole.TIP);
|
||||
}
|
||||
|
||||
private static double azimuth(CrystalDistribution distribution, int index, RNG rng) {
|
||||
if (distribution == CrystalDistribution.GOLDEN_ANGLE) {
|
||||
return Math.toRadians(index * GOLDEN_ANGLE);
|
||||
}
|
||||
return rng.d(0.0, Math.PI * 2.0);
|
||||
}
|
||||
|
||||
private static double fanFraction(int count, int index, RNG rng) {
|
||||
if (count <= 1) {
|
||||
return rng.d(0.0, 1.0);
|
||||
}
|
||||
double base = index / (double) (count - 1);
|
||||
return Math.max(0.0, Math.min(1.0, base * 0.7 + rng.d(0.0, 0.3)));
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.crystal;
|
||||
|
||||
import art.arcane.iris.modules.objects.crystal.Crystal;
|
||||
import art.arcane.iris.engine.object.procedural.ProceduralShape;
|
||||
import art.arcane.iris.engine.object.procedural.ResolvedProceduralPlacement;
|
||||
import art.arcane.iris.modules.objects.ObjectBuilder;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.resource.PackResources;
|
||||
|
||||
/** A crystal cluster made placeable: its variants are baked by {@link CrystalGenerator}. */
|
||||
public final class ResolvedCrystal extends ResolvedProceduralPlacement {
|
||||
private final Crystal settings;
|
||||
|
||||
public ResolvedCrystal(Crystal settings, PackResources resources) {
|
||||
super(new Shape(settings.name(), settings.chance(), settings.density(), settings.seed(), settings.variants(), settings.mode(),
|
||||
settings.rotation(), settings.clamp(), settings.carvingSupport(), settings.underwater(), settings.translate(),
|
||||
settings.stiltSettings().orElse(null), settings.vacuumSettings().orElse(null)), resources);
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ProceduralShape generate(int index, RNG rng, ObjectBuilder blocks) {
|
||||
return CrystalGenerator.generate(settings, index, rng, blocks);
|
||||
}
|
||||
}
|
||||
-67
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.formation;
|
||||
|
||||
import com.volmit.block.PaletteSpec;
|
||||
import java.util.Optional;
|
||||
import art.arcane.iris.modules.objects.formation.Formation;
|
||||
import art.arcane.iris.modules.objects.ObjectBuilder;
|
||||
import art.arcane.iris.engine.object.procedural.IrisProceduralBlocks;
|
||||
import com.volmit.block.BlockState;
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
public final class FormationBlockResolver {
|
||||
private FormationBlockResolver() {
|
||||
}
|
||||
|
||||
public static BlockState resolve(Formation f, ObjectBuilder blocks, FormationCanvas.Role role, Vector3i raw) {
|
||||
int x = raw.getBlockX();
|
||||
int y = raw.getBlockY();
|
||||
int z = raw.getBlockZ();
|
||||
RNG paletteRng = new RNG(f.seed());
|
||||
|
||||
if (role == FormationCanvas.Role.CAP && capDefined(f)) {
|
||||
BlockState cap = IrisProceduralBlocks.resolve(f.capBlock(), f.capPalette(), blocks, x, y, z, paletteRng);
|
||||
if (cap != null) {
|
||||
return cap;
|
||||
}
|
||||
}
|
||||
|
||||
if (strataDefined(f)) {
|
||||
PaletteSpec strata = f.strataPalette().orElseThrow();
|
||||
int thickness = Math.max(1, f.strataThickness());
|
||||
int band = Math.floorDiv(y, thickness);
|
||||
BlockState strataState = blocks.pick(strata, f.seed() + (band * 31L), x, band, z);
|
||||
if (strataState != null) {
|
||||
return strataState;
|
||||
}
|
||||
}
|
||||
|
||||
return IrisProceduralBlocks.resolve(f.block(), f.blockPalette(), blocks, x, y, z, paletteRng);
|
||||
}
|
||||
|
||||
private static boolean capDefined(Formation f) {
|
||||
return IrisProceduralBlocks.paletteSet(f.capPalette()) || f.capBlock().filter(block -> !block.isEmpty()).isPresent();
|
||||
}
|
||||
|
||||
private static boolean strataDefined(Formation f) {
|
||||
return IrisProceduralBlocks.paletteSet(f.strataPalette());
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.formation;
|
||||
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class FormationCanvas {
|
||||
public enum Role {
|
||||
BODY,
|
||||
CAP
|
||||
}
|
||||
|
||||
private final Map<Vector3i, Role> cells = new HashMap<>();
|
||||
|
||||
public void setBody(int x, int y, int z) {
|
||||
Vector3i key = new Vector3i(x, y, z);
|
||||
if (cells.get(key) == Role.CAP) {
|
||||
return;
|
||||
}
|
||||
cells.put(key, Role.BODY);
|
||||
}
|
||||
|
||||
public void setCap(int x, int y, int z) {
|
||||
cells.put(new Vector3i(x, y, z), Role.CAP);
|
||||
}
|
||||
|
||||
public void remove(int x, int y, int z) {
|
||||
cells.remove(new Vector3i(x, y, z));
|
||||
}
|
||||
|
||||
public boolean has(int x, int y, int z) {
|
||||
return cells.containsKey(new Vector3i(x, y, z));
|
||||
}
|
||||
|
||||
public Map<Vector3i, Role> getCells() {
|
||||
return cells;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return cells.isEmpty();
|
||||
}
|
||||
}
|
||||
-75
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.formation;
|
||||
|
||||
import art.arcane.iris.modules.objects.formation.Formation;
|
||||
import art.arcane.iris.modules.objects.ObjectBuilder;
|
||||
import art.arcane.iris.engine.object.procedural.ProceduralShape;
|
||||
import art.arcane.iris.engine.object.procedural.IrisProceduralBlocks;
|
||||
import com.volmit.block.BlockState;
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class FormationGenerator {
|
||||
private FormationGenerator() {
|
||||
}
|
||||
|
||||
public static ProceduralShape generate(Formation f, int variantIndex, RNG rng, ObjectBuilder blocks) {
|
||||
int lo = Math.min(f.heightMin(), f.heightMax());
|
||||
int hi = Math.max(f.heightMin(), f.heightMax());
|
||||
int height = Math.max(3, rng.i(lo, hi + 1));
|
||||
|
||||
int wLo = Math.min(f.baseWidthMin(), f.baseWidthMax());
|
||||
int wHi = Math.max(f.baseWidthMin(), f.baseWidthMax());
|
||||
double baseRadius = Math.max(1, rng.i(wLo, wHi + 1));
|
||||
|
||||
FormationCanvas canvas = new FormationCanvas();
|
||||
|
||||
switch (f.form()) {
|
||||
case SPIRE -> FormationShapeBuilder.spire(canvas, f, height, baseRadius, rng);
|
||||
case HOODOO -> FormationShapeBuilder.hoodoo(canvas, f, height, baseRadius, rng);
|
||||
case ARCH -> FormationShapeBuilder.arch(canvas, f, height, baseRadius, rng);
|
||||
case SEA_STACK -> FormationShapeBuilder.seaStack(canvas, f, height, baseRadius, rng);
|
||||
case BOULDER -> FormationShapeBuilder.boulder(canvas, f, height, baseRadius, rng);
|
||||
case BASALT_COLUMN -> FormationShapeBuilder.basaltColumns(canvas, f, height, baseRadius, rng);
|
||||
case ICEBERG -> FormationShapeBuilder.iceberg(canvas, f, height, baseRadius, rng);
|
||||
case FISSURE -> FormationShapeBuilder.fissure(canvas, f, height, baseRadius, rng);
|
||||
case SPIRAL -> FormationShapeBuilder.spiral(canvas, f, height, baseRadius, rng);
|
||||
case OVERHANG -> FormationShapeBuilder.overhang(canvas, f, height, baseRadius, rng);
|
||||
}
|
||||
|
||||
if (canvas.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Map<Vector3i, BlockState> resolved = new HashMap<>();
|
||||
for (Map.Entry<Vector3i, FormationCanvas.Role> entry : canvas.getCells().entrySet()) {
|
||||
BlockState bd = FormationBlockResolver.resolve(f, blocks, entry.getValue(), entry.getKey());
|
||||
if (bd == null) {
|
||||
continue;
|
||||
}
|
||||
resolved.put(entry.getKey(), bd);
|
||||
}
|
||||
|
||||
return IrisProceduralBlocks.assemble(resolved);
|
||||
}
|
||||
}
|
||||
-58
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.formation;
|
||||
|
||||
import art.arcane.iris.modules.objects.formation.Formation;
|
||||
|
||||
|
||||
public final class FormationProfiles {
|
||||
private FormationProfiles() {
|
||||
}
|
||||
|
||||
public static double radiusAt(Formation f, double baseRadius, double topRadius, double t) {
|
||||
double clamped = Math.max(0.0, Math.min(1.0, t));
|
||||
return switch (f.profile()) {
|
||||
case CONSTANT -> baseRadius;
|
||||
case LINEAR -> baseRadius + (topRadius - baseRadius) * clamped;
|
||||
case TAPER -> baseRadius + (topRadius - baseRadius) * smoothstep(clamped);
|
||||
case PARABOLIC -> parabolic(f, baseRadius, topRadius, clamped);
|
||||
case BULGE -> baseRadius + (Math.max(baseRadius, topRadius) - baseRadius) * bell(clamped) + (topRadius - baseRadius) * clamped * 0.25;
|
||||
};
|
||||
}
|
||||
|
||||
private static double parabolic(Formation f, double baseRadius, double topRadius, double t) {
|
||||
double waist = Math.max(0.0, Math.min(1.0, f.profileWaist()));
|
||||
double floor = Math.max(0.0, Math.min(1.0, f.profileWaistFloor()));
|
||||
double denom = Math.pow(Math.max(waist, 1.0 - waist), 2);
|
||||
if (denom == 0) {
|
||||
denom = 1;
|
||||
}
|
||||
double envelope = baseRadius + (topRadius - baseRadius) * t;
|
||||
double pinch = floor + (1.0 - floor) * (Math.pow(t - waist, 2) / denom);
|
||||
return Math.max(0.5, envelope * pinch);
|
||||
}
|
||||
|
||||
private static double smoothstep(double t) {
|
||||
return 3.0 * t * t - 2.0 * t * t * t;
|
||||
}
|
||||
|
||||
private static double bell(double t) {
|
||||
return Math.exp(-Math.pow(t - 0.5, 2) / (2.0 * 0.22 * 0.22));
|
||||
}
|
||||
}
|
||||
-429
@@ -1,429 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.formation;
|
||||
|
||||
import art.arcane.iris.modules.objects.formation.Formation;
|
||||
import art.arcane.iris.engine.object.procedural.tree.TreeFunctions;
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class FormationShapeBuilder {
|
||||
private FormationShapeBuilder() {
|
||||
}
|
||||
|
||||
public static void spire(FormationCanvas canvas, Formation f, int height, double baseRadius, RNG rng) {
|
||||
double topRadius = f.topWidth();
|
||||
column(canvas, f, height, baseRadius, topRadius, 0, 0, rng, true);
|
||||
double lean = Math.toRadians(f.lean());
|
||||
double azimuth = Math.toRadians(f.leanAzimuth());
|
||||
int previousX = 0;
|
||||
int previousZ = 0;
|
||||
for (int y = 0; y < height; y++) {
|
||||
double shear = Math.tan(lean) * y;
|
||||
int centerX = (int) Math.round(Math.cos(azimuth) * shear);
|
||||
int centerZ = (int) Math.round(Math.sin(azimuth) * shear);
|
||||
boolean cap = y >= height - 2;
|
||||
for (int x = Math.min(previousX, centerX); x <= Math.max(previousX, centerX); x++) {
|
||||
setSpireCenter(canvas, x, y, previousZ, cap);
|
||||
}
|
||||
for (int z = Math.min(previousZ, centerZ); z <= Math.max(previousZ, centerZ); z++) {
|
||||
setSpireCenter(canvas, centerX, y, z, cap);
|
||||
}
|
||||
previousX = centerX;
|
||||
previousZ = centerZ;
|
||||
}
|
||||
}
|
||||
|
||||
public static void seaStack(FormationCanvas canvas, Formation f, int height, double baseRadius, RNG rng) {
|
||||
double topRadius = Math.max(1.0, baseRadius * 0.55);
|
||||
if (f.topWidth() > 0) {
|
||||
topRadius = f.topWidth();
|
||||
}
|
||||
column(canvas, f, height, baseRadius, topRadius, 0, 0, rng, true);
|
||||
}
|
||||
|
||||
public static void hoodoo(FormationCanvas canvas, Formation f, int height, double baseRadius, RNG rng) {
|
||||
double topRadius = f.topWidth() > 0 ? f.topWidth() : Math.max(1.0, baseRadius * 0.7);
|
||||
column(canvas, f, height, baseRadius, topRadius, 0, 0, rng, false);
|
||||
|
||||
int capRadius = f.hoodooCapRadius();
|
||||
if (capRadius <= 0) {
|
||||
return;
|
||||
}
|
||||
int capHeight = Math.max(1, f.hoodooCapHeight());
|
||||
double lean = Math.toRadians(f.lean());
|
||||
double azimuth = Math.toRadians(f.leanAzimuth());
|
||||
double shear = Math.tan(lean) * height;
|
||||
double topOffX = Math.cos(azimuth) * shear;
|
||||
double topOffZ = Math.sin(azimuth) * shear;
|
||||
double wideRadius = topRadius + capRadius;
|
||||
|
||||
for (int cy = 0; cy < capHeight; cy++) {
|
||||
int y = height + cy;
|
||||
double shrink = capHeight <= 1 ? 0 : (cy / (double) (capHeight - 1)) * 0.5;
|
||||
double r = wideRadius * (1.0 - shrink);
|
||||
disc(canvas, f, (int) Math.round(topOffX), y, (int) Math.round(topOffZ), r, true, rng);
|
||||
}
|
||||
}
|
||||
|
||||
public static void boulder(FormationCanvas canvas, Formation f, int height, double baseRadius, RNG rng) {
|
||||
double rx = baseRadius;
|
||||
double ry = Math.max(2.0, height * 0.5);
|
||||
double rz = baseRadius * (0.8 + rng.d(0.0, 0.3));
|
||||
double roughness = Math.max(0.0, Math.min(1.0, f.roughness()));
|
||||
long noiseSeed = f.seed() + 4201L;
|
||||
|
||||
int maxR = (int) Math.ceil(Math.max(rx, Math.max(ry, rz))) + 2;
|
||||
for (int x = -maxR; x <= maxR; x++) {
|
||||
for (int y = 0; y <= (int) Math.ceil(ry * 2) + 1; y++) {
|
||||
for (int z = -maxR; z <= maxR; z++) {
|
||||
double nx = x / rx;
|
||||
double ny = (y - ry) / ry;
|
||||
double nz = z / rz;
|
||||
double d = nx * nx + ny * ny + nz * nz;
|
||||
double wobble = (TreeFunctions.valueNoise3D(x, y, z, noiseSeed) - 0.5) * roughness * 0.9;
|
||||
if (d + wobble <= 1.0) {
|
||||
canvas.setBody(x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void arch(FormationCanvas canvas, Formation f, int height, double baseRadius, RNG rng) {
|
||||
double span = Math.max(2.0, f.archSpan());
|
||||
double tubeRadius = Math.max(0.75, f.archThickness() * 0.5);
|
||||
double asymmetry = Math.max(0.0, Math.min(1.0, f.archAsymmetry()));
|
||||
double leftFootX = -span * 0.5 - tubeRadius - rng.d(0.0, span * 0.16) * asymmetry;
|
||||
double rightFootX = span * 0.5 + tubeRadius + rng.d(0.0, span * 0.16) * asymmetry;
|
||||
double leftFootZ = rng.d(-tubeRadius * 0.45, tubeRadius * 0.45) * asymmetry;
|
||||
double rightFootZ = rng.d(-tubeRadius * 0.45, tubeRadius * 0.45) * asymmetry;
|
||||
double crownZ = rng.d(-span * 0.2, span * 0.2) * asymmetry;
|
||||
double crownShiftX = rng.d(-span * 0.12, span * 0.12) * asymmetry;
|
||||
double depthTwist = rng.d(-span * 0.1, span * 0.1) * asymmetry;
|
||||
double crownPosition = 0.5 + rng.d(-0.12, 0.12) * asymmetry;
|
||||
double leftSteepness = 0.58 + rng.d(-0.16, 0.16) * asymmetry;
|
||||
double rightSteepness = 0.58 + rng.d(-0.16, 0.16) * asymmetry;
|
||||
double radiusWave = rng.d(-0.22, 0.22) * asymmetry;
|
||||
double radiusPhase = rng.d(0.0, Math.PI * 2.0);
|
||||
double crownCenterY = Math.max(tubeRadius + 2.0, height - 1.0 - tubeRadius);
|
||||
double footRadius = tubeRadius + Math.min(tubeRadius * 0.45, baseRadius * 0.18);
|
||||
long noiseSeed = rng.nextLong();
|
||||
int steps = Math.max(24, (int) Math.ceil((rightFootX - leftFootX + height) * 4.0));
|
||||
|
||||
ball(canvas, f, (int) Math.round(leftFootX), (int) Math.round(footRadius),
|
||||
(int) Math.round(leftFootZ), footRadius, false, noiseSeed, rng);
|
||||
ball(canvas, f, (int) Math.round(rightFootX), (int) Math.round(footRadius),
|
||||
(int) Math.round(rightFootZ), footRadius, false, noiseSeed, rng);
|
||||
|
||||
for (int step = 0; step <= steps; step++) {
|
||||
double t = step / (double) steps;
|
||||
double normalizedRise;
|
||||
double steepness;
|
||||
if (t <= crownPosition) {
|
||||
normalizedRise = Math.sin((t / crownPosition) * Math.PI * 0.5);
|
||||
steepness = leftSteepness;
|
||||
} else {
|
||||
normalizedRise = Math.sin(((1.0 - t) / (1.0 - crownPosition)) * Math.PI * 0.5);
|
||||
steepness = rightSteepness;
|
||||
}
|
||||
double rise = Math.pow(Math.max(0.0, normalizedRise), steepness);
|
||||
double x = leftFootX + (rightFootX - leftFootX) * t
|
||||
+ Math.sin(Math.PI * t) * crownShiftX;
|
||||
double inverse = 1.0 - t;
|
||||
double z = inverse * inverse * leftFootZ + 2.0 * inverse * t * crownZ + t * t * rightFootZ
|
||||
+ Math.sin(Math.PI * 2.0 * t) * depthTwist;
|
||||
double y = tubeRadius + (crownCenterY - tubeRadius) * rise;
|
||||
double radius = tubeRadius * (1.0 + radiusWave * Math.sin(Math.PI * t)
|
||||
* Math.sin(Math.PI * 2.0 * t + radiusPhase));
|
||||
radius = Math.max(tubeRadius * 0.68, Math.min(tubeRadius * 1.32, radius));
|
||||
ball(canvas, f, (int) Math.round(x), (int) Math.round(y), (int) Math.round(z),
|
||||
radius, false, noiseSeed, rng);
|
||||
}
|
||||
if (asymmetry == 0.0) {
|
||||
mirrorAcrossX(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
public static void basaltColumns(FormationCanvas canvas, Formation f, int height, double baseRadius, RNG rng) {
|
||||
int count = Math.max(2, f.basaltColumns());
|
||||
int colRadius = Math.max(1, f.basaltColumnRadius());
|
||||
double variance = Math.max(0.0, Math.min(1.0, f.basaltHeightVariance()));
|
||||
int spread = (int) Math.ceil(baseRadius);
|
||||
|
||||
for (int c = 0; c < count; c++) {
|
||||
double angle = rng.d(0.0, Math.PI * 2.0);
|
||||
double dist = rng.d(0.0, spread);
|
||||
int ox = (int) Math.round(Math.cos(angle) * dist);
|
||||
int oz = (int) Math.round(Math.sin(angle) * dist);
|
||||
double hVar = 1.0 - variance + rng.d(0.0, variance * 2.0);
|
||||
int colHeight = Math.max(3, (int) Math.round(height * hVar));
|
||||
|
||||
for (int y = 0; y < colHeight; y++) {
|
||||
for (int x = -colRadius; x <= colRadius; x++) {
|
||||
for (int z = -colRadius; z <= colRadius; z++) {
|
||||
if (Math.abs(x) + Math.abs(z) > colRadius) {
|
||||
continue;
|
||||
}
|
||||
canvas.setBody(ox + x, y, oz + z);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (colRadius > 0) {
|
||||
canvas.setCap(ox, colHeight - 1, oz);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void iceberg(FormationCanvas canvas, Formation f, int height, double baseRadius, RNG rng) {
|
||||
long noiseSeed = rng.nextLong();
|
||||
double bodyHeight = Math.max(2.0, height * 0.42);
|
||||
double radiusX = baseRadius * rng.d(1.15, 1.5);
|
||||
double radiusZ = baseRadius * rng.d(1.0, 1.35);
|
||||
ellipsoid(canvas, radiusX, bodyHeight, radiusZ, bodyHeight * 0.36, noiseSeed, f.roughness());
|
||||
|
||||
int peaks = Math.max(1, f.icebergPeaks());
|
||||
double phase = rng.d(0.0, Math.PI * 2.0);
|
||||
for (int i = 0; i < peaks; i++) {
|
||||
double angle = phase + (Math.PI * 2.0 * i / peaks) + rng.d(-0.35, 0.35);
|
||||
double distance = rng.d(0.0, baseRadius * 0.62);
|
||||
int offsetX = (int) Math.round(Math.cos(angle) * distance);
|
||||
int offsetZ = (int) Math.round(Math.sin(angle) * distance);
|
||||
int peakHeight = Math.max(3, (int) Math.round(height * rng.d(0.58, 1.0)));
|
||||
double peakRadius = Math.max(1.0, baseRadius * rng.d(0.28, 0.58));
|
||||
double leanDistance = rng.d(0.0, Math.max(1.0, baseRadius * 0.45));
|
||||
taperedPeak(canvas, f, peakHeight, peakRadius, offsetX, offsetZ, angle, leanDistance, rng);
|
||||
}
|
||||
}
|
||||
|
||||
public static void fissure(FormationCanvas canvas, Formation f, int height, double baseRadius, RNG rng) {
|
||||
int count = Math.max(2, f.fractureCount());
|
||||
double separation = Math.max(1.0, f.fractureSeparation());
|
||||
double shardRadius = Math.max(1.0, baseRadius / Math.max(1.6, count * 0.72));
|
||||
double phase = rng.d(0.0, Math.PI * 2.0);
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
double lane = i - ((count - 1) / 2.0);
|
||||
double offset = lane * (shardRadius * 2.0 + separation);
|
||||
int offsetX = (int) Math.round(Math.cos(phase) * offset);
|
||||
int offsetZ = (int) Math.round(Math.sin(phase) * offset);
|
||||
double outwardAngle = lane < 0 ? phase + Math.PI : phase;
|
||||
int shardHeight = Math.max(3, (int) Math.round(height * rng.d(0.62, 1.0)));
|
||||
double leanDistance = rng.d(separation * 0.4, separation + baseRadius * 0.8);
|
||||
taperedPeak(canvas, f, shardHeight, shardRadius, offsetX, offsetZ, outwardAngle, leanDistance, rng);
|
||||
}
|
||||
}
|
||||
|
||||
public static void spiral(FormationCanvas canvas, Formation f, int height, double baseRadius, RNG rng) {
|
||||
int steps = Math.max(12, height * 4);
|
||||
double turns = Math.max(0.25, f.spiralTurns());
|
||||
double startRadius = Math.max(1.0, f.spiralRadius());
|
||||
double startThickness = Math.max(1.0, f.spiralThickness());
|
||||
double phase = rng.d(0.0, Math.PI * 2.0);
|
||||
long noiseSeed = rng.nextLong();
|
||||
|
||||
for (int step = 0; step <= steps; step++) {
|
||||
double t = step / (double) steps;
|
||||
double angle = phase + Math.PI * 2.0 * turns * t;
|
||||
double radius = startRadius * (1.0 - 0.72 * t);
|
||||
int x = (int) Math.round(Math.cos(angle) * radius);
|
||||
int y = (int) Math.round(t * (height - 1));
|
||||
int z = (int) Math.round(Math.sin(angle) * radius);
|
||||
double thickness = Math.max(0.75, startThickness * (1.0 - 0.48 * t));
|
||||
ball(canvas, f, x, y, z, thickness, step == steps, noiseSeed, rng);
|
||||
}
|
||||
|
||||
double footRadius = Math.max(1.0, Math.min(baseRadius, startThickness + 1.0));
|
||||
disc(canvas, f, (int) Math.round(Math.cos(phase) * startRadius), 0,
|
||||
(int) Math.round(Math.sin(phase) * startRadius), footRadius, false, rng);
|
||||
}
|
||||
|
||||
public static void overhang(FormationCanvas canvas, Formation f, int height, double baseRadius, RNG rng) {
|
||||
int steps = Math.max(12, height * 4);
|
||||
double reach = Math.max(1.0, f.overhangReach());
|
||||
double drop = Math.max(0.0, f.overhangDrop());
|
||||
double phase = Math.toRadians(f.leanAzimuth()) + rng.d(-0.18, 0.18);
|
||||
double trunkHeight = Math.max(3.0, height * 0.62);
|
||||
long noiseSeed = rng.nextLong();
|
||||
|
||||
for (int step = 0; step <= steps; step++) {
|
||||
double t = step / (double) steps;
|
||||
double extension;
|
||||
double y;
|
||||
if (t <= 0.58) {
|
||||
double rise = t / 0.58;
|
||||
extension = reach * 0.16 * rise * rise;
|
||||
y = trunkHeight * rise;
|
||||
} else {
|
||||
double hook = (t - 0.58) / 0.42;
|
||||
extension = reach * (0.16 + 0.84 * Math.sin(hook * Math.PI * 0.5));
|
||||
y = trunkHeight + Math.sin(hook * Math.PI) * height * 0.18 - drop * hook * hook;
|
||||
}
|
||||
int x = (int) Math.round(Math.cos(phase) * extension);
|
||||
int z = (int) Math.round(Math.sin(phase) * extension);
|
||||
double thickness = Math.max(0.9, baseRadius * (1.0 - 0.64 * t));
|
||||
ball(canvas, f, x, Math.max(0, (int) Math.round(y)), z, thickness, step == steps, noiseSeed, rng);
|
||||
}
|
||||
}
|
||||
|
||||
private static void column(FormationCanvas canvas, Formation f, int height, double baseRadius, double topRadius, int extraBaseX, int extraBaseZ, RNG rng, boolean capTop) {
|
||||
double lean = Math.toRadians(f.lean());
|
||||
double azimuth = Math.toRadians(f.leanAzimuth());
|
||||
double roughness = Math.max(0.0, Math.min(1.0, f.roughness()));
|
||||
double jitter = Math.max(0.0, Math.min(1.0, f.jitter()));
|
||||
long noiseSeed = f.seed() + 9001L;
|
||||
|
||||
for (int y = 0; y < height; y++) {
|
||||
double t = height <= 1 ? 1.0 : (y / (double) (height - 1));
|
||||
double radius = FormationProfiles.radiusAt(f, baseRadius, topRadius, t);
|
||||
double shear = Math.tan(lean) * y;
|
||||
int cx = extraBaseX + (int) Math.round(Math.cos(azimuth) * shear);
|
||||
int cz = extraBaseZ + (int) Math.round(Math.sin(azimuth) * shear);
|
||||
boolean cap = capTop && y >= height - 2;
|
||||
ringDisc(canvas, f, cx, y, cz, radius, roughness, jitter, noiseSeed, cap, rng);
|
||||
}
|
||||
}
|
||||
|
||||
private static void setSpireCenter(FormationCanvas canvas, int x, int y, int z, boolean cap) {
|
||||
if (cap) {
|
||||
canvas.setCap(x, y, z);
|
||||
} else {
|
||||
canvas.setBody(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ringDisc(FormationCanvas canvas, Formation f, int cx, int y, int cz, double radius, double roughness, double jitter, long noiseSeed, boolean cap, RNG rng) {
|
||||
int r = (int) Math.ceil(radius) + 1;
|
||||
for (int x = -r; x <= r; x++) {
|
||||
for (int z = -r; z <= r; z++) {
|
||||
double dist = Math.sqrt(x * x + z * z);
|
||||
double perturb = (TreeFunctions.valueNoise3D(cx + x, y, cz + z, noiseSeed) - 0.5) * roughness * (radius + 1.0);
|
||||
double effective = radius + perturb;
|
||||
if (dist <= effective) {
|
||||
if (jitter > 0 && dist > effective - 1.0 && rng.chance(jitter * 0.5)) {
|
||||
continue;
|
||||
}
|
||||
if (cap) {
|
||||
canvas.setCap(cx + x, y, cz + z);
|
||||
} else {
|
||||
canvas.setBody(cx + x, y, cz + z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void disc(FormationCanvas canvas, Formation f, int cx, int y, int cz, double radius, boolean cap, RNG rng) {
|
||||
int r = (int) Math.ceil(radius) + 1;
|
||||
for (int x = -r; x <= r; x++) {
|
||||
for (int z = -r; z <= r; z++) {
|
||||
if (Math.sqrt(x * x + z * z) <= radius) {
|
||||
if (cap) {
|
||||
canvas.setCap(cx + x, y, cz + z);
|
||||
} else {
|
||||
canvas.setBody(cx + x, y, cz + z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void taperedPeak(FormationCanvas canvas, Formation f, int height, double radius,
|
||||
int offsetX, int offsetZ, double leanAngle, double leanDistance, RNG rng) {
|
||||
long noiseSeed = rng.nextLong();
|
||||
double roughness = Math.max(0.0, Math.min(1.0, f.roughness()));
|
||||
double jitter = Math.max(0.0, Math.min(1.0, f.jitter()));
|
||||
for (int y = 0; y < height; y++) {
|
||||
double t = height <= 1 ? 1.0 : y / (double) (height - 1);
|
||||
int x = offsetX + (int) Math.round(Math.cos(leanAngle) * leanDistance * t * t);
|
||||
int z = offsetZ + (int) Math.round(Math.sin(leanAngle) * leanDistance * t * t);
|
||||
double layerRadius = Math.max(0.45, radius * Math.pow(1.0 - t, 0.72));
|
||||
ringDisc(canvas, f, x, y, z, layerRadius, roughness, jitter, noiseSeed, y >= height - 2, rng);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ellipsoid(FormationCanvas canvas, double radiusX, double radiusY, double radiusZ,
|
||||
double centerY, long noiseSeed, double configuredRoughness) {
|
||||
double roughness = Math.max(0.0, Math.min(1.0, configuredRoughness));
|
||||
int maxX = (int) Math.ceil(radiusX) + 1;
|
||||
int maxY = (int) Math.ceil(radiusY) + 1;
|
||||
int maxZ = (int) Math.ceil(radiusZ) + 1;
|
||||
for (int x = -maxX; x <= maxX; x++) {
|
||||
for (int y = 0; y <= maxY; y++) {
|
||||
for (int z = -maxZ; z <= maxZ; z++) {
|
||||
double nx = x / radiusX;
|
||||
double ny = (y - centerY) / radiusY;
|
||||
double nz = z / radiusZ;
|
||||
double distance = nx * nx + ny * ny + nz * nz;
|
||||
double wobble = (TreeFunctions.valueNoise3D(x, y, z, noiseSeed) - 0.5) * roughness * 0.55;
|
||||
if (distance + wobble <= 1.0) {
|
||||
canvas.setBody(x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void ball(FormationCanvas canvas, Formation f, int centerX, int centerY, int centerZ,
|
||||
double radius, boolean cap, long noiseSeed, RNG rng) {
|
||||
int extent = (int) Math.ceil(radius);
|
||||
double roughness = Math.max(0.0, Math.min(1.0, f.roughness()));
|
||||
double jitter = Math.max(0.0, Math.min(1.0, f.jitter()));
|
||||
for (int x = -extent; x <= extent; x++) {
|
||||
for (int y = -extent; y <= extent; y++) {
|
||||
for (int z = -extent; z <= extent; z++) {
|
||||
double distance = Math.sqrt(x * x + y * y + z * z);
|
||||
double perturb = (TreeFunctions.valueNoise3D(centerX + x, centerY + y, centerZ + z, noiseSeed) - 0.5)
|
||||
* roughness * Math.max(1.0, radius * 0.6);
|
||||
double effectiveRadius = radius + perturb;
|
||||
if (distance > effectiveRadius + 0.2) {
|
||||
continue;
|
||||
}
|
||||
if (jitter > 0.0 && distance > effectiveRadius - 0.75 && rng.chance(jitter * 0.35)) {
|
||||
continue;
|
||||
}
|
||||
int targetY = centerY + y;
|
||||
if (targetY < 0) {
|
||||
continue;
|
||||
}
|
||||
if (cap) {
|
||||
canvas.setCap(centerX + x, targetY, centerZ + z);
|
||||
} else {
|
||||
canvas.setBody(centerX + x, targetY, centerZ + z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void mirrorAcrossX(FormationCanvas canvas) {
|
||||
Map<Vector3i, FormationCanvas.Role> cells = new HashMap<>(canvas.getCells());
|
||||
for (Map.Entry<Vector3i, FormationCanvas.Role> entry : cells.entrySet()) {
|
||||
Vector3i position = entry.getKey();
|
||||
if (entry.getValue() == FormationCanvas.Role.CAP) {
|
||||
canvas.setCap(-position.getBlockX(), position.getBlockY(), position.getBlockZ());
|
||||
} else {
|
||||
canvas.setBody(-position.getBlockX(), position.getBlockY(), position.getBlockZ());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
-48
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.formation;
|
||||
|
||||
import art.arcane.iris.modules.objects.formation.Formation;
|
||||
import art.arcane.iris.engine.object.procedural.ProceduralShape;
|
||||
import art.arcane.iris.engine.object.procedural.ResolvedProceduralPlacement;
|
||||
import art.arcane.iris.modules.objects.ObjectBuilder;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.resource.PackResources;
|
||||
|
||||
/** A rock formation made placeable: its variants are baked by {@link FormationGenerator}. */
|
||||
public final class ResolvedFormation extends ResolvedProceduralPlacement {
|
||||
private final Formation settings;
|
||||
|
||||
public ResolvedFormation(Formation settings, PackResources resources) {
|
||||
super(new Shape(settings.name(), settings.chance(), settings.density(), settings.seed(), settings.variants(), settings.mode(),
|
||||
settings.rotation(), settings.clamp(), settings.carvingSupport(), settings.underwater(), settings.translate(),
|
||||
settings.stiltSettings().orElse(null), settings.vacuumSettings().orElse(null)), resources);
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int surfaceSupportBuffer() {
|
||||
return settings.surfaceSupportBuffer();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ProceduralShape generate(int index, RNG rng, ObjectBuilder blocks) {
|
||||
return FormationGenerator.generate(settings, index, rng, blocks);
|
||||
}
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.fungi;
|
||||
|
||||
import com.volmit.block.PaletteSpec;
|
||||
import java.util.Optional;
|
||||
import art.arcane.iris.modules.objects.fungi.FungusCapShape;
|
||||
import art.arcane.iris.modules.objects.fungi.Fungus;
|
||||
import art.arcane.iris.engine.object.procedural.IrisProceduralBlocks;
|
||||
import art.arcane.iris.engine.object.procedural.tree.TreeFunctions;
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public final class FungusCapBuilder {
|
||||
private FungusCapBuilder() {
|
||||
}
|
||||
|
||||
public static void build(Map<Vector3i, FungusCellRole> roles, Fungus fungus, int baseRadius, double cx, int baseY, double cz, long seed) {
|
||||
int radius = (int) Math.round(baseRadius + Math.max(0.0, fungus.capOverhang()));
|
||||
int thickness = Math.max(1, Math.min(3, fungus.capThickness()));
|
||||
double squish = Math.max(0.0, Math.min(1.0, fungus.capSquish()));
|
||||
double droop = Math.max(0.0, fungus.capDroop());
|
||||
FungusCapShape shape = fungus.capShape() == null ? FungusCapShape.DOME : fungus.capShape();
|
||||
int icx = (int) Math.round(cx);
|
||||
int icz = (int) Math.round(cz);
|
||||
|
||||
boolean hasGill = blockOrPaletteSet(fungus.gillBlock(), fungus.gillPalette());
|
||||
boolean hasSpot = blockOrPaletteSet(fungus.spotBlock(), fungus.spotPalette());
|
||||
|
||||
double apexRise = apexRise(shape, radius) * (1.0 - 0.6 * squish);
|
||||
double droopReach = Math.tan(Math.toRadians(droop)) * radius;
|
||||
|
||||
for (int dx = -radius; dx <= radius; dx++) {
|
||||
for (int dz = -radius; dz <= radius; dz++) {
|
||||
double dist = Math.sqrt(dx * dx + dz * dz);
|
||||
if (dist > radius + 0.5) {
|
||||
continue;
|
||||
}
|
||||
double normalized = dist / Math.max(1.0, radius);
|
||||
double surfaceTop = baseY + capSurface(shape, normalized, apexRise);
|
||||
surfaceTop -= droopReach * Math.pow(normalized, 3);
|
||||
|
||||
int topYi = (int) Math.round(surfaceTop);
|
||||
for (int layer = 0; layer < thickness; layer++) {
|
||||
int y = topYi - layer;
|
||||
if (y < baseY - thickness) {
|
||||
continue;
|
||||
}
|
||||
Vector3i pos = new Vector3i(icx + dx, y, icz + dz);
|
||||
FungusCellRole role = FungusCellRole.CAP;
|
||||
|
||||
boolean underside = layer == thickness - 1;
|
||||
boolean topFace = layer == 0;
|
||||
|
||||
if (underside && hasGill && rollNoise(icx + dx, y, icz + dz, seed + 4111L) <= fungus.gillChance()) {
|
||||
role = FungusCellRole.GILL;
|
||||
} else if (topFace && hasSpot && spotNoise(icx + dx, y, icz + dz, seed + 9311L) <= fungus.spotChance()) {
|
||||
role = FungusCellRole.SPOT;
|
||||
}
|
||||
|
||||
roles.putIfAbsent(pos, role);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static double apexRise(FungusCapShape shape, int radius) {
|
||||
return switch (shape) {
|
||||
case DOME -> radius * 0.85;
|
||||
case CONICAL -> radius * 1.4;
|
||||
case FUNNEL -> radius * 0.5;
|
||||
case FLAT -> radius * 0.35;
|
||||
case FLAT_WIDE -> radius * 0.2;
|
||||
};
|
||||
}
|
||||
|
||||
private static double capSurface(FungusCapShape shape, double normalized, double apexRise) {
|
||||
double n = Math.max(0.0, Math.min(1.0, normalized));
|
||||
return switch (shape) {
|
||||
case DOME -> apexRise * Math.sqrt(Math.max(0.0, 1.0 - n * n));
|
||||
case CONICAL -> apexRise * (1.0 - n);
|
||||
case FUNNEL -> apexRise * (n * n);
|
||||
case FLAT -> apexRise * Math.max(0.0, 1.0 - Math.pow(n, 4));
|
||||
case FLAT_WIDE -> apexRise * Math.max(0.0, 1.0 - Math.pow(n, 6));
|
||||
};
|
||||
}
|
||||
|
||||
private static double rollNoise(int x, int y, int z, long seed) {
|
||||
return TreeFunctions.valueNoise3D(x, y, z, seed);
|
||||
}
|
||||
|
||||
private static double spotNoise(int x, int y, int z, long seed) {
|
||||
return TreeFunctions.valueNoise3D(Math.floorDiv(x, 2), y, Math.floorDiv(z, 2), seed);
|
||||
}
|
||||
|
||||
static boolean blockOrPaletteSet(Optional<String> block, Optional<PaletteSpec> palette) {
|
||||
if (IrisProceduralBlocks.paletteSet(palette)) {
|
||||
return true;
|
||||
}
|
||||
return block.filter(name -> !name.isEmpty()).isPresent();
|
||||
}
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.fungi;
|
||||
|
||||
import art.arcane.iris.modules.objects.fungi.Fungus;
|
||||
import art.arcane.iris.modules.objects.ObjectBuilder;
|
||||
import art.arcane.iris.engine.object.procedural.ProceduralShape;
|
||||
import art.arcane.iris.engine.object.procedural.IrisProceduralBlocks;
|
||||
import com.volmit.block.BlockState;
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class FungusGenerator {
|
||||
private FungusGenerator() {
|
||||
}
|
||||
|
||||
public static ProceduralShape generate(Fungus fungus, int height, RNG rng, ObjectBuilder blocks) {
|
||||
Map<Vector3i, FungusCellRole> roles = new HashMap<>();
|
||||
long baseSeed = rng.getSeed();
|
||||
|
||||
if (fungus.shelf()) {
|
||||
FungusShelfBuilder.build(roles, fungus, rng, baseSeed);
|
||||
} else {
|
||||
buildUpright(roles, fungus, height, rng, baseSeed);
|
||||
}
|
||||
|
||||
if (roles.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
RNG paletteRng = new RNG(fungus.seed());
|
||||
Map<Vector3i, BlockState> resolved = new HashMap<>();
|
||||
for (Map.Entry<Vector3i, FungusCellRole> entry : roles.entrySet()) {
|
||||
Vector3i pos = entry.getKey();
|
||||
BlockState bd = resolveRole(fungus, entry.getValue(), blocks, pos, paletteRng);
|
||||
if (bd == null) {
|
||||
continue;
|
||||
}
|
||||
resolved.put(pos, bd);
|
||||
}
|
||||
|
||||
return IrisProceduralBlocks.assemble(resolved);
|
||||
}
|
||||
|
||||
private static void buildUpright(Map<Vector3i, FungusCellRole> roles, Fungus fungus, int height, RNG rng, long baseSeed) {
|
||||
int stemHeight = Math.max(1, height);
|
||||
Map<Vector3i, BlockState> stemCells = new HashMap<>();
|
||||
double[] top = FungusStemBuilder.build(stemCells, fungus, stemHeight, baseSeed);
|
||||
for (Vector3i v : stemCells.keySet()) {
|
||||
roles.put(v, FungusCellRole.STEM);
|
||||
}
|
||||
|
||||
int radius = pickRadius(fungus, rng);
|
||||
double cx = top[0];
|
||||
double cz = top[2];
|
||||
int capBaseY = (int) Math.round(top[1]);
|
||||
FungusCapBuilder.build(roles, fungus, radius, cx, capBaseY, cz, baseSeed + 5557L);
|
||||
}
|
||||
|
||||
private static int pickRadius(Fungus fungus, RNG rng) {
|
||||
int lo = Math.min(fungus.capRadiusMin(), fungus.capRadiusMax());
|
||||
int hi = Math.max(fungus.capRadiusMin(), fungus.capRadiusMax());
|
||||
lo = Math.max(1, lo);
|
||||
hi = Math.max(lo, hi);
|
||||
return rng.i(lo, hi + 1);
|
||||
}
|
||||
|
||||
private static BlockState resolveRole(Fungus fungus, FungusCellRole role, ObjectBuilder blocks, Vector3i pos, RNG paletteRng) {
|
||||
int x = pos.getBlockX();
|
||||
int y = pos.getBlockY();
|
||||
int z = pos.getBlockZ();
|
||||
return switch (role) {
|
||||
case STEM -> IrisProceduralBlocks.resolve(fungus.stem(), fungus.stemPalette(), blocks, x, y, z, paletteRng);
|
||||
case CAP -> IrisProceduralBlocks.resolve(fungus.cap(), fungus.capPalette(), blocks, x, y, z, paletteRng);
|
||||
case GILL -> {
|
||||
BlockState gill = IrisProceduralBlocks.resolve(fungus.gillBlock(), fungus.gillPalette(), blocks, x, y, z, paletteRng);
|
||||
yield gill != null ? gill : IrisProceduralBlocks.resolve(fungus.cap(), fungus.capPalette(), blocks, x, y, z, paletteRng);
|
||||
}
|
||||
case SPOT -> {
|
||||
BlockState spot = IrisProceduralBlocks.resolve(fungus.spotBlock(), fungus.spotPalette(), blocks, x, y, z, paletteRng);
|
||||
yield spot != null ? spot : IrisProceduralBlocks.resolve(fungus.cap(), fungus.capPalette(), blocks, x, y, z, paletteRng);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.fungi;
|
||||
|
||||
import art.arcane.iris.modules.objects.fungi.Fungus;
|
||||
import art.arcane.iris.engine.object.procedural.tree.TreeFunctions;
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public final class FungusShelfBuilder {
|
||||
private FungusShelfBuilder() {
|
||||
}
|
||||
|
||||
public static void build(Map<Vector3i, FungusCellRole> roles, Fungus fungus, RNG rng, long seed) {
|
||||
int radius = Math.max(1, fungus.shelfRadius());
|
||||
double azimuth = rng.d(0.0, Math.PI * 2.0);
|
||||
double fanX = Math.sin(azimuth);
|
||||
double fanZ = Math.cos(azimuth);
|
||||
int stubHeight = Math.max(0, Math.min(2, fungus.stemWidth()));
|
||||
|
||||
for (int y = 0; y < stubHeight; y++) {
|
||||
roles.put(new Vector3i(0, y, 0), FungusCellRole.STEM);
|
||||
}
|
||||
|
||||
int fanY = stubHeight;
|
||||
boolean hasGill = FungusCapBuilder.blockOrPaletteSet(fungus.gillBlock(), fungus.gillPalette());
|
||||
boolean hasSpot = FungusCapBuilder.blockOrPaletteSet(fungus.spotBlock(), fungus.spotPalette());
|
||||
|
||||
for (int dx = -radius; dx <= radius; dx++) {
|
||||
for (int dz = -radius; dz <= radius; dz++) {
|
||||
double dist = Math.sqrt(dx * dx + dz * dz);
|
||||
if (dist > radius + 0.5) {
|
||||
continue;
|
||||
}
|
||||
double forward = dx * fanX + dz * fanZ;
|
||||
if (forward < -0.5) {
|
||||
continue;
|
||||
}
|
||||
double normalized = dist / Math.max(1.0, radius);
|
||||
int lift = (int) Math.round(radius * 0.25 * (1.0 - normalized));
|
||||
int y = fanY + lift;
|
||||
|
||||
FungusCellRole role = FungusCellRole.CAP;
|
||||
if (hasSpot && spotNoise(dx, y, dz, seed + 9311L) <= fungus.spotChance()) {
|
||||
role = FungusCellRole.SPOT;
|
||||
}
|
||||
roles.putIfAbsent(new Vector3i(dx, y, dz), role);
|
||||
|
||||
if (hasGill && rollNoise(dx, y - 1, dz, seed + 4111L) <= fungus.gillChance()) {
|
||||
roles.putIfAbsent(new Vector3i(dx, y - 1, dz), FungusCellRole.GILL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static double rollNoise(int x, int y, int z, long seed) {
|
||||
return TreeFunctions.valueNoise3D(x, y, z, seed);
|
||||
}
|
||||
|
||||
private static double spotNoise(int x, int y, int z, long seed) {
|
||||
return TreeFunctions.valueNoise3D(Math.floorDiv(x, 2), y, Math.floorDiv(z, 2), seed);
|
||||
}
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.fungi;
|
||||
|
||||
import art.arcane.iris.modules.objects.fungi.Fungus;
|
||||
import art.arcane.iris.engine.object.procedural.tree.TreeFunctions;
|
||||
import com.volmit.block.BlockState;
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public final class FungusStemBuilder {
|
||||
private FungusStemBuilder() {
|
||||
}
|
||||
|
||||
public static double[] build(Map<Vector3i, BlockState> stemCells, Fungus fungus, int stemHeight, long seed) {
|
||||
int width = Math.max(1, Math.min(3, fungus.stemWidth()));
|
||||
double maxLean = stemHeight * Math.tan(Math.toRadians(Math.max(0.0, fungus.stemCurve())));
|
||||
double leanRad = Math.toRadians(fungus.stemLeanAzimuth());
|
||||
double leanX = Math.sin(leanRad);
|
||||
double leanZ = Math.cos(leanRad);
|
||||
double waveAmp = Math.max(0.0, fungus.stemWaveAmplitude());
|
||||
double wavePeriods = fungus.stemWavePeriods() == 0 ? 1.0 : fungus.stemWavePeriods();
|
||||
double waveAzimuth = Math.toRadians(fungus.stemLeanAzimuth() + 90.0);
|
||||
double waveX = Math.sin(waveAzimuth);
|
||||
double waveZ = Math.cos(waveAzimuth);
|
||||
|
||||
double topCx = 0.0;
|
||||
double topCz = 0.0;
|
||||
int topY = Math.max(0, stemHeight - 1);
|
||||
|
||||
for (int y = 0; y < stemHeight; y++) {
|
||||
double t = stemHeight <= 1 ? 0.0 : y / (double) (stemHeight - 1);
|
||||
double lean = maxLean * (t * t);
|
||||
double wave = waveAmp * Math.sin(2.0 * Math.PI * wavePeriods * t + TreeFunctions.valueNoise1D(seed, seed) * Math.PI * 2.0);
|
||||
double cx = lean * leanX + wave * waveX;
|
||||
double cz = lean * leanZ + wave * waveZ;
|
||||
|
||||
for (int[] xz : squarePositions(cx, cz, width)) {
|
||||
stemCells.put(new Vector3i(xz[0], y, xz[1]), null);
|
||||
}
|
||||
|
||||
topCx = cx;
|
||||
topCz = cz;
|
||||
}
|
||||
|
||||
return new double[]{topCx, topY, topCz};
|
||||
}
|
||||
|
||||
static int[][] squarePositions(double cx, double cz, int width) {
|
||||
if (width % 2 == 1) {
|
||||
int half = width / 2;
|
||||
int icx = (int) Math.round(cx);
|
||||
int icz = (int) Math.round(cz);
|
||||
int[][] out = new int[width * width][2];
|
||||
int idx = 0;
|
||||
for (int dx = -half; dx <= half; dx++) {
|
||||
for (int dz = -half; dz <= half; dz++) {
|
||||
out[idx][0] = icx + dx;
|
||||
out[idx][1] = icz + dz;
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
int ox = (int) Math.floor(cx) - width / 2 + 1;
|
||||
int oz = (int) Math.floor(cz) - width / 2 + 1;
|
||||
int[][] out = new int[width * width][2];
|
||||
int idx = 0;
|
||||
for (int dx = 0; dx < width; dx++) {
|
||||
for (int dz = 0; dz < width; dz++) {
|
||||
out[idx][0] = ox + dx;
|
||||
out[idx][1] = oz + dz;
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.fungi;
|
||||
|
||||
import art.arcane.iris.modules.objects.fungi.Fungus;
|
||||
import art.arcane.iris.engine.object.procedural.ProceduralShape;
|
||||
import art.arcane.iris.engine.object.procedural.ResolvedProceduralPlacement;
|
||||
import art.arcane.iris.modules.objects.ObjectBuilder;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.object.PlaceableObject;
|
||||
import com.volmit.resource.PackResources;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** A fungus made placeable: its variants are baked by {@link FungusGenerator}. */
|
||||
public final class ResolvedFungus extends ResolvedProceduralPlacement {
|
||||
private final Fungus settings;
|
||||
|
||||
public ResolvedFungus(Fungus settings, PackResources resources) {
|
||||
super(new Shape(settings.name(), settings.chance(), settings.density(), settings.seed(), settings.variants(), settings.mode(),
|
||||
settings.rotation(), settings.clamp(), settings.carvingSupport(), settings.underwater(), settings.translate(),
|
||||
settings.stiltSettings().orElse(null), settings.vacuumSettings().orElse(null)), resources);
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ProceduralShape generate(int index, RNG rng, ObjectBuilder blocks) {
|
||||
throw new UnsupportedOperationException("A fungus bakes its variants itself, from the stem heights");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<PlaceableObject> bake(ObjectBuilder blocks) {
|
||||
List<PlaceableObject> baked = new ArrayList<>();
|
||||
int count = variantCount();
|
||||
int lo = Math.min(settings.stemHeightMin(), settings.stemHeightMax());
|
||||
int hi = Math.max(settings.stemHeightMin(), settings.stemHeightMax());
|
||||
RNG heightRng = new RNG(seed());
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
int height;
|
||||
if (count == 1 || lo == hi) {
|
||||
height = heightRng.i(lo, hi + 1);
|
||||
} else {
|
||||
double step = (hi - lo) / (double) (count - 1);
|
||||
double base = lo + step * i;
|
||||
double jitter = heightRng.d(-step * 0.3, step * 0.3);
|
||||
height = (int) Math.round(Math.max(lo, Math.min(hi, base + jitter)));
|
||||
}
|
||||
|
||||
ProceduralShape generated = FungusGenerator.generate(settings, Math.max(1, height), variantRng(i), blocks);
|
||||
if (generated == null || generated.blocks().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
baked.add(build(blocks, "procedural/" + name() + "#" + i, generated));
|
||||
}
|
||||
|
||||
return baked;
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.ruin;
|
||||
|
||||
import art.arcane.iris.modules.objects.ruin.Ruin;
|
||||
import art.arcane.iris.engine.object.procedural.ProceduralShape;
|
||||
import art.arcane.iris.engine.object.procedural.ResolvedProceduralPlacement;
|
||||
import art.arcane.iris.modules.objects.ObjectBuilder;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.resource.PackResources;
|
||||
|
||||
/** A ruin made placeable: its variants are baked by {@link RuinGenerator}. */
|
||||
public final class ResolvedRuin extends ResolvedProceduralPlacement {
|
||||
private final Ruin settings;
|
||||
|
||||
public ResolvedRuin(Ruin settings, PackResources resources) {
|
||||
super(new Shape(settings.name(), settings.chance(), settings.density(), settings.seed(), settings.variants(), settings.mode(),
|
||||
settings.rotation(), settings.clamp(), settings.carvingSupport(), settings.underwater(), settings.translate(),
|
||||
settings.stiltSettings().orElse(null), settings.vacuumSettings().orElse(null)), resources);
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ProceduralShape generate(int index, RNG rng, ObjectBuilder blocks) {
|
||||
return RuinGenerator.generate(settings, index, rng, blocks);
|
||||
}
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.ruin;
|
||||
|
||||
import com.volmit.block.BlockState;
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
final class RuinBlockCanvas {
|
||||
enum Role {
|
||||
STRUCTURE,
|
||||
ACCENT
|
||||
}
|
||||
|
||||
static final class Cell {
|
||||
private Role role;
|
||||
private boolean structural;
|
||||
private BlockState accentData;
|
||||
|
||||
Cell(Role role, boolean structural) {
|
||||
this.role = role;
|
||||
this.structural = structural;
|
||||
}
|
||||
|
||||
Role role() {
|
||||
return role;
|
||||
}
|
||||
|
||||
boolean structural() {
|
||||
return structural;
|
||||
}
|
||||
|
||||
BlockState accentData() {
|
||||
return accentData;
|
||||
}
|
||||
|
||||
void promote(Role next, boolean structuralNext) {
|
||||
this.role = next;
|
||||
this.structural = this.structural || structuralNext;
|
||||
}
|
||||
|
||||
void makeAccent(BlockState data) {
|
||||
this.role = Role.ACCENT;
|
||||
this.structural = false;
|
||||
this.accentData = data;
|
||||
}
|
||||
}
|
||||
|
||||
private final Map<Vector3i, Cell> cells = new HashMap<>();
|
||||
|
||||
Map<Vector3i, Cell> cells() {
|
||||
return cells;
|
||||
}
|
||||
|
||||
void set(int x, int y, int z, Role role, boolean structural) {
|
||||
Vector3i key = new Vector3i(x, y, z);
|
||||
Cell existing = cells.get(key);
|
||||
if (existing == null) {
|
||||
cells.put(key, new Cell(role, structural));
|
||||
} else {
|
||||
existing.promote(role, structural);
|
||||
}
|
||||
}
|
||||
|
||||
void accent(int x, int y, int z, BlockState data) {
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
cells.put(new Vector3i(x, y, z), accentCell(data));
|
||||
}
|
||||
|
||||
private static Cell accentCell(BlockState data) {
|
||||
Cell cell = new Cell(Role.ACCENT, false);
|
||||
cell.makeAccent(data);
|
||||
return cell;
|
||||
}
|
||||
|
||||
boolean has(int x, int y, int z) {
|
||||
return cells.containsKey(new Vector3i(x, y, z));
|
||||
}
|
||||
|
||||
Cell get(int x, int y, int z) {
|
||||
return cells.get(new Vector3i(x, y, z));
|
||||
}
|
||||
|
||||
void remove(int x, int y, int z) {
|
||||
cells.remove(new Vector3i(x, y, z));
|
||||
}
|
||||
}
|
||||
-122
@@ -1,122 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.ruin;
|
||||
|
||||
import art.arcane.iris.modules.objects.ruin.RuinDecorator;
|
||||
import art.arcane.iris.modules.objects.ObjectBuilder;
|
||||
import art.arcane.iris.engine.object.procedural.IrisProceduralBlocks;
|
||||
import com.volmit.block.BlockState;
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
final class RuinDecoratorApplier {
|
||||
private static final int[][] HORIZONTAL = {{1, 0, 0}, {-1, 0, 0}, {0, 0, 1}, {0, 0, -1}};
|
||||
|
||||
private RuinDecoratorApplier() {
|
||||
}
|
||||
|
||||
static void apply(RuinBlockCanvas canvas, RuinDecorator decorator, ObjectBuilder blocks, long seed, RNG rng) {
|
||||
List<Vector3i> candidates = switch (decorator.target()) {
|
||||
case TOP -> topCandidates(canvas);
|
||||
case SURFACE -> surfaceCandidates(canvas);
|
||||
case BASE_SCATTER -> baseScatterCandidates(canvas, Math.max(1, decorator.scatterRadius()));
|
||||
};
|
||||
|
||||
RNG paletteRng = new RNG(seed);
|
||||
for (Vector3i v : candidates) {
|
||||
if (!rng.chance(decorator.chance())) {
|
||||
continue;
|
||||
}
|
||||
BlockState bd = IrisProceduralBlocks.resolve(decorator.block(), decorator.palette(), blocks, v.getBlockX(), v.getBlockY(), v.getBlockZ(), paletteRng);
|
||||
if (bd != null) {
|
||||
canvas.accent(v.getBlockX(), v.getBlockY(), v.getBlockZ(), bd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static List<Vector3i> topCandidates(RuinBlockCanvas canvas) {
|
||||
Map<Long, Integer> highest = new HashMap<>();
|
||||
for (Vector3i v : canvas.cells().keySet()) {
|
||||
long key = columnKey(v.getBlockX(), v.getBlockZ());
|
||||
Integer current = highest.get(key);
|
||||
if (current == null || v.getBlockY() > current) {
|
||||
highest.put(key, v.getBlockY());
|
||||
}
|
||||
}
|
||||
List<Vector3i> out = new ArrayList<>();
|
||||
for (Map.Entry<Long, Integer> entry : highest.entrySet()) {
|
||||
int x = (int) (entry.getKey() >> 32);
|
||||
int z = (int) (entry.getKey() & 0xFFFFFFFFL);
|
||||
int y = entry.getValue() + 1;
|
||||
if (!canvas.has(x, y, z)) {
|
||||
out.add(new Vector3i(x, y, z));
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
private static List<Vector3i> surfaceCandidates(RuinBlockCanvas canvas) {
|
||||
List<Vector3i> out = new ArrayList<>();
|
||||
for (Vector3i v : new ArrayList<>(canvas.cells().keySet())) {
|
||||
for (int[] dir : HORIZONTAL) {
|
||||
int nx = v.getBlockX() + dir[0];
|
||||
int ny = v.getBlockY();
|
||||
int nz = v.getBlockZ() + dir[2];
|
||||
if (!canvas.has(nx, ny, nz)) {
|
||||
out.add(new Vector3i(nx, ny, nz));
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
private static List<Vector3i> baseScatterCandidates(RuinBlockCanvas canvas, int radius) {
|
||||
int minX = Integer.MAX_VALUE;
|
||||
int minZ = Integer.MAX_VALUE;
|
||||
int maxX = Integer.MIN_VALUE;
|
||||
int maxZ = Integer.MIN_VALUE;
|
||||
int minY = Integer.MAX_VALUE;
|
||||
for (Vector3i v : canvas.cells().keySet()) {
|
||||
minX = Math.min(minX, v.getBlockX());
|
||||
minZ = Math.min(minZ, v.getBlockZ());
|
||||
maxX = Math.max(maxX, v.getBlockX());
|
||||
maxZ = Math.max(maxZ, v.getBlockZ());
|
||||
minY = Math.min(minY, v.getBlockY());
|
||||
}
|
||||
|
||||
List<Vector3i> out = new ArrayList<>();
|
||||
for (int x = minX - radius; x <= maxX + radius; x++) {
|
||||
for (int z = minZ - radius; z <= maxZ + radius; z++) {
|
||||
if (!canvas.has(x, minY, z) && !canvas.has(x, minY + 1, z)) {
|
||||
out.add(new Vector3i(x, minY, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
private static long columnKey(int x, int z) {
|
||||
return ((long) x << 32) | (z & 0xFFFFFFFFL);
|
||||
}
|
||||
}
|
||||
@@ -1,200 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.ruin;
|
||||
|
||||
import art.arcane.iris.modules.objects.ruin.RuinDecorator;
|
||||
import art.arcane.iris.modules.objects.ruin.Ruin;
|
||||
import art.arcane.iris.modules.objects.ObjectBuilder;
|
||||
import art.arcane.iris.engine.object.procedural.ProceduralShape;
|
||||
import art.arcane.iris.engine.object.procedural.IrisProceduralBlocks;
|
||||
import com.volmit.block.BlockState;
|
||||
import art.arcane.iris.engine.object.procedural.tree.TreeFunctions;
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public final class RuinGenerator {
|
||||
private RuinGenerator() {
|
||||
}
|
||||
|
||||
public static ProceduralShape generate(Ruin ruin, int variantIndex, RNG rng, ObjectBuilder blocks) {
|
||||
int count = Math.max(1, ruin.variants());
|
||||
int height = pick(ruin.heightMin(), ruin.heightMax(), variantIndex, count, rng);
|
||||
int width = pick(ruin.widthMin(), ruin.widthMax(), variantIndex, count, rng);
|
||||
int length = pick(ruin.lengthMin(), ruin.lengthMax(), variantIndex, count, rng);
|
||||
|
||||
RuinBlockCanvas canvas = new RuinBlockCanvas();
|
||||
switch (ruin.form()) {
|
||||
case PILLAR -> RuinShapes.pillar(canvas, Math.max(1, width), Math.max(2, height), rng);
|
||||
case WALL -> RuinShapes.wall(canvas, Math.max(1, width), Math.max(2, length), Math.max(2, height), rng);
|
||||
case ARCH -> RuinShapes.arch(canvas, Math.max(1, width), Math.max(3, length), Math.max(3, height), rng);
|
||||
case FLOOR_SLAB -> RuinShapes.floorSlab(canvas, Math.max(3, width), Math.max(3, length), Math.max(1, Math.min(height, 2)));
|
||||
case RUBBLE -> RuinShapes.rubble(canvas, Math.max(3, width), Math.max(3, length), Math.max(1, Math.min(height, 4)), rng);
|
||||
}
|
||||
|
||||
applyBurial(ruin, canvas, height);
|
||||
applyErosion(ruin, canvas);
|
||||
applyAccents(ruin, canvas, rng, blocks);
|
||||
|
||||
return resolve(ruin, canvas, blocks);
|
||||
}
|
||||
|
||||
private static int pick(int lo, int hi, int variantIndex, int count, RNG rng) {
|
||||
int min = Math.min(lo, hi);
|
||||
int max = Math.max(lo, hi);
|
||||
if (min == max || count <= 1) {
|
||||
return rng.i(min, max + 1);
|
||||
}
|
||||
double step = (max - min) / (double) (count - 1);
|
||||
double base = min + step * variantIndex;
|
||||
double jitter = rng.d(-step * 0.3, step * 0.3);
|
||||
return (int) Math.round(Math.max(min, Math.min(max, base + jitter)));
|
||||
}
|
||||
|
||||
private static void applyBurial(Ruin ruin, RuinBlockCanvas canvas, int height) {
|
||||
double fraction = clamp01(ruin.buriedFraction());
|
||||
if (fraction <= 0.0) {
|
||||
return;
|
||||
}
|
||||
int sink = (int) Math.round(height * fraction);
|
||||
if (sink <= 0) {
|
||||
return;
|
||||
}
|
||||
Map<Vector3i, RuinBlockCanvas.Cell> moved = new HashMap<>();
|
||||
for (Map.Entry<Vector3i, RuinBlockCanvas.Cell> entry : canvas.cells().entrySet()) {
|
||||
Vector3i v = entry.getKey();
|
||||
moved.put(new Vector3i(v.getBlockX(), v.getBlockY() - sink, v.getBlockZ()), entry.getValue());
|
||||
}
|
||||
canvas.cells().clear();
|
||||
canvas.cells().putAll(moved);
|
||||
}
|
||||
|
||||
private static void applyErosion(Ruin ruin, RuinBlockCanvas canvas) {
|
||||
double erosion = clamp01(ruin.erosion());
|
||||
if (erosion <= 0.0) {
|
||||
return;
|
||||
}
|
||||
double scale = Math.max(0.0001, ruin.erosionScale());
|
||||
long erosionSeed = ruin.seed() * 0x2545F4914F6CDD1DL + 17L;
|
||||
int minY = Integer.MAX_VALUE;
|
||||
for (Vector3i v : canvas.cells().keySet()) {
|
||||
minY = Math.min(minY, v.getBlockY());
|
||||
}
|
||||
|
||||
List<Vector3i> doomed = new ArrayList<>();
|
||||
for (Map.Entry<Vector3i, RuinBlockCanvas.Cell> entry : canvas.cells().entrySet()) {
|
||||
Vector3i v = entry.getKey();
|
||||
RuinBlockCanvas.Cell cell = entry.getValue();
|
||||
if (cell.structural() || v.getBlockY() <= minY) {
|
||||
continue;
|
||||
}
|
||||
int sx = (int) Math.round(v.getBlockX() * scale);
|
||||
int sy = (int) Math.round(v.getBlockY() * scale);
|
||||
int sz = (int) Math.round(v.getBlockZ() * scale);
|
||||
double n = TreeFunctions.valueNoise3D(sx, sy, sz, erosionSeed);
|
||||
if (n < erosion) {
|
||||
doomed.add(v);
|
||||
}
|
||||
}
|
||||
for (Vector3i v : doomed) {
|
||||
canvas.cells().remove(v);
|
||||
}
|
||||
}
|
||||
|
||||
private static void applyAccents(Ruin ruin, RuinBlockCanvas canvas, RNG rng, ObjectBuilder blocks) {
|
||||
if (ruin.accents() == null || ruin.accents().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
int decoratorIndex = 0;
|
||||
for (art.arcane.iris.modules.objects.ruin.RuinDecorator decorator : ruin.accents()) {
|
||||
RuinDecoratorApplier.apply(canvas, decorator, blocks, ruin.seed() + decoratorIndex * 911L, rng.nextParallelRNG(decoratorIndex + 1));
|
||||
decoratorIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
private static ProceduralShape resolve(Ruin ruin, RuinBlockCanvas canvas, ObjectBuilder blocks) {
|
||||
if (canvas.cells().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
double scale = Math.max(0.0001, ruin.weatheringScale());
|
||||
double mossiness = clamp01(ruin.mossiness());
|
||||
long weatherSeed = ruin.seed() * 0x9E3779B97F4A7C15L + 101L;
|
||||
RNG paletteRng = new RNG(ruin.seed());
|
||||
|
||||
int minY = Integer.MAX_VALUE;
|
||||
int maxY = Integer.MIN_VALUE;
|
||||
for (Vector3i v : canvas.cells().keySet()) {
|
||||
minY = Math.min(minY, v.getBlockY());
|
||||
maxY = Math.max(maxY, v.getBlockY());
|
||||
}
|
||||
int span = Math.max(1, maxY - minY);
|
||||
|
||||
Map<Vector3i, BlockState> resolved = new HashMap<>();
|
||||
for (Map.Entry<Vector3i, RuinBlockCanvas.Cell> entry : canvas.cells().entrySet()) {
|
||||
Vector3i v = entry.getKey();
|
||||
RuinBlockCanvas.Cell cell = entry.getValue();
|
||||
BlockState bd;
|
||||
if (cell.role() == RuinBlockCanvas.Role.ACCENT) {
|
||||
bd = cell.accentData();
|
||||
} else {
|
||||
bd = structuralBlock(ruin, cell, v, blocks, paletteRng, scale, mossiness, weatherSeed, minY, span);
|
||||
}
|
||||
if (bd != null) {
|
||||
resolved.put(v, bd);
|
||||
}
|
||||
}
|
||||
|
||||
return IrisProceduralBlocks.assemble(resolved);
|
||||
}
|
||||
|
||||
private static BlockState structuralBlock(Ruin ruin, RuinBlockCanvas.Cell cell, Vector3i v, ObjectBuilder blocks, RNG paletteRng, double scale, double mossiness, long weatherSeed, int minY, int span) {
|
||||
boolean weathered = false;
|
||||
if (mossiness > 0.0) {
|
||||
int sx = (int) Math.round(v.getBlockX() * scale);
|
||||
int sy = (int) Math.round(v.getBlockY() * scale);
|
||||
int sz = (int) Math.round(v.getBlockZ() * scale);
|
||||
double n = TreeFunctions.valueNoise3D(sx, sy, sz, weatherSeed);
|
||||
double normalized = (v.getBlockY() - minY) / (double) span;
|
||||
double gradient = 1.0 - 0.6 * normalized;
|
||||
weathered = n < mossiness * gradient;
|
||||
}
|
||||
|
||||
if (weathered) {
|
||||
BlockState wd = IrisProceduralBlocks.resolve(ruin.weatheredBlock(), ruin.weatheringPalette(), blocks, v.getBlockX(), v.getBlockY(), v.getBlockZ(), paletteRng);
|
||||
if (wd != null) {
|
||||
return wd;
|
||||
}
|
||||
}
|
||||
return IrisProceduralBlocks.resolve(ruin.block(), ruin.blockPalette(), blocks, v.getBlockX(), v.getBlockY(), v.getBlockZ(), paletteRng);
|
||||
}
|
||||
|
||||
private static double clamp01(double value) {
|
||||
if (value < 0.0) {
|
||||
return 0.0;
|
||||
}
|
||||
if (value > 1.0) {
|
||||
return 1.0;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -1,146 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.ruin;
|
||||
|
||||
import art.arcane.iris.engine.object.procedural.tree.TreeFunctions;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
final class RuinShapes {
|
||||
private RuinShapes() {
|
||||
}
|
||||
|
||||
static void pillar(RuinBlockCanvas canvas, int width, int height, RNG rng) {
|
||||
int half = (width - 1) / 2;
|
||||
int broken = Math.max(2, height - rng.i(0, Math.max(1, height / 3)));
|
||||
for (int y = 0; y < broken; y++) {
|
||||
boolean bottom = y == 0;
|
||||
int jitter = y >= broken - 1 ? rng.i(0, 2) : 0;
|
||||
for (int x = -half; x <= half; x++) {
|
||||
for (int z = -half; z <= half; z++) {
|
||||
if (y == broken - 1 && jitter > 0 && (Math.abs(x) == half || Math.abs(z) == half) && rng.chance(0.5)) {
|
||||
continue;
|
||||
}
|
||||
canvas.set(x, y, z, RuinBlockCanvas.Role.STRUCTURE, bottom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int stub = rng.i(0, 3);
|
||||
if (stub > 0) {
|
||||
int dir = rng.i(0, 4);
|
||||
int dx = dir == 0 ? 1 : (dir == 1 ? -1 : 0);
|
||||
int dz = dir == 2 ? 1 : (dir == 3 ? -1 : 0);
|
||||
for (int s = 1; s <= stub; s++) {
|
||||
canvas.set((half + s) * dx, 0, (half + s) * dz, RuinBlockCanvas.Role.STRUCTURE, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void wall(RuinBlockCanvas canvas, int thickness, int length, int height, RNG rng) {
|
||||
int half = (length - 1) / 2;
|
||||
int tHalf = (thickness - 1) / 2;
|
||||
long edgeSeed = rng.lmax();
|
||||
for (int z = -half; z <= half; z++) {
|
||||
int top = height - jaggedDrop(z, height, edgeSeed);
|
||||
for (int y = 0; y < top; y++) {
|
||||
if (y > 0 && rng.chance(0.10)) {
|
||||
continue;
|
||||
}
|
||||
for (int x = -tHalf; x <= thickness - 1 - tHalf; x++) {
|
||||
canvas.set(x, y, z, RuinBlockCanvas.Role.STRUCTURE, y == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void arch(RuinBlockCanvas canvas, int thickness, int span, int height, RNG rng) {
|
||||
int legSpacing = Math.max(2, span);
|
||||
int legGap = (legSpacing - 1) / 2;
|
||||
int tHalf = (thickness - 1) / 2;
|
||||
int legTop = Math.max(2, height - Math.max(2, (legSpacing / 2)));
|
||||
|
||||
for (int side = -1; side <= 1; side += 2) {
|
||||
int legZ = side * legGap;
|
||||
for (int y = 0; y < legTop; y++) {
|
||||
for (int x = -tHalf; x <= thickness - 1 - tHalf; x++) {
|
||||
canvas.set(x, y, legZ, RuinBlockCanvas.Role.STRUCTURE, y <= 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double radius = legGap;
|
||||
int crown = legTop + (int) Math.round(radius);
|
||||
for (int z = -legGap; z <= legGap; z++) {
|
||||
double inside = radius * radius - (z * z);
|
||||
if (inside < 0) {
|
||||
continue;
|
||||
}
|
||||
int y = legTop + (int) Math.round(Math.sqrt(inside));
|
||||
for (int yy = legTop; yy <= y && yy <= crown; yy++) {
|
||||
boolean keystone = Math.abs(z) <= 1;
|
||||
for (int x = -tHalf; x <= thickness - 1 - tHalf; x++) {
|
||||
canvas.set(x, yy, z, RuinBlockCanvas.Role.STRUCTURE, keystone);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void floorSlab(RuinBlockCanvas canvas, int width, int length, int thickness) {
|
||||
int xHalf = (width - 1) / 2;
|
||||
int zHalf = (length - 1) / 2;
|
||||
for (int y = 0; y < thickness; y++) {
|
||||
for (int x = -xHalf; x <= width - 1 - xHalf; x++) {
|
||||
for (int z = -zHalf; z <= length - 1 - zHalf; z++) {
|
||||
canvas.set(x, y, z, RuinBlockCanvas.Role.STRUCTURE, y == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void rubble(RuinBlockCanvas canvas, int width, int length, int peak, RNG rng) {
|
||||
int xHalf = (width - 1) / 2;
|
||||
int zHalf = (length - 1) / 2;
|
||||
long blobSeed = rng.lmax();
|
||||
double rx = Math.max(1.0, width / 2.0);
|
||||
double rz = Math.max(1.0, length / 2.0);
|
||||
|
||||
for (int x = -xHalf; x <= width - 1 - xHalf; x++) {
|
||||
for (int z = -zHalf; z <= length - 1 - zHalf; z++) {
|
||||
double radial = (x * x) / (rx * rx) + (z * z) / (rz * rz);
|
||||
if (radial > 1.2) {
|
||||
continue;
|
||||
}
|
||||
double falloff = Math.max(0.0, 1.0 - radial);
|
||||
double noise = art.arcane.iris.engine.object.procedural.tree.TreeFunctions.valueNoise3D(x, 0, z, blobSeed);
|
||||
int columnHeight = (int) Math.round(peak * falloff * (0.6 + 0.4 * noise));
|
||||
for (int y = 0; y <= columnHeight; y++) {
|
||||
if (y > 0 && rng.chance(0.25)) {
|
||||
continue;
|
||||
}
|
||||
canvas.set(x, y, z, RuinBlockCanvas.Role.STRUCTURE, y == 0 && radial < 0.5);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static int jaggedDrop(int z, int height, long seed) {
|
||||
double n = art.arcane.iris.engine.object.procedural.tree.TreeFunctions.valueNoise1D(z * 0.9, seed);
|
||||
return (int) Math.round(n * Math.max(1, height - 1) * 0.6);
|
||||
}
|
||||
}
|
||||
-127
@@ -1,127 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.tree;
|
||||
|
||||
import art.arcane.iris.modules.objects.ObjectBuilder;
|
||||
import art.arcane.iris.modules.objects.tree.Tree;
|
||||
import art.arcane.iris.engine.object.procedural.ProceduralShape;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.object.ObjectBlock;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public final class ProceduralTreeGenerator {
|
||||
private ProceduralTreeGenerator() {
|
||||
}
|
||||
|
||||
public static ProceduralShape generate(Tree tree, int height, RNG rng, ObjectBuilder blocks) {
|
||||
TreeBlockCanvas canvas = new TreeBlockCanvas();
|
||||
long baseSeed = rng.getSeed();
|
||||
|
||||
List<TreeTrunkBuilder.Limb> limbs = TreeTrunkBuilder.build(canvas, tree, height);
|
||||
|
||||
boolean wantEndpoints = tree.decorators() != null && !tree.decorators().isEmpty();
|
||||
List<int[]> branchEndpoints = wantEndpoints ? new ArrayList<>() : null;
|
||||
|
||||
int limbIndex = 0;
|
||||
for (TreeTrunkBuilder.Limb limb : limbs) {
|
||||
TreeCanopyBuilder.build(canvas, tree, height, limb.offsets(), limb.branchStartY(), baseSeed + limbIndex * 131L, branchEndpoints);
|
||||
limbIndex++;
|
||||
}
|
||||
|
||||
if (wantEndpoints) {
|
||||
TreeDecoratorApplier.apply(canvas, tree, baseSeed, branchEndpoints);
|
||||
}
|
||||
|
||||
if (tree.roots()) {
|
||||
TreeRootBuilder.build(canvas, tree, height, baseSeed);
|
||||
}
|
||||
|
||||
if (tree.plausible()) {
|
||||
TreeSupport.ensureLeavesSupported(canvas, 24);
|
||||
}
|
||||
|
||||
Map<TreeBlockCanvas.Vec, BlockState> resolved = new HashMap<>();
|
||||
Set<TreeBlockCanvas.Vec> trunkPositions = new HashSet<>();
|
||||
Set<TreeBlockCanvas.Vec> leafPositions = new HashSet<>();
|
||||
for (Map.Entry<TreeBlockCanvas.Vec, TreeBlockCanvas.Cell> entry : canvas.getCells().entrySet()) {
|
||||
TreeBlockCanvas.Cell cell = entry.getValue();
|
||||
BlockState state = TreeBlockResolver.resolve(tree, blocks, cell, entry.getKey());
|
||||
if (state == null) {
|
||||
continue;
|
||||
}
|
||||
resolved.put(entry.getKey(), state);
|
||||
if (cell.role() == TreeBlockCanvas.Role.TRUNK || cell.role() == TreeBlockCanvas.Role.SECONDARY_TRUNK) {
|
||||
trunkPositions.add(entry.getKey());
|
||||
} else if (cell.role() == TreeBlockCanvas.Role.LEAF || cell.role() == TreeBlockCanvas.Role.SECONDARY_LEAF) {
|
||||
leafPositions.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
TreePlausibility.apply(resolved, trunkPositions, leafPositions, tree, blocks);
|
||||
|
||||
return assemble(resolved);
|
||||
}
|
||||
|
||||
private static ProceduralShape assemble(Map<TreeBlockCanvas.Vec, BlockState> resolved) {
|
||||
if (resolved.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int minX = Integer.MAX_VALUE;
|
||||
int minY = Integer.MAX_VALUE;
|
||||
int minZ = Integer.MAX_VALUE;
|
||||
int maxX = Integer.MIN_VALUE;
|
||||
int maxY = Integer.MIN_VALUE;
|
||||
int maxZ = Integer.MIN_VALUE;
|
||||
for (TreeBlockCanvas.Vec v : resolved.keySet()) {
|
||||
minX = Math.min(minX, v.x());
|
||||
minY = Math.min(minY, v.y());
|
||||
minZ = Math.min(minZ, v.z());
|
||||
maxX = Math.max(maxX, v.x());
|
||||
maxY = Math.max(maxY, v.y());
|
||||
maxZ = Math.max(maxZ, v.z());
|
||||
}
|
||||
|
||||
int w = maxX - minX + 1;
|
||||
int h = maxY - minY + 1;
|
||||
int d = maxZ - minZ + 1;
|
||||
int cx = w / 2;
|
||||
int cy = h / 2;
|
||||
int cz = d / 2;
|
||||
|
||||
List<ObjectBlock> placed = new ArrayList<>(resolved.size());
|
||||
for (Map.Entry<TreeBlockCanvas.Vec, BlockState> entry : resolved.entrySet()) {
|
||||
TreeBlockCanvas.Vec v = entry.getKey();
|
||||
int nx = v.x() - minX - cx;
|
||||
int ny = v.y() - cy + 1;
|
||||
int nz = v.z() - minZ - cz;
|
||||
placed.add(new ObjectBlock(new BlockPosition(nx, ny, nz), entry.getValue()));
|
||||
}
|
||||
|
||||
return new ProceduralShape(w, h, d, placed);
|
||||
}
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.tree;
|
||||
|
||||
import art.arcane.iris.modules.objects.tree.Tree;
|
||||
import art.arcane.iris.engine.object.procedural.ProceduralShape;
|
||||
import art.arcane.iris.engine.object.procedural.ResolvedProceduralPlacement;
|
||||
import art.arcane.iris.modules.objects.ObjectBuilder;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.object.PlaceableObject;
|
||||
import com.volmit.resource.PackResources;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** A procedural tree made placeable: its variants are baked by {@link ProceduralTreeGenerator}, at heights spread between its limits. */
|
||||
public final class ResolvedTree extends ResolvedProceduralPlacement {
|
||||
private static final long VARIANT_SEED_STRIDE = 7919L;
|
||||
private static final double HEIGHT_JITTER_FRACTION = 0.3;
|
||||
private static final int MINIMUM_HEIGHT = 2;
|
||||
|
||||
private final Tree settings;
|
||||
|
||||
public ResolvedTree(Tree settings, PackResources resources) {
|
||||
super(new Shape(settings.name(), settings.chance(), settings.density(), settings.seed(), settings.variants(), settings.mode(),
|
||||
settings.rotation(), settings.clamp(), settings.carvingSupport(), settings.underwater(), settings.translate(),
|
||||
settings.stiltSettings().orElse(null), settings.vacuumSettings().orElse(null)), resources);
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
public String getVariantLoadKey(int index) {
|
||||
return Tree.variantLoadKey(settings.name(), index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean plausible() {
|
||||
return settings.plausible();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tree() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ProceduralShape generate(int index, RNG rng, ObjectBuilder blocks) {
|
||||
throw new UnsupportedOperationException("Tree variants are baked with heights spread over the limits");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<PlaceableObject> bake(ObjectBuilder blocks) {
|
||||
List<PlaceableObject> baked = new ArrayList<>();
|
||||
int count = Math.max(1, settings.variants());
|
||||
int lo = Math.min(settings.heightMin(), settings.heightMax());
|
||||
int hi = Math.max(settings.heightMin(), settings.heightMax());
|
||||
RNG heightRng = new RNG(settings.seed());
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
int height = variantHeight(heightRng, lo, hi, count, i);
|
||||
ProceduralShape generated = ProceduralTreeGenerator.generate(settings, Math.max(MINIMUM_HEIGHT, height),
|
||||
new RNG(settings.seed() + (i * VARIANT_SEED_STRIDE)), blocks);
|
||||
if (generated == null || generated.blocks().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
baked.add(build(blocks, getVariantLoadKey(i), generated));
|
||||
}
|
||||
|
||||
return baked;
|
||||
}
|
||||
|
||||
private static int variantHeight(RNG heightRng, int lo, int hi, int count, int index) {
|
||||
if (count == 1 || lo == hi) {
|
||||
return heightRng.i(lo, hi + 1);
|
||||
}
|
||||
double step = (hi - lo) / (double) (count - 1);
|
||||
double base = lo + step * index;
|
||||
double jitter = heightRng.d(-step * HEIGHT_JITTER_FRACTION, step * HEIGHT_JITTER_FRACTION);
|
||||
return (int) Math.round(Math.max(lo, Math.min(hi, base + jitter)));
|
||||
}
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.tree;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class TreeBlockCanvas {
|
||||
public record Vec(int x, int y, int z) {
|
||||
}
|
||||
|
||||
public enum Role {
|
||||
TRUNK, SECONDARY_TRUNK, LEAF, SECONDARY_LEAF, DECORATOR
|
||||
}
|
||||
|
||||
public enum Axis {
|
||||
NONE, X, Y, Z
|
||||
}
|
||||
|
||||
public record Cell(Role role, Axis axis, boolean exposed, int decoratorIndex, String facing) {
|
||||
}
|
||||
|
||||
private final Map<Vec, Cell> cells = new HashMap<>();
|
||||
private final Set<Vec> trunk = new HashSet<>();
|
||||
private final Set<Vec> leaf = new HashSet<>();
|
||||
|
||||
public boolean has(int x, int y, int z) {
|
||||
return cells.containsKey(new Vec(x, y, z));
|
||||
}
|
||||
|
||||
public Cell get(int x, int y, int z) {
|
||||
return cells.get(new Vec(x, y, z));
|
||||
}
|
||||
|
||||
public void setTrunk(int x, int y, int z, Role role, Axis axis) {
|
||||
Vec v = new Vec(x, y, z);
|
||||
cells.put(v, new Cell(role, axis, false, -1, null));
|
||||
trunk.add(v);
|
||||
leaf.remove(v);
|
||||
}
|
||||
|
||||
public boolean setLeaf(int x, int y, int z, Role role) {
|
||||
Vec v = new Vec(x, y, z);
|
||||
if (cells.containsKey(v)) {
|
||||
return false;
|
||||
}
|
||||
cells.put(v, new Cell(role, Axis.NONE, false, -1, null));
|
||||
leaf.add(v);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean setDecor(int x, int y, int z, int decoratorIndex, String facing) {
|
||||
Vec v = new Vec(x, y, z);
|
||||
if (cells.containsKey(v)) {
|
||||
return false;
|
||||
}
|
||||
cells.put(v, new Cell(Role.DECORATOR, Axis.NONE, false, decoratorIndex, facing));
|
||||
return true;
|
||||
}
|
||||
|
||||
public void markExposed(int x, int y, int z) {
|
||||
Vec v = new Vec(x, y, z);
|
||||
Cell c = cells.get(v);
|
||||
if (c != null && !c.exposed()) {
|
||||
cells.put(v, new Cell(c.role(), c.axis(), true, c.decoratorIndex(), c.facing()));
|
||||
}
|
||||
}
|
||||
|
||||
public Map<Vec, Cell> getCells() {
|
||||
return cells;
|
||||
}
|
||||
|
||||
public Set<Vec> getTrunk() {
|
||||
return trunk;
|
||||
}
|
||||
|
||||
public Set<Vec> getLeaf() {
|
||||
return leaf;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return cells.isEmpty();
|
||||
}
|
||||
}
|
||||
@@ -1,165 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.tree;
|
||||
|
||||
import art.arcane.iris.modules.objects.tree.TreeSecondaryLeaf;
|
||||
import art.arcane.iris.modules.objects.tree.TreeDecorator;
|
||||
import art.arcane.iris.modules.objects.ObjectBuilder;
|
||||
import com.volmit.block.PaletteSpec;
|
||||
import art.arcane.iris.engine.object.procedural.IrisProceduralBlocks;
|
||||
import art.arcane.iris.modules.objects.tree.Tree;
|
||||
import com.volmit.block.BlockState;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
public final class TreeBlockResolver {
|
||||
private TreeBlockResolver() {
|
||||
}
|
||||
|
||||
public static BlockState resolve(Tree tree, ObjectBuilder blocks, TreeBlockCanvas.Cell cell, TreeBlockCanvas.Vec pos) {
|
||||
RNG paletteRng = new RNG(tree.seed());
|
||||
RNG posRng = new RNG(tree.seed() ^ positionHash(pos));
|
||||
|
||||
switch (cell.role()) {
|
||||
case TRUNK -> {
|
||||
BlockState state = resolveBlock(tree.trunk(), tree.trunkPalette().orElse(null), blocks, pos, paletteRng);
|
||||
return finishTrunk(state, cell, blocks);
|
||||
}
|
||||
case SECONDARY_TRUNK -> {
|
||||
BlockState state = resolveBlock(tree.secondaryTrunk().orElse(null), tree.secondaryTrunkPalette().orElse(null), blocks, pos, paletteRng);
|
||||
if (state == null) {
|
||||
state = resolveBlock(tree.trunk(), tree.trunkPalette().orElse(null), blocks, pos, paletteRng);
|
||||
}
|
||||
return finishTrunk(state, cell, blocks);
|
||||
}
|
||||
case LEAF -> {
|
||||
return resolveBlock(tree.leaves(), tree.leavesPalette().orElse(null), blocks, pos, paletteRng);
|
||||
}
|
||||
case SECONDARY_LEAF -> {
|
||||
BlockState state = resolveSecondaryLeaf(tree, blocks, pos, paletteRng, posRng);
|
||||
if (state == null) {
|
||||
state = resolveBlock(tree.leaves(), tree.leavesPalette().orElse(null), blocks, pos, paletteRng);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
case DECORATOR -> {
|
||||
int index = cell.decoratorIndex();
|
||||
if (index < 0 || tree.decorators() == null || index >= tree.decorators().size()) {
|
||||
return null;
|
||||
}
|
||||
TreeDecorator dec = tree.decorators().get(index);
|
||||
BlockState state = resolveBlock(dec.block(), dec.palette().orElse(null), blocks, pos, paletteRng);
|
||||
if (state != null && cell.facing() != null && IrisProceduralBlocks.hasProperty(state, "facing")) {
|
||||
try {
|
||||
state = blocks.withProperty(state, "facing", cell.facing().toLowerCase());
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
}
|
||||
return state;
|
||||
}
|
||||
default -> {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static BlockState finishTrunk(BlockState state, TreeBlockCanvas.Cell cell, ObjectBuilder blocks) {
|
||||
if (state == null) {
|
||||
return null;
|
||||
}
|
||||
if (cell.axis() != TreeBlockCanvas.Axis.NONE && IrisProceduralBlocks.hasProperty(state, "axis")) {
|
||||
try {
|
||||
state = blocks.withProperty(state, "axis", cell.axis().name().toLowerCase());
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
}
|
||||
if (cell.exposed()) {
|
||||
return woodCap(state, blocks);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
private static BlockState resolveSecondaryLeaf(Tree tree, ObjectBuilder blocks, TreeBlockCanvas.Vec pos, RNG paletteRng, RNG posRng) {
|
||||
PaletteSpec secondaryPalette = tree.secondaryLeavesPalette().orElse(null);
|
||||
if (IrisProceduralBlocks.paletteSet(secondaryPalette)) {
|
||||
return blocks.pick(secondaryPalette, paletteRng.getSeed(), pos.x(), pos.y(), pos.z());
|
||||
}
|
||||
if (tree.weightedSecondaryLeaves() != null && !tree.weightedSecondaryLeaves().isEmpty()) {
|
||||
String picked = pickWeighted(tree, posRng);
|
||||
return picked == null ? null : blocks.block(picked);
|
||||
}
|
||||
if (tree.secondaryLeaves().isPresent() && !tree.secondaryLeaves().get().isEmpty()) {
|
||||
return blocks.block(tree.secondaryLeaves().get());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String pickWeighted(Tree tree, RNG rng) {
|
||||
int total = 0;
|
||||
for (art.arcane.iris.modules.objects.tree.TreeSecondaryLeaf s : tree.weightedSecondaryLeaves()) {
|
||||
total += Math.max(0, s.weight());
|
||||
}
|
||||
if (total <= 0) {
|
||||
return null;
|
||||
}
|
||||
double r = rng.nextDouble() * total;
|
||||
double cumulative = 0;
|
||||
for (art.arcane.iris.modules.objects.tree.TreeSecondaryLeaf s : tree.weightedSecondaryLeaves()) {
|
||||
cumulative += Math.max(0, s.weight());
|
||||
if (r < cumulative) {
|
||||
return s.block();
|
||||
}
|
||||
}
|
||||
return tree.weightedSecondaryLeaves().get(tree.weightedSecondaryLeaves().size() - 1).block();
|
||||
}
|
||||
|
||||
private static BlockState resolveBlock(String block, PaletteSpec palette, ObjectBuilder blocks, TreeBlockCanvas.Vec pos, RNG paletteRng) {
|
||||
return IrisProceduralBlocks.resolve(block, palette, blocks, pos.x(), pos.y(), pos.z(), paletteRng);
|
||||
}
|
||||
|
||||
private static BlockState woodCap(BlockState state, ObjectBuilder blocks) {
|
||||
String key = state.key();
|
||||
int bracket = key.indexOf('[');
|
||||
String base = bracket < 0 ? key : key.substring(0, bracket);
|
||||
String woodKey = null;
|
||||
if (base.endsWith("_log")) {
|
||||
woodKey = base.substring(0, base.length() - 4) + "_wood";
|
||||
} else if (base.endsWith("_stem")) {
|
||||
woodKey = base.substring(0, base.length() - 5) + "_hyphae";
|
||||
}
|
||||
if (woodKey == null) {
|
||||
return state;
|
||||
}
|
||||
BlockState wood = blocks.block(woodKey);
|
||||
if (wood == null) {
|
||||
return state;
|
||||
}
|
||||
String axis = IrisProceduralBlocks.propertyValue(state, "axis");
|
||||
if (axis != null && IrisProceduralBlocks.hasProperty(wood, "axis")) {
|
||||
try {
|
||||
wood = blocks.withProperty(wood, "axis", axis);
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
}
|
||||
return wood;
|
||||
}
|
||||
|
||||
private static long positionHash(TreeBlockCanvas.Vec pos) {
|
||||
return pos.x() * 73856093L ^ pos.y() * 19349663L ^ pos.z() * 83492791L;
|
||||
}
|
||||
}
|
||||
@@ -1,352 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.tree;
|
||||
|
||||
import art.arcane.iris.modules.objects.tree.TreeSubBranches;
|
||||
import art.arcane.iris.modules.objects.tree.TreeLayer;
|
||||
import art.arcane.iris.modules.objects.tree.TreeCanopy;
|
||||
import art.arcane.iris.modules.objects.tree.TreeBranches;
|
||||
import art.arcane.iris.modules.objects.tree.TreeProfile;
|
||||
import art.arcane.iris.modules.objects.tree.TreeLeafMode;
|
||||
import art.arcane.iris.modules.objects.tree.Tree;
|
||||
import art.arcane.iris.engine.object.procedural.IrisProceduralBlocks;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public final class TreeCanopyBuilder {
|
||||
private TreeCanopyBuilder() {
|
||||
}
|
||||
|
||||
public static void build(TreeBlockCanvas canvas, Tree tree, int height, double[][] offsets,
|
||||
int branchStartY, long baseSeed, List<int[]> branchEndpoints) {
|
||||
TreeCanopy canopy = tree.canopy();
|
||||
if (canopy == null) {
|
||||
canopy = new TreeCanopy();
|
||||
}
|
||||
TreeBranches branches = canopy.branches().orElse(null);
|
||||
|
||||
double[][] layers = resolveLayers(canopy, tree.profile(), height, branches != null);
|
||||
|
||||
if (branches != null) {
|
||||
if (layers.length > 0) {
|
||||
double[][] crown = new double[][]{layers[layers.length - 1]};
|
||||
volumeCanopy(canvas, tree, crown, canopy, baseSeed, offsets);
|
||||
}
|
||||
placeApexCap(canvas, tree, height, layers, offsets, baseSeed);
|
||||
branchCanopy(canvas, tree, height, branches, branchStartY, baseSeed, offsets, branchEndpoints);
|
||||
} else {
|
||||
volumeCanopy(canvas, tree, layers, canopy, baseSeed, offsets);
|
||||
}
|
||||
}
|
||||
|
||||
private static void placeApexCap(TreeBlockCanvas canvas, Tree tree, int height, double[][] layers,
|
||||
double[][] offsets, long baseSeed) {
|
||||
int ocx = 0;
|
||||
int ocz = 0;
|
||||
if (offsets != null && offsets.length > 0) {
|
||||
ocx = (int) Math.round(offsets[offsets.length - 1][0]);
|
||||
ocz = (int) Math.round(offsets[offsets.length - 1][1]);
|
||||
}
|
||||
double maxR = 2;
|
||||
for (double[] layer : layers) {
|
||||
maxR = Math.max(maxR, layer[1]);
|
||||
}
|
||||
int capRadius = Math.max(2, Math.min(3, (int) Math.round(maxR * 0.35)));
|
||||
TreeCanopy canopy = tree.canopy();
|
||||
TreeLeafMode mode = canopy != null ? canopy.mode() : TreeLeafMode.TRIMMED;
|
||||
double density = canopy != null ? canopy.leafDensity() : 1.0;
|
||||
placeLeafCluster(canvas, tree, ocx, height - 1, ocz, capRadius, mode, density, baseSeed + 5555L);
|
||||
}
|
||||
|
||||
private static double[][] resolveLayers(TreeCanopy canopy, TreeProfile profile, int height, boolean branchDriven) {
|
||||
KList<TreeLayer> explicit = new KList<>(canopy.layers());
|
||||
if (explicit != null && !explicit.isEmpty()) {
|
||||
double[][] out = new double[explicit.size()][2];
|
||||
for (int i = 0; i < explicit.size(); i++) {
|
||||
out[i][0] = explicit.get(i).yOffset();
|
||||
out[i][1] = explicit.get(i).radius();
|
||||
}
|
||||
return out;
|
||||
}
|
||||
return TreeProfiles.presetLayers(profile, height, branchDriven);
|
||||
}
|
||||
|
||||
private static void volumeCanopy(TreeBlockCanvas canvas, Tree tree, double[][] layers,
|
||||
TreeCanopy canopy, long baseSeed, double[][] offsets) {
|
||||
int ocx = 0;
|
||||
int ocz = 0;
|
||||
if (offsets != null && offsets.length > 0) {
|
||||
ocx = (int) Math.round(offsets[offsets.length - 1][0]);
|
||||
ocz = (int) Math.round(offsets[offsets.length - 1][1]);
|
||||
}
|
||||
|
||||
double startAngle = canopy.startAngle();
|
||||
double squish = canopy.squish();
|
||||
TreeLeafMode mode = canopy.mode();
|
||||
double leafDensity = canopy.leafDensity();
|
||||
|
||||
for (double[] layer : layers) {
|
||||
int yCenter = (int) Math.round(layer[0]);
|
||||
double radius = layer[1];
|
||||
int halfH = layerHalfHeight(radius, startAngle, squish);
|
||||
int downH = startAngle < 90.0
|
||||
? (int) Math.ceil(radius * Math.cos(Math.toRadians(startAngle)) * squish)
|
||||
: 0;
|
||||
int skirt = downH;
|
||||
|
||||
for (int y = yCenter - skirt; y <= yCenter + halfH; y++) {
|
||||
int dy = y - yCenter;
|
||||
double layerR;
|
||||
if (halfH > 0 && dy >= 0) {
|
||||
layerR = radius * Math.sqrt(Math.max(0.0, 1.0 - Math.pow(dy / (double) halfH, 2)));
|
||||
} else if (skirt > 0 && dy < 0) {
|
||||
layerR = radius * Math.sqrt(Math.max(0.0, 1.0 - Math.pow(dy / (double) skirt, 2)));
|
||||
} else {
|
||||
layerR = radius;
|
||||
}
|
||||
if (layerR < 0.5) {
|
||||
continue;
|
||||
}
|
||||
placeLeafDisc(canvas, tree, ocx, y, ocz, layerR, mode, leafDensity, baseSeed + y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static int layerHalfHeight(double radius, double startAngle, double squish) {
|
||||
if (startAngle >= 180.0) {
|
||||
return 0;
|
||||
}
|
||||
return (int) Math.ceil(radius * squish);
|
||||
}
|
||||
|
||||
private static void placeLeafDisc(TreeBlockCanvas canvas, Tree tree, int cx, int cy, int cz,
|
||||
double radius, TreeLeafMode mode, double density, long seed) {
|
||||
double sx = stretchX(tree);
|
||||
double sz = stretchZ(tree);
|
||||
RNG rng = new RNG(seed);
|
||||
int irx = (int) Math.ceil(radius * sx);
|
||||
int irz = (int) Math.ceil(radius * sz);
|
||||
for (int dx = -irx; dx <= irx; dx++) {
|
||||
for (int dz = -irz; dz <= irz; dz++) {
|
||||
double ddx = dx / sx;
|
||||
double ddz = dz / sz;
|
||||
double dist = Math.sqrt(ddx * ddx + ddz * ddz);
|
||||
boolean corner = Math.abs(dx) == irx && Math.abs(dz) == irz;
|
||||
if (!passesLeafTest(mode, dist, radius, density, rng, cx + dx, cy, cz + dz, seed, corner)) {
|
||||
continue;
|
||||
}
|
||||
canvas.setLeaf(cx + dx, cy, cz + dz, resolveLeaf(tree, rng));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void placeLeafCluster(TreeBlockCanvas canvas, Tree tree, int cx, int cy, int cz,
|
||||
int radius, TreeLeafMode mode, double density, long seed) {
|
||||
double sx = stretchX(tree);
|
||||
double sz = stretchZ(tree);
|
||||
RNG rng = new RNG(seed);
|
||||
int irx = (int) Math.ceil(radius * sx);
|
||||
int irz = (int) Math.ceil(radius * sz);
|
||||
for (int dx = -irx; dx <= irx; dx++) {
|
||||
for (int dy = -radius; dy <= radius; dy++) {
|
||||
for (int dz = -irz; dz <= irz; dz++) {
|
||||
double ddx = dx / sx;
|
||||
double ddz = dz / sz;
|
||||
double dist = Math.sqrt(ddx * ddx + dy * dy + ddz * ddz);
|
||||
boolean corner = Math.abs(dx) == irx && Math.abs(dz) == irz;
|
||||
if (!passesLeafTest(mode, dist, radius, density, rng, cx + dx, cy + dy, cz + dz, seed, corner)) {
|
||||
continue;
|
||||
}
|
||||
canvas.setLeaf(cx + dx, cy + dy, cz + dz, resolveLeaf(tree, rng));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static double stretchX(Tree tree) {
|
||||
TreeCanopy c = tree.canopy();
|
||||
return c == null ? 1.0 : Math.max(0.1, c.crownStretchX());
|
||||
}
|
||||
|
||||
private static double stretchZ(Tree tree) {
|
||||
TreeCanopy c = tree.canopy();
|
||||
return c == null ? 1.0 : Math.max(0.1, c.crownStretchZ());
|
||||
}
|
||||
|
||||
private static boolean passesLeafTest(TreeLeafMode mode, double dist, double radius, double density,
|
||||
RNG rng, int wx, int wy, int wz, long seed, boolean corner) {
|
||||
switch (mode) {
|
||||
case TRIMMED -> {
|
||||
return !(dist > radius || corner);
|
||||
}
|
||||
case FILLED -> {
|
||||
return dist <= radius;
|
||||
}
|
||||
case DENSITY -> {
|
||||
if (dist > radius) {
|
||||
return false;
|
||||
}
|
||||
return rng.nextDouble() <= density * (1.0 - (dist / (radius + 1.0)));
|
||||
}
|
||||
case NOISE -> {
|
||||
if (dist > radius) {
|
||||
return false;
|
||||
}
|
||||
return TreeFunctions.valueNoise3D(wx, wy, wz, seed) <= density;
|
||||
}
|
||||
case HOLLOW -> {
|
||||
return dist <= radius && dist > radius - 1.0;
|
||||
}
|
||||
case GRADIENT -> {
|
||||
if (dist > radius) {
|
||||
return false;
|
||||
}
|
||||
return rng.nextDouble() <= density * Math.pow(1.0 - (dist / (radius + 1.0)), 2);
|
||||
}
|
||||
case CLUMPED -> {
|
||||
if (dist > radius) {
|
||||
return false;
|
||||
}
|
||||
return TreeFunctions.valueNoise3D(Math.floorDiv(wx, 2), Math.floorDiv(wy, 2), Math.floorDiv(wz, 2), seed) <= density;
|
||||
}
|
||||
case TATTERED -> {
|
||||
if (dist > radius || corner) {
|
||||
return false;
|
||||
}
|
||||
return !(dist > radius - 1.5 && rng.nextDouble() < 0.6);
|
||||
}
|
||||
case SPARSE -> {
|
||||
if (dist > radius) {
|
||||
return false;
|
||||
}
|
||||
return rng.nextDouble() <= density * 0.4;
|
||||
}
|
||||
default -> {
|
||||
return dist <= radius;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static TreeBlockCanvas.Role resolveLeaf(Tree tree, RNG rng) {
|
||||
boolean hasSecondary = IrisProceduralBlocks.paletteSet(tree.secondaryLeavesPalette())
|
||||
|| (tree.weightedSecondaryLeaves() != null && !tree.weightedSecondaryLeaves().isEmpty())
|
||||
|| tree.secondaryLeaves().filter(leaves -> !leaves.isEmpty()).isPresent();
|
||||
if (!hasSecondary || tree.secondaryLeafFraction() <= 0.0) {
|
||||
return TreeBlockCanvas.Role.LEAF;
|
||||
}
|
||||
if (rng.nextDouble() >= tree.secondaryLeafFraction()) {
|
||||
return TreeBlockCanvas.Role.LEAF;
|
||||
}
|
||||
return TreeBlockCanvas.Role.SECONDARY_LEAF;
|
||||
}
|
||||
|
||||
private static void branchCanopy(TreeBlockCanvas canvas, Tree tree, int height,
|
||||
TreeBranches branches, int branchStartY, long baseSeed, double[][] offsets,
|
||||
List<int[]> branchEndpoints) {
|
||||
long branchSeed = baseSeed + 9999;
|
||||
RNG branchRng = new RNG(branchSeed);
|
||||
TreeSubBranches sub = branches.subBranches().orElse(null);
|
||||
int depth = branches.branchDepth();
|
||||
int branchIndex = 0;
|
||||
|
||||
for (int y = Math.max(0, branchStartY); y < height; y++) {
|
||||
double t = y / (double) Math.max(height - 1, 1);
|
||||
double p = TreeFunctions.branchProbability(branches, t, branchSeed);
|
||||
if (branchRng.nextDouble() > p) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int ox = 0;
|
||||
int oz = 0;
|
||||
if (offsets != null && y < offsets.length) {
|
||||
ox = (int) Math.round(offsets[y][0]);
|
||||
oz = (int) Math.round(offsets[y][1]);
|
||||
}
|
||||
|
||||
double az = TreeFunctions.azimuthDegrees(branches.azimuthMode(), t, branchIndex, tree, branches.azimuth(), branchRng);
|
||||
branchIndex++;
|
||||
double branchLen = TreeFunctions.branchLength(branches, t);
|
||||
double effElevation = branches.leafStartUp() ? Math.max(0.0, branches.elevation()) : branches.elevation();
|
||||
int[] end = branchEndpoint(ox, y, oz, az, effElevation, branchLen);
|
||||
int[] tip = rasterizeBranch(canvas, ox, y, oz, end[0], end[1], end[2], branches.sag());
|
||||
|
||||
if (branchEndpoints != null) {
|
||||
branchEndpoints.add(new int[]{tip[0], tip[1], tip[2], ox, oz});
|
||||
}
|
||||
placeLeafCluster(canvas, tree, tip[0], tip[1], tip[2], branches.clusterRadius(),
|
||||
branches.clusterMode(), branches.clusterDensity(), branchSeed + y);
|
||||
|
||||
growSubBranches(canvas, tree, tip[0], tip[1], tip[2], az, effElevation, branchLen, sub, depth, branchSeed + y + 1000L);
|
||||
}
|
||||
}
|
||||
|
||||
private static void growSubBranches(TreeBlockCanvas canvas, Tree tree, int ox, int oy, int oz,
|
||||
double az, double el, double len, TreeSubBranches sub, int depth, long seed) {
|
||||
if (sub == null || depth <= 0) {
|
||||
return;
|
||||
}
|
||||
int count = Math.max(1, sub.count());
|
||||
for (int si = 0; si < count; si++) {
|
||||
double yawOffset = sub.yawDelta() * (si - (count - 1) / 2.0);
|
||||
double subAz = az + yawOffset;
|
||||
double subEl = el + sub.pitchDelta();
|
||||
double subLen = len * sub.lengthScale();
|
||||
int[] end = branchEndpoint(ox, oy, oz, subAz, subEl, subLen);
|
||||
int[] tip = rasterizeBranch(canvas, ox, oy, oz, end[0], end[1], end[2], sub.sag());
|
||||
placeLeafCluster(canvas, tree, tip[0], tip[1], tip[2], sub.clusterRadius(),
|
||||
sub.clusterMode(), sub.clusterDensity(), seed + si * 131L);
|
||||
growSubBranches(canvas, tree, tip[0], tip[1], tip[2], subAz, subEl, subLen, sub, depth - 1, seed + si * 131L + 17L);
|
||||
}
|
||||
}
|
||||
|
||||
private static int[] branchEndpoint(int ox, int oy, int oz, double azimuthDeg, double elevationDeg, double length) {
|
||||
double azRad = Math.toRadians(azimuthDeg);
|
||||
double elRad = Math.toRadians(elevationDeg);
|
||||
double dx = length * Math.cos(elRad) * Math.sin(azRad);
|
||||
double dy = length * Math.sin(elRad);
|
||||
double dz = length * Math.cos(elRad) * Math.cos(azRad);
|
||||
return new int[]{ox + (int) Math.round(dx), oy + (int) Math.round(dy), oz + (int) Math.round(dz)};
|
||||
}
|
||||
|
||||
private static int[] rasterizeBranch(TreeBlockCanvas canvas, int ox, int oy, int oz, int ex, int ey, int ez, double sag) {
|
||||
int dx = ex - ox;
|
||||
int dy = ey - oy;
|
||||
int dz = ez - oz;
|
||||
double horizontal = Math.sqrt(dx * dx + dz * dz);
|
||||
double sagBlocks = sag * horizontal;
|
||||
int steps = Math.max(Math.max(Math.abs(dx), Math.abs(dz)),
|
||||
Math.max((int) (Math.abs(dy) + Math.ceil(sagBlocks)), 1));
|
||||
TreeBlockCanvas.Axis axis = TreeFunctions.logAxis(dx, dy, dz);
|
||||
|
||||
int[] tip = new int[]{ox, oy, oz};
|
||||
for (int i = 0; i <= steps; i++) {
|
||||
double t = i / (double) steps;
|
||||
int x = (int) Math.round(ox + dx * t);
|
||||
int y = (int) Math.round(oy + dy * t - sagBlocks * t * t);
|
||||
int z = (int) Math.round(oz + dz * t);
|
||||
if (!canvas.has(x, y, z)) {
|
||||
canvas.setTrunk(x, y, z, TreeBlockCanvas.Role.TRUNK, axis);
|
||||
}
|
||||
tip = new int[]{x, y, z};
|
||||
}
|
||||
return tip;
|
||||
}
|
||||
}
|
||||
-280
@@ -1,280 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.tree;
|
||||
|
||||
import art.arcane.iris.modules.objects.tree.TreeDecorator;
|
||||
import art.arcane.iris.modules.objects.tree.Tree;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.collection.KMap;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public final class TreeDecoratorApplier {
|
||||
private TreeDecoratorApplier() {
|
||||
}
|
||||
|
||||
public static void apply(TreeBlockCanvas canvas, Tree tree, long baseSeed, List<int[]> branchEndpoints) {
|
||||
List<TreeDecorator> decorators = tree.decorators();
|
||||
if (decorators == null || decorators.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
RNG rng = new RNG(baseSeed + 77777L);
|
||||
|
||||
for (int idx = 0; idx < decorators.size(); idx++) {
|
||||
TreeDecorator dec = decorators.get(idx);
|
||||
boolean hasBlock = (dec.block() != null && !dec.block().isEmpty()) || dec.palette().isPresent();
|
||||
if (!hasBlock) {
|
||||
continue;
|
||||
}
|
||||
switch (dec.target()) {
|
||||
case BRANCH_TIP -> branchTip(canvas, dec, idx, branchEndpoints, rng);
|
||||
case TRUNK_SURFACE -> trunkSurface(canvas, dec, idx, rng);
|
||||
case CANOPY_TOP -> canopyTop(canvas, dec, idx, rng);
|
||||
case CANOPY_BOTTOM -> canopyBottom(canvas, dec, idx, rng);
|
||||
case TRUNK_BASE -> trunkBase(canvas, dec, idx, rng);
|
||||
case LEAF_SURFACE -> leafSurface(canvas, dec, idx, rng);
|
||||
case CANOPY_HANG -> canopyHang(canvas, dec, idx, rng);
|
||||
case BRANCH_SURFACE -> branchSurface(canvas, dec, idx, rng);
|
||||
case TRUNK_TOP -> trunkTop(canvas, dec, idx, rng);
|
||||
case GROUND_SCATTER -> groundScatter(canvas, dec, idx, rng);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void branchTip(TreeBlockCanvas canvas, TreeDecorator dec, int idx, List<int[]> branchEndpoints, RNG rng) {
|
||||
if (branchEndpoints == null) {
|
||||
return;
|
||||
}
|
||||
for (int[] e : branchEndpoints) {
|
||||
if (rng.nextDouble() > dec.chance()) {
|
||||
continue;
|
||||
}
|
||||
if (canvas.has(e[0], e[1], e[2])) {
|
||||
continue;
|
||||
}
|
||||
String facing = dec.axisAware() ? facingAway(e[3], e[4], e[0], e[2]) : null;
|
||||
canvas.setDecor(e[0], e[1], e[2], idx, facing);
|
||||
}
|
||||
}
|
||||
|
||||
private static void trunkSurface(TreeBlockCanvas canvas, TreeDecorator dec, int idx, RNG rng) {
|
||||
int[][] sides = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
|
||||
String[] facings = {"west", "east", "north", "south"};
|
||||
for (TreeBlockCanvas.Vec v : new KList<>(canvas.getTrunk())) {
|
||||
for (int i = 0; i < sides.length; i++) {
|
||||
int nx = v.x() + sides[i][0];
|
||||
int nz = v.z() + sides[i][1];
|
||||
if (canvas.has(nx, v.y(), nz) || rng.nextDouble() > dec.chance()) {
|
||||
continue;
|
||||
}
|
||||
canvas.setDecor(nx, v.y(), nz, idx, dec.axisAware() ? facings[i] : null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void leafSurface(TreeBlockCanvas canvas, TreeDecorator dec, int idx, RNG rng) {
|
||||
int[][] sides = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
|
||||
String[] facings = {"west", "east", "north", "south"};
|
||||
for (TreeBlockCanvas.Vec v : new KList<>(canvas.getLeaf())) {
|
||||
for (int i = 0; i < sides.length; i++) {
|
||||
int nx = v.x() + sides[i][0];
|
||||
int nz = v.z() + sides[i][1];
|
||||
if (canvas.has(nx, v.y(), nz) || rng.nextDouble() > dec.chance()) {
|
||||
continue;
|
||||
}
|
||||
canvas.setDecor(nx, v.y(), nz, idx, dec.axisAware() ? facings[i] : null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void branchSurface(TreeBlockCanvas canvas, TreeDecorator dec, int idx, RNG rng) {
|
||||
for (TreeBlockCanvas.Vec v : new KList<>(canvas.getTrunk())) {
|
||||
int ay = v.y() + 1;
|
||||
if (canvas.has(v.x(), ay, v.z()) || rng.nextDouble() > dec.chance()) {
|
||||
continue;
|
||||
}
|
||||
canvas.setDecor(v.x(), ay, v.z(), idx, null);
|
||||
}
|
||||
}
|
||||
|
||||
private static void canopyTop(TreeBlockCanvas canvas, TreeDecorator dec, int idx, RNG rng) {
|
||||
KMap<Long, Integer> colTop = new KMap<>();
|
||||
for (TreeBlockCanvas.Vec v : canvas.getCells().keySet()) {
|
||||
long key = pack(v.x(), v.z());
|
||||
Integer cur = colTop.get(key);
|
||||
if (cur == null || v.y() > cur) {
|
||||
colTop.put(key, v.y());
|
||||
}
|
||||
}
|
||||
for (Map.Entry<Long, Integer> e : colTop.entrySet()) {
|
||||
int x = unpackX(e.getKey());
|
||||
int z = unpackZ(e.getKey());
|
||||
int aboveY = e.getValue() + 1;
|
||||
if (canvas.has(x, aboveY, z) || rng.nextDouble() > dec.chance()) {
|
||||
continue;
|
||||
}
|
||||
canvas.setDecor(x, aboveY, z, idx, null);
|
||||
}
|
||||
}
|
||||
|
||||
private static void canopyBottom(TreeBlockCanvas canvas, TreeDecorator dec, int idx, RNG rng) {
|
||||
KMap<Long, Integer> colBottom = columnLeafBottoms(canvas);
|
||||
for (Map.Entry<Long, Integer> e : colBottom.entrySet()) {
|
||||
int x = unpackX(e.getKey());
|
||||
int z = unpackZ(e.getKey());
|
||||
int belowY = e.getValue() - 1;
|
||||
if (canvas.has(x, belowY, z) || rng.nextDouble() > dec.chance()) {
|
||||
continue;
|
||||
}
|
||||
canvas.setDecor(x, belowY, z, idx, null);
|
||||
}
|
||||
}
|
||||
|
||||
private static void canopyHang(TreeBlockCanvas canvas, TreeDecorator dec, int idx, RNG rng) {
|
||||
int maxLen = Math.max(1, dec.length());
|
||||
KMap<Long, Integer> colBottom = columnLeafBottoms(canvas);
|
||||
for (Map.Entry<Long, Integer> e : colBottom.entrySet()) {
|
||||
if (rng.nextDouble() > dec.chance()) {
|
||||
continue;
|
||||
}
|
||||
int x = unpackX(e.getKey());
|
||||
int z = unpackZ(e.getKey());
|
||||
int strand = rng.i(1, maxLen + 1);
|
||||
for (int k = 1; k <= strand; k++) {
|
||||
int yy = e.getValue() - k;
|
||||
if (canvas.has(x, yy, z)) {
|
||||
break;
|
||||
}
|
||||
canvas.setDecor(x, yy, z, idx, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void trunkBase(TreeBlockCanvas canvas, TreeDecorator dec, int idx, RNG rng) {
|
||||
int[][] sides = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
|
||||
for (TreeBlockCanvas.Vec v : new KList<>(canvas.getTrunk())) {
|
||||
if (v.y() != 0) {
|
||||
continue;
|
||||
}
|
||||
for (int[] side : sides) {
|
||||
int nx = v.x() + side[0];
|
||||
int nz = v.z() + side[1];
|
||||
if (canvas.has(nx, 0, nz) || rng.nextDouble() > dec.chance()) {
|
||||
continue;
|
||||
}
|
||||
canvas.setDecor(nx, 0, nz, idx, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void trunkTop(TreeBlockCanvas canvas, TreeDecorator dec, int idx, RNG rng) {
|
||||
int maxY = Integer.MIN_VALUE;
|
||||
for (TreeBlockCanvas.Vec v : canvas.getTrunk()) {
|
||||
maxY = Math.max(maxY, v.y());
|
||||
}
|
||||
if (maxY == Integer.MIN_VALUE) {
|
||||
return;
|
||||
}
|
||||
for (TreeBlockCanvas.Vec v : new KList<>(canvas.getTrunk())) {
|
||||
if (v.y() != maxY) {
|
||||
continue;
|
||||
}
|
||||
int aboveY = v.y() + 1;
|
||||
if (canvas.has(v.x(), aboveY, v.z()) || rng.nextDouble() > dec.chance()) {
|
||||
continue;
|
||||
}
|
||||
canvas.setDecor(v.x(), aboveY, v.z(), idx, null);
|
||||
}
|
||||
}
|
||||
|
||||
private static void groundScatter(TreeBlockCanvas canvas, TreeDecorator dec, int idx, RNG rng) {
|
||||
double cx = 0;
|
||||
double cz = 0;
|
||||
int count = 0;
|
||||
double footprint = 1.0;
|
||||
for (TreeBlockCanvas.Vec v : canvas.getTrunk()) {
|
||||
if (v.y() == 0) {
|
||||
cx += v.x();
|
||||
cz += v.z();
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (count == 0) {
|
||||
return;
|
||||
}
|
||||
cx /= count;
|
||||
cz /= count;
|
||||
for (TreeBlockCanvas.Vec v : canvas.getTrunk()) {
|
||||
if (v.y() == 0) {
|
||||
footprint = Math.max(footprint, Math.hypot(v.x() - cx, v.z() - cz));
|
||||
}
|
||||
}
|
||||
int radius = (int) Math.ceil(footprint + 3.0);
|
||||
int icx = (int) Math.round(cx);
|
||||
int icz = (int) Math.round(cz);
|
||||
for (int dx = -radius; dx <= radius; dx++) {
|
||||
for (int dz = -radius; dz <= radius; dz++) {
|
||||
if (Math.hypot(dx, dz) > radius) {
|
||||
continue;
|
||||
}
|
||||
int x = icx + dx;
|
||||
int z = icz + dz;
|
||||
if (canvas.has(x, 0, z) || rng.nextDouble() > dec.chance()) {
|
||||
continue;
|
||||
}
|
||||
canvas.setDecor(x, 0, z, idx, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static KMap<Long, Integer> columnLeafBottoms(TreeBlockCanvas canvas) {
|
||||
KMap<Long, Integer> colBottom = new KMap<>();
|
||||
for (TreeBlockCanvas.Vec v : canvas.getLeaf()) {
|
||||
long key = pack(v.x(), v.z());
|
||||
Integer cur = colBottom.get(key);
|
||||
if (cur == null || v.y() < cur) {
|
||||
colBottom.put(key, v.y());
|
||||
}
|
||||
}
|
||||
return colBottom;
|
||||
}
|
||||
|
||||
private static String facingAway(int cx, int cz, int x, int z) {
|
||||
int dx = x - cx;
|
||||
int dz = z - cz;
|
||||
if (Math.abs(dx) >= Math.abs(dz)) {
|
||||
return dx >= 0 ? "east" : "west";
|
||||
}
|
||||
return dz >= 0 ? "south" : "north";
|
||||
}
|
||||
|
||||
private static long pack(int x, int z) {
|
||||
return (((long) x) << 32) ^ (z & 0xFFFFFFFFL);
|
||||
}
|
||||
|
||||
private static int unpackX(long key) {
|
||||
return (int) (key >> 32);
|
||||
}
|
||||
|
||||
private static int unpackZ(long key) {
|
||||
return (int) (key & 0xFFFFFFFFL);
|
||||
}
|
||||
}
|
||||
@@ -1,197 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.tree;
|
||||
|
||||
import art.arcane.iris.modules.objects.tree.TreeBranches;
|
||||
import art.arcane.iris.modules.objects.tree.TreeFunction;
|
||||
import art.arcane.iris.modules.objects.tree.TreeAzimuthMode;
|
||||
import art.arcane.iris.modules.objects.tree.Tree;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
public final class TreeFunctions {
|
||||
private static final double GOLDEN_ANGLE = 137.50776405003785;
|
||||
|
||||
private TreeFunctions() {
|
||||
}
|
||||
|
||||
public static double trunkWidthMultiplier(Tree tree, double t) {
|
||||
double start = tree.shapeStart();
|
||||
double end = tree.shapeEnd();
|
||||
return switch (tree.trunkShape()) {
|
||||
case CONSTANT -> 1.0;
|
||||
case LINEAR -> start + (end - start) * t;
|
||||
case SIGMOID -> 1.0 / (1.0 + Math.exp(tree.shapeSteepness() * (t - 0.5)));
|
||||
case LOG -> {
|
||||
double base = Math.max(1.0001, tree.shapeBase());
|
||||
if (t <= 0.0) {
|
||||
yield 1.0;
|
||||
}
|
||||
yield Math.max(0.0, 1.0 - Math.log(1.0 + t * (base - 1.0)) / Math.log(base));
|
||||
}
|
||||
case SINE -> {
|
||||
double period = tree.shapePeriod() == 0 ? 1.0 : tree.shapePeriod();
|
||||
yield 1.0 + tree.shapeAmplitude() * Math.sin(2.0 * Math.PI * t / period);
|
||||
}
|
||||
case PARABOLIC -> {
|
||||
double peak = tree.shapePeakOffset();
|
||||
double floor = tree.shapeFloor();
|
||||
double denom = Math.pow(Math.max(peak, 1.0 - peak), 2);
|
||||
if (denom == 0) {
|
||||
denom = 1;
|
||||
}
|
||||
yield floor + (1.0 - floor) * (Math.pow(t - peak, 2) / denom);
|
||||
}
|
||||
case EXPONENTIAL -> geometric(start, end, t);
|
||||
case SQRT -> start + (end - start) * Math.sqrt(t);
|
||||
case STEP -> t < tree.shapePeakOffset() ? start : end;
|
||||
case BELL -> start + (end - start) * bell(t);
|
||||
case EASE_IN_OUT -> start + (end - start) * smoothstep(t);
|
||||
};
|
||||
}
|
||||
|
||||
public static double curveProgress(TreeFunction fn, double t, double steepness) {
|
||||
return switch (fn) {
|
||||
case LINEAR, CONSTANT, SINE -> t;
|
||||
case LOG -> Math.log(1.0 + t * (Math.E - 1.0));
|
||||
case SIGMOID -> 1.0 / (1.0 + Math.exp(-steepness * (t - 0.5)));
|
||||
case PARABOLIC, EASE_IN_OUT -> smoothstep(t);
|
||||
case EXPONENTIAL -> Math.pow(t, Math.max(1.0, steepness));
|
||||
case SQRT -> Math.sqrt(t);
|
||||
case STEP -> t < 0.5 ? 0.0 : 1.0;
|
||||
case BELL -> bell(t);
|
||||
};
|
||||
}
|
||||
|
||||
public static double branchLength(TreeBranches b, double t) {
|
||||
double base = b.lengthBase();
|
||||
double crown = b.lengthCrown();
|
||||
double max = b.lengthMax();
|
||||
double v = switch (b.lengthFunction()) {
|
||||
case CONSTANT -> b.lengthConstant();
|
||||
case LINEAR, SINE -> base + (crown - base) * t;
|
||||
case SIGMOID -> max / (1.0 + Math.exp(-b.lengthSteepness() * (t - 0.5)));
|
||||
case LOG -> max * Math.log(1.0 + t * (Math.E - 1.0));
|
||||
case PARABOLIC -> max * (1.0 - Math.pow(2.0 * t - 1.0, 2));
|
||||
case EXPONENTIAL -> geometric(base, crown, t);
|
||||
case SQRT -> base + (crown - base) * Math.sqrt(t);
|
||||
case STEP -> t < 0.5 ? base : crown;
|
||||
case BELL -> base + (max - base) * bell(t);
|
||||
case EASE_IN_OUT -> base + (crown - base) * smoothstep(t);
|
||||
};
|
||||
return Math.max(1.0, v);
|
||||
}
|
||||
|
||||
public static double branchProbability(TreeBranches b, double t, long seed) {
|
||||
double std = Math.max(b.probabilityStd(), 1e-6);
|
||||
return switch (b.probabilityFunction()) {
|
||||
case CONSTANT -> b.probabilityConstant();
|
||||
case LINEAR -> b.probabilityBase() + (b.probabilityCrown() - b.probabilityBase()) * t;
|
||||
case SIGMOID -> 1.0 / (1.0 + Math.exp(-b.probabilitySteepness() * (t - b.probabilityMidpoint())));
|
||||
case TOP_HEAVY -> Math.pow(t, b.probabilityExponent());
|
||||
case GAUSSIAN -> Math.exp(-0.5 * Math.pow((t - b.probabilityMean()) / std, 2));
|
||||
case NOISE -> valueNoise1D(t * b.probabilityScale(), seed);
|
||||
case BOTTOM_HEAVY -> Math.pow(1.0 - t, b.probabilityExponent());
|
||||
case PERIODIC -> b.probabilityConstant() * Math.pow(Math.max(0.0, Math.sin(2.0 * Math.PI * t * b.probabilityPeriods())), 8);
|
||||
case BAND -> Math.abs(t - b.probabilityMean()) <= b.probabilityStd() ? b.probabilityConstant() : 0.0;
|
||||
case INVERSE_GAUSSIAN -> b.probabilityConstant() * (1.0 - Math.exp(-0.5 * Math.pow((t - b.probabilityMean()) / std, 2)));
|
||||
case EXPONENTIAL_DECAY -> b.probabilityConstant() * Math.exp(-b.probabilityExponent() * t);
|
||||
};
|
||||
}
|
||||
|
||||
public static double azimuthDegrees(TreeAzimuthMode mode, double t, int index, Tree tree, double constantBase, RNG rng) {
|
||||
return switch (mode) {
|
||||
case CONSTANT -> constantBase;
|
||||
case LINEAR -> tree.azimuthStart() + (tree.azimuthEnd() - tree.azimuthStart()) * t;
|
||||
case SPIRAL -> tree.azimuthStart() + tree.azimuthTurns() * 360.0 * t;
|
||||
case SINE -> {
|
||||
double period = tree.azimuthPeriod() == 0 ? 1.0 : tree.azimuthPeriod();
|
||||
yield tree.azimuthOffset() + tree.azimuthAmplitude() * Math.sin(2.0 * Math.PI * t / period);
|
||||
}
|
||||
case NOISE -> noiseAzimuth(t, tree.azimuthScale(), tree.seed());
|
||||
case RANDOM -> rng != null ? rng.d(0.0, 360.0) : constantBase;
|
||||
case GOLDEN_ANGLE -> index >= 0 ? constantBase + index * GOLDEN_ANGLE : constantBase;
|
||||
case ALTERNATING -> index >= 0 ? constantBase + (index % 2) * 180.0 : constantBase;
|
||||
case WHORL -> {
|
||||
int count = Math.max(1, tree.azimuthWhorlCount());
|
||||
yield index >= 0 ? constantBase + (index % count) * (360.0 / count) : constantBase;
|
||||
}
|
||||
case ZIGZAG -> index >= 0 ? constantBase + ((index % 2 == 0) ? -tree.azimuthAmplitude() : tree.azimuthAmplitude()) : constantBase;
|
||||
};
|
||||
}
|
||||
|
||||
public static TreeBlockCanvas.Axis logAxis(double dx, double dy, double dz) {
|
||||
double ax = Math.abs(dx);
|
||||
double ay = Math.abs(dy) * 1.8;
|
||||
double az = Math.abs(dz);
|
||||
if (ay >= ax && ay >= az) {
|
||||
return TreeBlockCanvas.Axis.Y;
|
||||
}
|
||||
if (ax >= az) {
|
||||
return TreeBlockCanvas.Axis.X;
|
||||
}
|
||||
return TreeBlockCanvas.Axis.Z;
|
||||
}
|
||||
|
||||
private static double geometric(double a, double b, double t) {
|
||||
if (a <= 0.0 || b <= 0.0) {
|
||||
return a + (b - a) * t;
|
||||
}
|
||||
return a * Math.pow(b / a, t);
|
||||
}
|
||||
|
||||
private static double bell(double t) {
|
||||
return Math.exp(-Math.pow(t - 0.5, 2) / (2.0 * 0.15 * 0.15));
|
||||
}
|
||||
|
||||
private static double smoothstep(double t) {
|
||||
return 3.0 * t * t - 2.0 * t * t * t;
|
||||
}
|
||||
|
||||
public static double noiseAzimuth(double t, double scale, long seed) {
|
||||
double a = valueNoise1D(t * scale, seed);
|
||||
double b = valueNoise1D(t * scale * 0.5, seed + 1);
|
||||
return ((a + b) / 2.0) * 360.0;
|
||||
}
|
||||
|
||||
public static double valueNoise1D(double x, long seed) {
|
||||
long h = mix(seed * 0x9E3779B97F4A7C15L + Math.round(x * 1000.0));
|
||||
return unit(h);
|
||||
}
|
||||
|
||||
public static double valueNoise3D(int x, int y, int z, long seed) {
|
||||
long h = mix(seed);
|
||||
h = mix(h + x * 0x9E3779B97F4A7C15L);
|
||||
h = mix(h + y * 0xC2B2AE3D27D4EB4FL);
|
||||
h = mix(h + z * 0x165667B19E3779F9L);
|
||||
return unit(h);
|
||||
}
|
||||
|
||||
private static long mix(long a) {
|
||||
a ^= (a >>> 33);
|
||||
a *= 0xff51afd7ed558ccdL;
|
||||
a ^= (a >>> 33);
|
||||
a *= 0xc4ceb9fe1a85ec53L;
|
||||
a ^= (a >>> 33);
|
||||
return a;
|
||||
}
|
||||
|
||||
private static double unit(long h) {
|
||||
return (h >>> 11) * 0x1.0p-53;
|
||||
}
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.tree;
|
||||
|
||||
import art.arcane.iris.engine.object.procedural.IrisProceduralBlocks;
|
||||
import art.arcane.iris.modules.objects.tree.Tree;
|
||||
import art.arcane.iris.modules.objects.ObjectBuilder;
|
||||
import com.volmit.block.BlockState;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public final class TreePlausibility {
|
||||
private static final int MAX_DISTANCE = 7;
|
||||
private static final int[][] NEIGHBORS = {
|
||||
{1, 0, 0}, {-1, 0, 0}, {0, 1, 0}, {0, -1, 0}, {0, 0, 1}, {0, 0, -1}
|
||||
};
|
||||
|
||||
private TreePlausibility() {
|
||||
}
|
||||
|
||||
public static void apply(Map<TreeBlockCanvas.Vec, BlockState> resolved, Set<TreeBlockCanvas.Vec> trunkPositions,
|
||||
Set<TreeBlockCanvas.Vec> leafPositions, Tree tree, ObjectBuilder blocks) {
|
||||
Set<TreeBlockCanvas.Vec> realLeaves = new HashSet<>();
|
||||
for (TreeBlockCanvas.Vec v : leafPositions) {
|
||||
BlockState state = resolved.get(v);
|
||||
if (state != null && IrisProceduralBlocks.hasProperty(state, "persistent") && IrisProceduralBlocks.hasProperty(state, "distance")) {
|
||||
realLeaves.add(v);
|
||||
}
|
||||
}
|
||||
if (realLeaves.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<TreeBlockCanvas.Vec, Integer> distance = computeDistances(trunkPositions, realLeaves);
|
||||
|
||||
for (TreeBlockCanvas.Vec v : realLeaves) {
|
||||
BlockState leaf = resolved.get(v);
|
||||
Integer d = distance.get(v);
|
||||
if (!tree.plausible()) {
|
||||
leaf = withLeafState(blocks, leaf, "true", "1");
|
||||
} else if (d != null && d < MAX_DISTANCE) {
|
||||
leaf = withLeafState(blocks, leaf, "false", String.valueOf(Math.max(1, d)));
|
||||
} else {
|
||||
leaf = withLeafState(blocks, leaf, "true", String.valueOf(MAX_DISTANCE));
|
||||
}
|
||||
resolved.put(v, leaf);
|
||||
}
|
||||
}
|
||||
|
||||
private static BlockState withLeafState(ObjectBuilder blocks, BlockState leaf, String persistent, String distance) {
|
||||
return blocks.withProperty(blocks.withProperty(leaf, "persistent", persistent), "distance", distance);
|
||||
}
|
||||
|
||||
static Map<TreeBlockCanvas.Vec, Integer> computeDistances(Set<TreeBlockCanvas.Vec> trunkPositions, Set<TreeBlockCanvas.Vec> realLeaves) {
|
||||
Map<TreeBlockCanvas.Vec, Integer> distance = new HashMap<>();
|
||||
ArrayDeque<TreeBlockCanvas.Vec> queue = new ArrayDeque<>();
|
||||
|
||||
for (TreeBlockCanvas.Vec v : realLeaves) {
|
||||
for (int[] n : NEIGHBORS) {
|
||||
if (trunkPositions.contains(new TreeBlockCanvas.Vec(v.x() + n[0], v.y() + n[1], v.z() + n[2]))) {
|
||||
distance.put(v, 1);
|
||||
queue.add(v);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (!queue.isEmpty()) {
|
||||
TreeBlockCanvas.Vec v = queue.poll();
|
||||
int d = distance.get(v);
|
||||
if (d >= MAX_DISTANCE) {
|
||||
continue;
|
||||
}
|
||||
for (int[] n : NEIGHBORS) {
|
||||
TreeBlockCanvas.Vec nv = new TreeBlockCanvas.Vec(v.x() + n[0], v.y() + n[1], v.z() + n[2]);
|
||||
if (!realLeaves.contains(nv)) {
|
||||
continue;
|
||||
}
|
||||
Integer existing = distance.get(nv);
|
||||
if (existing == null || existing > d + 1) {
|
||||
distance.put(nv, d + 1);
|
||||
queue.add(nv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return distance;
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.tree;
|
||||
|
||||
import art.arcane.iris.modules.objects.tree.TreeProfile;
|
||||
|
||||
|
||||
public final class TreeProfiles {
|
||||
private TreeProfiles() {
|
||||
}
|
||||
|
||||
static double radiusScale(TreeProfile profile) {
|
||||
return switch (profile) {
|
||||
case OAK, DARK_OAK, CHERRY -> 1.0;
|
||||
case BIRCH -> 0.7;
|
||||
case SPRUCE -> 0.55;
|
||||
case JUNGLE -> 0.45;
|
||||
case ACACIA -> 0.6;
|
||||
case DARK_OAK_FLAT -> 1.25;
|
||||
case DARK_OAK_FLAT_WIDE -> 1.8;
|
||||
case PALM -> 0.5;
|
||||
case WILLOW -> 1.1;
|
||||
case COLUMNAR -> 0.35;
|
||||
case BUSH -> 1.3;
|
||||
case MEGA_SPRUCE -> 0.7;
|
||||
};
|
||||
}
|
||||
|
||||
static double[][] fractions(TreeProfile profile) {
|
||||
return switch (profile) {
|
||||
case OAK -> new double[][]{{0.55, 0.6}, {0.65, 0.9}, {0.75, 1.0}, {0.85, 0.9}, {0.92, 0.65}, {0.98, 0.35}};
|
||||
case BIRCH -> new double[][]{{0.6, 0.45}, {0.7, 0.75}, {0.8, 0.85}, {0.88, 0.75}, {0.94, 0.45}, {0.99, 0.2}};
|
||||
case SPRUCE, MEGA_SPRUCE -> new double[][]{{0.3, 1.0}, {0.42, 0.85}, {0.54, 0.7}, {0.65, 0.55}, {0.75, 0.4}, {0.84, 0.25}, {0.91, 0.15}, {0.97, 0.05}};
|
||||
case JUNGLE -> new double[][]{{0.82, 0.4}, {0.88, 0.8}, {0.93, 1.0}, {0.97, 0.7}, {1.0, 0.3}};
|
||||
case ACACIA -> new double[][]{{0.9, 0.5}, {0.95, 0.8}, {0.99, 0.4}};
|
||||
case DARK_OAK -> new double[][]{{0.5, 0.7}, {0.62, 1.0}, {0.72, 1.0}, {0.82, 0.9}, {0.91, 0.6}, {0.97, 0.3}};
|
||||
case DARK_OAK_FLAT -> new double[][]{{0.74, 0.62}, {0.83, 1.0}, {0.92, 1.0}, {1.0, 0.6}};
|
||||
case DARK_OAK_FLAT_WIDE -> new double[][]{{0.74, 0.62}, {0.83, 1.0}, {0.92, 1.0}, {1.0, 0.62}};
|
||||
case CHERRY -> new double[][]{{0.5, 0.5}, {0.62, 0.9}, {0.74, 1.0}, {0.84, 1.0}, {0.92, 0.7}, {0.98, 0.4}};
|
||||
case PALM -> new double[][]{{0.92, 0.45}, {0.97, 0.9}, {1.0, 1.0}, {1.03, 0.6}};
|
||||
case WILLOW -> new double[][]{{0.55, 0.7}, {0.68, 1.0}, {0.8, 1.0}, {0.9, 0.85}, {0.97, 0.6}};
|
||||
case COLUMNAR -> new double[][]{{0.4, 0.6}, {0.55, 0.9}, {0.7, 1.0}, {0.82, 0.9}, {0.92, 0.7}, {0.98, 0.4}};
|
||||
case BUSH -> new double[][]{{0.25, 0.7}, {0.45, 1.0}, {0.65, 1.0}, {0.82, 0.8}, {0.95, 0.5}};
|
||||
};
|
||||
}
|
||||
|
||||
static double[][] presetLayers(TreeProfile profile, int height, boolean branchDriven) {
|
||||
double scale = radiusScale(profile);
|
||||
int baseRadius = Math.max(3, (int) Math.round(height / 2.0 * scale));
|
||||
double[][] fractions = fractions(profile);
|
||||
|
||||
int crownExtra = branchDriven ? 0 : Math.max(2, height / 4);
|
||||
int yTop = (height - 1) + crownExtra;
|
||||
|
||||
double[][] layers = new double[fractions.length][2];
|
||||
for (int i = 0; i < fractions.length; i++) {
|
||||
int yOff = (int) Math.round(fractions[i][0] * yTop);
|
||||
double radius = Math.max(1.5, baseRadius * fractions[i][1]);
|
||||
layers[i][0] = yOff;
|
||||
layers[i][1] = radius;
|
||||
}
|
||||
return layers;
|
||||
}
|
||||
}
|
||||
@@ -1,154 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.tree;
|
||||
|
||||
import art.arcane.iris.modules.objects.tree.TreeRootStyle;
|
||||
import art.arcane.iris.modules.objects.tree.Tree;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class TreeRootBuilder {
|
||||
private TreeRootBuilder() {
|
||||
}
|
||||
|
||||
public static void build(TreeBlockCanvas canvas, Tree tree, int height, long baseSeed) {
|
||||
List<int[]> cells = new ArrayList<>();
|
||||
for (TreeBlockCanvas.Vec v : canvas.getTrunk()) {
|
||||
if (v.y() == 0) {
|
||||
cells.add(new int[]{v.x(), v.z()});
|
||||
}
|
||||
}
|
||||
if (cells.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int depth = tree.rootDepth() > 0 ? tree.rootDepth() : autoDepth(height);
|
||||
RNG rng = new RNG(baseSeed ^ 0x5009L);
|
||||
|
||||
double cx = 0;
|
||||
double cz = 0;
|
||||
for (int[] c : cells) {
|
||||
cx += c[0];
|
||||
cz += c[1];
|
||||
}
|
||||
cx /= cells.size();
|
||||
cz /= cells.size();
|
||||
|
||||
double baseRadius = 1.0;
|
||||
for (int[] c : cells) {
|
||||
baseRadius = Math.max(baseRadius, Math.hypot(c[0] - cx, c[1] - cz) + 0.5);
|
||||
}
|
||||
double flare = tree.rootFlare() > 0 ? tree.rootFlare() : baseRadius + Math.max(2.0, depth * 0.6);
|
||||
|
||||
TreeRootStyle style = tree.rootStyle();
|
||||
switch (style) {
|
||||
case TAPROOT -> taproot(canvas, cells, cx, cz, baseRadius, depth);
|
||||
case BUTTRESS -> {
|
||||
taproot(canvas, cells, cx, cz, baseRadius, depth);
|
||||
buttress(canvas, cells, cx, cz, baseRadius, depth, flare, rng);
|
||||
}
|
||||
case STILT -> {
|
||||
taproot(canvas, cells, cx, cz, baseRadius, Math.min(depth, 3));
|
||||
stilts(canvas, cx, cz, baseRadius, flare, height, cells.size(), rng);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void taproot(TreeBlockCanvas canvas, List<int[]> cells, double cx, double cz, double baseRadius, int depth) {
|
||||
int icx = (int) Math.round(cx);
|
||||
int icz = (int) Math.round(cz);
|
||||
for (int k = 1; k <= depth; k++) {
|
||||
double frac = k / (double) depth;
|
||||
double keepR = baseRadius * (1.0 - 0.6 * frac);
|
||||
for (int[] c : cells) {
|
||||
if (Math.hypot(c[0] - cx, c[1] - cz) <= keepR + 1e-6) {
|
||||
placeRoot(canvas, c[0], -k, c[1], TreeBlockCanvas.Axis.Y);
|
||||
}
|
||||
}
|
||||
placeRoot(canvas, icx, -k, icz, TreeBlockCanvas.Axis.Y);
|
||||
}
|
||||
}
|
||||
|
||||
private static void buttress(TreeBlockCanvas canvas, List<int[]> cells, double cx, double cz, double baseRadius,
|
||||
int depth, double flare, RNG rng) {
|
||||
int nLegs = Math.max(4, Math.min(12, cells.size() + 2));
|
||||
for (int li = 0; li < nLegs; li++) {
|
||||
double ang = 2.0 * Math.PI * li / nLegs + rng.d(-0.25, 0.25);
|
||||
double ca = Math.cos(ang);
|
||||
double sa = Math.sin(ang);
|
||||
int prevX = (int) Math.round(cx + baseRadius * ca);
|
||||
int prevZ = (int) Math.round(cz + baseRadius * sa);
|
||||
for (int k = 1; k <= depth; k++) {
|
||||
double frac = k / (double) depth;
|
||||
double r = baseRadius + (flare - baseRadius) * frac;
|
||||
int x = (int) Math.round(cx + r * ca);
|
||||
int z = (int) Math.round(cz + r * sa);
|
||||
placeRoot(canvas, x, -k, z, TreeBlockCanvas.Axis.Y);
|
||||
if (x != prevX || z != prevZ) {
|
||||
placeRoot(canvas, prevX, -k, prevZ, TreeBlockCanvas.Axis.Y);
|
||||
}
|
||||
prevX = x;
|
||||
prevZ = z;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void stilts(TreeBlockCanvas canvas, double cx, double cz, double baseRadius, double flare,
|
||||
int height, int cellCount, RNG rng) {
|
||||
int stiltTop = Math.max(2, Math.min(7, (int) Math.round(0.25 * height)));
|
||||
int nProps = Math.max(4, Math.min(10, cellCount + 2));
|
||||
for (int p = 0; p < nProps; p++) {
|
||||
double ang = 2.0 * Math.PI * p / nProps + rng.d(-0.25, 0.25);
|
||||
double ca = Math.cos(ang);
|
||||
double sa = Math.sin(ang);
|
||||
int sx = (int) Math.round(cx + baseRadius * ca);
|
||||
int sz = (int) Math.round(cz + baseRadius * sa);
|
||||
int fx = (int) Math.round(cx + flare * ca);
|
||||
int fz = (int) Math.round(cz + flare * sa);
|
||||
rasterizeRoot(canvas, sx, stiltTop, sz, fx, -2, fz);
|
||||
}
|
||||
}
|
||||
|
||||
private static void rasterizeRoot(TreeBlockCanvas canvas, int ox, int oy, int oz, int ex, int ey, int ez) {
|
||||
int dx = ex - ox;
|
||||
int dy = ey - oy;
|
||||
int dz = ez - oz;
|
||||
int steps = Math.max(Math.max(Math.abs(dx), Math.abs(dy)), Math.max(Math.abs(dz), 1));
|
||||
TreeBlockCanvas.Axis axis = TreeFunctions.logAxis(dx, dy, dz);
|
||||
for (int i = 0; i <= steps; i++) {
|
||||
double t = i / (double) steps;
|
||||
int x = (int) Math.round(ox + dx * t);
|
||||
int y = (int) Math.round(oy + dy * t);
|
||||
int z = (int) Math.round(oz + dz * t);
|
||||
placeRoot(canvas, x, y, z, axis);
|
||||
}
|
||||
}
|
||||
|
||||
private static void placeRoot(TreeBlockCanvas canvas, int x, int y, int z, TreeBlockCanvas.Axis axis) {
|
||||
if (!canvas.has(x, y, z)) {
|
||||
canvas.setTrunk(x, y, z, TreeBlockCanvas.Role.TRUNK, axis);
|
||||
}
|
||||
}
|
||||
|
||||
private static int autoDepth(int height) {
|
||||
return Math.max(2, Math.min(16, (int) Math.round(0.18 * height)));
|
||||
}
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.tree;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
public final class TreeSupport {
|
||||
private static final int LEGAL_DISTANCE = 6;
|
||||
private static final int REACH_GAP = 4;
|
||||
|
||||
private TreeSupport() {
|
||||
}
|
||||
|
||||
public static void ensureLeavesSupported(TreeBlockCanvas canvas, int maxTendrils) {
|
||||
for (int iter = 0; iter < maxTendrils; iter++) {
|
||||
Map<TreeBlockCanvas.Vec, Integer> dist = TreePlausibility.computeDistances(canvas.getTrunk(), canvas.getLeaf());
|
||||
|
||||
TreeBlockCanvas.Vec worstLeaf = null;
|
||||
TreeBlockCanvas.Vec worstWood = null;
|
||||
int worstGap = -1;
|
||||
|
||||
for (TreeBlockCanvas.Vec leaf : new ArrayList<>(canvas.getLeaf())) {
|
||||
Integer d = dist.get(leaf);
|
||||
if (d != null && d <= LEGAL_DISTANCE) {
|
||||
continue;
|
||||
}
|
||||
TreeBlockCanvas.Vec nearest = null;
|
||||
int best = Integer.MAX_VALUE;
|
||||
for (TreeBlockCanvas.Vec wood : canvas.getTrunk()) {
|
||||
int cd = chebyshev(leaf, wood);
|
||||
if (cd < best) {
|
||||
best = cd;
|
||||
nearest = wood;
|
||||
if (cd <= 1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (nearest != null && best > worstGap) {
|
||||
worstGap = best;
|
||||
worstLeaf = leaf;
|
||||
worstWood = nearest;
|
||||
}
|
||||
}
|
||||
|
||||
if (worstLeaf == null) {
|
||||
return;
|
||||
}
|
||||
growTendril(canvas, worstWood, worstLeaf);
|
||||
}
|
||||
}
|
||||
|
||||
private static void growTendril(TreeBlockCanvas canvas, TreeBlockCanvas.Vec from, TreeBlockCanvas.Vec to) {
|
||||
int dx = to.x() - from.x();
|
||||
int dy = to.y() - from.y();
|
||||
int dz = to.z() - from.z();
|
||||
int length = Math.max(Math.max(Math.abs(dx), Math.abs(dy)), Math.max(Math.abs(dz), 1));
|
||||
int steps = Math.max(1, length - REACH_GAP);
|
||||
TreeBlockCanvas.Axis axis = TreeFunctions.logAxis(dx, dy, dz);
|
||||
|
||||
for (int i = 1; i <= steps; i++) {
|
||||
double t = i / (double) length;
|
||||
int x = from.x() + (int) Math.round(dx * t);
|
||||
int y = from.y() + (int) Math.round(dy * t);
|
||||
int z = from.z() + (int) Math.round(dz * t);
|
||||
canvas.setTrunk(x, y, z, TreeBlockCanvas.Role.TRUNK, axis);
|
||||
}
|
||||
}
|
||||
|
||||
private static int chebyshev(TreeBlockCanvas.Vec a, TreeBlockCanvas.Vec b) {
|
||||
return Math.max(Math.max(Math.abs(a.x() - b.x()), Math.abs(a.y() - b.y())), Math.abs(a.z() - b.z()));
|
||||
}
|
||||
}
|
||||
@@ -1,202 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.tree;
|
||||
|
||||
import art.arcane.iris.modules.objects.tree.TreeAzimuthMode;
|
||||
import art.arcane.iris.engine.object.procedural.IrisProceduralBlocks;
|
||||
import art.arcane.iris.modules.objects.tree.Tree;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class TreeTrunkBuilder {
|
||||
public record Limb(double[][] offsets, int branchStartY) {
|
||||
}
|
||||
|
||||
private TreeTrunkBuilder() {
|
||||
}
|
||||
|
||||
public static List<Limb> build(TreeBlockCanvas canvas, Tree tree, int height) {
|
||||
boolean hasSecondary = hasSecondaryTrunk(tree);
|
||||
double[][] mainOffsets = leanPath(tree, height);
|
||||
int forks = Math.max(1, tree.trunkForks());
|
||||
|
||||
List<Limb> limbs = new ArrayList<>();
|
||||
if (forks == 1) {
|
||||
placeColumn(canvas, tree, mainOffsets, height, 0, height - 1, hasSecondary);
|
||||
limbs.add(new Limb(mainOffsets, 0));
|
||||
markExposedEnds(canvas);
|
||||
return limbs;
|
||||
}
|
||||
|
||||
int forkY = Math.max(1, Math.min(height - 2, (int) Math.round(tree.forkHeight() * (height - 1))));
|
||||
placeColumn(canvas, tree, mainOffsets, height, 0, forkY, hasSecondary);
|
||||
|
||||
double baseCx = mainOffsets[forkY][0];
|
||||
double baseCz = mainOffsets[forkY][1];
|
||||
double reachMax = (height - forkY) * Math.tan(Math.toRadians(tree.forkAngle()));
|
||||
|
||||
for (int f = 0; f < forks; f++) {
|
||||
double az = Math.toRadians((360.0 / forks) * f);
|
||||
double[][] forkOffsets = new double[height][2];
|
||||
for (int y = 0; y <= forkY; y++) {
|
||||
forkOffsets[y][0] = mainOffsets[y][0];
|
||||
forkOffsets[y][1] = mainOffsets[y][1];
|
||||
}
|
||||
for (int y = forkY + 1; y < height; y++) {
|
||||
double p = (y - forkY) / (double) Math.max(1, height - 1 - forkY);
|
||||
double reach = reachMax * p;
|
||||
forkOffsets[y][0] = baseCx + reach * Math.sin(az);
|
||||
forkOffsets[y][1] = baseCz + reach * Math.cos(az);
|
||||
}
|
||||
placeColumn(canvas, tree, forkOffsets, height, forkY + 1, height - 1, hasSecondary);
|
||||
limbs.add(new Limb(forkOffsets, forkY));
|
||||
}
|
||||
|
||||
markExposedEnds(canvas);
|
||||
return limbs;
|
||||
}
|
||||
|
||||
private static double[][] leanPath(Tree tree, int height) {
|
||||
double[][] offsets = new double[height][2];
|
||||
for (int y = 0; y < height; y++) {
|
||||
double[] lean = leanOffset(tree, y, height);
|
||||
offsets[y][0] = lean[0];
|
||||
offsets[y][1] = lean[1];
|
||||
}
|
||||
return offsets;
|
||||
}
|
||||
|
||||
private static void placeColumn(TreeBlockCanvas canvas, Tree tree, double[][] offsets, int height,
|
||||
int yStart, int yEnd, boolean hasSecondary) {
|
||||
double prevCx = yStart > 0 ? offsets[yStart - 1][0] : 0.0;
|
||||
double prevCz = yStart > 0 ? offsets[yStart - 1][1] : 0.0;
|
||||
|
||||
for (int y = yStart; y <= yEnd; y++) {
|
||||
double cx = offsets[y][0];
|
||||
double cz = offsets[y][1];
|
||||
int w = widthAt(tree, y, height);
|
||||
TreeBlockCanvas.Axis axis = TreeFunctions.logAxis(cx - prevCx, 1.0, cz - prevCz);
|
||||
TreeBlockCanvas.Role role = trunkRole(tree, hasSecondary, y, height);
|
||||
|
||||
for (int[] xz : squarePositions(cx, cz, w)) {
|
||||
canvas.setTrunk(xz[0], y, xz[1], role, axis);
|
||||
}
|
||||
|
||||
double shift = Math.hypot(cx - prevCx, cz - prevCz);
|
||||
if (shift > 1.0) {
|
||||
int steps = (int) Math.ceil(shift);
|
||||
for (int s = 1; s < steps; s++) {
|
||||
double tFill = s / (double) steps;
|
||||
double icx = prevCx + (cx - prevCx) * tFill;
|
||||
double icz = prevCz + (cz - prevCz) * tFill;
|
||||
int fillY = (int) Math.round(y - 1 + tFill);
|
||||
for (int[] xz : squarePositions(icx, icz, w)) {
|
||||
if (!canvas.has(xz[0], fillY, xz[1])) {
|
||||
canvas.setTrunk(xz[0], fillY, xz[1], role, axis);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
prevCx = cx;
|
||||
prevCz = cz;
|
||||
}
|
||||
}
|
||||
|
||||
private static void markExposedEnds(TreeBlockCanvas canvas) {
|
||||
for (TreeBlockCanvas.Vec v : new ArrayList<>(canvas.getTrunk())) {
|
||||
if (!canvas.has(v.x(), v.y() + 1, v.z()) || !canvas.has(v.x(), v.y() - 1, v.z())) {
|
||||
canvas.markExposed(v.x(), v.y(), v.z());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static int widthAt(Tree tree, int y, int height) {
|
||||
double t = y / (double) Math.max(height - 1, 1);
|
||||
double multiplier = TreeFunctions.trunkWidthMultiplier(tree, t);
|
||||
return Math.max(1, (int) Math.round(tree.trunkWidth() * multiplier));
|
||||
}
|
||||
|
||||
private static TreeBlockCanvas.Role trunkRole(Tree tree, boolean hasSecondary, int y, int height) {
|
||||
if (!hasSecondary) {
|
||||
return TreeBlockCanvas.Role.TRUNK;
|
||||
}
|
||||
double t = y / (double) Math.max(height - 1, 1);
|
||||
if (tree.secondaryTrunkStart() <= t && t <= tree.secondaryTrunkEnd()) {
|
||||
return TreeBlockCanvas.Role.SECONDARY_TRUNK;
|
||||
}
|
||||
return TreeBlockCanvas.Role.TRUNK;
|
||||
}
|
||||
|
||||
private static boolean hasSecondaryTrunk(Tree tree) {
|
||||
if (IrisProceduralBlocks.paletteSet(tree.secondaryTrunkPalette())) {
|
||||
return true;
|
||||
}
|
||||
return tree.secondaryTrunk().filter(trunk -> !trunk.isEmpty()).isPresent();
|
||||
}
|
||||
|
||||
private static double[] leanOffset(Tree tree, int y, int height) {
|
||||
if (tree.leanAngle() == 0.0 || height <= 1) {
|
||||
return new double[]{0.0, 0.0};
|
||||
}
|
||||
double t = y / (double) Math.max(height - 1, 1);
|
||||
double progress = TreeFunctions.curveProgress(tree.trunkCurve(), t, tree.curveSteepness());
|
||||
double maxReach = height * Math.tan(Math.toRadians(tree.leanAngle()));
|
||||
double reach = maxReach * progress;
|
||||
double azDeg = tree.leanAzimuthMode() == TreeAzimuthMode.CONSTANT
|
||||
? tree.leanAzimuth()
|
||||
: TreeFunctions.azimuthDegrees(tree.leanAzimuthMode(), t, -1, tree, tree.leanAzimuth(), null);
|
||||
double azRad = Math.toRadians(azDeg);
|
||||
double dx = reach * Math.sin(azRad);
|
||||
double dz = reach * Math.cos(azRad);
|
||||
return new double[]{dx, dz};
|
||||
}
|
||||
|
||||
private static List<int[]> squarePositions(double cx, double cz, int width) {
|
||||
List<int[]> out = new ArrayList<>();
|
||||
if (width % 2 == 1) {
|
||||
int half = width / 2;
|
||||
int icx = (int) Math.round(cx);
|
||||
int icz = (int) Math.round(cz);
|
||||
for (int dx = -half; dx <= half; dx++) {
|
||||
for (int dz = -half; dz <= half; dz++) {
|
||||
out.add(new int[]{icx + dx, icz + dz});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int ox = (int) Math.floor(cx) - width / 2 + 1;
|
||||
int oz = (int) Math.floor(cz) - width / 2 + 1;
|
||||
for (int dx = 0; dx < width; dx++) {
|
||||
for (int dz = 0; dz < width; dz++) {
|
||||
out.add(new int[]{ox + dx, oz + dz});
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
static String stripState(String block) {
|
||||
if (block == null) {
|
||||
return null;
|
||||
}
|
||||
int idx = block.indexOf('[');
|
||||
return idx < 0 ? block : block.substring(0, idx);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.engine.procedural;
|
||||
|
||||
/**
|
||||
* How long baking a pool of variants took, stage by stage, added up over every variant. {@link #NONE} times nothing,
|
||||
* so world generation bakes at full speed.
|
||||
*/
|
||||
public class BakeProfile {
|
||||
public static final BakeProfile NONE = new BakeProfile() {
|
||||
@Override
|
||||
public void startVariant() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lap(Stage stage) {
|
||||
}
|
||||
};
|
||||
|
||||
/** The steps a variant is baked in, in order. */
|
||||
public enum Stage {
|
||||
PARTS("Parts"),
|
||||
PAINT("Paint"),
|
||||
DECORATE("Decorate"),
|
||||
LEAVES("Leaves"),
|
||||
BUILD("Build");
|
||||
|
||||
private final String label;
|
||||
|
||||
Stage(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public String label() {
|
||||
return label;
|
||||
}
|
||||
}
|
||||
|
||||
private final long[] nanosByStage = new long[Stage.values().length];
|
||||
private long lapStartNanos;
|
||||
private int variantCount;
|
||||
|
||||
public void startVariant() {
|
||||
variantCount++;
|
||||
lapStartNanos = System.nanoTime();
|
||||
}
|
||||
|
||||
/** Adds the time since the variant started, or since the last lap, to {@code stage}. */
|
||||
public void lap(Stage stage) {
|
||||
long now = System.nanoTime();
|
||||
nanosByStage[stage.ordinal()] += now - lapStartNanos;
|
||||
lapStartNanos = now;
|
||||
}
|
||||
|
||||
public long nanos(Stage stage) {
|
||||
return nanosByStage[stage.ordinal()];
|
||||
}
|
||||
|
||||
public long totalNanos() {
|
||||
long total = 0L;
|
||||
for (long nanos : nanosByStage) {
|
||||
total += nanos;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
public int variantCount() {
|
||||
return variantCount;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.procedural;
|
||||
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.block.PaletteSpec;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
import com.volmit.object.ObjectBlock;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Block helpers for baking procedural objects: reading a state's properties, and assembling a raw block map into a
|
||||
* shape centered on x and z with its lowest layer one block above the anchor.
|
||||
*/
|
||||
public final class IrisProceduralBlocks {
|
||||
/** The distance vanilla gives a leaf with no wood near enough to keep it. */
|
||||
public static final int UNREACHED_LEAF_DISTANCE = 7;
|
||||
|
||||
private IrisProceduralBlocks() {
|
||||
}
|
||||
|
||||
/** Whether {@code state} is a leaf baked with no wood near enough for vanilla to keep it. */
|
||||
public static boolean isLeafTooFarFromWood(BlockState state) {
|
||||
return hasProperty(state, "persistent") && String.valueOf(UNREACHED_LEAF_DISTANCE).equals(propertyValue(state, "distance"));
|
||||
}
|
||||
|
||||
public static boolean paletteSet(PaletteSpec palette) {
|
||||
return palette != null && !palette.palette().isEmpty();
|
||||
}
|
||||
|
||||
public static boolean hasProperty(BlockState state, String property) {
|
||||
return state.properties().containsKey(property);
|
||||
}
|
||||
|
||||
public static String propertyValue(BlockState state, String property) {
|
||||
return state.properties().get(property);
|
||||
}
|
||||
|
||||
/** The blocks centered on x and z, with their lowest layer one block above the anchor; null when there are none. */
|
||||
public static ProceduralShape assemble(Map<Vector3i, BlockState> blocks) {
|
||||
if (blocks == null || blocks.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Anchor anchor = Anchor.of(blocks.keySet());
|
||||
List<ObjectBlock> placed = new ArrayList<>(blocks.size());
|
||||
for (Map.Entry<Vector3i, BlockState> entry : blocks.entrySet()) {
|
||||
placed.add(new ObjectBlock(anchor.place(entry.getKey()), entry.getValue()));
|
||||
}
|
||||
|
||||
return new ProceduralShape(anchor.width(), anchor.height(), anchor.depth(), placed);
|
||||
}
|
||||
|
||||
/** Where {@link #assemble} moves each block of a set: centered on x and z, its lowest layer one block above the anchor. */
|
||||
public record Anchor(int minX, int minZ, int width, int height, int depth) {
|
||||
public static Anchor of(Collection<Vector3i> positions) {
|
||||
int minX = Integer.MAX_VALUE;
|
||||
int minY = Integer.MAX_VALUE;
|
||||
int minZ = Integer.MAX_VALUE;
|
||||
int maxX = Integer.MIN_VALUE;
|
||||
int maxY = Integer.MIN_VALUE;
|
||||
int maxZ = Integer.MIN_VALUE;
|
||||
for (Vector3i v : positions) {
|
||||
minX = Math.min(minX, v.getBlockX());
|
||||
minY = Math.min(minY, v.getBlockY());
|
||||
minZ = Math.min(minZ, v.getBlockZ());
|
||||
maxX = Math.max(maxX, v.getBlockX());
|
||||
maxY = Math.max(maxY, v.getBlockY());
|
||||
maxZ = Math.max(maxZ, v.getBlockZ());
|
||||
}
|
||||
return new Anchor(minX, minZ, maxX - minX + 1, maxY - minY + 1, maxZ - minZ + 1);
|
||||
}
|
||||
|
||||
public BlockPosition place(Vector3i position) {
|
||||
return new BlockPosition(position.getBlockX() - minX - width / 2, position.getBlockY() - height / 2 + 1,
|
||||
position.getBlockZ() - minZ - depth / 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.procedural;
|
||||
|
||||
import art.arcane.iris.engine.procedural.part.ProceduralObject;
|
||||
import art.arcane.iris.engine.procedural.part.ResolvedProceduralObject;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.object.PlaceableObject;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.resource.ResourceKind;
|
||||
import com.volmit.world.PackWorld;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* The pack's procedural objects, each read from {@code procedural/<path>.json} and placed from any object placement
|
||||
* as {@code procedural/<path>}, or one variant as {@code procedural/<path>#<index>}. Variants are baked on first use.
|
||||
*/
|
||||
public final class ProceduralObjectCatalog {
|
||||
/** The definitions, in {@code procedural/}; a placement's key for one is its file path, like {@code procedural/trees/oak}. */
|
||||
public static final ResourceKind<ProceduralObject> DEFINITIONS =
|
||||
ResourceKind.of("iris:objects/procedural", "procedural", ProceduralObject.class);
|
||||
public static final String KEY_PREFIX = DEFINITIONS.folder() + "/";
|
||||
public static final char VARIANT_SEPARATOR = '#';
|
||||
|
||||
private final PackResources resources;
|
||||
private final ModuleLog log;
|
||||
private final Map<String, Optional<ProceduralVariants>> variantsByPath = new ConcurrentHashMap<>();
|
||||
|
||||
private ProceduralObjectCatalog(PackResources resources, ModuleLog log) {
|
||||
this.resources = resources;
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
/** The catalog {@code world} keeps, so each definition bakes once per world. */
|
||||
public static ProceduralObjectCatalog of(PackWorld world) {
|
||||
return world.state(ProceduralObjectCatalog.class, generating -> new ProceduralObjectCatalog(generating.resources(), generating.log()));
|
||||
}
|
||||
|
||||
/** A catalog of its own, for work outside any world such as working out the pack's reach; it bakes anew. */
|
||||
public static ProceduralObjectCatalog detached(PackResources resources, ModuleLog log) {
|
||||
return new ProceduralObjectCatalog(resources, log);
|
||||
}
|
||||
|
||||
/** Whether {@code key} names a procedural object rather than a pack object. */
|
||||
public static boolean isProceduralKey(String key) {
|
||||
return key != null && key.startsWith(KEY_PREFIX);
|
||||
}
|
||||
|
||||
/** The variant {@code key} pins, or for a key naming the whole pool the one {@code rng} picks; empty when none. */
|
||||
public Optional<PlaceableObject> object(String key, RNG rng) {
|
||||
ObjectKey parsed = ObjectKey.parse(key);
|
||||
return variantsNamedBy(parsed).flatMap(variants -> parsed.isPinned() ? variants.variant(parsed.variantIndex()) : variants.variant(rng));
|
||||
}
|
||||
|
||||
/**
|
||||
* The variant {@code key} pins, or for a key naming the whole pool its first variant, so a caller without a random
|
||||
* stream still gets the same object every time; empty when none.
|
||||
*/
|
||||
public Optional<PlaceableObject> object(String key) {
|
||||
ObjectKey parsed = ObjectKey.parse(key);
|
||||
return variantsNamedBy(parsed).flatMap(variants -> parsed.isPinned()
|
||||
? variants.variant(parsed.variantIndex())
|
||||
: variants.variants().stream().findFirst());
|
||||
}
|
||||
|
||||
/** The variants {@code key} names, pinned to one or not; empty when the pack has no such object. */
|
||||
public Optional<ProceduralVariants> variants(String key) {
|
||||
return variantsNamedBy(ObjectKey.parse(key));
|
||||
}
|
||||
|
||||
/** Every variant {@code key} may place: the one it pins, or the whole pool. */
|
||||
public List<PlaceableObject> placeable(String key) {
|
||||
ObjectKey parsed = ObjectKey.parse(key);
|
||||
return variantsNamedBy(parsed).map(variants -> parsed.isPinned()
|
||||
? variants.variant(parsed.variantIndex()).stream().toList()
|
||||
: variants.variants()).orElse(List.of());
|
||||
}
|
||||
|
||||
private Optional<ProceduralVariants> variantsNamedBy(ObjectKey key) {
|
||||
return variantsByPath.computeIfAbsent(key.path(), this::resolve);
|
||||
}
|
||||
|
||||
private Optional<ProceduralVariants> resolve(String path) {
|
||||
ResourceId id = resources.idOf(path);
|
||||
Optional<ProceduralObject> definition;
|
||||
try {
|
||||
definition = resources.find(DEFINITIONS, id);
|
||||
} catch (IllegalStateException failedToLoad) {
|
||||
log.warnOnce("procedural-unreadable:" + path, "Couldn't read procedural object " + KEY_PREFIX + path + ": " + failedToLoad.getMessage());
|
||||
return Optional.empty();
|
||||
}
|
||||
if (definition.isEmpty()) {
|
||||
log.warnOnce("procedural-missing:" + path, "Couldn't find procedural object " + KEY_PREFIX + path);
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(new ResolvedProceduralObject(path, definition.get(), resources));
|
||||
}
|
||||
|
||||
/** A procedural object key split into the definition's path and, when it pins one, a variant index. */
|
||||
private record ObjectKey(String path, int variantIndex) {
|
||||
private static final int UNPINNED = -1;
|
||||
|
||||
static ObjectKey parse(String key) {
|
||||
String path = key.substring(KEY_PREFIX.length());
|
||||
int separator = path.lastIndexOf(VARIANT_SEPARATOR);
|
||||
if (separator < 0) {
|
||||
return new ObjectKey(path, UNPINNED);
|
||||
}
|
||||
try {
|
||||
return new ObjectKey(path.substring(0, separator), Integer.parseInt(path.substring(separator + 1)));
|
||||
} catch (NumberFormatException notAnIndex) {
|
||||
return new ObjectKey(path, UNPINNED);
|
||||
}
|
||||
}
|
||||
|
||||
boolean isPinned() {
|
||||
return variantIndex != UNPINNED;
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.procedural;
|
||||
package art.arcane.iris.engine.procedural;
|
||||
|
||||
import com.volmit.object.ObjectBlock;
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.procedural;
|
||||
|
||||
import art.arcane.iris.modules.objects.ObjectBuilder;
|
||||
import art.arcane.iris.modules.objects.ObjectSize;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.object.PlaceableObject;
|
||||
import com.volmit.resource.PackResources;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* The pool of variants one procedural definition bakes, placed through the object key {@code procedural/<path>}: a
|
||||
* placement picks one variant per object it places, or always the same one with {@code procedural/<path>#<index>}.
|
||||
*/
|
||||
public abstract class ProceduralVariants {
|
||||
private static final long VARIANT_SEED_STRIDE = 7919L;
|
||||
|
||||
private final String path;
|
||||
private final long seed;
|
||||
private final int variantCount;
|
||||
private final PackResources resources;
|
||||
private volatile List<PlaceableObject> baked;
|
||||
|
||||
protected ProceduralVariants(String path, long seed, int variantCount, PackResources resources) {
|
||||
this.path = path;
|
||||
this.seed = seed;
|
||||
this.variantCount = Math.max(1, variantCount);
|
||||
this.resources = resources;
|
||||
}
|
||||
|
||||
/** The shape variant {@code index} is baked as, from its own seeded stream; null when it has no blocks. */
|
||||
protected abstract ProceduralShape generate(int index, RNG rng, ObjectBuilder blocks, BakeProfile profile);
|
||||
|
||||
/** Where the pack keeps the definition, under {@code procedural/}, like {@code trees/oak}. */
|
||||
public String path() {
|
||||
return path;
|
||||
}
|
||||
|
||||
/** The key placements name the whole pool by, like {@code procedural/trees/oak}. */
|
||||
public String key() {
|
||||
return ProceduralObjectCatalog.KEY_PREFIX + path;
|
||||
}
|
||||
|
||||
/** The key variant {@code index} is placed under, like {@code procedural/trees/oak#0}. */
|
||||
public String variantKey(int index) {
|
||||
return key() + ProceduralObjectCatalog.VARIANT_SEPARATOR + index;
|
||||
}
|
||||
|
||||
/** Every variant, baked on first use. */
|
||||
public List<PlaceableObject> variants() {
|
||||
List<PlaceableObject> known = baked;
|
||||
if (known != null) {
|
||||
return known;
|
||||
}
|
||||
synchronized (this) {
|
||||
if (baked == null) {
|
||||
baked = List.copyOf(bake(newBuilder(), BakeProfile.NONE));
|
||||
}
|
||||
return baked;
|
||||
}
|
||||
}
|
||||
|
||||
/** Bakes every variant again the way world generation does, without keeping them, and times each stage. */
|
||||
public BakeProfile profileBake() {
|
||||
BakeProfile profile = new BakeProfile();
|
||||
bake(newBuilder(), profile);
|
||||
return profile;
|
||||
}
|
||||
|
||||
/** One of the variants, picked with {@code rng}; empty when none baked. */
|
||||
public Optional<PlaceableObject> variant(RNG rng) {
|
||||
List<PlaceableObject> all = variants();
|
||||
return all.isEmpty() ? Optional.empty() : Optional.of(all.get(rng.i(all.size())));
|
||||
}
|
||||
|
||||
/** The variant baked at {@code index}; empty when it baked no blocks or the definition asks for fewer. */
|
||||
public Optional<PlaceableObject> variant(int index) {
|
||||
String key = variantKey(index);
|
||||
return variants().stream().filter(variant -> variant.name().equals(key)).findFirst();
|
||||
}
|
||||
|
||||
/** The widest, tallest and deepest any variant reaches, each measured on its own. */
|
||||
public ObjectSize largestSize() {
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
int depth = 0;
|
||||
for (PlaceableObject variant : variants()) {
|
||||
width = Math.max(width, variant.width());
|
||||
height = Math.max(height, variant.height());
|
||||
depth = Math.max(depth, variant.depth());
|
||||
}
|
||||
return new ObjectSize(width, height, depth);
|
||||
}
|
||||
|
||||
/** Bakes every variant; variant {@code i} is drawn from {@code seed + i * stride}. */
|
||||
private List<PlaceableObject> bake(ObjectBuilder blocks, BakeProfile profile) {
|
||||
List<PlaceableObject> all = new ArrayList<>();
|
||||
for (int i = 0; i < variantCount; i++) {
|
||||
profile.startVariant();
|
||||
ProceduralShape generated = generate(i, variantRng(i), blocks, profile);
|
||||
if (generated == null || generated.blocks().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
all.add(blocks.build(variantKey(i), generated.width(), generated.height(), generated.depth(), generated.blocks()));
|
||||
profile.lap(BakeProfile.Stage.BUILD);
|
||||
}
|
||||
return all;
|
||||
}
|
||||
|
||||
protected final RNG variantRng(int index) {
|
||||
return new RNG(seed + (index * VARIANT_SEED_STRIDE));
|
||||
}
|
||||
|
||||
/** The index {@code variant} was baked at; -1 when it is not one of these variants. */
|
||||
protected final int bakeIndexOf(PlaceableObject variant) {
|
||||
for (int index = 0; index < variantCount; index++) {
|
||||
if (variantKey(index).equals(variant.name())) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
protected final ObjectBuilder newBuilder() {
|
||||
return new ObjectBuilder(resources);
|
||||
}
|
||||
|
||||
/** The seed every variant is baked from. */
|
||||
public final long seed() {
|
||||
return seed;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.engine.procedural.part;
|
||||
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
/**
|
||||
* A blob: a volume around a center whose horizontal cross-section is scaled by a profile from its bottom to its top,
|
||||
* an ellipsoid unless the pack shapes it, optionally hollowed into a shell.
|
||||
*/
|
||||
final class BlobShape implements PartShape {
|
||||
private static final double LARGEST_RADIUS_BLOCKS = 96;
|
||||
private static final double MINIMUM_RADIUS_BLOCKS = 0.05;
|
||||
private static final int[][] SHELL_DIRECTIONS = {{1, 0, 0}, {-1, 0, 0}, {0, 0, 1}, {0, 0, -1}, {0, 1, 0}, {0, -1, 0}};
|
||||
private static final int[][] OPEN_SHELL_DIRECTIONS = {{1, 0, 0}, {-1, 0, 0}, {0, 0, 1}, {0, 0, -1}, {0, 1, 0}};
|
||||
|
||||
private final double[] center;
|
||||
private final double radiusX;
|
||||
private final double radiusZ;
|
||||
private final double up;
|
||||
private final double down;
|
||||
private final ProceduralValue profile;
|
||||
private final PartSection section;
|
||||
private final double shell;
|
||||
private final boolean open;
|
||||
private final double outward;
|
||||
|
||||
private BlobShape(double[] center, double radiusX, double radiusZ, double up, double down, ProceduralValue profile,
|
||||
PartSection section, double shell, boolean open, double outward) {
|
||||
this.center = center;
|
||||
this.radiusX = radiusX;
|
||||
this.radiusZ = radiusZ;
|
||||
this.up = up;
|
||||
this.down = down;
|
||||
this.profile = profile;
|
||||
this.section = section;
|
||||
this.shell = shell;
|
||||
this.open = open;
|
||||
this.outward = outward;
|
||||
}
|
||||
|
||||
static BlobShape trace(PartBlob blob, PartSpot spot, RNG rng) {
|
||||
double t = spot.parentT();
|
||||
double radius = clampRadius(blob.radius().sample(rng, t));
|
||||
double up = blob.height() == null ? radius : clampRadius(blob.height().sample(rng, t));
|
||||
double down = blob.depth() == null ? up : Math.max(0, Math.min(LARGEST_RADIUS_BLOCKS, blob.depth().sample(rng, t)));
|
||||
double shell = Math.max(0, blob.shell().sample(rng, t));
|
||||
double outward = spot.hasOutward() ? spot.outward() : rng.d(0, 360);
|
||||
return new BlobShape(spot.origin(), Math.max(MINIMUM_RADIUS_BLOCKS, radius * blob.stretchX()),
|
||||
Math.max(MINIMUM_RADIUS_BLOCKS, radius * blob.stretchZ()), up, down,
|
||||
blob.profile() == null ? null : blob.profile().fix(rng), blob.section(), shell, blob.open(), outward);
|
||||
}
|
||||
|
||||
void draw(PartFill fill, double roughness, double jitter) {
|
||||
int reachX = (int) Math.ceil(radiusX * (1 + roughness) + 1);
|
||||
int reachZ = (int) Math.ceil(radiusZ * (1 + roughness) + 1);
|
||||
int cx = (int) Math.round(center[0]);
|
||||
int cy = (int) Math.round(center[1]);
|
||||
int cz = (int) Math.round(center[2]);
|
||||
for (int y = cy - (int) Math.ceil(down) - 1; y <= cy + (int) Math.ceil(up) + 1; y++) {
|
||||
for (int x = cx - reachX; x <= cx + reachX; x++) {
|
||||
for (int z = cz - reachZ; z <= cz + reachZ; z++) {
|
||||
drawBlock(fill, x, y, z, roughness, jitter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void drawBlock(PartFill fill, int x, int y, int z, double roughness, double jitter) {
|
||||
if (!inside(x, y, z, roughness, fill.seed())) {
|
||||
return;
|
||||
}
|
||||
if (shell > 0 && !nearSurface(x, y, z, roughness, fill.seed())) {
|
||||
return;
|
||||
}
|
||||
double dx = x - center[0];
|
||||
double dy = y - center[1];
|
||||
double dz = z - center[2];
|
||||
double edge = edge(dx, dy, dz);
|
||||
if (jitter > 0 && edge > 1 - 1 / (Math.max(radiusX, radiusZ) + 1) && PartNoise.hash(x, y, z, fill.seed() + 77L) < jitter * 0.35) {
|
||||
return;
|
||||
}
|
||||
double height = (dy + down + 0.5) / (up + down + 1);
|
||||
double falloffEdge = Math.sqrt(sq(dx / (radiusX + 1)) + sq(dy / ((dy >= 0 ? up : down) + 1)) + sq(dz / (radiusZ + 1)));
|
||||
fill.place(x, y, z, falloffEdge, height, PartCanvas.Axis.Y);
|
||||
}
|
||||
|
||||
private boolean inside(int x, int y, int z, double roughness, long seed) {
|
||||
double wobble = roughness <= 0 ? 0 : (PartNoise.hash(x, y, z, seed + 4201L) - 0.5) * roughness * 1.2;
|
||||
return edge(x - center[0], y - center[1], z - center[2]) <= 1 + wobble;
|
||||
}
|
||||
|
||||
/** Whether the outside lies within the shell's thickness, looking up and sideways, and down unless the shell is open. */
|
||||
private boolean nearSurface(int x, int y, int z, double roughness, long seed) {
|
||||
int thickness = Math.max(1, (int) Math.round(shell));
|
||||
int[][] directions = open ? OPEN_SHELL_DIRECTIONS : SHELL_DIRECTIONS;
|
||||
for (int step = 1; step <= thickness; step++) {
|
||||
for (int[] direction : directions) {
|
||||
if (!inside(x + direction[0] * step, y + direction[1] * step, z + direction[2] * step, roughness, seed)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** How far out a point is, where 1 is the surface; above 1 is outside. */
|
||||
private double edge(double dx, double dy, double dz) {
|
||||
double vertical = dy >= 0 ? dy / (up + 0.5) : dy / (down + 0.5);
|
||||
if (Math.abs(vertical) > 1) {
|
||||
return Double.MAX_VALUE;
|
||||
}
|
||||
double width = profile == null
|
||||
? Math.sqrt(1 - vertical * vertical)
|
||||
: Math.max(0, profile.at((dy + down + 0.5) / (up + down + 1)));
|
||||
if (width <= 0) {
|
||||
return Double.MAX_VALUE;
|
||||
}
|
||||
return Sections.norm(section, dx / radiusX, dz / radiusZ) / width;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PartSpot spotAt(double t) {
|
||||
double y = center[1] - down + Math.max(0, Math.min(1, t)) * (up + down);
|
||||
return new PartSpot(new double[]{center[0], y, center[2]}, Vectors.UP.clone(), t, up + down + 1, outward);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double length() {
|
||||
return up + down + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double defaultAt() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static double clampRadius(double radius) {
|
||||
return Math.max(0, Math.min(LARGEST_RADIUS_BLOCKS, radius));
|
||||
}
|
||||
|
||||
private static double sq(double value) {
|
||||
return value * value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.engine.procedural.part;
|
||||
|
||||
import art.arcane.iris.engine.procedural.IrisProceduralBlocks;
|
||||
import art.arcane.iris.modules.objects.ObjectBuilder;
|
||||
import com.volmit.block.PaletteSpec;
|
||||
import com.volmit.block.BlockState;
|
||||
|
||||
/** A block or a noise palette to take one from, optionally banded by height for strata. */
|
||||
record BlockChoice(String block, PaletteSpec palette, int bands) {
|
||||
/** The block at the position; null when neither block nor palette names one. */
|
||||
BlockState at(ObjectBuilder blocks, long seed, int x, int y, int z) {
|
||||
if (IrisProceduralBlocks.paletteSet(palette)) {
|
||||
if (bands > 0) {
|
||||
int band = Math.floorDiv(y, bands);
|
||||
return blocks.pick(palette, seed + band * 31L, x, band, z);
|
||||
}
|
||||
return blocks.pick(palette, seed, x, y, z);
|
||||
}
|
||||
if (block == null || block.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return blocks.block(block);
|
||||
}
|
||||
|
||||
boolean isSet() {
|
||||
return IrisProceduralBlocks.paletteSet(palette) || (block != null && !block.isEmpty());
|
||||
}
|
||||
}
|
||||
+14
-11
@@ -15,19 +15,22 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.modules.objects.coral;
|
||||
package art.arcane.iris.engine.procedural.part;
|
||||
|
||||
import com.volmit.config.Desc;
|
||||
|
||||
@Desc("How the arms of a BRANCHING coral are distributed around the central stalk by compass azimuth.")
|
||||
public enum CoralBranchAzimuth {
|
||||
@Desc("Distribute arms by the golden angle (about 137.5 degrees per arm) for a natural phyllotactic spiral where no two arms overlap.")
|
||||
GOLDEN_ANGLE,
|
||||
|
||||
@Desc("Distribute arms in evenly spaced spokes, dividing 360 degrees equally between them like a radial whorl.")
|
||||
@Desc("Which way around its parent each new branch points.")
|
||||
public enum BranchAzimuth {
|
||||
@Desc("Any direction.")
|
||||
RANDOM,
|
||||
@Desc("Each branch turns the golden angle (about 137.5 degrees) from the last, so none line up.")
|
||||
GOLDEN,
|
||||
@Desc("Each branch points opposite the last.")
|
||||
ALTERNATE,
|
||||
@Desc("Branches come in rings of 'whorl' evenly spaced branches.")
|
||||
WHORL,
|
||||
@Desc("All branches are spread evenly around the parent.")
|
||||
EVEN,
|
||||
|
||||
@Desc("Place each arm at a fully random azimuth using the deterministic per-variant RNG, for an irregular wild reef.")
|
||||
RANDOM
|
||||
@Desc("Branches fan out side by side around the parent's own direction, 'fan' degrees apart.")
|
||||
FAN
|
||||
}
|
||||
+11
-10
@@ -15,17 +15,18 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.modules.objects.tree;
|
||||
package art.arcane.iris.engine.procedural.part;
|
||||
|
||||
import com.volmit.config.Desc;
|
||||
|
||||
@Desc("How a procedural tree's root system is built below (and around) the trunk base.")
|
||||
public enum TreeRootStyle {
|
||||
@Desc("A single tapering taproot straight down from the base.")
|
||||
TAPROOT,
|
||||
@Desc("A taproot plus a ring of flared buttress legs that splay outward as they descend (default).")
|
||||
BUTTRESS,
|
||||
@Desc("Visible above-ground prop roots that arch out and down from the lower trunk to the ground (mangrove style).")
|
||||
STILT
|
||||
@Desc("How the parts of a cluster are laid out around its center.")
|
||||
public enum ClusterLayout {
|
||||
@Desc("Anywhere inside the radius.")
|
||||
RANDOM,
|
||||
@Desc("Evenly spaced on a circle of the radius.")
|
||||
RING,
|
||||
@Desc("In a row across the radius.")
|
||||
LINE,
|
||||
@Desc("A sunflower spiral filling the radius evenly.")
|
||||
GOLDEN
|
||||
}
|
||||
+16
-9
@@ -15,17 +15,24 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.modules.objects.ruin;
|
||||
package art.arcane.iris.engine.procedural.part;
|
||||
|
||||
import com.volmit.config.Desc;
|
||||
|
||||
@Desc("Where a ruin accent block is placed after the ruin has been built and eroded.")
|
||||
public enum RuinDecoratorTarget {
|
||||
@Desc("On top of the highest surviving block in each column (moss carpets, snow, sculk, lanterns on broken tops).")
|
||||
@Desc("Where a decoration is placed on the object.")
|
||||
public enum DecorationSpot {
|
||||
@Desc("On every block that is open above.")
|
||||
ABOVE,
|
||||
@Desc("Under every block that is open below; set length for hanging strands.")
|
||||
BELOW,
|
||||
@Desc("Against every open horizontal side.")
|
||||
SIDE,
|
||||
@Desc("On the highest block of each column.")
|
||||
TOP,
|
||||
@Desc("On air-facing vertical sides of any surviving block (vines, glow lichen, climbing growth on the ruin faces).")
|
||||
SURFACE,
|
||||
@Desc("Scattered across the ground footprint around the y=0 base ring, wider than the structure itself (loose rubble, mushrooms, grass tufts ringing the ruin).")
|
||||
BASE_SCATTER
|
||||
@Desc("Under the lowest block of each column; set length for hanging strands.")
|
||||
BOTTOM,
|
||||
@Desc("Just past the end of every stem.")
|
||||
TIPS,
|
||||
@Desc("On the ground around where the object stands, out to the radius.")
|
||||
GROUND
|
||||
}
|
||||
@@ -0,0 +1,271 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.engine.procedural.part;
|
||||
|
||||
import art.arcane.iris.engine.procedural.IrisProceduralBlocks;
|
||||
import art.arcane.iris.modules.objects.ObjectBuilder;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.block.BlockTrait;
|
||||
import com.volmit.geometry.BlockFace;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
/**
|
||||
* Places decorations against the painted object. A decoration attaches to the block it rests on: vines and lichen
|
||||
* grow toward it, directional blocks face away from it and lanterns hang under it.
|
||||
*/
|
||||
final class Decorator {
|
||||
private static final long DECORATION_SEED_STRIDE = 911L;
|
||||
private static final BlockFace[] SIDES = {BlockFace.EAST, BlockFace.WEST, BlockFace.SOUTH, BlockFace.NORTH};
|
||||
|
||||
private final PartCanvas canvas;
|
||||
private final Map<Long, BlockState> painted;
|
||||
private final ObjectBuilder blocks;
|
||||
private final long paletteSeed;
|
||||
private final int groundY;
|
||||
|
||||
/** @param groundY the lowest height above the terrain; anything below it ends up buried, so nothing decorates there */
|
||||
Decorator(PartCanvas canvas, Map<Long, BlockState> painted, ObjectBuilder blocks, long paletteSeed, int groundY) {
|
||||
this.canvas = canvas;
|
||||
this.painted = painted;
|
||||
this.blocks = blocks;
|
||||
this.paletteSeed = paletteSeed;
|
||||
this.groundY = groundY;
|
||||
}
|
||||
|
||||
void decorate(List<ProceduralDecoration> decorations, long seed) {
|
||||
for (int index = 0; index < decorations.size(); index++) {
|
||||
ProceduralDecoration decoration = decorations.get(index);
|
||||
if (!decoration.choice().isSet()) {
|
||||
continue;
|
||||
}
|
||||
long decorationSeed = seed + index * DECORATION_SEED_STRIDE;
|
||||
RNG rng = new RNG(decorationSeed);
|
||||
for (Spot spot : spots(decoration, rng)) {
|
||||
if (spot.y() >= groundY && PartNoise.passes(decoration.pattern(), decoration.chance(), decoration.scale(), spot.x(), spot.y(), spot.z(), decorationSeed)) {
|
||||
place(decoration, spot, rng);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void place(ProceduralDecoration decoration, Spot spot, RNG rng) {
|
||||
boolean hangs = decoration.at() == DecorationSpot.BELOW || decoration.at() == DecorationSpot.BOTTOM;
|
||||
int strand = hangs ? Math.max(1, (int) Math.round(decoration.length().sample(rng, 0))) : 1;
|
||||
for (int step = 0; step < strand; step++) {
|
||||
int y = spot.y() - step;
|
||||
long key = PartCanvas.key(spot.x(), y, spot.z());
|
||||
if (y < groundY || painted.containsKey(key)) {
|
||||
return;
|
||||
}
|
||||
BlockState state = decoration.choice().at(blocks, paletteSeed, spot.x(), y, spot.z());
|
||||
if (state == null || blocks.has(state, BlockTrait.AIR)) {
|
||||
return;
|
||||
}
|
||||
painted.put(key, attached(state, spot.support()));
|
||||
}
|
||||
}
|
||||
|
||||
private List<Spot> spots(ProceduralDecoration decoration, RNG rng) {
|
||||
List<Long> decorated = decoratedBlocks(decoration);
|
||||
return switch (decoration.at()) {
|
||||
case ABOVE -> besideEach(decorated, BlockFace.UP);
|
||||
case BELOW -> besideEach(decorated, BlockFace.DOWN);
|
||||
case SIDE -> besideEach(decorated, SIDES);
|
||||
case TOP -> columnEnds(decorated, true);
|
||||
case BOTTOM -> columnEnds(decorated, false);
|
||||
case TIPS -> tips(decoration);
|
||||
case GROUND -> ground(decoration.radius().sample(rng, 0));
|
||||
};
|
||||
}
|
||||
|
||||
/** The painted blocks of the roles the decoration is for, in a stable order. */
|
||||
private List<Long> decoratedBlocks(ProceduralDecoration decoration) {
|
||||
Set<Integer> roles = new HashSet<>();
|
||||
for (String role : decoration.on()) {
|
||||
roles.add(canvas.role(role));
|
||||
}
|
||||
List<Long> decorated = new ArrayList<>();
|
||||
for (long key : painted.keySet()) {
|
||||
PartCanvas.Cell cell = canvas.get(key);
|
||||
if (cell != null && (roles.isEmpty() || roles.contains(cell.role()))) {
|
||||
decorated.add(key);
|
||||
}
|
||||
}
|
||||
decorated.sort(Long::compare);
|
||||
return decorated;
|
||||
}
|
||||
|
||||
private List<Spot> besideEach(List<Long> decorated, BlockFace... faces) {
|
||||
List<Spot> spots = new ArrayList<>();
|
||||
Set<Long> taken = new HashSet<>();
|
||||
for (long key : decorated) {
|
||||
for (BlockFace face : faces) {
|
||||
int[] step = stepToward(face);
|
||||
int x = PartCanvas.x(key) + step[0];
|
||||
int y = PartCanvas.y(key) + step[1];
|
||||
int z = PartCanvas.z(key) + step[2];
|
||||
long spotKey = PartCanvas.key(x, y, z);
|
||||
if (!painted.containsKey(spotKey) && taken.add(spotKey)) {
|
||||
spots.add(new Spot(x, y, z, opposite(face)));
|
||||
}
|
||||
}
|
||||
}
|
||||
return spots;
|
||||
}
|
||||
|
||||
private List<Spot> columnEnds(List<Long> decorated, boolean top) {
|
||||
Map<Long, Integer> endByColumn = new HashMap<>();
|
||||
for (long key : decorated) {
|
||||
long column = PartCanvas.key(PartCanvas.x(key), 0, PartCanvas.z(key));
|
||||
int y = PartCanvas.y(key);
|
||||
endByColumn.merge(column, y, top ? Math::max : Math::min);
|
||||
}
|
||||
List<Spot> spots = new ArrayList<>();
|
||||
endByColumn.entrySet().stream().sorted(Map.Entry.comparingByKey()).forEach(entry -> {
|
||||
int x = PartCanvas.x(entry.getKey());
|
||||
int z = PartCanvas.z(entry.getKey());
|
||||
int y = entry.getValue() + (top ? 1 : -1);
|
||||
if (!painted.containsKey(PartCanvas.key(x, y, z))) {
|
||||
spots.add(new Spot(x, y, z, top ? BlockFace.DOWN : BlockFace.UP));
|
||||
}
|
||||
});
|
||||
return spots;
|
||||
}
|
||||
|
||||
private List<Spot> tips(ProceduralDecoration decoration) {
|
||||
Set<Integer> roles = new HashSet<>();
|
||||
for (String role : decoration.on()) {
|
||||
roles.add(canvas.role(role));
|
||||
}
|
||||
List<Spot> spots = new ArrayList<>();
|
||||
for (PartCanvas.Tip tip : canvas.tips()) {
|
||||
if (!roles.isEmpty() && !roles.contains(tip.role())) {
|
||||
continue;
|
||||
}
|
||||
int x = tip.x() + (int) Math.round(tip.heading()[0]);
|
||||
int y = tip.y() + (int) Math.round(tip.heading()[1]);
|
||||
int z = tip.z() + (int) Math.round(tip.heading()[2]);
|
||||
if (!painted.containsKey(PartCanvas.key(x, y, z))) {
|
||||
spots.add(new Spot(x, y, z, supportToward(tip.x() - x, tip.y() - y, tip.z() - z)));
|
||||
}
|
||||
}
|
||||
return spots;
|
||||
}
|
||||
|
||||
/** Every open ground spot within the radius of where the object stands, so an arch gets plants around both feet. */
|
||||
private List<Spot> ground(double radius) {
|
||||
int reach = (int) Math.ceil(radius);
|
||||
Set<Long> nearby = new TreeSet<>();
|
||||
for (long foot : footprint()) {
|
||||
int footX = PartCanvas.x(foot);
|
||||
int footZ = PartCanvas.z(foot);
|
||||
for (int x = footX - reach; x <= footX + reach; x++) {
|
||||
for (int z = footZ - reach; z <= footZ + reach; z++) {
|
||||
if (Math.hypot(x - footX, z - footZ) <= radius) {
|
||||
nearby.add(PartCanvas.key(x, groundY, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
List<Spot> spots = new ArrayList<>();
|
||||
for (long key : nearby) {
|
||||
int x = PartCanvas.x(key);
|
||||
int z = PartCanvas.z(key);
|
||||
if (!painted.containsKey(key) && !painted.containsKey(PartCanvas.key(x, groundY + 1, z))) {
|
||||
spots.add(new Spot(x, groundY, z, BlockFace.DOWN));
|
||||
}
|
||||
}
|
||||
return spots;
|
||||
}
|
||||
|
||||
/** The columns where the object meets the ground, or its origin if it does not reach the ground. */
|
||||
private Set<Long> footprint() {
|
||||
Set<Long> footprint = new TreeSet<>();
|
||||
for (long key : painted.keySet()) {
|
||||
if (PartCanvas.y(key) == groundY) {
|
||||
footprint.add(PartCanvas.key(PartCanvas.x(key), groundY, PartCanvas.z(key)));
|
||||
}
|
||||
}
|
||||
if (footprint.isEmpty()) {
|
||||
footprint.add(PartCanvas.key(0, groundY, 0));
|
||||
}
|
||||
return footprint;
|
||||
}
|
||||
|
||||
private static BlockFace supportToward(int dx, int dy, int dz) {
|
||||
if (dy > 0) {
|
||||
return BlockFace.UP;
|
||||
}
|
||||
if (dy < 0) {
|
||||
return BlockFace.DOWN;
|
||||
}
|
||||
if (Math.abs(dx) >= Math.abs(dz)) {
|
||||
return dx >= 0 ? BlockFace.EAST : BlockFace.WEST;
|
||||
}
|
||||
return dz >= 0 ? BlockFace.SOUTH : BlockFace.NORTH;
|
||||
}
|
||||
|
||||
/** {@code state} turned to rest on the block toward {@code support}. */
|
||||
private BlockState attached(BlockState state, BlockFace support) {
|
||||
String side = support.name().toLowerCase();
|
||||
if ("false".equals(IrisProceduralBlocks.propertyValue(state, side))) {
|
||||
return blocks.withProperty(state, side, "true");
|
||||
}
|
||||
if (support == BlockFace.UP && IrisProceduralBlocks.hasProperty(state, "hanging")) {
|
||||
return blocks.withProperty(state, "hanging", "true");
|
||||
}
|
||||
if (IrisProceduralBlocks.hasProperty(state, "facing")) {
|
||||
return blocks.withProperty(state, "facing", opposite(support).name().toLowerCase());
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
private static int[] stepToward(BlockFace face) {
|
||||
return switch (face) {
|
||||
case UP -> new int[]{0, 1, 0};
|
||||
case DOWN -> new int[]{0, -1, 0};
|
||||
case NORTH -> new int[]{0, 0, -1};
|
||||
case SOUTH -> new int[]{0, 0, 1};
|
||||
case EAST -> new int[]{1, 0, 0};
|
||||
case WEST -> new int[]{-1, 0, 0};
|
||||
};
|
||||
}
|
||||
|
||||
private static BlockFace opposite(BlockFace face) {
|
||||
return switch (face) {
|
||||
case UP -> BlockFace.DOWN;
|
||||
case DOWN -> BlockFace.UP;
|
||||
case NORTH -> BlockFace.SOUTH;
|
||||
case SOUTH -> BlockFace.NORTH;
|
||||
case EAST -> BlockFace.WEST;
|
||||
case WEST -> BlockFace.EAST;
|
||||
};
|
||||
}
|
||||
|
||||
/** An empty block a decoration may go in, and the side its support is on. */
|
||||
private record Spot(int x, int y, int z, BlockFace support) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.procedural.part;
|
||||
|
||||
import art.arcane.iris.engine.procedural.IrisProceduralBlocks;
|
||||
import art.arcane.iris.modules.objects.ObjectBuilder;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.block.BlockTrait;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Gives leaves the state vanilla decay expects: every leaf is told its distance to wood. Leaves farther from wood than
|
||||
* vanilla keeps are made persistent, so they stay; the pack's parts should keep wood near them instead.
|
||||
*/
|
||||
final class LeafDecay {
|
||||
private static final int UNREACHED_DISTANCE = IrisProceduralBlocks.UNREACHED_LEAF_DISTANCE;
|
||||
private static final int[][] NEIGHBORS = {{1, 0, 0}, {-1, 0, 0}, {0, 1, 0}, {0, -1, 0}, {0, 0, 1}, {0, 0, -1}};
|
||||
|
||||
private final Map<Long, BlockState> blocks;
|
||||
private final ObjectBuilder builder;
|
||||
private final Set<Long> leaves = new LinkedHashSet<>();
|
||||
|
||||
private LeafDecay(Map<Long, BlockState> blocks, ObjectBuilder builder) {
|
||||
this.blocks = blocks;
|
||||
this.builder = builder;
|
||||
List<Long> keys = new ArrayList<>(blocks.keySet());
|
||||
keys.sort(Long::compare);
|
||||
for (long key : keys) {
|
||||
if (isLeaf(blocks.get(key))) {
|
||||
leaves.add(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Leaves that decay naturally, except those too far from wood, which are kept persistent. */
|
||||
static void supportLeaves(Map<Long, BlockState> blocks, ObjectBuilder builder) {
|
||||
LeafDecay decay = new LeafDecay(blocks, builder);
|
||||
if (decay.leaves.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
decay.markDistances();
|
||||
}
|
||||
|
||||
/** Leaves that never decay. */
|
||||
static void persistLeaves(Map<Long, BlockState> blocks, ObjectBuilder builder) {
|
||||
LeafDecay decay = new LeafDecay(blocks, builder);
|
||||
for (long leaf : decay.leaves) {
|
||||
decay.setLeafState(leaf, true, 1);
|
||||
}
|
||||
}
|
||||
|
||||
private void markDistances() {
|
||||
Map<Long, Integer> distance = distances();
|
||||
for (long leaf : leaves) {
|
||||
Integer d = distance.get(leaf);
|
||||
if (d != null && d < UNREACHED_DISTANCE) {
|
||||
setLeafState(leaf, false, Math.max(1, d));
|
||||
} else {
|
||||
setLeafState(leaf, true, UNREACHED_DISTANCE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** How many leaf steps each leaf is from wood, up to the farthest vanilla tracks. */
|
||||
private Map<Long, Integer> distances() {
|
||||
Map<Long, Integer> distance = new HashMap<>();
|
||||
ArrayDeque<Long> queue = new ArrayDeque<>();
|
||||
for (long leaf : leaves) {
|
||||
for (int[] n : NEIGHBORS) {
|
||||
BlockState neighbor = blocks.get(PartCanvas.key(PartCanvas.x(leaf) + n[0], PartCanvas.y(leaf) + n[1], PartCanvas.z(leaf) + n[2]));
|
||||
if (neighbor != null && builder.has(neighbor, BlockTrait.LOG)) {
|
||||
distance.put(leaf, 1);
|
||||
queue.add(leaf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
while (!queue.isEmpty()) {
|
||||
long leaf = queue.poll();
|
||||
int d = distance.get(leaf);
|
||||
if (d >= UNREACHED_DISTANCE) {
|
||||
continue;
|
||||
}
|
||||
for (int[] n : NEIGHBORS) {
|
||||
long next = PartCanvas.key(PartCanvas.x(leaf) + n[0], PartCanvas.y(leaf) + n[1], PartCanvas.z(leaf) + n[2]);
|
||||
BlockState state = blocks.get(next);
|
||||
if (state == null || !isLeaf(state)) {
|
||||
continue;
|
||||
}
|
||||
Integer known = distance.get(next);
|
||||
if (known == null || known > d + 1) {
|
||||
distance.put(next, d + 1);
|
||||
queue.add(next);
|
||||
}
|
||||
}
|
||||
}
|
||||
return distance;
|
||||
}
|
||||
|
||||
private void setLeafState(long leaf, boolean persistent, int distance) {
|
||||
BlockState state = blocks.get(leaf);
|
||||
state = builder.withProperty(state, "persistent", String.valueOf(persistent));
|
||||
blocks.put(leaf, builder.withProperty(state, "distance", String.valueOf(distance)));
|
||||
}
|
||||
|
||||
private static boolean isLeaf(BlockState state) {
|
||||
return IrisProceduralBlocks.hasProperty(state, "persistent") && IrisProceduralBlocks.hasProperty(state, "distance");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.engine.procedural.part;
|
||||
|
||||
import art.arcane.iris.engine.procedural.IrisProceduralBlocks;
|
||||
import art.arcane.iris.modules.objects.ObjectBuilder;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.block.BlockTrait;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/** Turns the canvas into block data: each block takes its role's material, or the first of its rules that applies. */
|
||||
final class MaterialPainter {
|
||||
private static final long RULE_SEED_STRIDE = 7907L;
|
||||
private static final int[][] SIDES = {{1, 0, 0}, {-1, 0, 0}, {0, 0, 1}, {0, 0, -1}};
|
||||
|
||||
private final PartCanvas canvas;
|
||||
private final Map<Integer, ProceduralMaterial> materialByRole = new HashMap<>();
|
||||
private final ProceduralMaterial fallback;
|
||||
private final ObjectBuilder blocks;
|
||||
private final long paletteSeed;
|
||||
private final long ruleSeed;
|
||||
private final int lowestY;
|
||||
private final int heightSpan;
|
||||
|
||||
MaterialPainter(PartCanvas canvas, List<ProceduralMaterial> materials, ObjectBuilder blocks, long paletteSeed, long ruleSeed) {
|
||||
this.canvas = canvas;
|
||||
this.blocks = blocks;
|
||||
this.paletteSeed = paletteSeed;
|
||||
this.ruleSeed = ruleSeed;
|
||||
this.fallback = materials.isEmpty() ? null : materials.getFirst();
|
||||
for (ProceduralMaterial material : materials) {
|
||||
materialByRole.putIfAbsent(canvas.role(material.role()), material);
|
||||
}
|
||||
int lowest = Integer.MAX_VALUE;
|
||||
int highest = Integer.MIN_VALUE;
|
||||
for (long key : canvas.cells().keySet()) {
|
||||
lowest = Math.min(lowest, PartCanvas.y(key));
|
||||
highest = Math.max(highest, PartCanvas.y(key));
|
||||
}
|
||||
this.lowestY = lowest;
|
||||
this.heightSpan = Math.max(1, highest - lowest);
|
||||
}
|
||||
|
||||
/** The block of every claimed position, leaving out those a rule turned to air. */
|
||||
Map<Long, BlockState> paint() {
|
||||
Map<Long, BlockState> painted = new HashMap<>();
|
||||
for (Map.Entry<Long, PartCanvas.Cell> entry : canvas.cells().entrySet()) {
|
||||
BlockState state = blockFor(entry.getKey(), entry.getValue());
|
||||
if (state != null && !blocks.has(state, BlockTrait.AIR)) {
|
||||
painted.put(entry.getKey(), state);
|
||||
}
|
||||
}
|
||||
return painted;
|
||||
}
|
||||
|
||||
private BlockState blockFor(long key, PartCanvas.Cell cell) {
|
||||
ProceduralMaterial material = materialByRole.getOrDefault(cell.role(), fallback);
|
||||
if (material == null) {
|
||||
return null;
|
||||
}
|
||||
int x = PartCanvas.x(key);
|
||||
int y = PartCanvas.y(key);
|
||||
int z = PartCanvas.z(key);
|
||||
BlockChoice choice = material.choice();
|
||||
List<MaterialRule> rules = material.rules();
|
||||
for (int index = 0; index < rules.size(); index++) {
|
||||
if (applies(rules.get(index), index, x, y, z, cell)) {
|
||||
choice = rules.get(index).choice();
|
||||
break;
|
||||
}
|
||||
}
|
||||
BlockState state = choice.at(blocks, paletteSeed, x, y, z);
|
||||
if (state == null || blocks.has(state, BlockTrait.AIR)) {
|
||||
return state;
|
||||
}
|
||||
return alignedToAxis(state, cell.axis());
|
||||
}
|
||||
|
||||
private boolean applies(MaterialRule rule, int index, int x, int y, int z, PartCanvas.Cell cell) {
|
||||
double height = (y - lowestY) / (double) heightSpan;
|
||||
if (rule.height() != null && !rule.height().contains(height)) {
|
||||
return false;
|
||||
}
|
||||
if (rule.along() != null && !rule.along().contains(cell.along())) {
|
||||
return false;
|
||||
}
|
||||
if (rule.face() != null && !open(rule.face(), x, y, z)) {
|
||||
return false;
|
||||
}
|
||||
return PartNoise.passes(rule.pattern(), rule.chance().at(height), rule.scale(), x, y, z, ruleSeed + index * RULE_SEED_STRIDE);
|
||||
}
|
||||
|
||||
private boolean open(RuleFace face, int x, int y, int z) {
|
||||
return switch (face) {
|
||||
case UP -> !canvas.has(x, y + 1, z);
|
||||
case DOWN -> !canvas.has(x, y - 1, z);
|
||||
case SIDE -> openSide(x, y, z);
|
||||
case ANY -> openSide(x, y, z) || !canvas.has(x, y + 1, z) || !canvas.has(x, y - 1, z);
|
||||
};
|
||||
}
|
||||
|
||||
private boolean openSide(int x, int y, int z) {
|
||||
for (int[] side : SIDES) {
|
||||
if (!canvas.has(x + side[0], y, z + side[2])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private BlockState alignedToAxis(BlockState state, PartCanvas.Axis axis) {
|
||||
if (axis == PartCanvas.Axis.NONE || !IrisProceduralBlocks.hasProperty(state, "axis")) {
|
||||
return state;
|
||||
}
|
||||
return blocks.withProperty(state, "axis", axis.name().toLowerCase());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.engine.procedural.part;
|
||||
|
||||
import com.volmit.block.PaletteSpec;
|
||||
import com.volmit.config.Desc;
|
||||
import com.volmit.config.MinNumber;
|
||||
import com.volmit.config.Ref;
|
||||
import com.volmit.config.Reference;
|
||||
|
||||
@Desc("Swaps a material's block where its conditions hold, such as moss on top faces or a cap on the highest blocks. Use minecraft:air to erode blocks away.")
|
||||
public final class MaterialRule {
|
||||
@Ref(Reference.BLOCK)
|
||||
@Desc("The block to swap in. Ignored when palette is set.")
|
||||
private String block;
|
||||
|
||||
@Desc("A noise palette to swap in.")
|
||||
private PaletteSpec palette;
|
||||
|
||||
@MinNumber(0)
|
||||
@Desc("If above 0, the palette changes every this many blocks of height, for strata.")
|
||||
private int bands = 0;
|
||||
|
||||
@Desc("The chance a block that meets the conditions is swapped. A curve runs from the bottom (0) to the top (1) of the object.")
|
||||
private ProceduralValue chance = ProceduralValue.constant(1);
|
||||
|
||||
@Desc("How the chance is spread over the blocks.")
|
||||
private PartPattern pattern = PartPattern.RANDOM;
|
||||
|
||||
@MinNumber(1)
|
||||
@Desc("The size of the patches in blocks for the PATCHES pattern.")
|
||||
private double scale = 3;
|
||||
|
||||
@Desc("Only swaps blocks within this stretch of the object's height, from the bottom (0) to the top (1).")
|
||||
private ProceduralSpan height;
|
||||
|
||||
@Desc("Only swaps blocks within this stretch of their own part, from its base (0) to its tip (1).")
|
||||
private ProceduralSpan along;
|
||||
|
||||
@Desc("Only swaps blocks open to the air on this side.")
|
||||
private RuleFace face;
|
||||
|
||||
public BlockChoice choice() {
|
||||
return new BlockChoice(block, palette, bands);
|
||||
}
|
||||
|
||||
public ProceduralValue chance() {
|
||||
return chance == null ? ProceduralValue.constant(1) : chance;
|
||||
}
|
||||
|
||||
public PartPattern pattern() {
|
||||
return pattern == null ? PartPattern.RANDOM : pattern;
|
||||
}
|
||||
|
||||
public double scale() {
|
||||
return scale;
|
||||
}
|
||||
|
||||
public ProceduralSpan height() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public ProceduralSpan along() {
|
||||
return along;
|
||||
}
|
||||
|
||||
public RuleFace face() {
|
||||
return face;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.engine.procedural.part;
|
||||
|
||||
import art.arcane.iris.engine.procedural.BakeProfile;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
import art.arcane.iris.engine.procedural.IrisProceduralBlocks;
|
||||
import art.arcane.iris.modules.objects.ObjectBuilder;
|
||||
import art.arcane.iris.engine.procedural.ProceduralShape;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
import com.volmit.block.BlockState;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/** Bakes one variant of a procedural object: grows its parts, paints them, decorates them and settles the leaves. */
|
||||
final class ObjectBaker {
|
||||
private static final long DECORATION_SEED_SALT = 77777L;
|
||||
private static final long RULE_SEED_SALT = 4111L;
|
||||
|
||||
private ObjectBaker() {
|
||||
}
|
||||
|
||||
static ProceduralShape bake(ProceduralObject definition, PartOutline outline, RNG rng, ObjectBuilder blocks, BakeProfile profile) {
|
||||
BakedBlocks baked = bakeBlocks(definition, outline, rng, blocks, profile);
|
||||
return baked == null ? null : IrisProceduralBlocks.assemble(baked.placed());
|
||||
}
|
||||
|
||||
/** Bakes the variant {@code rng} draws, the same as {@link #bake}, and tells which part placed each of its blocks. */
|
||||
static PartTrace trace(ProceduralObject definition, PartOutline outline, RNG rng, ObjectBuilder blocks) {
|
||||
BakedBlocks baked = bakeBlocks(definition, outline, rng, blocks, BakeProfile.NONE);
|
||||
if (baked == null) {
|
||||
return PartTrace.EMPTY;
|
||||
}
|
||||
IrisProceduralBlocks.Anchor anchor = IrisProceduralBlocks.Anchor.of(baked.placed().keySet());
|
||||
Map<Long, Integer> partsByBlock = new HashMap<>();
|
||||
for (long key : baked.painted().keySet()) {
|
||||
PartCanvas.Cell cell = baked.canvas().get(key);
|
||||
if (cell == null) {
|
||||
continue;
|
||||
}
|
||||
BlockPosition position = anchor.place(baked.sunkPosition(key));
|
||||
partsByBlock.put(PartCanvas.key(position.x(), position.y(), position.z()), cell.part());
|
||||
}
|
||||
return new PartTrace(partsByBlock);
|
||||
}
|
||||
|
||||
private static BakedBlocks bakeBlocks(ProceduralObject definition, PartOutline outline, RNG rng, ObjectBuilder blocks,
|
||||
BakeProfile profile) {
|
||||
PartCanvas canvas = new PartCanvas();
|
||||
long variantSeed = rng.nextLong();
|
||||
new PartGrower(canvas, definition.defaultRole(), outline).growRoots(definition.parts(), variantSeed);
|
||||
profile.lap(BakeProfile.Stage.PARTS);
|
||||
if (canvas.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Map<Long, BlockState> painted = new MaterialPainter(canvas, definition.materials(), blocks, definition.seed(),
|
||||
variantSeed + RULE_SEED_SALT).paint();
|
||||
int sinkDepth = sinkDepth(painted, definition.sink());
|
||||
profile.lap(BakeProfile.Stage.PAINT);
|
||||
new Decorator(canvas, painted, blocks, definition.seed(), sinkDepth).decorate(definition.decorations(), variantSeed + DECORATION_SEED_SALT);
|
||||
profile.lap(BakeProfile.Stage.DECORATE);
|
||||
if (definition.leafDecay()) {
|
||||
LeafDecay.supportLeaves(painted, blocks);
|
||||
} else {
|
||||
LeafDecay.persistLeaves(painted, blocks);
|
||||
}
|
||||
if (definition.waterlogged()) {
|
||||
waterlog(painted, blocks);
|
||||
}
|
||||
profile.lap(BakeProfile.Stage.LEAVES);
|
||||
return new BakedBlocks(canvas, painted, sinkDepth);
|
||||
}
|
||||
|
||||
private static void waterlog(Map<Long, BlockState> painted, ObjectBuilder blocks) {
|
||||
painted.replaceAll((key, state) -> "false".equals(IrisProceduralBlocks.propertyValue(state, "waterlogged"))
|
||||
? blocks.withProperty(state, "waterlogged", "true") : state);
|
||||
}
|
||||
|
||||
/** How far the object sinks: a fraction of its height. Heights below it end up underground. */
|
||||
private static int sinkDepth(Map<Long, BlockState> painted, double sink) {
|
||||
int lowest = Integer.MAX_VALUE;
|
||||
int highest = Integer.MIN_VALUE;
|
||||
for (long key : painted.keySet()) {
|
||||
lowest = Math.min(lowest, PartCanvas.y(key));
|
||||
highest = Math.max(highest, PartCanvas.y(key));
|
||||
}
|
||||
return (int) Math.round(Math.max(0, Math.min(1, sink)) * (highest - lowest + 1));
|
||||
}
|
||||
|
||||
/** A variant's blocks before they are anchored: the parts' canvas, the painted blocks and how far they sink. */
|
||||
private record BakedBlocks(PartCanvas canvas, Map<Long, BlockState> painted, int sinkDepth) {
|
||||
Map<Vector3i, BlockState> placed() {
|
||||
Map<Vector3i, BlockState> placed = new HashMap<>();
|
||||
painted.forEach((key, state) -> placed.put(sunkPosition(key), state));
|
||||
return placed;
|
||||
}
|
||||
|
||||
Vector3i sunkPosition(long key) {
|
||||
return new Vector3i(PartCanvas.x(key), PartCanvas.y(key) - sinkDepth, PartCanvas.z(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.engine.procedural.part;
|
||||
|
||||
import com.volmit.config.Desc;
|
||||
import com.volmit.config.MaxNumber;
|
||||
import com.volmit.config.MinNumber;
|
||||
|
||||
@Desc("A rounded volume centered where the part sits: a leaf crown, boulder, cap, coral head or base. Values given as a curve run over where the blob sits on its parent.")
|
||||
public final class PartBlob {
|
||||
@Desc("The horizontal radius in blocks.")
|
||||
private ProceduralValue radius = ProceduralValue.constant(2);
|
||||
|
||||
@Desc("How far the blob reaches above its center, in blocks. Unset, it matches the radius.")
|
||||
private ProceduralValue height;
|
||||
|
||||
@Desc("How far the blob reaches below its center, in blocks. Unset, it matches the height; 0 makes a dome.")
|
||||
private ProceduralValue depth;
|
||||
|
||||
@MinNumber(0)
|
||||
@Desc("Stretches the blob along east-west; 0.1 flattens it into a north-south fan.")
|
||||
private double stretchX = 1;
|
||||
|
||||
@MinNumber(0)
|
||||
@Desc("Stretches the blob along north-south; 0.1 flattens it into an east-west fan.")
|
||||
private double stretchZ = 1;
|
||||
|
||||
@Desc("A multiplier on the radius from the bottom (0) to the top (1) of the blob. Unset, the blob is an ellipsoid; [[0, 1], [1, 0]] makes a cone, [[0, 1], [1, 1]] a cylinder.")
|
||||
private ProceduralValue profile;
|
||||
|
||||
@Desc("The horizontal cross-section of the blob.")
|
||||
private PartSection section = PartSection.ROUND;
|
||||
|
||||
@Desc("If above 0, the blob is hollow, keeping only the blocks this many blocks or fewer from its surface.")
|
||||
private ProceduralValue shell = ProceduralValue.constant(0);
|
||||
|
||||
@Desc("If true the shell has no floor: only the surface above and around counts, like a mushroom cap.")
|
||||
private boolean open = false;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Desc("How lumpy the surface is, from 0 (smooth) to 1 (very lumpy).")
|
||||
private double roughness = 0;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Desc("How many blocks along the surface are knocked off at random, from 0 to 1.")
|
||||
private double jitter = 0;
|
||||
|
||||
public ProceduralValue radius() {
|
||||
return radius == null ? ProceduralValue.constant(2) : radius;
|
||||
}
|
||||
|
||||
public ProceduralValue height() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public ProceduralValue depth() {
|
||||
return depth;
|
||||
}
|
||||
|
||||
public double stretchX() {
|
||||
return stretchX;
|
||||
}
|
||||
|
||||
public double stretchZ() {
|
||||
return stretchZ;
|
||||
}
|
||||
|
||||
public ProceduralValue profile() {
|
||||
return profile;
|
||||
}
|
||||
|
||||
public PartSection section() {
|
||||
return section == null ? PartSection.ROUND : section;
|
||||
}
|
||||
|
||||
public ProceduralValue shell() {
|
||||
return shell == null ? ProceduralValue.constant(0) : shell;
|
||||
}
|
||||
|
||||
public boolean open() {
|
||||
return open;
|
||||
}
|
||||
|
||||
public double roughness() {
|
||||
return roughness;
|
||||
}
|
||||
|
||||
public double jitter() {
|
||||
return jitter;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.engine.procedural.part;
|
||||
|
||||
import com.volmit.config.Desc;
|
||||
import com.volmit.config.MaxNumber;
|
||||
import com.volmit.config.MinNumber;
|
||||
import com.volmit.config.Required;
|
||||
|
||||
@Desc("Grows copies of a part out of its parent: branches off a trunk, arms off a coral stalk, forks at a tip. Values given as a curve run from the parent's base (0) to its tip (1).")
|
||||
public final class PartBranches {
|
||||
@Desc("How many copies grow. Ignored when chance is set.")
|
||||
private ProceduralValue count = ProceduralValue.constant(4);
|
||||
|
||||
@Desc("If set, every block along the parent rolls this chance to grow a copy, such as {\"shape\": \"power\", \"exponent\": 2} for more toward the top.")
|
||||
private ProceduralValue chance;
|
||||
|
||||
@Desc("The stretch of the parent copies grow from; from 1 to 1 grows them all at the tip.")
|
||||
private ProceduralSpan along = new ProceduralSpan();
|
||||
|
||||
@Desc("Which way around the parent each copy points.")
|
||||
private BranchAzimuth azimuth = BranchAzimuth.RANDOM;
|
||||
|
||||
@Desc("Turns every copy this many degrees further around the parent.")
|
||||
private ProceduralValue azimuthOffset = ProceduralValue.constant(0);
|
||||
|
||||
@MinNumber(1)
|
||||
@Desc("How many copies make a ring for the WHORL azimuth.")
|
||||
private int whorl = 4;
|
||||
|
||||
@Desc("The degrees between copies for the FAN azimuth.")
|
||||
private double fan = 40;
|
||||
|
||||
@Desc("The angle in degrees above the horizon each copy grows toward; negative droops. With relative set, the angle is added to the parent's own.")
|
||||
private ProceduralValue pitch = ProceduralValue.constant(0);
|
||||
|
||||
@Desc("If true the copies point relative to the parent's direction instead of the compass, as forks and twigs do.")
|
||||
private boolean relative = false;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(6)
|
||||
@Desc("How many times branching repeats: 2 grows copies off the copies too, and so on.")
|
||||
private int depth = 1;
|
||||
|
||||
@Required
|
||||
@Desc("The part each copy is made of.")
|
||||
private ProceduralPart part;
|
||||
|
||||
public ProceduralValue count() {
|
||||
return count == null ? ProceduralValue.constant(4) : count;
|
||||
}
|
||||
|
||||
public ProceduralValue chance() {
|
||||
return chance;
|
||||
}
|
||||
|
||||
public ProceduralSpan along() {
|
||||
return along == null ? new ProceduralSpan() : along;
|
||||
}
|
||||
|
||||
public BranchAzimuth azimuth() {
|
||||
return azimuth == null ? BranchAzimuth.RANDOM : azimuth;
|
||||
}
|
||||
|
||||
public ProceduralValue azimuthOffset() {
|
||||
return azimuthOffset == null ? ProceduralValue.constant(0) : azimuthOffset;
|
||||
}
|
||||
|
||||
public int whorl() {
|
||||
return Math.max(1, whorl);
|
||||
}
|
||||
|
||||
public double fan() {
|
||||
return fan;
|
||||
}
|
||||
|
||||
public ProceduralValue pitch() {
|
||||
return pitch == null ? ProceduralValue.constant(0) : pitch;
|
||||
}
|
||||
|
||||
public boolean relative() {
|
||||
return relative;
|
||||
}
|
||||
|
||||
public int depth() {
|
||||
return Math.max(1, Math.min(6, depth));
|
||||
}
|
||||
|
||||
public ProceduralPart part() {
|
||||
return part;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.engine.procedural.part;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The blocks the parts of one variant claim, before materials turn them into block data: each with the role of the
|
||||
* part that placed it, how far along that part it sits, and the axis a log there would follow.
|
||||
*/
|
||||
final class PartCanvas {
|
||||
/** Enough for any sensible object; a typo asking for more stops growing instead of baking for minutes. */
|
||||
static final int MAXIMUM_BLOCKS = 1_500_000;
|
||||
|
||||
enum Axis {
|
||||
NONE, X, Y, Z;
|
||||
|
||||
/** The axis a log along {@code direction} lies on, leaning toward upright as trees do. */
|
||||
static Axis along(double[] direction) {
|
||||
double x = Math.abs(direction[0]);
|
||||
double y = Math.abs(direction[1]) * 1.8;
|
||||
double z = Math.abs(direction[2]);
|
||||
if (y >= x && y >= z) {
|
||||
return Y;
|
||||
}
|
||||
return x >= z ? X : Z;
|
||||
}
|
||||
}
|
||||
|
||||
/** @param part the {@link PartOutline} id of the part that placed the block */
|
||||
record Cell(int role, float along, Axis axis, int part) {
|
||||
}
|
||||
|
||||
/** The end of a stem, where tip decorations go. */
|
||||
record Tip(int x, int y, int z, double[] heading, int role) {
|
||||
}
|
||||
|
||||
private final Map<Long, Cell> cells = new HashMap<>();
|
||||
private final List<Tip> tips = new ArrayList<>();
|
||||
private final List<String> roles = new ArrayList<>();
|
||||
private boolean full;
|
||||
|
||||
int role(String name) {
|
||||
int index = roles.indexOf(name);
|
||||
if (index >= 0) {
|
||||
return index;
|
||||
}
|
||||
roles.add(name);
|
||||
return roles.size() - 1;
|
||||
}
|
||||
|
||||
String roleName(int role) {
|
||||
return roles.get(role);
|
||||
}
|
||||
|
||||
void place(int x, int y, int z, PartMode mode, Cell cell) {
|
||||
long key = key(x, y, z);
|
||||
switch (mode) {
|
||||
case ADD -> {
|
||||
if (!full || cells.containsKey(key)) {
|
||||
cells.put(key, cell);
|
||||
}
|
||||
}
|
||||
case FILL -> {
|
||||
if (!full && !cells.containsKey(key)) {
|
||||
cells.put(key, cell);
|
||||
}
|
||||
}
|
||||
case CARVE -> cells.remove(key);
|
||||
}
|
||||
full = cells.size() >= MAXIMUM_BLOCKS;
|
||||
}
|
||||
|
||||
boolean has(int x, int y, int z) {
|
||||
return cells.containsKey(key(x, y, z));
|
||||
}
|
||||
|
||||
Cell get(long key) {
|
||||
return cells.get(key);
|
||||
}
|
||||
|
||||
Map<Long, Cell> cells() {
|
||||
return Collections.unmodifiableMap(cells);
|
||||
}
|
||||
|
||||
void addTip(Tip tip) {
|
||||
tips.add(tip);
|
||||
}
|
||||
|
||||
List<Tip> tips() {
|
||||
return Collections.unmodifiableList(tips);
|
||||
}
|
||||
|
||||
boolean isEmpty() {
|
||||
return cells.isEmpty();
|
||||
}
|
||||
|
||||
boolean isFull() {
|
||||
return full;
|
||||
}
|
||||
|
||||
static long key(int x, int y, int z) {
|
||||
return ((long) (x & 0x1FFFFF)) | ((long) (y & 0x1FFFFF) << 21) | ((long) (z & 0x1FFFFF) << 42);
|
||||
}
|
||||
|
||||
static int x(long key) {
|
||||
return signed((int) (key & 0x1FFFFF));
|
||||
}
|
||||
|
||||
static int y(long key) {
|
||||
return signed((int) ((key >>> 21) & 0x1FFFFF));
|
||||
}
|
||||
|
||||
static int z(long key) {
|
||||
return signed((int) ((key >>> 42) & 0x1FFFFF));
|
||||
}
|
||||
|
||||
private static int signed(int value) {
|
||||
return (value << 11) >> 11;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.engine.procedural.part;
|
||||
|
||||
import com.volmit.config.Desc;
|
||||
import com.volmit.config.Required;
|
||||
|
||||
@Desc("Places copies of a part around a center: columns in a causeway, peaks on an iceberg, shards on a crystal. Each copy leans away from the center unless its stem says otherwise.")
|
||||
public final class PartCluster {
|
||||
@Desc("How many copies to place.")
|
||||
private ProceduralValue count = ProceduralValue.constant(5);
|
||||
|
||||
@Desc("How far from the center copies are placed, in blocks.")
|
||||
private ProceduralValue radius = ProceduralValue.constant(2);
|
||||
|
||||
@Desc("How the copies are laid out.")
|
||||
private ClusterLayout layout = ClusterLayout.RANDOM;
|
||||
|
||||
@Desc("How far each copy tilts away from the center, in degrees from straight up. A range gives each copy its own tilt; a curve runs from the center (0) to the edge (1).")
|
||||
private ProceduralValue tilt = ProceduralValue.constant(0);
|
||||
|
||||
@Required
|
||||
@Desc("The part each copy is made of.")
|
||||
private ProceduralPart part;
|
||||
|
||||
public ProceduralValue count() {
|
||||
return count == null ? ProceduralValue.constant(5) : count;
|
||||
}
|
||||
|
||||
public ProceduralValue radius() {
|
||||
return radius == null ? ProceduralValue.constant(2) : radius;
|
||||
}
|
||||
|
||||
public ClusterLayout layout() {
|
||||
return layout == null ? ClusterLayout.RANDOM : layout;
|
||||
}
|
||||
|
||||
public ProceduralValue tilt() {
|
||||
return tilt == null ? ProceduralValue.constant(0) : tilt;
|
||||
}
|
||||
|
||||
public ProceduralPart part() {
|
||||
return part;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.engine.procedural.part;
|
||||
|
||||
/** How one part writes its blocks: the mode it combines with, and the density that thins it. */
|
||||
record PartFill(PartCanvas canvas, PartMode mode, int role, int partId, double density, PartPattern pattern, double scale,
|
||||
double falloff, long seed) {
|
||||
static PartFill of(PartCanvas canvas, ProceduralPart part, int partId, int role, long seed) {
|
||||
return new PartFill(canvas, part.mode(), role, partId, part.density(), part.pattern(), part.scale(), part.falloff(), seed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Places the block if the density lets it; {@code edge} is how far toward the shape's edge it is, from 0 at the
|
||||
* center to 1 at the edge, for the falloff.
|
||||
*/
|
||||
void place(int x, int y, int z, double edge, double along, PartCanvas.Axis axis) {
|
||||
double chance = density;
|
||||
if (falloff > 0) {
|
||||
chance *= Math.pow(Math.max(0, 1 - edge), falloff);
|
||||
}
|
||||
if (!PartNoise.passes(pattern, chance, scale, x, y, z, seed)) {
|
||||
return;
|
||||
}
|
||||
canvas.place(x, y, z, mode, new PartCanvas.Cell(role, (float) along, axis, partId));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.engine.procedural.part;
|
||||
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Grows a part tree onto a canvas: each part is drawn from where it sits on its parent, then its children grow from it.
|
||||
* Every part draws from its own seed, taken from its parent's in order, so adding a part only changes what grows after it.
|
||||
*/
|
||||
final class PartGrower {
|
||||
private static final double GOLDEN_ANGLE_DEGREES = 137.50776405003785;
|
||||
private static final int MOST_COPIES = 256;
|
||||
private static final int DEEPEST_NESTING = 24;
|
||||
|
||||
private final PartCanvas canvas;
|
||||
private final String defaultRole;
|
||||
private final PartOutline outline;
|
||||
|
||||
PartGrower(PartCanvas canvas, String defaultRole, PartOutline outline) {
|
||||
this.canvas = canvas;
|
||||
this.defaultRole = defaultRole;
|
||||
this.outline = outline;
|
||||
}
|
||||
|
||||
void growRoots(List<ProceduralPart> parts, long seed) {
|
||||
RNG seeds = new RNG(seed);
|
||||
for (ProceduralPart part : parts) {
|
||||
growChild(part, PartShape.ROOT, canvas.role(defaultRole), seeds.nextLong(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
/** Grows a part that sits on its parent where its own 'at' and 'offset' say. */
|
||||
private void growChild(ProceduralPart part, PartShape parent, int parentRole, long seed, int nesting) {
|
||||
if (part == null || canvas.isFull()) {
|
||||
return;
|
||||
}
|
||||
RNG rng = new RNG(seed);
|
||||
double at = part.at() == null ? parent.defaultAt() : part.at().sample(rng, 0);
|
||||
PartSpot spot = parent.spotAt(at);
|
||||
if (part.offset() != null) {
|
||||
spot = spot.movedBy(part.offset().roll(rng));
|
||||
}
|
||||
grow(part, parent, spot, parentRole, rng, List.of(), nesting);
|
||||
}
|
||||
|
||||
/** Grows a part at {@code spot}, then its children, then any branching it repeats from its own copy. */
|
||||
private void grow(ProceduralPart part, PartShape parent, PartSpot spot, int parentRole, RNG rng,
|
||||
List<Repeat> repeats, int nesting) {
|
||||
if (nesting > DEEPEST_NESTING || canvas.isFull()) {
|
||||
return;
|
||||
}
|
||||
int role = part.role() == null || part.role().isBlank() ? parentRole : canvas.role(part.role());
|
||||
PartFill fill = PartFill.of(canvas, part, outline.idOf(part), role, rng.nextLong());
|
||||
PartShape shape = parent;
|
||||
if (part.stem() != null) {
|
||||
StemShape stem = StemShape.trace(part.stem(), spot, rng);
|
||||
stem.draw(fill, part.stem().section(), part.stem().roughness(), part.stem().jitter());
|
||||
shape = stem;
|
||||
} else if (part.blob() != null) {
|
||||
BlobShape blob = BlobShape.trace(part.blob(), spot, rng);
|
||||
blob.draw(fill, part.blob().roughness(), part.blob().jitter());
|
||||
shape = blob;
|
||||
} else if (part.branches() != null) {
|
||||
branch(part.branches(), parent, role, rng, part.branches().depth(), nesting);
|
||||
} else if (part.cluster() != null) {
|
||||
cluster(part.cluster(), spot, role, rng, nesting);
|
||||
}
|
||||
|
||||
for (ProceduralPart child : part.children()) {
|
||||
growChild(child, shape, role, rng.nextLong(), nesting + 1);
|
||||
}
|
||||
for (Repeat repeat : repeats) {
|
||||
branch(repeat.branches(), shape, role, rng, repeat.depthLeft(), nesting);
|
||||
}
|
||||
}
|
||||
|
||||
private void branch(PartBranches branches, PartShape parent, int role, RNG rng, int depthLeft, int nesting) {
|
||||
if (branches.part() == null || depthLeft <= 0) {
|
||||
return;
|
||||
}
|
||||
List<Double> positions = branchPositions(branches, parent, rng);
|
||||
List<Repeat> repeats = depthLeft > 1 ? List.of(new Repeat(branches, depthLeft - 1)) : List.of();
|
||||
double azimuthOffset = branches.azimuthOffset().sample(rng, 0);
|
||||
for (int index = 0; index < positions.size(); index++) {
|
||||
double t = positions.get(index);
|
||||
PartSpot onParent = parent.spotAt(t);
|
||||
double pitch = branches.pitch().sample(rng, t);
|
||||
double[] heading = branchHeading(branches, onParent, index, positions.size(), azimuthOffset, pitch, rng);
|
||||
PartSpot spot = new PartSpot(onParent.origin(), heading, t, parent.length(), Vectors.azimuth(heading));
|
||||
RNG copyRng = new RNG(rng.nextLong());
|
||||
ProceduralPart copy = branches.part();
|
||||
if (copy.offset() != null) {
|
||||
spot = spot.movedBy(copy.offset().roll(copyRng));
|
||||
}
|
||||
grow(copy, parent, spot, role, copyRng, repeats, nesting + 1);
|
||||
}
|
||||
}
|
||||
|
||||
private static List<Double> branchPositions(PartBranches branches, PartShape parent, RNG rng) {
|
||||
ProceduralSpan along = branches.along();
|
||||
List<Double> positions = new ArrayList<>();
|
||||
if (branches.chance() != null) {
|
||||
double blocks = Math.max(1, parent.length());
|
||||
int first = (int) Math.ceil(along.from() * blocks);
|
||||
int last = (int) Math.floor(along.to() * blocks);
|
||||
for (int block = first; block <= last && positions.size() < MOST_COPIES; block++) {
|
||||
double t = Math.min(1, block / blocks);
|
||||
if (rng.nextDouble() < branches.chance().at(t)) {
|
||||
positions.add(t);
|
||||
}
|
||||
}
|
||||
return positions;
|
||||
}
|
||||
int count = Math.min(MOST_COPIES, Math.max(0, (int) Math.round(branches.count().sample(rng, 0))));
|
||||
for (int index = 0; index < count; index++) {
|
||||
double fraction = along.to() - along.from() < 1e-9 ? 0 : (index + rng.d(0.25, 0.75)) / count;
|
||||
positions.add(along.from() + (along.to() - along.from()) * fraction);
|
||||
}
|
||||
return positions;
|
||||
}
|
||||
|
||||
private static double[] branchHeading(PartBranches branches, PartSpot onParent, int index, int count,
|
||||
double azimuthOffset, double pitch, RNG rng) {
|
||||
double parentAzimuth = Vectors.isVertical(onParent.heading()) && onParent.hasOutward()
|
||||
? onParent.outward() : Vectors.azimuth(onParent.heading());
|
||||
double turn = switch (branches.azimuth()) {
|
||||
case RANDOM -> rng.d(0, 360);
|
||||
case GOLDEN -> index * GOLDEN_ANGLE_DEGREES;
|
||||
case ALTERNATE -> (index % 2) * 180.0;
|
||||
case WHORL -> (index % branches.whorl()) * (360.0 / branches.whorl());
|
||||
case EVEN -> index * (360.0 / Math.max(1, count));
|
||||
case FAN -> branches.fan() * (index - (count - 1) / 2.0);
|
||||
};
|
||||
boolean relative = branches.relative() || branches.azimuth() == BranchAzimuth.FAN;
|
||||
double azimuth = (relative ? parentAzimuth : 0) + turn + azimuthOffset;
|
||||
double finalPitch = branches.relative() ? Vectors.pitch(onParent.heading()) + pitch : pitch;
|
||||
return Vectors.direction(azimuth, Math.max(-90, Math.min(90, finalPitch)));
|
||||
}
|
||||
|
||||
private void cluster(PartCluster cluster, PartSpot spot, int role, RNG rng, int nesting) {
|
||||
if (cluster.part() == null) {
|
||||
return;
|
||||
}
|
||||
int count = Math.min(MOST_COPIES, Math.max(0, (int) Math.round(cluster.count().sample(rng, 0))));
|
||||
double radius = Math.max(0, cluster.radius().sample(rng, 0));
|
||||
double phase = rng.d(0, 360);
|
||||
for (int index = 0; index < count; index++) {
|
||||
Placed placed = placeInCluster(cluster.layout(), index, count, radius, phase, rng);
|
||||
double[] origin = Vectors.add(spot.origin(), Vectors.scale(Vectors.direction(placed.azimuth(), 0), placed.distance()));
|
||||
RNG copyRng = new RNG(rng.nextLong());
|
||||
double fromCenter = radius <= 0 ? 0 : Math.min(1, placed.distance() / radius);
|
||||
double tilt = cluster.tilt().sample(copyRng, fromCenter);
|
||||
double[] heading = tilt == 0 ? spot.heading().clone() : Vectors.tilted(spot.heading(), placed.azimuth(), tilt);
|
||||
PartSpot copySpot = new PartSpot(origin, heading, fromCenter, Math.max(1, radius), placed.azimuth());
|
||||
ProceduralPart copy = cluster.part();
|
||||
if (copy.offset() != null) {
|
||||
copySpot = copySpot.movedBy(copy.offset().roll(copyRng));
|
||||
}
|
||||
grow(copy, PartShape.ROOT, copySpot, role, copyRng, List.of(), nesting + 1);
|
||||
}
|
||||
}
|
||||
|
||||
private static Placed placeInCluster(ClusterLayout layout, int index, int count, double radius, double phase, RNG rng) {
|
||||
return switch (layout) {
|
||||
case RANDOM -> new Placed(rng.d(0, 360), radius * Math.sqrt(rng.nextDouble()));
|
||||
case RING -> new Placed(phase + index * 360.0 / Math.max(1, count), radius);
|
||||
case GOLDEN -> new Placed(phase + index * GOLDEN_ANGLE_DEGREES, radius * Math.sqrt((index + 0.5) / Math.max(1, count)));
|
||||
case LINE -> {
|
||||
double lane = count <= 1 ? 0 : -radius + 2 * radius * index / (count - 1.0);
|
||||
yield new Placed(lane < 0 ? phase + 180 : phase, Math.abs(lane));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/** A branching that repeats on the copies it grows, with how many more times it may. */
|
||||
private record Repeat(PartBranches branches, int depthLeft) {
|
||||
}
|
||||
|
||||
/** Where a cluster copy sits: which way from the center, and how far. */
|
||||
private record Placed(double azimuth, double distance) {
|
||||
}
|
||||
}
|
||||
+9
-9
@@ -15,16 +15,16 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.modules.objects.crystal;
|
||||
package art.arcane.iris.engine.procedural.part;
|
||||
|
||||
import com.volmit.config.Desc;
|
||||
|
||||
@Desc("How the shards of a crystal cluster are angularly distributed around the surface normal.")
|
||||
public enum CrystalDistribution {
|
||||
@Desc("Each shard gets a uniformly random azimuth around the normal. Produces a chaotic, naturally clumped cluster.")
|
||||
RANDOM,
|
||||
|
||||
@Desc("Each shard's azimuth advances by the golden angle (~137.5 degrees) from the previous one. Produces an evenly spaced sunflower-like fan with no two shards overlapping, ideal for a geode rosette.")
|
||||
GOLDEN_ANGLE
|
||||
@Desc("How a part's blocks combine with the blocks already there.")
|
||||
public enum PartMode {
|
||||
@Desc("Places blocks, replacing whatever earlier parts put there.")
|
||||
ADD,
|
||||
@Desc("Places blocks only where nothing is yet, like leaves around wood.")
|
||||
FILL,
|
||||
@Desc("Removes the blocks earlier parts put inside this part's shape.")
|
||||
CARVE
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.engine.procedural.part;
|
||||
|
||||
/** Seeded noise for parts: a hash per block for speckle, and smooth value noise for patches and wandering. */
|
||||
final class PartNoise {
|
||||
private static final double PATCH_CONTRAST = 1.8;
|
||||
|
||||
private PartNoise() {
|
||||
}
|
||||
|
||||
/** A value from 0 to 1 that is the same for the same block and seed. */
|
||||
static double hash(int x, int y, int z, long seed) {
|
||||
long h = mix(seed);
|
||||
h = mix(h + x * 0x9E3779B97F4A7C15L);
|
||||
h = mix(h + y * 0xC2B2AE3D27D4EB4FL);
|
||||
h = mix(h + z * 0x165667B19E3779F9L);
|
||||
return unit(h);
|
||||
}
|
||||
|
||||
/** Smooth value noise from 0 to 1 with features {@code scale} blocks across, stretched so thresholds split it evenly. */
|
||||
static double patches(double x, double y, double z, double scale, long seed) {
|
||||
double size = Math.max(1, scale);
|
||||
double value = smooth(x / size, y / size, z / size, seed);
|
||||
return Math.max(0, Math.min(1, (value - 0.5) * PATCH_CONTRAST + 0.5));
|
||||
}
|
||||
|
||||
/** Smooth value noise from 0 to 1 along a line. */
|
||||
static double line(double t, long seed) {
|
||||
int cell = (int) Math.floor(t);
|
||||
double blend = fade(t - cell);
|
||||
double a = hash(cell, 0, 0, seed);
|
||||
double b = hash(cell + 1, 0, 0, seed);
|
||||
return a + (b - a) * blend;
|
||||
}
|
||||
|
||||
/** Whether a block passes a chance under a pattern. */
|
||||
static boolean passes(PartPattern pattern, double chance, double scale, int x, int y, int z, long seed) {
|
||||
if (chance >= 1) {
|
||||
return true;
|
||||
}
|
||||
if (chance <= 0) {
|
||||
return false;
|
||||
}
|
||||
double roll = pattern == PartPattern.PATCHES ? patches(x, y, z, scale, seed) : hash(x, y, z, seed);
|
||||
return roll < chance;
|
||||
}
|
||||
|
||||
private static double smooth(double x, double y, double z, long seed) {
|
||||
int x0 = (int) Math.floor(x);
|
||||
int y0 = (int) Math.floor(y);
|
||||
int z0 = (int) Math.floor(z);
|
||||
double fx = fade(x - x0);
|
||||
double fy = fade(y - y0);
|
||||
double fz = fade(z - z0);
|
||||
double c00 = lerp(hash(x0, y0, z0, seed), hash(x0 + 1, y0, z0, seed), fx);
|
||||
double c10 = lerp(hash(x0, y0 + 1, z0, seed), hash(x0 + 1, y0 + 1, z0, seed), fx);
|
||||
double c01 = lerp(hash(x0, y0, z0 + 1, seed), hash(x0 + 1, y0, z0 + 1, seed), fx);
|
||||
double c11 = lerp(hash(x0, y0 + 1, z0 + 1, seed), hash(x0 + 1, y0 + 1, z0 + 1, seed), fx);
|
||||
return lerp(lerp(c00, c10, fy), lerp(c01, c11, fy), fz);
|
||||
}
|
||||
|
||||
private static double fade(double t) {
|
||||
return t * t * (3 - 2 * t);
|
||||
}
|
||||
|
||||
private static double lerp(double a, double b, double t) {
|
||||
return a + (b - a) * t;
|
||||
}
|
||||
|
||||
static long mix(long a) {
|
||||
a ^= (a >>> 33);
|
||||
a *= 0xff51afd7ed558ccdL;
|
||||
a ^= (a >>> 33);
|
||||
a *= 0xc4ceb9fe1a85ec53L;
|
||||
a ^= (a >>> 33);
|
||||
return a;
|
||||
}
|
||||
|
||||
private static double unit(long h) {
|
||||
return (h >>> 11) * 0x1.0p-53;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.engine.procedural.part;
|
||||
|
||||
import com.volmit.config.Desc;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
@Desc("A shift in blocks along each axis. Each axis takes a number or a [min, max] range.")
|
||||
public final class PartOffset {
|
||||
@Desc("Blocks east (negative is west).")
|
||||
private ProceduralValue x;
|
||||
|
||||
@Desc("Blocks up (negative is down).")
|
||||
private ProceduralValue y;
|
||||
|
||||
@Desc("Blocks south (negative is north).")
|
||||
private ProceduralValue z;
|
||||
|
||||
public double[] roll(RNG rng) {
|
||||
return new double[]{roll(x, rng), roll(y, rng), roll(z, rng)};
|
||||
}
|
||||
|
||||
private static double roll(ProceduralValue value, RNG rng) {
|
||||
return value == null ? 0 : value.sample(rng, 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.engine.procedural.part;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The part tree of a procedural object as a viewer lists it, with an id per node that {@link PartTrace} tags blocks
|
||||
* with. A part that copies another, like branches, shares its node with the copied part, so the tree reads one level
|
||||
* shallower than the settings. Ids number the nodes in order, so they stay the same across seeds and variants.
|
||||
*/
|
||||
public final class PartOutline {
|
||||
public static final int NO_PART = -1;
|
||||
|
||||
/**
|
||||
* One row of the tree.
|
||||
*
|
||||
* @param shape what the part is, like {@code Branches ×12 · Stem}
|
||||
* @param detail the role its blocks get, and whether it carves them away instead
|
||||
*/
|
||||
public record Node(int id, String shape, String detail, List<Node> children) {
|
||||
}
|
||||
|
||||
private final Map<ProceduralPart, Integer> idsByPart = new IdentityHashMap<>();
|
||||
private final List<Node> roots;
|
||||
private int nodeCount;
|
||||
|
||||
private PartOutline(ProceduralObject definition) {
|
||||
this.roots = nodesFor(definition.parts(), definition.defaultRole());
|
||||
}
|
||||
|
||||
public static PartOutline of(ProceduralObject definition) {
|
||||
return new PartOutline(definition);
|
||||
}
|
||||
|
||||
public List<Node> roots() {
|
||||
return roots;
|
||||
}
|
||||
|
||||
public int nodeCount() {
|
||||
return nodeCount;
|
||||
}
|
||||
|
||||
public int idOf(ProceduralPart part) {
|
||||
return idsByPart.getOrDefault(part, NO_PART);
|
||||
}
|
||||
|
||||
private List<Node> nodesFor(List<ProceduralPart> parts, String parentRole) {
|
||||
List<Node> nodes = new ArrayList<>();
|
||||
for (ProceduralPart part : parts) {
|
||||
if (part != null) {
|
||||
nodes.add(nodeFor(part, parentRole));
|
||||
}
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
|
||||
// Children follow the order the grower draws them in: the copies' own children first, then the part's.
|
||||
private Node nodeFor(ProceduralPart part, String parentRole) {
|
||||
int id = nodeCount++;
|
||||
idsByPart.put(part, id);
|
||||
String role = roleOf(part, parentRole);
|
||||
ProceduralPart copied = copiedPart(part);
|
||||
List<Node> children = new ArrayList<>();
|
||||
String shape;
|
||||
String detail;
|
||||
if (copied != null && copiedPart(copied) == null) {
|
||||
idsByPart.put(copied, id);
|
||||
String copiedRole = roleOf(copied, role);
|
||||
shape = copiesLabel(part) + " · " + shapeName(copied);
|
||||
detail = detailOf(copied, copiedRole);
|
||||
children.addAll(nodesFor(copied.children(), copiedRole));
|
||||
} else {
|
||||
shape = copied != null ? copiesLabel(part) : shapeName(part);
|
||||
detail = detailOf(part, role);
|
||||
if (copied != null) {
|
||||
children.add(nodeFor(copied, role));
|
||||
}
|
||||
}
|
||||
children.addAll(nodesFor(part.children(), role));
|
||||
return new Node(id, shape, detail, List.copyOf(children));
|
||||
}
|
||||
|
||||
private static String roleOf(ProceduralPart part, String parentRole) {
|
||||
return part.role() == null || part.role().isBlank() ? parentRole : part.role();
|
||||
}
|
||||
|
||||
private static ProceduralPart copiedPart(ProceduralPart part) {
|
||||
if (part.branches() != null) {
|
||||
return part.branches().part();
|
||||
}
|
||||
return part.cluster() != null ? part.cluster().part() : null;
|
||||
}
|
||||
|
||||
private static String copiesLabel(ProceduralPart part) {
|
||||
if (part.branches() != null) {
|
||||
return part.branches().chance() != null ? "Branches by chance" : "Branches ×" + part.branches().count().summary();
|
||||
}
|
||||
return "Cluster ×" + part.cluster().count().summary();
|
||||
}
|
||||
|
||||
private static String shapeName(ProceduralPart part) {
|
||||
if (part.stem() != null) {
|
||||
return "Stem";
|
||||
}
|
||||
if (part.blob() != null) {
|
||||
return "Blob";
|
||||
}
|
||||
return "Group";
|
||||
}
|
||||
|
||||
// Carving places no blocks, so it is named to explain why nothing lights up.
|
||||
private static String detailOf(ProceduralPart part, String role) {
|
||||
return part.mode() == PartMode.CARVE ? role + " · carve" : role;
|
||||
}
|
||||
}
|
||||
+8
-5
@@ -15,11 +15,14 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.engine.procedural.part;
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.crystal;
|
||||
import com.volmit.config.Desc;
|
||||
|
||||
public enum CrystalRole {
|
||||
BASE,
|
||||
SHARD,
|
||||
TIP
|
||||
@Desc("How a chance is spread over blocks.")
|
||||
public enum PartPattern {
|
||||
@Desc("Every block rolls on its own, for an even speckle.")
|
||||
RANDOM,
|
||||
@Desc("Smooth noise decides, so blocks come in patches the size of the scale.")
|
||||
PATCHES
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.engine.procedural.part;
|
||||
|
||||
import com.volmit.config.Desc;
|
||||
|
||||
@Desc("The cross-section of a stem or blob.")
|
||||
public enum PartSection {
|
||||
@Desc("A circle.")
|
||||
ROUND,
|
||||
@Desc("A square, like a vanilla trunk.")
|
||||
SQUARE,
|
||||
@Desc("A diamond (a square turned 45 degrees).")
|
||||
DIAMOND,
|
||||
@Desc("A hexagon, like a basalt column.")
|
||||
HEX
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.engine.procedural.part;
|
||||
|
||||
/** A drawn part that others can grow from. */
|
||||
interface PartShape {
|
||||
/** Where a child sitting at {@code t}, from the base (0) to the tip (1), starts. */
|
||||
PartSpot spotAt(double t);
|
||||
|
||||
/** The length children measure against, in blocks. */
|
||||
double length();
|
||||
|
||||
/** Where children sit when they do not say. */
|
||||
double defaultAt();
|
||||
|
||||
/** The parent of the object's root parts: a single point at the base, pointing up. */
|
||||
PartShape ROOT = new PartShape() {
|
||||
@Override
|
||||
public PartSpot spotAt(double t) {
|
||||
return PartSpot.root();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double length() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double defaultAt() {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.engine.procedural.part;
|
||||
|
||||
/**
|
||||
* Where a part starts: its position, the direction it grows, where it sits on its parent from base (0) to tip (1),
|
||||
* how long that parent is, and the compass direction pointing away from the parent's center (NaN when there is none).
|
||||
*/
|
||||
record PartSpot(double[] origin, double[] heading, double parentT, double parentLength, double outward) {
|
||||
static PartSpot root() {
|
||||
return new PartSpot(new double[]{0, 0, 0}, Vectors.UP.clone(), 0, 0, Double.NaN);
|
||||
}
|
||||
|
||||
PartSpot movedBy(double[] offset) {
|
||||
return new PartSpot(Vectors.add(origin, offset), heading, parentT, parentLength, outward);
|
||||
}
|
||||
|
||||
boolean hasOutward() {
|
||||
return !Double.isNaN(outward);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.engine.procedural.part;
|
||||
|
||||
import com.volmit.config.Desc;
|
||||
import com.volmit.config.MaxNumber;
|
||||
import com.volmit.config.MinNumber;
|
||||
|
||||
@Desc("A line that grows from where the part sits: a trunk, branch, spire, stalk, root or shard. Values given as a curve run over where the stem sits on its parent, except taper, lean curve, bend curve and helix radius, which run from the stem's base (0) to its tip (1).")
|
||||
public final class PartStem {
|
||||
@Desc("How long the stem grows, in blocks.")
|
||||
private ProceduralValue length = ProceduralValue.constant(8);
|
||||
|
||||
@MinNumber(0)
|
||||
@Desc("If above 0, the stem is this fraction of its parent stem's length instead, for branches that shrink as they split.")
|
||||
private double lengthScale = 0;
|
||||
|
||||
@Desc("The radius at the base in blocks. 0.5 is one block wide.")
|
||||
private ProceduralValue radius = ProceduralValue.constant(0.5);
|
||||
|
||||
@Desc("A multiplier on the radius from the base (0) to the tip (1), such as [[0, 1], [1, 0]] to taper to a point.")
|
||||
private ProceduralValue taper;
|
||||
|
||||
@Desc("The cross-section of the stem.")
|
||||
private PartSection section = PartSection.ROUND;
|
||||
|
||||
@Desc("The angle in degrees above the horizon the stem grows toward: 90 is straight up, -90 straight down. Unset, it carries on its parent's direction (up for a root part).")
|
||||
private ProceduralValue pitch;
|
||||
|
||||
@Desc("The compass direction in degrees the stem grows toward when pitch is set. Unset, it keeps its parent's direction, or grows toward its facing.")
|
||||
private ProceduralValue azimuth;
|
||||
|
||||
@Desc("The compass direction in degrees the stem leans and bends toward. Unset, it leans away from the center of its cluster or branch, or a random way.")
|
||||
private ProceduralValue facing;
|
||||
|
||||
@Desc("How far the stem leans, in degrees from its direction, by the time it reaches its tip.")
|
||||
private ProceduralValue lean = ProceduralValue.constant(0);
|
||||
|
||||
@Desc("How the lean builds up from base (0) to tip (1), from 0 to 1. Unset, it grows evenly.")
|
||||
private ProceduralValue leanCurve;
|
||||
|
||||
@Desc("How far the stem turns, in degrees, by its tip: 90 turns an upright stem sideways, 180 brings it back down like an arch.")
|
||||
private ProceduralValue bend = ProceduralValue.constant(0);
|
||||
|
||||
@Desc("How the bend builds up from base (0) to tip (1), from 0 to 1. Unset, it turns evenly.")
|
||||
private ProceduralValue bendCurve;
|
||||
|
||||
@Desc("How much the stem sags under its own weight, as a fraction of its length: 0.2 drops the tip a fifth of the length.")
|
||||
private ProceduralValue droop = ProceduralValue.constant(0);
|
||||
|
||||
@Desc("How far the stem wanders sideways at random, in blocks.")
|
||||
private ProceduralValue sway = ProceduralValue.constant(0);
|
||||
|
||||
@Desc("How far the stem waves from side to side, in blocks.")
|
||||
private ProceduralValue wave = ProceduralValue.constant(0);
|
||||
|
||||
@Desc("How many full waves the stem makes over its length.")
|
||||
private ProceduralValue wavePeriods = ProceduralValue.constant(1);
|
||||
|
||||
@Desc("The radius in blocks of a corkscrew the stem winds around, from base (0) to tip (1). It starts on the facing side, so copies facing apart wind as a double helix.")
|
||||
private ProceduralValue helixRadius = ProceduralValue.constant(0);
|
||||
|
||||
@Desc("How many full turns the corkscrew makes over the stem's length.")
|
||||
private ProceduralValue helixTurns = ProceduralValue.constant(1);
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Desc("How rough the surface is, from 0 (smooth) to 1 (heavily pitted).")
|
||||
private double roughness = 0;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Desc("How many blocks along the surface are knocked off at random, from 0 to 1.")
|
||||
private double jitter = 0;
|
||||
|
||||
public ProceduralValue length() {
|
||||
return length == null ? ProceduralValue.constant(8) : length;
|
||||
}
|
||||
|
||||
public double lengthScale() {
|
||||
return lengthScale;
|
||||
}
|
||||
|
||||
public ProceduralValue radius() {
|
||||
return radius == null ? ProceduralValue.constant(0.5) : radius;
|
||||
}
|
||||
|
||||
public ProceduralValue taper() {
|
||||
return taper;
|
||||
}
|
||||
|
||||
public PartSection section() {
|
||||
return section == null ? PartSection.ROUND : section;
|
||||
}
|
||||
|
||||
public ProceduralValue pitch() {
|
||||
return pitch;
|
||||
}
|
||||
|
||||
public ProceduralValue azimuth() {
|
||||
return azimuth;
|
||||
}
|
||||
|
||||
public ProceduralValue facing() {
|
||||
return facing;
|
||||
}
|
||||
|
||||
public ProceduralValue lean() {
|
||||
return lean;
|
||||
}
|
||||
|
||||
public ProceduralValue leanCurve() {
|
||||
return leanCurve;
|
||||
}
|
||||
|
||||
public ProceduralValue bend() {
|
||||
return bend;
|
||||
}
|
||||
|
||||
public ProceduralValue bendCurve() {
|
||||
return bendCurve;
|
||||
}
|
||||
|
||||
public ProceduralValue droop() {
|
||||
return droop;
|
||||
}
|
||||
|
||||
public ProceduralValue sway() {
|
||||
return sway;
|
||||
}
|
||||
|
||||
public ProceduralValue wave() {
|
||||
return wave;
|
||||
}
|
||||
|
||||
public ProceduralValue wavePeriods() {
|
||||
return wavePeriods;
|
||||
}
|
||||
|
||||
public ProceduralValue helixRadius() {
|
||||
return helixRadius;
|
||||
}
|
||||
|
||||
public ProceduralValue helixTurns() {
|
||||
return helixTurns;
|
||||
}
|
||||
|
||||
public double roughness() {
|
||||
return roughness;
|
||||
}
|
||||
|
||||
public double jitter() {
|
||||
return jitter;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.engine.procedural.part;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Which part placed each block of one baked variant, by the block's position in the variant's object. Decorations
|
||||
* belong to no part.
|
||||
*/
|
||||
public final class PartTrace {
|
||||
public static final PartTrace EMPTY = new PartTrace(Map.of());
|
||||
|
||||
private final Map<Long, Integer> partsByBlock;
|
||||
|
||||
PartTrace(Map<Long, Integer> partsByBlock) {
|
||||
this.partsByBlock = partsByBlock;
|
||||
}
|
||||
|
||||
/** The {@link PartOutline} id of the part that placed the block, or {@link PartOutline#NO_PART}. */
|
||||
public int partAt(int x, int y, int z) {
|
||||
return partsByBlock.getOrDefault(PartCanvas.key(x, y, z), PartOutline.NO_PART);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.engine.procedural.part;
|
||||
|
||||
import com.volmit.block.PaletteSpec;
|
||||
import com.volmit.config.MinItems;
|
||||
import com.volmit.config.Desc;
|
||||
import com.volmit.config.MaxNumber;
|
||||
import com.volmit.config.MinNumber;
|
||||
import com.volmit.config.Ref;
|
||||
import com.volmit.config.Reference;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Desc("Blocks placed against the finished object, such as vines, moss, fruit or lanterns. Vines and lichen attach to the block they touch.")
|
||||
public final class ProceduralDecoration {
|
||||
@Ref(Reference.BLOCK)
|
||||
@Desc("The block to place. Ignored when palette is set.")
|
||||
private String block = "minecraft:vine";
|
||||
|
||||
@Desc("A noise palette to place.")
|
||||
private PaletteSpec palette;
|
||||
|
||||
@MinItems(1)
|
||||
@Desc("The roles to decorate. Empty decorates every block.")
|
||||
private List<String> on = List.of();
|
||||
|
||||
@Desc("Where on those blocks to place it.")
|
||||
private DecorationSpot at = DecorationSpot.SIDE;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Desc("The chance each spot gets one.")
|
||||
private double chance = 0.3;
|
||||
|
||||
@Desc("How the chance is spread over the spots.")
|
||||
private PartPattern pattern = PartPattern.RANDOM;
|
||||
|
||||
@MinNumber(1)
|
||||
@Desc("The size of the patches in blocks for the PATCHES pattern.")
|
||||
private double scale = 3;
|
||||
|
||||
@Desc("How many blocks long a strand hangs for BELOW and BOTTOM.")
|
||||
private ProceduralValue length = ProceduralValue.constant(1);
|
||||
|
||||
@Desc("How far from where the object stands GROUND decorations spread, in blocks.")
|
||||
private ProceduralValue radius = ProceduralValue.constant(3);
|
||||
|
||||
public BlockChoice choice() {
|
||||
return new BlockChoice(block, palette, 0);
|
||||
}
|
||||
|
||||
public List<String> on() {
|
||||
return on == null ? List.of() : Collections.unmodifiableList(on);
|
||||
}
|
||||
|
||||
public DecorationSpot at() {
|
||||
return at == null ? DecorationSpot.SIDE : at;
|
||||
}
|
||||
|
||||
public double chance() {
|
||||
return chance;
|
||||
}
|
||||
|
||||
public PartPattern pattern() {
|
||||
return pattern == null ? PartPattern.RANDOM : pattern;
|
||||
}
|
||||
|
||||
public double scale() {
|
||||
return scale;
|
||||
}
|
||||
|
||||
public ProceduralValue length() {
|
||||
return length == null ? ProceduralValue.constant(1) : length;
|
||||
}
|
||||
|
||||
public ProceduralValue radius() {
|
||||
return radius == null ? ProceduralValue.constant(3) : radius;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.engine.procedural.part;
|
||||
|
||||
import com.volmit.block.PaletteSpec;
|
||||
import com.volmit.config.MinItems;
|
||||
import com.volmit.config.Desc;
|
||||
import com.volmit.config.MinNumber;
|
||||
import com.volmit.config.Ref;
|
||||
import com.volmit.config.Reference;
|
||||
import com.volmit.config.Required;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Desc("The blocks of one role. Logs are turned along the part they belong to, and leaves get decay distances.")
|
||||
public final class ProceduralMaterial {
|
||||
@Required
|
||||
@Desc("The role the parts refer to, such as wood, leaves, rock or cap.")
|
||||
private String role = "main";
|
||||
|
||||
@Ref(Reference.BLOCK)
|
||||
@Desc("The block. Ignored when palette is set.")
|
||||
private String block = "minecraft:stone";
|
||||
|
||||
@Desc("A noise palette mixing several blocks.")
|
||||
private PaletteSpec palette;
|
||||
|
||||
@MinNumber(0)
|
||||
@Desc("If above 0, the palette changes every this many blocks of height, for strata.")
|
||||
private int bands = 0;
|
||||
|
||||
@MinItems(1)
|
||||
@Desc("Swaps for blocks that meet conditions; the first rule that applies wins.")
|
||||
private List<MaterialRule> rules = List.of();
|
||||
|
||||
public String role() {
|
||||
return role == null ? "main" : role;
|
||||
}
|
||||
|
||||
public BlockChoice choice() {
|
||||
return new BlockChoice(block, palette, bands);
|
||||
}
|
||||
|
||||
public List<MaterialRule> rules() {
|
||||
return rules == null ? List.of() : Collections.unmodifiableList(rules);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.engine.procedural.part;
|
||||
|
||||
import com.volmit.config.MinItems;
|
||||
import com.volmit.config.Desc;
|
||||
import com.volmit.config.MaxNumber;
|
||||
import com.volmit.config.MinNumber;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Desc("A procedural object built from parts: stems, blobs, branches and clusters, each placing blocks of a role. Anything from a tree to a rock arch to a crystal-studded boulder. Iris bakes a pool of variants from it once. Place it from any object placement as procedural/<path>, or a single variant as procedural/<path>#<index>.")
|
||||
public final class ProceduralObject {
|
||||
@MinNumber(1)
|
||||
@MaxNumber(64)
|
||||
@Desc("How many different variants to bake. More means more variety for a little memory.")
|
||||
private int variants = 6;
|
||||
|
||||
@Desc("The seed every variant is baked from. The same seed and settings always bake the same variants.")
|
||||
private long seed = 1337;
|
||||
|
||||
|
||||
@MinItems(1)
|
||||
@Desc("The blocks of each role. A part whose role has no material uses the first one.")
|
||||
private List<ProceduralMaterial> materials = List.of();
|
||||
|
||||
@MinItems(1)
|
||||
@Desc("The parts the object grows from, each starting at the object's base.")
|
||||
private List<ProceduralPart> parts = List.of();
|
||||
|
||||
@MinItems(1)
|
||||
@Desc("Blocks placed against the finished object, such as vines, moss or fruit.")
|
||||
private List<ProceduralDecoration> decorations = List.of();
|
||||
|
||||
@Desc("If true leaves get the distances from wood vanilla needs to keep them. Leaves more than 6 blocks from wood are made persistent; the object view in /iris studio map shows them. If false all leaves are persistent.")
|
||||
private boolean leafDecay = true;
|
||||
|
||||
@Desc("If true every block that can hold water is waterlogged, so coral stays alive.")
|
||||
private boolean waterlogged = false;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Desc("Sinks the object into the ground by this fraction of its height.")
|
||||
private double sink = 0;
|
||||
|
||||
public int variants() {
|
||||
return variants;
|
||||
}
|
||||
|
||||
public long seed() {
|
||||
return seed;
|
||||
}
|
||||
|
||||
public List<ProceduralMaterial> materials() {
|
||||
return materials == null ? List.of() : Collections.unmodifiableList(materials);
|
||||
}
|
||||
|
||||
/** The role of a root part that sets none: the first material's. */
|
||||
public String defaultRole() {
|
||||
return materials().isEmpty() ? "main" : materials().getFirst().role();
|
||||
}
|
||||
|
||||
public List<ProceduralPart> parts() {
|
||||
return parts == null ? List.of() : Collections.unmodifiableList(parts);
|
||||
}
|
||||
|
||||
public List<ProceduralDecoration> decorations() {
|
||||
return decorations == null ? List.of() : Collections.unmodifiableList(decorations);
|
||||
}
|
||||
|
||||
public boolean leafDecay() {
|
||||
return leafDecay;
|
||||
}
|
||||
|
||||
public boolean waterlogged() {
|
||||
return waterlogged;
|
||||
}
|
||||
|
||||
public double sink() {
|
||||
return sink;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.engine.procedural.part;
|
||||
|
||||
import com.volmit.config.MinItems;
|
||||
import com.volmit.config.Desc;
|
||||
import com.volmit.config.MaxNumber;
|
||||
import com.volmit.config.MinNumber;
|
||||
import com.volmit.config.Snippet;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Snippet("iris/objects/procedural-part")
|
||||
@Desc("One piece of a procedural object. Set exactly one of stem, blob, branches or cluster; children grow from this part.")
|
||||
public final class ProceduralPart {
|
||||
@Desc("The role of the blocks this part places, matching a material's role, such as wood or leaves. Unset, it takes its parent's role.")
|
||||
private String role;
|
||||
|
||||
@Desc("Where on its parent this part sits, from the base (0) to the tip (1). Unset, it sits at the tip of a stem or the top of a blob.")
|
||||
private ProceduralValue at;
|
||||
|
||||
@Desc("Moves this part from where it sits, in blocks.")
|
||||
private PartOffset offset;
|
||||
|
||||
@Desc("How this part's blocks combine with the blocks earlier parts placed.")
|
||||
private PartMode mode = PartMode.ADD;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Desc("The fraction of this part's blocks that are placed, for sparse leaves or eroded carving.")
|
||||
private double density = 1;
|
||||
|
||||
@Desc("How the density is spread over the blocks.")
|
||||
private PartPattern pattern = PartPattern.RANDOM;
|
||||
|
||||
@MinNumber(1)
|
||||
@Desc("The size of the patches in blocks for the PATCHES pattern.")
|
||||
private double scale = 3;
|
||||
|
||||
@MinNumber(0)
|
||||
@Desc("Thins the blocks toward the edge of the shape: 1 thins evenly, 2 keeps a dense core.")
|
||||
private double falloff = 0;
|
||||
|
||||
@Desc("A line that grows from here: a trunk, branch, spire, stalk or shard.")
|
||||
private PartStem stem;
|
||||
|
||||
@Desc("A rounded volume: a leaf crown, boulder, cap or coral head.")
|
||||
private PartBlob blob;
|
||||
|
||||
@Desc("Copies of a part grown out of this part's parent along its length.")
|
||||
private PartBranches branches;
|
||||
|
||||
@Desc("Copies of a part placed around this spot.")
|
||||
private PartCluster cluster;
|
||||
|
||||
@MinItems(1)
|
||||
@Desc("The parts that grow from this one.")
|
||||
private List<ProceduralPart> children = List.of();
|
||||
|
||||
public String role() {
|
||||
return role;
|
||||
}
|
||||
|
||||
public ProceduralValue at() {
|
||||
return at;
|
||||
}
|
||||
|
||||
public PartOffset offset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
public PartMode mode() {
|
||||
return mode == null ? PartMode.ADD : mode;
|
||||
}
|
||||
|
||||
public double density() {
|
||||
return density;
|
||||
}
|
||||
|
||||
public PartPattern pattern() {
|
||||
return pattern == null ? PartPattern.RANDOM : pattern;
|
||||
}
|
||||
|
||||
public double scale() {
|
||||
return scale;
|
||||
}
|
||||
|
||||
public double falloff() {
|
||||
return falloff;
|
||||
}
|
||||
|
||||
public PartStem stem() {
|
||||
return stem;
|
||||
}
|
||||
|
||||
public PartBlob blob() {
|
||||
return blob;
|
||||
}
|
||||
|
||||
public PartBranches branches() {
|
||||
return branches;
|
||||
}
|
||||
|
||||
public PartCluster cluster() {
|
||||
return cluster;
|
||||
}
|
||||
|
||||
public List<ProceduralPart> children() {
|
||||
return children == null ? List.of() : Collections.unmodifiableList(children);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.engine.procedural.part;
|
||||
|
||||
import com.volmit.config.Desc;
|
||||
import com.volmit.config.MaxNumber;
|
||||
import com.volmit.config.MinNumber;
|
||||
|
||||
@Desc("A stretch between two points from 0 to 1, such as from the base (0) to the tip (1) of a part.")
|
||||
public final class ProceduralSpan {
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Desc("Where the stretch starts.")
|
||||
private double from = 0;
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Desc("Where the stretch ends.")
|
||||
private double to = 1;
|
||||
|
||||
public ProceduralSpan() {
|
||||
}
|
||||
|
||||
public ProceduralSpan(double from, double to) {
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
public double from() {
|
||||
return Math.min(from, to);
|
||||
}
|
||||
|
||||
public double to() {
|
||||
return Math.max(from, to);
|
||||
}
|
||||
|
||||
public boolean contains(double t) {
|
||||
return t >= from() - 1e-9 && t <= to() + 1e-9;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,299 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.engine.procedural.part;
|
||||
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.config.Desc;
|
||||
import com.volmit.config.JsonForms;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A number a pack author may write as a constant ({@code 5}), a random range ({@code [3, 8]} or
|
||||
* {@code {"min": 3, "max": 8}}), a curve of keyframes ({@code [[0, 1], [0.6, 0.8], [1, 0.2]]}) or a named curve
|
||||
* ({@code {"shape": "power", "exponent": 3, "from": 0, "to": 1}}). Each field says what a curve runs over.
|
||||
*/
|
||||
@Desc("A number, a [min, max] range rolled once per use, or a curve: [[t, value], ...] keyframes or {\"shape\": ..., \"from\": ..., \"to\": ...}.")
|
||||
@JsonForms(ProceduralValue.Forms.class)
|
||||
public final class ProceduralValue {
|
||||
private final Object written;
|
||||
private final Form form;
|
||||
|
||||
private ProceduralValue(Object written, Form form) {
|
||||
this.written = written;
|
||||
this.form = form;
|
||||
}
|
||||
|
||||
public static ProceduralValue constant(double value) {
|
||||
return new ProceduralValue(value, new Constant(value));
|
||||
}
|
||||
|
||||
public static ProceduralValue range(double min, double max) {
|
||||
return new ProceduralValue(List.of(min, max), new Range(min, max));
|
||||
}
|
||||
|
||||
/** This value with any range rolled once, so a curve or constant is all that is left. */
|
||||
public ProceduralValue fix(RNG rng) {
|
||||
if (form instanceof Range range) {
|
||||
return constant(range.roll(rng));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/** The value at {@code t}, from 0 to 1; a range gives its middle, so fix it first to roll it. */
|
||||
public double at(double t) {
|
||||
return form.at(Math.max(0, Math.min(1, t)));
|
||||
}
|
||||
|
||||
/** The value at {@code t}, with a range rolled with {@code rng}. */
|
||||
public double sample(RNG rng, double t) {
|
||||
return fix(rng).at(t);
|
||||
}
|
||||
|
||||
public boolean isCurve() {
|
||||
return form instanceof Keyframes || form instanceof Shape;
|
||||
}
|
||||
|
||||
/** A short reading of the value for labels: {@code 12}, {@code 4–9} or {@code curve}. */
|
||||
public String summary() {
|
||||
return switch (form) {
|
||||
case Constant constant -> shortNumber(constant.value());
|
||||
case Range range -> shortNumber(range.min()) + "–" + shortNumber(range.max());
|
||||
case Keyframes ignored -> "curve";
|
||||
case Shape ignored -> "curve";
|
||||
};
|
||||
}
|
||||
|
||||
private static String shortNumber(double value) {
|
||||
return value == Math.rint(value) ? Long.toString((long) value) : String.format(Locale.ROOT, "%.4g", value).replaceAll("\\.?0+$", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return written.toString();
|
||||
}
|
||||
|
||||
private sealed interface Form permits Constant, Range, Keyframes, Shape {
|
||||
double at(double t);
|
||||
}
|
||||
|
||||
private record Constant(double value) implements Form {
|
||||
@Override
|
||||
public double at(double t) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
private record Range(double min, double max) implements Form {
|
||||
double roll(RNG rng) {
|
||||
return min == max ? min : rng.d(Math.min(min, max), Math.max(min, max));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double at(double t) {
|
||||
return (min + max) / 2;
|
||||
}
|
||||
}
|
||||
|
||||
private record Keyframes(double[] times, double[] values) implements Form {
|
||||
@Override
|
||||
public double at(double t) {
|
||||
if (t <= times[0]) {
|
||||
return values[0];
|
||||
}
|
||||
for (int i = 1; i < times.length; i++) {
|
||||
if (t <= times[i]) {
|
||||
double span = times[i] - times[i - 1];
|
||||
double blend = span <= 0 ? 1 : (t - times[i - 1]) / span;
|
||||
return values[i - 1] + (values[i] - values[i - 1]) * blend;
|
||||
}
|
||||
}
|
||||
return values[values.length - 1];
|
||||
}
|
||||
}
|
||||
|
||||
private record Shape(CurveShape shape, double from, double to, Map<?, ?> parameters) implements Form {
|
||||
@Override
|
||||
public double at(double t) {
|
||||
return from + (to - from) * shape.at(t, parameters);
|
||||
}
|
||||
}
|
||||
|
||||
/** The named curves, each running from 0 at t = 0 toward 1, stretched between a value's from and to. */
|
||||
public enum CurveShape {
|
||||
LINEAR(List.of()) {
|
||||
@Override
|
||||
double at(double t, Map<?, ?> p) {
|
||||
return t;
|
||||
}
|
||||
},
|
||||
SMOOTH(List.of()) {
|
||||
@Override
|
||||
double at(double t, Map<?, ?> p) {
|
||||
return t * t * (3 - 2 * t);
|
||||
}
|
||||
},
|
||||
POWER(List.of(new Parameter("exponent", 2))) {
|
||||
@Override
|
||||
double at(double t, Map<?, ?> p) {
|
||||
return Math.pow(t, parameter(p, "exponent"));
|
||||
}
|
||||
},
|
||||
SIGMOID(List.of(new Parameter("steepness", 10), new Parameter("mid", 0.5))) {
|
||||
@Override
|
||||
double at(double t, Map<?, ?> p) {
|
||||
return 1 / (1 + Math.exp(-parameter(p, "steepness") * (t - parameter(p, "mid"))));
|
||||
}
|
||||
},
|
||||
BELL(List.of(new Parameter("mid", 0.5), new Parameter("width", 0.15))) {
|
||||
@Override
|
||||
double at(double t, Map<?, ?> p) {
|
||||
double spread = Math.max(1e-6, parameter(p, "width"));
|
||||
return Math.exp(-0.5 * Math.pow((t - parameter(p, "mid")) / spread, 2));
|
||||
}
|
||||
},
|
||||
PERIODIC(List.of(new Parameter("periods", 4), new Parameter("sharpness", 8))) {
|
||||
@Override
|
||||
double at(double t, Map<?, ?> p) {
|
||||
double wave = Math.max(0, Math.sin(2 * Math.PI * t * parameter(p, "periods")));
|
||||
return Math.pow(wave, parameter(p, "sharpness"));
|
||||
}
|
||||
},
|
||||
SINE(List.of(new Parameter("periods", 1))) {
|
||||
@Override
|
||||
double at(double t, Map<?, ?> p) {
|
||||
return 0.5 + 0.5 * Math.sin(2 * Math.PI * t * parameter(p, "periods"));
|
||||
}
|
||||
};
|
||||
|
||||
private final List<Parameter> parameters;
|
||||
|
||||
CurveShape(List<Parameter> parameters) {
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
abstract double at(double t, Map<?, ?> parameters);
|
||||
|
||||
/** What shapes this curve beyond its from and to, each with the value it has unless the curve sets it. */
|
||||
public List<Parameter> parameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
/** As a value writes it, like {@code power}. */
|
||||
public String key() {
|
||||
return name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
final double parameter(Map<?, ?> written, String name) {
|
||||
if (written.containsKey(name)) {
|
||||
return Forms.number(written.get(name), name);
|
||||
}
|
||||
return parameters.stream().filter(parameter -> parameter.name().equals(name)).findFirst().orElseThrow().fallback();
|
||||
}
|
||||
|
||||
public record Parameter(String name, double fallback) {
|
||||
}
|
||||
}
|
||||
|
||||
/** Reads the forms a pack writes and writes a value back exactly as it was read. */
|
||||
static final class Forms implements JsonForms.Codec<ProceduralValue> {
|
||||
private static final String SHAPE = "shape";
|
||||
private static final String MIN = "min";
|
||||
private static final String MAX = "max";
|
||||
private static final String FROM = "from";
|
||||
private static final String TO = "to";
|
||||
private static final double DEFAULT_FROM = 0;
|
||||
private static final double DEFAULT_TO = 1;
|
||||
|
||||
@Override
|
||||
public ProceduralValue read(Object json) {
|
||||
return new ProceduralValue(json, formOf(json));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object write(ProceduralValue value) {
|
||||
return value.written;
|
||||
}
|
||||
|
||||
private static Form formOf(Object json) {
|
||||
return switch (json) {
|
||||
case Number number -> new Constant(number.doubleValue());
|
||||
case List<?> list -> listForm(list);
|
||||
case Map<?, ?> object when object.containsKey(SHAPE) -> shapeForm(object);
|
||||
case Map<?, ?> object when object.containsKey(MIN) && object.containsKey(MAX) ->
|
||||
new Range(number(object.get(MIN), MIN), number(object.get(MAX), MAX));
|
||||
case Map<?, ?> object -> throw new IllegalArgumentException("A value needs min and max, or a shape: " + object);
|
||||
default -> throw new IllegalArgumentException("A value is a number, a [min, max] range or a curve, not " + json);
|
||||
};
|
||||
}
|
||||
|
||||
private static Form listForm(List<?> list) {
|
||||
if (list.isEmpty()) {
|
||||
throw new IllegalArgumentException("A value can not be an empty list");
|
||||
}
|
||||
if (list.getFirst() instanceof Number) {
|
||||
if (list.size() != 2) {
|
||||
throw new IllegalArgumentException("A range is written [min, max]: " + list);
|
||||
}
|
||||
return new Range(number(list.get(0), MIN), number(list.get(1), MAX));
|
||||
}
|
||||
return keyframes(list);
|
||||
}
|
||||
|
||||
private static Form keyframes(List<?> list) {
|
||||
List<double[]> keys = new ArrayList<>();
|
||||
for (Object key : list) {
|
||||
if (!(key instanceof List<?> pair) || pair.size() != 2) {
|
||||
throw new IllegalArgumentException("A keyframe is written [t, value]: " + key);
|
||||
}
|
||||
keys.add(new double[]{number(pair.get(0), "t"), number(pair.get(1), "value")});
|
||||
}
|
||||
keys.sort((a, b) -> Double.compare(a[0], b[0]));
|
||||
double[] times = new double[keys.size()];
|
||||
double[] values = new double[keys.size()];
|
||||
for (int i = 0; i < keys.size(); i++) {
|
||||
times[i] = keys.get(i)[0];
|
||||
values[i] = keys.get(i)[1];
|
||||
}
|
||||
return new Keyframes(times, values);
|
||||
}
|
||||
|
||||
private static Form shapeForm(Map<?, ?> object) {
|
||||
String name = String.valueOf(object.get(SHAPE)).toUpperCase(Locale.ROOT);
|
||||
CurveShape shape;
|
||||
try {
|
||||
shape = CurveShape.valueOf(name);
|
||||
} catch (IllegalArgumentException unknown) {
|
||||
throw new IllegalArgumentException("Unknown curve shape " + name.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
double from = object.containsKey(FROM) ? number(object.get(FROM), FROM) : DEFAULT_FROM;
|
||||
double to = object.containsKey(TO) ? number(object.get(TO), TO) : DEFAULT_TO;
|
||||
return new Shape(shape, from, to, object);
|
||||
}
|
||||
|
||||
static double number(Object written, String name) {
|
||||
if (written instanceof Number number) {
|
||||
return number.doubleValue();
|
||||
}
|
||||
throw new IllegalArgumentException(name + " needs a number, not " + written);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.engine.procedural.part;
|
||||
|
||||
import art.arcane.iris.engine.procedural.BakeProfile;
|
||||
import art.arcane.iris.engine.procedural.ProceduralShape;
|
||||
import art.arcane.iris.engine.procedural.ProceduralVariants;
|
||||
import art.arcane.iris.modules.objects.ObjectBuilder;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.object.PlaceableObject;
|
||||
import com.volmit.resource.PackResources;
|
||||
|
||||
/** The variants of a procedural object, baked by {@link ObjectBaker}. */
|
||||
public final class ResolvedProceduralObject extends ProceduralVariants {
|
||||
private final ProceduralObject definition;
|
||||
private final PartOutline outline;
|
||||
|
||||
public ResolvedProceduralObject(String path, ProceduralObject definition, PackResources resources) {
|
||||
super(path, definition.seed(), definition.variants(), resources);
|
||||
this.definition = definition;
|
||||
this.outline = PartOutline.of(definition);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ProceduralShape generate(int index, RNG rng, ObjectBuilder blocks, BakeProfile profile) {
|
||||
return ObjectBaker.bake(definition, outline, rng, blocks, profile);
|
||||
}
|
||||
|
||||
public PartOutline outline() {
|
||||
return outline;
|
||||
}
|
||||
|
||||
/** Which part placed each block of {@code variant}, baked again to find out; empty when it is not one of these. */
|
||||
public PartTrace trace(PlaceableObject variant) {
|
||||
int index = bakeIndexOf(variant);
|
||||
if (index < 0) {
|
||||
return PartTrace.EMPTY;
|
||||
}
|
||||
return ObjectBaker.trace(definition, outline, variantRng(index), newBuilder());
|
||||
}
|
||||
}
|
||||
+12
-6
@@ -15,12 +15,18 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.engine.procedural.part;
|
||||
|
||||
package art.arcane.iris.engine.object.procedural.fungi;
|
||||
import com.volmit.config.Desc;
|
||||
|
||||
enum FungusCellRole {
|
||||
STEM,
|
||||
CAP,
|
||||
GILL,
|
||||
SPOT
|
||||
@Desc("Which open side a block needs for a material rule to apply to it.")
|
||||
public enum RuleFace {
|
||||
@Desc("Any side open to the air.")
|
||||
ANY,
|
||||
@Desc("Open above.")
|
||||
UP,
|
||||
@Desc("Open below.")
|
||||
DOWN,
|
||||
@Desc("Open on a horizontal side.")
|
||||
SIDE
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.engine.procedural.part;
|
||||
|
||||
/** How far a point is from the center of a cross-section, in the section's own measure, so 1 is on its edge at radius 1. */
|
||||
final class Sections {
|
||||
private static final double HEX_SLANT = Math.sqrt(3) / 2;
|
||||
|
||||
private Sections() {
|
||||
}
|
||||
|
||||
static double norm(PartSection section, double u, double w) {
|
||||
double au = Math.abs(u);
|
||||
double aw = Math.abs(w);
|
||||
return switch (section) {
|
||||
case ROUND -> Math.sqrt(u * u + w * w);
|
||||
case SQUARE -> Math.max(au, aw);
|
||||
case DIAMOND -> au + aw;
|
||||
case HEX -> Math.max(aw, au * HEX_SLANT + aw * 0.5);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,243 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.engine.procedural.part;
|
||||
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
/**
|
||||
* A stem traced as a path of closely spaced samples, each with a center, a direction and a radius, then swept into
|
||||
* blocks: one block per sample while it is thin, a slice of its cross-section once it is thicker.
|
||||
*/
|
||||
final class StemShape implements PartShape {
|
||||
static final double LONGEST_BLOCKS = 256;
|
||||
private static final double SAMPLE_SPACING_BLOCKS = 0.25;
|
||||
private static final double THIN_RADIUS_BLOCKS = 0.5;
|
||||
private static final double SWAY_FREQUENCY = 0.35;
|
||||
|
||||
private final double length;
|
||||
private final double[][] centers;
|
||||
private final double[][] headings;
|
||||
private final double[] radii;
|
||||
private final double outward;
|
||||
|
||||
private StemShape(double length, double[][] centers, double[][] headings, double[] radii, double outward) {
|
||||
this.length = length;
|
||||
this.centers = centers;
|
||||
this.headings = headings;
|
||||
this.radii = radii;
|
||||
this.outward = outward;
|
||||
}
|
||||
|
||||
/** Traces the stem from {@code spot} without placing anything. */
|
||||
static StemShape trace(PartStem stem, PartSpot spot, RNG rng) {
|
||||
double length = stemLength(stem, spot, rng);
|
||||
double baseRadius = Math.max(0, stem.radius().sample(rng, spot.parentT()));
|
||||
ProceduralValue taper = stem.taper() == null ? null : stem.taper().fix(rng);
|
||||
double facing = stem.facing() != null ? stem.facing().sample(rng, spot.parentT())
|
||||
: spot.hasOutward() ? spot.outward() : rng.d(0, 360);
|
||||
double[] heading = startHeading(stem, spot, facing, rng);
|
||||
double[] toward = Vectors.across(heading, Vectors.direction(facing, 0));
|
||||
double[] beside = Vectors.normalize(Vectors.cross(heading, toward), toward);
|
||||
|
||||
Bends bends = Bends.of(stem, spot, rng, length);
|
||||
double pathLength = Math.max(0, length - 1);
|
||||
int steps = Math.max(2, (int) Math.ceil(pathLength / SAMPLE_SPACING_BLOCKS));
|
||||
double step = pathLength / steps;
|
||||
double[][] centers = new double[steps + 1][];
|
||||
double[] radii = new double[steps + 1];
|
||||
double[] base = spot.origin().clone();
|
||||
for (int i = 0; i <= steps; i++) {
|
||||
double t = i / (double) steps;
|
||||
if (i > 0) {
|
||||
double middle = (i - 0.5) / steps;
|
||||
base = Vectors.addScaled(base, bends.heading(heading, toward, middle), step);
|
||||
}
|
||||
centers[i] = Vectors.add(base, bends.offset(toward, beside, t, pathLength));
|
||||
radii[i] = baseRadius * (taper == null ? 1 : Math.max(0, taper.at(t)));
|
||||
}
|
||||
return new StemShape(length, centers, directions(centers, heading), radii, facing);
|
||||
}
|
||||
|
||||
/** Places the stem's blocks and records its tip. */
|
||||
void draw(PartFill fill, PartSection section, double roughness, double jitter) {
|
||||
for (int i = 0; i < centers.length; i++) {
|
||||
double t = i / (double) (centers.length - 1);
|
||||
PartCanvas.Axis axis = PartCanvas.Axis.along(headings[i]);
|
||||
if (radii[i] <= THIN_RADIUS_BLOCKS && roughness <= 0) {
|
||||
fill.place(round(centers[i][0]), round(centers[i][1]), round(centers[i][2]), 0, t, axis);
|
||||
continue;
|
||||
}
|
||||
sweepSlice(fill, i, t, axis, section, roughness, jitter);
|
||||
}
|
||||
double[] tip = centers[centers.length - 1];
|
||||
fill.canvas().addTip(new PartCanvas.Tip(round(tip[0]), round(tip[1]), round(tip[2]), headings[headings.length - 1], fill.role()));
|
||||
}
|
||||
|
||||
private void sweepSlice(PartFill fill, int index, double t, PartCanvas.Axis axis, PartSection section, double roughness, double jitter) {
|
||||
double[] center = centers[index];
|
||||
double[] heading = headings[index];
|
||||
double radius = Math.max(THIN_RADIUS_BLOCKS, radii[index]);
|
||||
double[] across = Vectors.across(heading, new double[]{1, 0, 0});
|
||||
double[] beside = Vectors.cross(heading, across);
|
||||
double slab = SAMPLE_SPACING_BLOCKS * 0.5 + 0.5;
|
||||
boolean first = index == 0;
|
||||
boolean last = index == centers.length - 1;
|
||||
int squareWidth = Math.max(1, (int) Math.round(radius * 2));
|
||||
double squareShift = section == PartSection.SQUARE && squareWidth % 2 == 0 ? 0.5 : 0;
|
||||
int reach = (int) Math.ceil(radius * (1 + roughness) + 1.5);
|
||||
int cx = round(center[0]);
|
||||
int cy = round(center[1]);
|
||||
int cz = round(center[2]);
|
||||
for (int x = cx - reach; x <= cx + reach; x++) {
|
||||
for (int y = cy - reach; y <= cy + reach; y++) {
|
||||
for (int z = cz - reach; z <= cz + reach; z++) {
|
||||
double[] offset = {x - center[0], y - center[1], z - center[2]};
|
||||
double axial = Vectors.dot(offset, heading);
|
||||
if (Math.abs(axial) > slab || (first && axial < -0.5) || (last && axial > 0.5)) {
|
||||
continue;
|
||||
}
|
||||
double[] radial = Vectors.addScaled(offset, heading, -axial);
|
||||
double u = Vectors.dot(radial, across) - squareShift;
|
||||
double w = Vectors.dot(radial, beside) - squareShift;
|
||||
double limit = section == PartSection.SQUARE ? squareWidth / 2.0 : radius;
|
||||
double edge = Sections.norm(section, u, w);
|
||||
if (roughness > 0) {
|
||||
limit += (PartNoise.hash(x, y, z, fill.seed() + 9001L) - 0.5) * roughness * (radius + 1);
|
||||
}
|
||||
boolean core = x == cx && y == cy && z == cz;
|
||||
if (!core && edge > limit) {
|
||||
continue;
|
||||
}
|
||||
if (!core && jitter > 0 && edge > limit - 1 && PartNoise.hash(x, y, z, fill.seed() + 77L) < jitter * 0.5) {
|
||||
continue;
|
||||
}
|
||||
fill.place(x, y, z, Math.min(edge, limit) / (limit + 1), t, axis);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PartSpot spotAt(double t) {
|
||||
double position = Math.max(0, Math.min(1, t)) * (centers.length - 1);
|
||||
int index = (int) Math.floor(position);
|
||||
int next = Math.min(centers.length - 1, index + 1);
|
||||
double blend = position - index;
|
||||
double[] center = Vectors.add(Vectors.scale(centers[index], 1 - blend), Vectors.scale(centers[next], blend));
|
||||
double[] heading = headings[index];
|
||||
double outwardHere = Vectors.isVertical(heading) ? outward : Vectors.azimuth(heading);
|
||||
return new PartSpot(center, heading.clone(), t, length, outwardHere);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double length() {
|
||||
return length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double defaultAt() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static double stemLength(PartStem stem, PartSpot spot, RNG rng) {
|
||||
double length = stem.lengthScale() > 0 && spot.parentLength() > 0
|
||||
? spot.parentLength() * stem.lengthScale()
|
||||
: stem.length().sample(rng, spot.parentT());
|
||||
return Math.max(1, Math.min(LONGEST_BLOCKS, length));
|
||||
}
|
||||
|
||||
private static double[] startHeading(PartStem stem, PartSpot spot, double facing, RNG rng) {
|
||||
if (stem.pitch() == null && stem.azimuth() == null) {
|
||||
return spot.heading().clone();
|
||||
}
|
||||
double pitch = stem.pitch() != null ? stem.pitch().sample(rng, spot.parentT()) : Vectors.pitch(spot.heading());
|
||||
double azimuth = stem.azimuth() != null ? stem.azimuth().sample(rng, spot.parentT())
|
||||
: Vectors.isVertical(spot.heading()) ? facing : Vectors.azimuth(spot.heading());
|
||||
return Vectors.direction(azimuth, pitch);
|
||||
}
|
||||
|
||||
/** The direction at each sample, from its neighbors, so offsets such as lean and corkscrew turn the slices too. */
|
||||
private static double[][] directions(double[][] centers, double[] fallback) {
|
||||
double[][] headings = new double[centers.length][];
|
||||
for (int i = 0; i < centers.length; i++) {
|
||||
double[] before = centers[Math.max(0, i - 1)];
|
||||
double[] after = centers[Math.min(centers.length - 1, i + 1)];
|
||||
headings[i] = Vectors.normalize(Vectors.subtract(after, before), i > 0 ? headings[i - 1] : fallback);
|
||||
}
|
||||
return headings;
|
||||
}
|
||||
|
||||
private static int round(double value) {
|
||||
return (int) Math.round(value);
|
||||
}
|
||||
|
||||
/** Everything that pulls a stem off a straight line, rolled once per stem. */
|
||||
private record Bends(double leanTangent, ProceduralValue leanCurve, double bendRadians, ProceduralValue bendCurve,
|
||||
double droop, double sway, double wave, double wavePeriods, double wavePhase,
|
||||
ProceduralValue helixRadius, double helixTurns, long swaySeed) {
|
||||
static Bends of(PartStem stem, PartSpot spot, RNG rng, double length) {
|
||||
double t = spot.parentT();
|
||||
double lean = Math.max(-85, Math.min(85, sample(stem.lean(), rng, t)));
|
||||
return new Bends(Math.tan(Math.toRadians(lean)), fixed(stem.leanCurve(), rng),
|
||||
Math.toRadians(sample(stem.bend(), rng, t)), fixed(stem.bendCurve(), rng),
|
||||
sample(stem.droop(), rng, t), sample(stem.sway(), rng, t),
|
||||
sample(stem.wave(), rng, t), sample(stem.wavePeriods(), rng, t), rng.d(0, Math.PI * 2),
|
||||
fixed(stem.helixRadius(), rng), sample(stem.helixTurns(), rng, t), rng.nextLong());
|
||||
}
|
||||
|
||||
double[] heading(double[] start, double[] toward, double t) {
|
||||
if (bendRadians == 0) {
|
||||
return start;
|
||||
}
|
||||
double angle = bendRadians * progress(bendCurve, t);
|
||||
return Vectors.add(Vectors.scale(start, Math.cos(angle)), Vectors.scale(toward, Math.sin(angle)));
|
||||
}
|
||||
|
||||
double[] offset(double[] toward, double[] beside, double t, double pathLength) {
|
||||
double[] offset = Vectors.scale(toward, pathLength * leanTangent * progress(leanCurve, t));
|
||||
offset[1] -= droop * pathLength * t * t;
|
||||
double helix = helixRadius == null ? 0 : helixRadius.at(t);
|
||||
if (helix != 0) {
|
||||
double angle = Math.PI * 2 * helixTurns * t;
|
||||
offset = Vectors.addScaled(offset, toward, Math.cos(angle) * helix);
|
||||
offset = Vectors.addScaled(offset, beside, Math.sin(angle) * helix);
|
||||
}
|
||||
if (wave != 0) {
|
||||
offset = Vectors.addScaled(offset, beside, wave * Math.sin(Math.PI * 2 * wavePeriods * t + wavePhase));
|
||||
}
|
||||
if (sway != 0) {
|
||||
double along = t * pathLength * SWAY_FREQUENCY;
|
||||
offset = Vectors.addScaled(offset, toward, sway * (PartNoise.line(along, swaySeed) * 2 - 1));
|
||||
offset = Vectors.addScaled(offset, beside, sway * (PartNoise.line(along, swaySeed + 1) * 2 - 1));
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
|
||||
private static double progress(ProceduralValue curve, double t) {
|
||||
return curve == null ? t : curve.at(t);
|
||||
}
|
||||
|
||||
private static double sample(ProceduralValue value, RNG rng, double t) {
|
||||
return value == null ? 0 : value.sample(rng, t);
|
||||
}
|
||||
|
||||
private static ProceduralValue fixed(ProceduralValue value, RNG rng) {
|
||||
return value == null ? null : value.fix(rng);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package art.arcane.iris.engine.procedural.part;
|
||||
|
||||
/** Small vector maths on {@code double[3]}, with compass azimuths measured from south (+z) toward east (+x). */
|
||||
final class Vectors {
|
||||
static final double[] UP = {0, 1, 0};
|
||||
|
||||
private Vectors() {
|
||||
}
|
||||
|
||||
/** The unit direction {@code azimuth} degrees around the compass and {@code pitch} degrees above the horizon. */
|
||||
static double[] direction(double azimuth, double pitch) {
|
||||
double a = Math.toRadians(azimuth);
|
||||
double p = Math.toRadians(pitch);
|
||||
return new double[]{Math.cos(p) * Math.sin(a), Math.sin(p), Math.cos(p) * Math.cos(a)};
|
||||
}
|
||||
|
||||
static double azimuth(double[] direction) {
|
||||
return Math.toDegrees(Math.atan2(direction[0], direction[2]));
|
||||
}
|
||||
|
||||
static double pitch(double[] direction) {
|
||||
return Math.toDegrees(Math.asin(Math.max(-1, Math.min(1, direction[1]))));
|
||||
}
|
||||
|
||||
static boolean isVertical(double[] direction) {
|
||||
return Math.abs(direction[1]) > 0.999;
|
||||
}
|
||||
|
||||
static double[] add(double[] a, double[] b) {
|
||||
return new double[]{a[0] + b[0], a[1] + b[1], a[2] + b[2]};
|
||||
}
|
||||
|
||||
static double[] subtract(double[] a, double[] b) {
|
||||
return new double[]{a[0] - b[0], a[1] - b[1], a[2] - b[2]};
|
||||
}
|
||||
|
||||
static double[] scale(double[] a, double factor) {
|
||||
return new double[]{a[0] * factor, a[1] * factor, a[2] * factor};
|
||||
}
|
||||
|
||||
static double[] addScaled(double[] a, double[] b, double factor) {
|
||||
return new double[]{a[0] + b[0] * factor, a[1] + b[1] * factor, a[2] + b[2] * factor};
|
||||
}
|
||||
|
||||
static double dot(double[] a, double[] b) {
|
||||
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
||||
}
|
||||
|
||||
static double[] cross(double[] a, double[] b) {
|
||||
return new double[]{a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]};
|
||||
}
|
||||
|
||||
static double length(double[] a) {
|
||||
return Math.sqrt(dot(a, a));
|
||||
}
|
||||
|
||||
/** {@code a} scaled to length 1; {@code fallback} when it has no length. */
|
||||
static double[] normalize(double[] a, double[] fallback) {
|
||||
double length = length(a);
|
||||
return length < 1e-9 ? fallback.clone() : scale(a, 1 / length);
|
||||
}
|
||||
|
||||
/** The unit vector across {@code axis} that points most toward {@code toward}; any across one when they line up. */
|
||||
static double[] across(double[] axis, double[] toward) {
|
||||
double[] flattened = subtract(toward, scale(axis, dot(toward, axis)));
|
||||
if (length(flattened) > 1e-6) {
|
||||
return normalize(flattened, UP);
|
||||
}
|
||||
double[] reference = Math.abs(axis[0]) < 0.9 ? new double[]{1, 0, 0} : new double[]{0, 0, 1};
|
||||
return normalize(subtract(reference, scale(axis, dot(reference, axis))), UP);
|
||||
}
|
||||
|
||||
/** {@code direction} turned {@code degrees} toward {@code azimuth}, for leaning something away from where it points. */
|
||||
static double[] tilted(double[] direction, double azimuth, double degrees) {
|
||||
double[] toward = across(direction, direction(azimuth, 0));
|
||||
double angle = Math.toRadians(degrees);
|
||||
return normalize(add(scale(direction, Math.cos(angle)), scale(toward, Math.sin(angle))), direction);
|
||||
}
|
||||
}
|
||||
@@ -19,30 +19,15 @@
|
||||
package art.arcane.iris.modules.objects;
|
||||
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.PlacementSource;
|
||||
import art.arcane.iris.builtin.prepare.AxisRotationClamp;
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* The object placement settings a placement is made with: an object placement's own, or the options a procedural object
|
||||
* is scattered with, with the changes {@code iris:objects} makes for where it places them. One per world, so each
|
||||
* procedural object's options are made once.
|
||||
*/
|
||||
/** The object placement settings a placement is made with: its own, with the changes {@code iris:objects} makes for where it places them. */
|
||||
public final class EffectiveSettings {
|
||||
private static final double UPSIDE_DOWN_TURN_DEGREES = 180D;
|
||||
private static final double QUARTER_TURN_DEGREES = 90D;
|
||||
|
||||
private final Map<ProceduralPlacement, ObjectPlacement> proceduralOptions = new ConcurrentHashMap<>();
|
||||
|
||||
/** The settings {@code placement} places with, with {@code changes} made to a copy of them. */
|
||||
public ObjectPlacement of(PlacementSource placement, PlacementChanges changes) {
|
||||
ObjectPlacement base = placement instanceof ObjectPlacement settings
|
||||
? settings
|
||||
: proceduralOptions.computeIfAbsent((ProceduralPlacement) placement, EffectiveSettings::optionsOf);
|
||||
return withChanges(base, changes);
|
||||
private EffectiveSettings() {
|
||||
}
|
||||
|
||||
/** {@code base} with {@code changes} made to a copy of it; {@code base} itself when there are none. */
|
||||
@@ -75,23 +60,6 @@ public final class EffectiveSettings {
|
||||
return changed.build();
|
||||
}
|
||||
|
||||
/** The options a procedural object is scattered with, as an object placement. */
|
||||
private static ObjectPlacement optionsOf(ProceduralPlacement procedural) {
|
||||
return ObjectPlacement.builder()
|
||||
.mode(procedural.mode())
|
||||
.rotation(procedural.rotation())
|
||||
.clamp(procedural.clamp())
|
||||
.carvingSupport(procedural.carvingSupport())
|
||||
.underwater(procedural.underwater())
|
||||
.translate(procedural.translate())
|
||||
.stiltSettings(procedural.stiltSettings().orElse(null))
|
||||
.vacuumSettings(procedural.vacuumSettings().orElse(null))
|
||||
.chance(procedural.chance())
|
||||
.density(procedural.density())
|
||||
.surfaceSupportBuffer(procedural.surfaceSupportBuffer())
|
||||
.build();
|
||||
}
|
||||
|
||||
private static ObjectRotation upsideDownRotation() {
|
||||
return ObjectRotation.of(true,
|
||||
AxisRotationClamp.of(true, true, UPSIDE_DOWN_TURN_DEGREES, UPSIDE_DOWN_TURN_DEGREES, QUARTER_TURN_DEGREES),
|
||||
|
||||
@@ -20,6 +20,7 @@ package art.arcane.iris.modules.objects;
|
||||
|
||||
import com.volmit.block.BlockRegistry;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.block.BlockTrait;
|
||||
import com.volmit.block.PaletteSpec;
|
||||
import com.volmit.object.ObjectBlock;
|
||||
import com.volmit.object.PackObjects;
|
||||
@@ -51,6 +52,11 @@ public final class ObjectBuilder {
|
||||
return blocks.palette(palette, seed).at(x, y, z);
|
||||
}
|
||||
|
||||
/** Whether the platform gives {@code state} the trait, such as a log or air. */
|
||||
public boolean has(BlockState state, BlockTrait trait) {
|
||||
return blocks.hasTrait(state, trait);
|
||||
}
|
||||
|
||||
/** {@code state} with the property set, as the platform sets it. */
|
||||
public BlockState withProperty(BlockState state, String name, String value) {
|
||||
return blocks.withProperty(state, name, value);
|
||||
|
||||
@@ -22,6 +22,7 @@ import art.arcane.iris.builtin.LegacyStreams;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.ObjectScale;
|
||||
import art.arcane.iris.builtin.objects.ScaleInterpolation;
|
||||
import art.arcane.iris.engine.procedural.ProceduralObjectCatalog;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.object.PackObjects;
|
||||
import com.volmit.object.PlaceableObject;
|
||||
@@ -42,15 +43,17 @@ public final class ObjectPool {
|
||||
|
||||
private final PackResources resources;
|
||||
private final LegacyStreams streams;
|
||||
private final ProceduralObjectCatalog procedural;
|
||||
|
||||
private ObjectPool(PackResources resources, LegacyStreams streams) {
|
||||
private ObjectPool(PackResources resources, LegacyStreams streams, ProceduralObjectCatalog procedural) {
|
||||
this.resources = resources;
|
||||
this.streams = streams;
|
||||
this.procedural = procedural;
|
||||
}
|
||||
|
||||
/** The objects of {@code world}'s pack. */
|
||||
/** The objects of {@code world}'s pack, its procedural objects among them. */
|
||||
public static ObjectPool of(PackWorld world) {
|
||||
return new ObjectPool(world.resources(), world.extension(LegacyStreams.class).orElseThrow());
|
||||
return new ObjectPool(world.resources(), world.extension(LegacyStreams.class).orElseThrow(), ProceduralObjectCatalog.of(world));
|
||||
}
|
||||
|
||||
/** The random a chunk's objects are placed with. */
|
||||
@@ -58,8 +61,11 @@ public final class ObjectPool {
|
||||
return streams.objectChunkRandom(chunkX, chunkZ);
|
||||
}
|
||||
|
||||
/** The pack object {@code key} names. */
|
||||
public Optional<PlaceableObject> object(String key) {
|
||||
/** The pack object {@code key} names; for a procedural pool, the variant {@code rng} picks. */
|
||||
public Optional<PlaceableObject> object(String key, RNG rng) {
|
||||
if (ProceduralObjectCatalog.isProceduralKey(key)) {
|
||||
return procedural.object(key, rng);
|
||||
}
|
||||
return objects().object(resources.idOf(key));
|
||||
}
|
||||
|
||||
@@ -69,7 +75,7 @@ public final class ObjectPool {
|
||||
if (keys.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return object(keys.get(rng.nextInt(keys.size()))).map(origin -> scaled(origin, placement.scale(), rng));
|
||||
return object(keys.get(rng.nextInt(keys.size())), rng).map(origin -> scaled(origin, placement.scale(), rng));
|
||||
}
|
||||
|
||||
/** {@code origin} shrunk or grown by exactly {@code factor}, without filling between its blocks. */
|
||||
@@ -82,9 +88,10 @@ public final class ObjectPool {
|
||||
return streams.density(placement, rng, x, z);
|
||||
}
|
||||
|
||||
/** Builds the noise the placement draws its density from, so the first chunk to place it does not wait. */
|
||||
/** Builds the noise the placement draws its density from and bakes its procedural objects, so the first chunk to place it does not wait. */
|
||||
public void warm(ObjectPlacement placement, RNG rng) {
|
||||
streams.density(placement, rng, 0, 0);
|
||||
placement.place().stream().filter(ProceduralObjectCatalog::isProceduralKey).forEach(procedural::placeable);
|
||||
}
|
||||
|
||||
private PlaceableObject scaled(PlaceableObject origin, ObjectScale scale, RNG rng) {
|
||||
|
||||
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.modules.objects;
|
||||
|
||||
import art.arcane.iris.modules.objects.coral.Coral;
|
||||
import art.arcane.iris.modules.objects.crystal.Crystal;
|
||||
import art.arcane.iris.modules.objects.formation.Formation;
|
||||
import art.arcane.iris.modules.objects.fungi.Fungus;
|
||||
import art.arcane.iris.modules.objects.ruin.Ruin;
|
||||
import art.arcane.iris.modules.objects.tree.Tree;
|
||||
import com.volmit.config.Level;
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.config.Desc;
|
||||
import com.volmit.config.Feature;
|
||||
import com.volmit.config.MinItems;
|
||||
import com.volmit.config.Snippet;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The procedural objects a region or biome declares, written as {@code "proceduralObjects": {"trees": [...], ...}}: things
|
||||
* Iris generates from scratch at world-gen time and places like object placements.
|
||||
*/
|
||||
@Snippet("iris/objects/procedural-objects")
|
||||
@Desc("Procedurally generated objects placed in a biome or region. Unlike the objects block (which loads iob files), these are generated from scratch at world-gen time.")
|
||||
@Feature(id = "iris:objects/procedural", name = "Procedural objects", key = "proceduralObjects", targets = {Level.REGION, Level.BIOME})
|
||||
public final class ProceduralObjectSettings implements IrisFeature {
|
||||
@MinItems(1)
|
||||
@Desc("Procedurally generated trees.")
|
||||
private List<Tree> trees = List.of();
|
||||
|
||||
@MinItems(1)
|
||||
@Desc("Procedurally generated ruins (crumbling pillars, walls, arches, rubble).")
|
||||
private List<Ruin> ruins = List.of();
|
||||
|
||||
@MinItems(1)
|
||||
@Desc("Procedurally generated natural rock formations (spires, hoodoos, arches, sea stacks, boulders, basalt columns).")
|
||||
private List<Formation> formations = List.of();
|
||||
|
||||
@MinItems(1)
|
||||
@Desc("Procedurally generated underwater coral structures.")
|
||||
private List<Coral> coral = List.of();
|
||||
|
||||
@MinItems(1)
|
||||
@Desc("Procedurally generated mushrooms and shelf fungi.")
|
||||
private List<Fungus> fungi = List.of();
|
||||
|
||||
@MinItems(1)
|
||||
@Desc("Procedurally generated crystal clusters (usually placed in caves).")
|
||||
private List<Crystal> crystals = List.of();
|
||||
|
||||
public ProceduralObjectSettings() {
|
||||
}
|
||||
|
||||
public List<Tree> trees() {
|
||||
return view(trees);
|
||||
}
|
||||
|
||||
public List<Ruin> ruins() {
|
||||
return view(ruins);
|
||||
}
|
||||
|
||||
public List<Formation> formations() {
|
||||
return view(formations);
|
||||
}
|
||||
|
||||
public List<Coral> coral() {
|
||||
return view(coral);
|
||||
}
|
||||
|
||||
public List<Fungus> fungi() {
|
||||
return view(fungi);
|
||||
}
|
||||
|
||||
public List<Crystal> crystals() {
|
||||
return view(crystals);
|
||||
}
|
||||
|
||||
private static <T> List<T> view(List<T> list) {
|
||||
return list == null ? List.of() : Collections.unmodifiableList(list);
|
||||
}
|
||||
}
|
||||
Loaded 100 of 126 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user