From d2ce5f4a05950ee14f8186280617a726391a43b2 Mon Sep 17 00:00:00 2001 From: piexel Date: Thu, 5 Nov 2026 23:00:20 +0100 Subject: [PATCH] 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/ and procedural/# 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. --- README.md | 5 +- builtin-modules.txt | 2 +- .../iris/builtin/objects/ObjectPlacement.java | 10 +- .../iris/builtin/objects/PlacementSource.java | 42 -- .../mantle/components/CaveSettings.java | 6 +- .../mantle/components/ChunkObjectPlacing.java | 149 +---- .../components/EffectivePlacements.java | 10 +- .../components/FloatingObjectPlacing.java | 5 +- .../engine/mantle/components/ObjectChunk.java | 33 +- .../mantle/components/ObjectModule.java | 13 +- .../mantle/components/ObjectPlacing.java | 4 +- .../mantle/components/ObjectWarmUp.java | 15 - .../mantle/components/PlacementReach.java | 38 +- .../engine/mantle/components/TreeGrowing.java | 41 +- .../procedural/IrisProceduralBlocks.java | 134 ----- .../procedural/ResolvedProceduralObjects.java | 76 --- .../ResolvedProceduralPlacement.java | 181 ------- .../object/procedural/coral/CoralCanvas.java | 64 --- .../procedural/coral/CoralGenerator.java | 263 --------- .../procedural/coral/ResolvedCoral.java | 43 -- .../crystal/CrystalBaseBuilder.java | 49 -- .../procedural/crystal/CrystalCanvas.java | 52 -- .../procedural/crystal/CrystalGenerator.java | 112 ---- .../procedural/crystal/CrystalGeometry.java | 85 --- .../crystal/CrystalShardBuilder.java | 125 ----- .../procedural/crystal/ResolvedCrystal.java | 43 -- .../formation/FormationBlockResolver.java | 67 --- .../procedural/formation/FormationCanvas.java | 61 --- .../formation/FormationGenerator.java | 75 --- .../formation/FormationProfiles.java | 58 -- .../formation/FormationShapeBuilder.java | 429 --------------- .../formation/ResolvedFormation.java | 48 -- .../procedural/fungi/FungusCapBuilder.java | 119 ---- .../procedural/fungi/FungusGenerator.java | 104 ---- .../procedural/fungi/FungusShelfBuilder.java | 81 --- .../procedural/fungi/FungusStemBuilder.java | 95 ---- .../procedural/fungi/ResolvedFungus.java | 76 --- .../object/procedural/ruin/ResolvedRuin.java | 43 -- .../procedural/ruin/RuinBlockCanvas.java | 107 ---- .../procedural/ruin/RuinDecoratorApplier.java | 122 ----- .../object/procedural/ruin/RuinGenerator.java | 200 ------- .../object/procedural/ruin/RuinShapes.java | 146 ----- .../tree/ProceduralTreeGenerator.java | 127 ----- .../object/procedural/tree/ResolvedTree.java | 96 ---- .../procedural/tree/TreeBlockCanvas.java | 102 ---- .../procedural/tree/TreeBlockResolver.java | 165 ------ .../procedural/tree/TreeCanopyBuilder.java | 352 ------------ .../procedural/tree/TreeDecoratorApplier.java | 280 ---------- .../object/procedural/tree/TreeFunctions.java | 197 ------- .../procedural/tree/TreePlausibility.java | 109 ---- .../object/procedural/tree/TreeProfiles.java | 80 --- .../procedural/tree/TreeRootBuilder.java | 154 ------ .../object/procedural/tree/TreeSupport.java | 90 --- .../procedural/tree/TreeTrunkBuilder.java | 202 ------- .../iris/engine/procedural/BakeProfile.java | 85 +++ .../procedural/IrisProceduralBlocks.java | 100 ++++ .../procedural/ProceduralObjectCatalog.java | 142 +++++ .../procedural/ProceduralShape.java | 2 +- .../engine/procedural/ProceduralVariants.java | 152 ++++++ .../engine/procedural/part/BlobShape.java | 160 ++++++ .../engine/procedural/part/BlockChoice.java | 45 ++ .../procedural/part/BranchAzimuth.java} | 25 +- .../procedural/part/ClusterLayout.java} | 21 +- .../procedural/part/DecorationSpot.java} | 25 +- .../engine/procedural/part/Decorator.java | 271 ++++++++++ .../engine/procedural/part/LeafDecay.java | 132 +++++ .../procedural/part/MaterialPainter.java | 135 +++++ .../engine/procedural/part/MaterialRule.java | 85 +++ .../engine/procedural/part/ObjectBaker.java | 120 ++++ .../iris/engine/procedural/part/PartBlob.java | 108 ++++ .../engine/procedural/part/PartBranches.java | 107 ++++ .../engine/procedural/part/PartCanvas.java | 140 +++++ .../engine/procedural/part/PartCluster.java | 60 ++ .../iris/engine/procedural/part/PartFill.java | 41 ++ .../engine/procedural/part/PartGrower.java | 201 +++++++ .../procedural/part/PartMode.java} | 18 +- .../engine/procedural/part/PartNoise.java | 98 ++++ .../engine/procedural/part/PartOffset.java | 41 ++ .../engine/procedural/part/PartOutline.java | 134 +++++ .../part/PartPattern.java} | 13 +- .../engine/procedural/part/PartSection.java | 32 ++ .../engine/procedural/part/PartShape.java | 48 ++ .../iris/engine/procedural/part/PartSpot.java | 36 ++ .../iris/engine/procedural/part/PartStem.java | 170 ++++++ .../engine/procedural/part/PartTrace.java | 39 ++ .../procedural/part/ProceduralDecoration.java | 96 ++++ .../procedural/part/ProceduralMaterial.java | 63 +++ .../procedural/part/ProceduralObject.java | 98 ++++ .../procedural/part/ProceduralPart.java | 127 +++++ .../procedural/part/ProceduralSpan.java | 55 ++ .../procedural/part/ProceduralValue.java | 299 ++++++++++ .../part/ResolvedProceduralObject.java | 56 ++ .../part/RuleFace.java} | 18 +- .../iris/engine/procedural/part/Sections.java | 37 ++ .../engine/procedural/part/StemShape.java | 243 +++++++++ .../iris/engine/procedural/part/Vectors.java | 96 ++++ .../modules/objects/EffectiveSettings.java | 36 +- .../iris/modules/objects/ObjectBuilder.java | 6 + .../iris/modules/objects/ObjectPool.java | 21 +- .../objects/ProceduralObjectSettings.java | 99 ---- .../modules/objects/ProceduralPlacement.java | 97 ---- .../iris/modules/objects/coral/Coral.java | 344 ------------ .../iris/modules/objects/coral/CoralForm.java | 39 -- .../iris/modules/objects/crystal/Crystal.java | 314 ----------- .../objects/crystal/CrystalSurface.java | 33 -- .../modules/objects/formation/Formation.java | 447 --------------- .../objects/formation/FormationForm.java | 45 -- .../objects/formation/FormationProfile.java | 35 -- .../iris/modules/objects/fungi/Fungus.java | 355 ------------ .../modules/objects/fungi/FungusCapShape.java | 35 -- .../iris/modules/objects/ruin/Ruin.java | 286 ---------- .../modules/objects/ruin/RuinDecorator.java | 78 --- .../iris/modules/objects/ruin/RuinForm.java | 35 -- .../iris/modules/objects/tree/Tree.java | 511 ------------------ .../modules/objects/tree/TreeAzimuthMode.java | 45 -- .../objects/tree/TreeBranchProbability.java | 47 -- .../modules/objects/tree/TreeBranches.java | 237 -------- .../iris/modules/objects/tree/TreeCanopy.java | 102 ---- .../modules/objects/tree/TreeDecorator.java | 85 --- .../objects/tree/TreeDecoratorTarget.java | 45 -- .../modules/objects/tree/TreeFunction.java | 47 -- .../iris/modules/objects/tree/TreeLayer.java | 45 -- .../modules/objects/tree/TreeLeafMode.java | 43 -- .../modules/objects/tree/TreeProfile.java | 53 -- .../objects/tree/TreeSecondaryLeaf.java | 50 -- .../modules/objects/tree/TreeSubBranches.java | 93 ---- 126 files changed, 4031 insertions(+), 9036 deletions(-) delete mode 100644 src/main/java/art/arcane/iris/builtin/objects/PlacementSource.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/IrisProceduralBlocks.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/ResolvedProceduralObjects.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/ResolvedProceduralPlacement.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/coral/CoralCanvas.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/coral/CoralGenerator.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/coral/ResolvedCoral.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/crystal/CrystalBaseBuilder.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/crystal/CrystalCanvas.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/crystal/CrystalGenerator.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/crystal/CrystalGeometry.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/crystal/CrystalShardBuilder.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/crystal/ResolvedCrystal.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/formation/FormationBlockResolver.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/formation/FormationCanvas.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/formation/FormationGenerator.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/formation/FormationProfiles.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/formation/FormationShapeBuilder.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/formation/ResolvedFormation.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/fungi/FungusCapBuilder.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/fungi/FungusGenerator.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/fungi/FungusShelfBuilder.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/fungi/FungusStemBuilder.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/fungi/ResolvedFungus.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/ruin/ResolvedRuin.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/ruin/RuinBlockCanvas.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/ruin/RuinDecoratorApplier.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/ruin/RuinGenerator.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/ruin/RuinShapes.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/tree/ProceduralTreeGenerator.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/tree/ResolvedTree.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/tree/TreeBlockCanvas.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/tree/TreeBlockResolver.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/tree/TreeCanopyBuilder.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/tree/TreeDecoratorApplier.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/tree/TreeFunctions.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/tree/TreePlausibility.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/tree/TreeProfiles.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/tree/TreeRootBuilder.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/tree/TreeSupport.java delete mode 100644 src/main/java/art/arcane/iris/engine/object/procedural/tree/TreeTrunkBuilder.java create mode 100644 src/main/java/art/arcane/iris/engine/procedural/BakeProfile.java create mode 100644 src/main/java/art/arcane/iris/engine/procedural/IrisProceduralBlocks.java create mode 100644 src/main/java/art/arcane/iris/engine/procedural/ProceduralObjectCatalog.java rename src/main/java/art/arcane/iris/engine/{object => }/procedural/ProceduralShape.java (95%) create mode 100644 src/main/java/art/arcane/iris/engine/procedural/ProceduralVariants.java create mode 100644 src/main/java/art/arcane/iris/engine/procedural/part/BlobShape.java create mode 100644 src/main/java/art/arcane/iris/engine/procedural/part/BlockChoice.java rename src/main/java/art/arcane/iris/{modules/objects/coral/CoralBranchAzimuth.java => engine/procedural/part/BranchAzimuth.java} (57%) rename src/main/java/art/arcane/iris/{modules/objects/tree/TreeRootStyle.java => engine/procedural/part/ClusterLayout.java} (62%) rename src/main/java/art/arcane/iris/{modules/objects/ruin/RuinDecoratorTarget.java => engine/procedural/part/DecorationSpot.java} (56%) create mode 100644 src/main/java/art/arcane/iris/engine/procedural/part/Decorator.java create mode 100644 src/main/java/art/arcane/iris/engine/procedural/part/LeafDecay.java create mode 100644 src/main/java/art/arcane/iris/engine/procedural/part/MaterialPainter.java create mode 100644 src/main/java/art/arcane/iris/engine/procedural/part/MaterialRule.java create mode 100644 src/main/java/art/arcane/iris/engine/procedural/part/ObjectBaker.java create mode 100644 src/main/java/art/arcane/iris/engine/procedural/part/PartBlob.java create mode 100644 src/main/java/art/arcane/iris/engine/procedural/part/PartBranches.java create mode 100644 src/main/java/art/arcane/iris/engine/procedural/part/PartCanvas.java create mode 100644 src/main/java/art/arcane/iris/engine/procedural/part/PartCluster.java create mode 100644 src/main/java/art/arcane/iris/engine/procedural/part/PartFill.java create mode 100644 src/main/java/art/arcane/iris/engine/procedural/part/PartGrower.java rename src/main/java/art/arcane/iris/{modules/objects/crystal/CrystalDistribution.java => engine/procedural/part/PartMode.java} (59%) create mode 100644 src/main/java/art/arcane/iris/engine/procedural/part/PartNoise.java create mode 100644 src/main/java/art/arcane/iris/engine/procedural/part/PartOffset.java create mode 100644 src/main/java/art/arcane/iris/engine/procedural/part/PartOutline.java rename src/main/java/art/arcane/iris/engine/{object/procedural/crystal/CrystalRole.java => procedural/part/PartPattern.java} (70%) create mode 100644 src/main/java/art/arcane/iris/engine/procedural/part/PartSection.java create mode 100644 src/main/java/art/arcane/iris/engine/procedural/part/PartShape.java create mode 100644 src/main/java/art/arcane/iris/engine/procedural/part/PartSpot.java create mode 100644 src/main/java/art/arcane/iris/engine/procedural/part/PartStem.java create mode 100644 src/main/java/art/arcane/iris/engine/procedural/part/PartTrace.java create mode 100644 src/main/java/art/arcane/iris/engine/procedural/part/ProceduralDecoration.java create mode 100644 src/main/java/art/arcane/iris/engine/procedural/part/ProceduralMaterial.java create mode 100644 src/main/java/art/arcane/iris/engine/procedural/part/ProceduralObject.java create mode 100644 src/main/java/art/arcane/iris/engine/procedural/part/ProceduralPart.java create mode 100644 src/main/java/art/arcane/iris/engine/procedural/part/ProceduralSpan.java create mode 100644 src/main/java/art/arcane/iris/engine/procedural/part/ProceduralValue.java create mode 100644 src/main/java/art/arcane/iris/engine/procedural/part/ResolvedProceduralObject.java rename src/main/java/art/arcane/iris/engine/{object/procedural/fungi/FungusCellRole.java => procedural/part/RuleFace.java} (69%) create mode 100644 src/main/java/art/arcane/iris/engine/procedural/part/Sections.java create mode 100644 src/main/java/art/arcane/iris/engine/procedural/part/StemShape.java create mode 100644 src/main/java/art/arcane/iris/engine/procedural/part/Vectors.java delete mode 100644 src/main/java/art/arcane/iris/modules/objects/ProceduralObjectSettings.java delete mode 100644 src/main/java/art/arcane/iris/modules/objects/ProceduralPlacement.java delete mode 100644 src/main/java/art/arcane/iris/modules/objects/coral/Coral.java delete mode 100644 src/main/java/art/arcane/iris/modules/objects/coral/CoralForm.java delete mode 100644 src/main/java/art/arcane/iris/modules/objects/crystal/Crystal.java delete mode 100644 src/main/java/art/arcane/iris/modules/objects/crystal/CrystalSurface.java delete mode 100644 src/main/java/art/arcane/iris/modules/objects/formation/Formation.java delete mode 100644 src/main/java/art/arcane/iris/modules/objects/formation/FormationForm.java delete mode 100644 src/main/java/art/arcane/iris/modules/objects/formation/FormationProfile.java delete mode 100644 src/main/java/art/arcane/iris/modules/objects/fungi/Fungus.java delete mode 100644 src/main/java/art/arcane/iris/modules/objects/fungi/FungusCapShape.java delete mode 100644 src/main/java/art/arcane/iris/modules/objects/ruin/Ruin.java delete mode 100644 src/main/java/art/arcane/iris/modules/objects/ruin/RuinDecorator.java delete mode 100644 src/main/java/art/arcane/iris/modules/objects/ruin/RuinForm.java delete mode 100644 src/main/java/art/arcane/iris/modules/objects/tree/Tree.java delete mode 100644 src/main/java/art/arcane/iris/modules/objects/tree/TreeAzimuthMode.java delete mode 100644 src/main/java/art/arcane/iris/modules/objects/tree/TreeBranchProbability.java delete mode 100644 src/main/java/art/arcane/iris/modules/objects/tree/TreeBranches.java delete mode 100644 src/main/java/art/arcane/iris/modules/objects/tree/TreeCanopy.java delete mode 100644 src/main/java/art/arcane/iris/modules/objects/tree/TreeDecorator.java delete mode 100644 src/main/java/art/arcane/iris/modules/objects/tree/TreeDecoratorTarget.java delete mode 100644 src/main/java/art/arcane/iris/modules/objects/tree/TreeFunction.java delete mode 100644 src/main/java/art/arcane/iris/modules/objects/tree/TreeLayer.java delete mode 100644 src/main/java/art/arcane/iris/modules/objects/tree/TreeLeafMode.java delete mode 100644 src/main/java/art/arcane/iris/modules/objects/tree/TreeProfile.java delete mode 100644 src/main/java/art/arcane/iris/modules/objects/tree/TreeSecondaryLeaf.java delete mode 100644 src/main/java/art/arcane/iris/modules/objects/tree/TreeSubBranches.java diff --git a/README.md b/README.md index 63a08a3c2..8d9f8b9ba 100644 --- a/README.md +++ b/README.md @@ -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/`, or `procedural/#` 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`, diff --git a/builtin-modules.txt b/builtin-modules.txt index 9d5af6cac..2be9067bf 100644 --- a/builtin-modules.txt +++ b/builtin-modules.txt @@ -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/** diff --git a/src/main/java/art/arcane/iris/builtin/objects/ObjectPlacement.java b/src/main/java/art/arcane/iris/builtin/objects/ObjectPlacement.java index 715751a4b..bd2588322 100644 --- a/src/main/java/art/arcane/iris/builtin/objects/ObjectPlacement.java +++ b/src/main/java/art/arcane/iris/builtin/objects/ObjectPlacement.java @@ -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; } diff --git a/src/main/java/art/arcane/iris/builtin/objects/PlacementSource.java b/src/main/java/art/arcane/iris/builtin/objects/PlacementSource.java deleted file mode 100644 index 96a33efd0..000000000 --- a/src/main/java/art/arcane/iris/builtin/objects/PlacementSource.java +++ /dev/null @@ -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 . - */ - -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(); -} diff --git a/src/main/java/art/arcane/iris/engine/mantle/components/CaveSettings.java b/src/main/java/art/arcane/iris/engine/mantle/components/CaveSettings.java index 9a9de5bb7..a62b89d82 100644 --- a/src/main/java/art/arcane/iris/engine/mantle/components/CaveSettings.java +++ b/src/main/java/art/arcane/iris/engine/mantle/components/CaveSettings.java @@ -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; diff --git a/src/main/java/art/arcane/iris/engine/mantle/components/ChunkObjectPlacing.java b/src/main/java/art/arcane/iris/engine/mantle/components/ChunkObjectPlacing.java index 809f5273a..fae8e63b0 100644 --- a/src/main/java/art/arcane/iris/engine/mantle/components/ChunkObjectPlacing.java +++ b/src/main/java/art/arcane/iris/engine/mantle/components/ChunkObjectPlacing.java @@ -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 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 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 surface = proceduralPlacements(column.procedural().surface()); - List 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 proceduralPlacements(ProceduralObjectSettings settings) { - return settings == null ? List.of() : ResolvedProceduralObjects.of(context.world(), settings); - } - - private void placeProceduralFrom(List 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 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 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 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) { } diff --git a/src/main/java/art/arcane/iris/engine/mantle/components/EffectivePlacements.java b/src/main/java/art/arcane/iris/engine/mantle/components/EffectivePlacements.java index e3b62a18d..a192f25cd 100644 --- a/src/main/java/art/arcane/iris/engine/mantle/components/EffectivePlacements.java +++ b/src/main/java/art/arcane/iris/engine/mantle/components/EffectivePlacements.java @@ -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()) { diff --git a/src/main/java/art/arcane/iris/engine/mantle/components/FloatingObjectPlacing.java b/src/main/java/art/arcane/iris/engine/mantle/components/FloatingObjectPlacing.java index 81bc3aacc..0d7964d2e 100644 --- a/src/main/java/art/arcane/iris/engine/mantle/components/FloatingObjectPlacing.java +++ b/src/main/java/art/arcane/iris/engine/mantle/components/FloatingObjectPlacing.java @@ -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 biomeObjects; private final ModuleLog log; private final Map> sizes = new HashMap<>(); @@ -433,6 +435,7 @@ public final class FloatingObjectPlacing { private Reach(PackResources resources, Map 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 size = sizes.computeIfAbsent(objectKey, key -> PlacementReach.sizeOf(resources, key)); + Optional size = sizes.computeIfAbsent(objectKey, key -> PlacementReach.sizeOf(resources, procedural, key)); if (size.isEmpty()) { return 0; } diff --git a/src/main/java/art/arcane/iris/engine/mantle/components/ObjectChunk.java b/src/main/java/art/arcane/iris/engine/mantle/components/ObjectChunk.java index 2ed257e1a..deac96b27 100644 --- a/src/main/java/art/arcane/iris/engine/mantle/components/ObjectChunk.java +++ b/src/main/java/art/arcane/iris/engine/mantle/components/ObjectChunk.java @@ -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); diff --git a/src/main/java/art/arcane/iris/engine/mantle/components/ObjectModule.java b/src/main/java/art/arcane/iris/engine/mantle/components/ObjectModule.java index 9b11db0da..ba70f3bc5 100644 --- a/src/main/java/art/arcane/iris/engine/mantle/components/ObjectModule.java +++ b/src/main/java/art/arcane/iris/engine/mantle/components/ObjectModule.java @@ -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); } diff --git a/src/main/java/art/arcane/iris/engine/mantle/components/ObjectPlacing.java b/src/main/java/art/arcane/iris/engine/mantle/components/ObjectPlacing.java index 7cf5256a9..7a2770d64 100644 --- a/src/main/java/art/arcane/iris/engine/mantle/components/ObjectPlacing.java +++ b/src/main/java/art/arcane/iris/engine/mantle/components/ObjectPlacing.java @@ -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. */ diff --git a/src/main/java/art/arcane/iris/engine/mantle/components/ObjectWarmUp.java b/src/main/java/art/arcane/iris/engine/mantle/components/ObjectWarmUp.java index d7b81c6cb..f48ddb42c 100644 --- a/src/main/java/art/arcane/iris/engine/mantle/components/ObjectWarmUp.java +++ b/src/main/java/art/arcane/iris/engine/mantle/components/ObjectWarmUp.java @@ -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> placements = byKey(Declaration.allOf(world, ObjectSettings.class)); - List> procedural = byKey(Declaration.allOf(world, ProceduralObjectSettings.class)); for (Level level : WARMED_LEVELS) { for (Declaration declaration : placements) { if (declaration.level() == level) { warmPlacements(declaration.settings().objects()); } } - for (Declaration 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++)); - } - } } diff --git a/src/main/java/art/arcane/iris/engine/mantle/components/PlacementReach.java b/src/main/java/art/arcane/iris/engine/mantle/components/PlacementReach.java index c9789c24b..ec695f57b 100644 --- a/src/main/java/art/arcane/iris/engine/mantle/components/PlacementReach.java +++ b/src/main/java/art/arcane/iris/engine/mantle/components/PlacementReach.java @@ -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> sizes = new HashMap<>(); private final Set 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 entry : settings.declared(ObjectSettings.class)) { radius = Math.max(radius, ofPlacements(entry.value().objects())); } - for (Entry 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 size = sizes.computeIfAbsent(objectKey, key -> sizeOf(resources, key)); + Optional 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 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 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(), diff --git a/src/main/java/art/arcane/iris/engine/mantle/components/TreeGrowing.java b/src/main/java/art/arcane/iris/engine/mantle/components/TreeGrowing.java index 9b737349b..1be4a3ac0 100644 --- a/src/main/java/art/arcane/iris/engine/mantle/components/TreeGrowing.java +++ b/src/main/java/art/arcane/iris/engine/mantle/components/TreeGrowing.java @@ -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 grow(PackWorld world, Sapling sapling, Surroundings surroundings) { @@ -75,7 +75,7 @@ public final class TreeGrowing implements SaplingGrowth { return Optional.empty(); } List keys = placement.get().place(); - Optional tree = ObjectPool.of(world).object(keys.get(RNG.r.i(keys.size()))); + Optional 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 objects = new HashSet<>(); - Set procedural = new HashSet<>(); for (Declaration declaration : Declaration.allOf(world, ObjectSettings.class)) { collectPlacements(declaration.settings().objects(), objects); } - for (Declaration 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 placedNames(PackWorld world, Set objectKeys) { + ProceduralObjectCatalog procedural = ProceduralObjectCatalog.of(world); + Set 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 idsOf(PackWorld world, Set 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 placements, Set 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 trees, Set 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); } /** diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/IrisProceduralBlocks.java b/src/main/java/art/arcane/iris/engine/object/procedural/IrisProceduralBlocks.java deleted file mode 100644 index 1901c28e5..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/IrisProceduralBlocks.java +++ /dev/null @@ -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 . - */ - -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 palette) { - return palette.filter(IrisProceduralBlocks::paletteSet).isPresent(); - } - - public static BlockState resolve(String block, Optional 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 block, Optional 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 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 placed = new ArrayList<>(blocks.size()); - for (Map.Entry 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); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/ResolvedProceduralObjects.java b/src/main/java/art/arcane/iris/engine/object/procedural/ResolvedProceduralObjects.java deleted file mode 100644 index f71fe1b9a..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/ResolvedProceduralObjects.java +++ /dev/null @@ -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 . - */ - -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 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 resolve(ProceduralObjectSettings settings, PackResources resources) { - List 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 void addAll(List all, List settings, PackResources resources, - BiFunction 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> placements = new ConcurrentHashMap<>(); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/ResolvedProceduralPlacement.java b/src/main/java/art/arcane/iris/engine/object/procedural/ResolvedProceduralPlacement.java deleted file mode 100644 index 1cd7fb26d..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/ResolvedProceduralPlacement.java +++ /dev/null @@ -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 . - */ - -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> 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() { - return Optional.ofNullable(shape.vacuumSettings()); - } - - @Override - public ObjectLimit clamp() { - return shape.clamp(); - } - - @Override - public Optional stiltSettings() { - return Optional.ofNullable(shape.stiltSettings()); - } - - @Override - public List variants() { - return variantCache.aquire(() -> bake(new ObjectBuilder(resources))); - } - - @Override - public Optional variant(RNG rng) { - List 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 bake(ObjectBuilder blocks) { - List 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(); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/coral/CoralCanvas.java b/src/main/java/art/arcane/iris/engine/object/procedural/coral/CoralCanvas.java deleted file mode 100644 index b0ee7a1c5..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/coral/CoralCanvas.java +++ /dev/null @@ -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 . - */ - -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 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 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}; - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/coral/CoralGenerator.java b/src/main/java/art/arcane/iris/engine/object/procedural/coral/CoralGenerator.java deleted file mode 100644 index ea6bce10f..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/coral/CoralGenerator.java +++ /dev/null @@ -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 . - */ - -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 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 resolve(CoralCanvas canvas, Coral coral, ObjectBuilder blocks) { - Map out = new HashMap<>(); - RNG paletteRng = new RNG(coral.seed()); - for (Map.Entry 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; - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/coral/ResolvedCoral.java b/src/main/java/art/arcane/iris/engine/object/procedural/coral/ResolvedCoral.java deleted file mode 100644 index c256d20b4..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/coral/ResolvedCoral.java +++ /dev/null @@ -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 . - */ - -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); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/crystal/CrystalBaseBuilder.java b/src/main/java/art/arcane/iris/engine/object/procedural/crystal/CrystalBaseBuilder.java deleted file mode 100644 index 93d1ca854..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/crystal/CrystalBaseBuilder.java +++ /dev/null @@ -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 . - */ - -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); - } - } - } - } - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/crystal/CrystalCanvas.java b/src/main/java/art/arcane/iris/engine/object/procedural/crystal/CrystalCanvas.java deleted file mode 100644 index 072c1029f..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/crystal/CrystalCanvas.java +++ /dev/null @@ -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 . - */ - -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 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 getCells() { - return cells; - } - - private static int rank(CrystalRole role) { - return switch (role) { - case BASE -> 0; - case SHARD -> 1; - case TIP -> 2; - }; - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/crystal/CrystalGenerator.java b/src/main/java/art/arcane/iris/engine/object/procedural/crystal/CrystalGenerator.java deleted file mode 100644 index 341650cb3..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/crystal/CrystalGenerator.java +++ /dev/null @@ -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 . - */ - -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 resolved = new HashMap<>(); - RNG paletteRng = new RNG(crystal.seed()); - RNG tipRng = new RNG(crystal.seed() + (variantIndex * 31337L) + 4099L); - - for (Map.Entry 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); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/crystal/CrystalGeometry.java b/src/main/java/art/arcane/iris/engine/object/procedural/crystal/CrystalGeometry.java deleted file mode 100644 index 8f21be72b..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/crystal/CrystalGeometry.java +++ /dev/null @@ -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 . - */ - -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; - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/crystal/CrystalShardBuilder.java b/src/main/java/art/arcane/iris/engine/object/procedural/crystal/CrystalShardBuilder.java deleted file mode 100644 index 08055b8c1..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/crystal/CrystalShardBuilder.java +++ /dev/null @@ -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 . - */ - -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))); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/crystal/ResolvedCrystal.java b/src/main/java/art/arcane/iris/engine/object/procedural/crystal/ResolvedCrystal.java deleted file mode 100644 index 03f036794..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/crystal/ResolvedCrystal.java +++ /dev/null @@ -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 . - */ - -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); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/formation/FormationBlockResolver.java b/src/main/java/art/arcane/iris/engine/object/procedural/formation/FormationBlockResolver.java deleted file mode 100644 index a1111167d..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/formation/FormationBlockResolver.java +++ /dev/null @@ -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 . - */ - -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()); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/formation/FormationCanvas.java b/src/main/java/art/arcane/iris/engine/object/procedural/formation/FormationCanvas.java deleted file mode 100644 index bc38eee3a..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/formation/FormationCanvas.java +++ /dev/null @@ -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 . - */ - -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 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 getCells() { - return cells; - } - - public boolean isEmpty() { - return cells.isEmpty(); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/formation/FormationGenerator.java b/src/main/java/art/arcane/iris/engine/object/procedural/formation/FormationGenerator.java deleted file mode 100644 index e20f622b9..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/formation/FormationGenerator.java +++ /dev/null @@ -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 . - */ - -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 resolved = new HashMap<>(); - for (Map.Entry 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); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/formation/FormationProfiles.java b/src/main/java/art/arcane/iris/engine/object/procedural/formation/FormationProfiles.java deleted file mode 100644 index 9bd54a7c0..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/formation/FormationProfiles.java +++ /dev/null @@ -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 . - */ - -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)); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/formation/FormationShapeBuilder.java b/src/main/java/art/arcane/iris/engine/object/procedural/formation/FormationShapeBuilder.java deleted file mode 100644 index 109db16d0..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/formation/FormationShapeBuilder.java +++ /dev/null @@ -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 . - */ - -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 cells = new HashMap<>(canvas.getCells()); - for (Map.Entry 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()); - } - } - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/formation/ResolvedFormation.java b/src/main/java/art/arcane/iris/engine/object/procedural/formation/ResolvedFormation.java deleted file mode 100644 index 54a7a44e3..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/formation/ResolvedFormation.java +++ /dev/null @@ -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 . - */ - -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); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/fungi/FungusCapBuilder.java b/src/main/java/art/arcane/iris/engine/object/procedural/fungi/FungusCapBuilder.java deleted file mode 100644 index 418a26c3a..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/fungi/FungusCapBuilder.java +++ /dev/null @@ -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 . - */ - -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 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 block, Optional palette) { - if (IrisProceduralBlocks.paletteSet(palette)) { - return true; - } - return block.filter(name -> !name.isEmpty()).isPresent(); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/fungi/FungusGenerator.java b/src/main/java/art/arcane/iris/engine/object/procedural/fungi/FungusGenerator.java deleted file mode 100644 index 43beea35e..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/fungi/FungusGenerator.java +++ /dev/null @@ -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 . - */ - -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 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 resolved = new HashMap<>(); - for (Map.Entry 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 roles, Fungus fungus, int height, RNG rng, long baseSeed) { - int stemHeight = Math.max(1, height); - Map 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); - } - }; - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/fungi/FungusShelfBuilder.java b/src/main/java/art/arcane/iris/engine/object/procedural/fungi/FungusShelfBuilder.java deleted file mode 100644 index 6708e7edc..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/fungi/FungusShelfBuilder.java +++ /dev/null @@ -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 . - */ - -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 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); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/fungi/FungusStemBuilder.java b/src/main/java/art/arcane/iris/engine/object/procedural/fungi/FungusStemBuilder.java deleted file mode 100644 index aba9fe361..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/fungi/FungusStemBuilder.java +++ /dev/null @@ -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 . - */ - -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 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; - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/fungi/ResolvedFungus.java b/src/main/java/art/arcane/iris/engine/object/procedural/fungi/ResolvedFungus.java deleted file mode 100644 index a59cf7130..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/fungi/ResolvedFungus.java +++ /dev/null @@ -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 . - */ - -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 bake(ObjectBuilder blocks) { - List 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; - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/ruin/ResolvedRuin.java b/src/main/java/art/arcane/iris/engine/object/procedural/ruin/ResolvedRuin.java deleted file mode 100644 index f5fcab16a..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/ruin/ResolvedRuin.java +++ /dev/null @@ -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 . - */ - -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); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/ruin/RuinBlockCanvas.java b/src/main/java/art/arcane/iris/engine/object/procedural/ruin/RuinBlockCanvas.java deleted file mode 100644 index a45cc8ccd..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/ruin/RuinBlockCanvas.java +++ /dev/null @@ -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 . - */ - -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 cells = new HashMap<>(); - - Map 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)); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/ruin/RuinDecoratorApplier.java b/src/main/java/art/arcane/iris/engine/object/procedural/ruin/RuinDecoratorApplier.java deleted file mode 100644 index 8136ffc49..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/ruin/RuinDecoratorApplier.java +++ /dev/null @@ -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 . - */ - -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 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 topCandidates(RuinBlockCanvas canvas) { - Map 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 out = new ArrayList<>(); - for (Map.Entry 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 surfaceCandidates(RuinBlockCanvas canvas) { - List 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 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 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); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/ruin/RuinGenerator.java b/src/main/java/art/arcane/iris/engine/object/procedural/ruin/RuinGenerator.java deleted file mode 100644 index ff0058a79..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/ruin/RuinGenerator.java +++ /dev/null @@ -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 . - */ - -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 moved = new HashMap<>(); - for (Map.Entry 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 doomed = new ArrayList<>(); - for (Map.Entry 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 resolved = new HashMap<>(); - for (Map.Entry 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; - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/ruin/RuinShapes.java b/src/main/java/art/arcane/iris/engine/object/procedural/ruin/RuinShapes.java deleted file mode 100644 index 83e8ba91d..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/ruin/RuinShapes.java +++ /dev/null @@ -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 . - */ - -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); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/tree/ProceduralTreeGenerator.java b/src/main/java/art/arcane/iris/engine/object/procedural/tree/ProceduralTreeGenerator.java deleted file mode 100644 index 48bbd4304..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/tree/ProceduralTreeGenerator.java +++ /dev/null @@ -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 . - */ - -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 limbs = TreeTrunkBuilder.build(canvas, tree, height); - - boolean wantEndpoints = tree.decorators() != null && !tree.decorators().isEmpty(); - List 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 resolved = new HashMap<>(); - Set trunkPositions = new HashSet<>(); - Set leafPositions = new HashSet<>(); - for (Map.Entry 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 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 placed = new ArrayList<>(resolved.size()); - for (Map.Entry 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); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/tree/ResolvedTree.java b/src/main/java/art/arcane/iris/engine/object/procedural/tree/ResolvedTree.java deleted file mode 100644 index f6560470a..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/tree/ResolvedTree.java +++ /dev/null @@ -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 . - */ - -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 bake(ObjectBuilder blocks) { - List 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))); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/tree/TreeBlockCanvas.java b/src/main/java/art/arcane/iris/engine/object/procedural/tree/TreeBlockCanvas.java deleted file mode 100644 index ad0261b81..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/tree/TreeBlockCanvas.java +++ /dev/null @@ -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 . - */ - -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 cells = new HashMap<>(); - private final Set trunk = new HashSet<>(); - private final Set 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 getCells() { - return cells; - } - - public Set getTrunk() { - return trunk; - } - - public Set getLeaf() { - return leaf; - } - - public boolean isEmpty() { - return cells.isEmpty(); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/tree/TreeBlockResolver.java b/src/main/java/art/arcane/iris/engine/object/procedural/tree/TreeBlockResolver.java deleted file mode 100644 index 745cf7d85..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/tree/TreeBlockResolver.java +++ /dev/null @@ -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 . - */ - -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; - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/tree/TreeCanopyBuilder.java b/src/main/java/art/arcane/iris/engine/object/procedural/tree/TreeCanopyBuilder.java deleted file mode 100644 index fb5e8dd97..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/tree/TreeCanopyBuilder.java +++ /dev/null @@ -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 . - */ - -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 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 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 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; - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/tree/TreeDecoratorApplier.java b/src/main/java/art/arcane/iris/engine/object/procedural/tree/TreeDecoratorApplier.java deleted file mode 100644 index 4f648781f..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/tree/TreeDecoratorApplier.java +++ /dev/null @@ -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 . - */ - -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 branchEndpoints) { - List 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 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 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 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 colBottom = columnLeafBottoms(canvas); - for (Map.Entry 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 colBottom = columnLeafBottoms(canvas); - for (Map.Entry 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 columnLeafBottoms(TreeBlockCanvas canvas) { - KMap 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); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/tree/TreeFunctions.java b/src/main/java/art/arcane/iris/engine/object/procedural/tree/TreeFunctions.java deleted file mode 100644 index 7e7eb9afd..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/tree/TreeFunctions.java +++ /dev/null @@ -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 . - */ - -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; - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/tree/TreePlausibility.java b/src/main/java/art/arcane/iris/engine/object/procedural/tree/TreePlausibility.java deleted file mode 100644 index c2e09d7d3..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/tree/TreePlausibility.java +++ /dev/null @@ -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 . - */ - -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 resolved, Set trunkPositions, - Set leafPositions, Tree tree, ObjectBuilder blocks) { - Set 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 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 computeDistances(Set trunkPositions, Set realLeaves) { - Map distance = new HashMap<>(); - ArrayDeque 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; - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/tree/TreeProfiles.java b/src/main/java/art/arcane/iris/engine/object/procedural/tree/TreeProfiles.java deleted file mode 100644 index f5ece60ca..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/tree/TreeProfiles.java +++ /dev/null @@ -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 . - */ - -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; - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/tree/TreeRootBuilder.java b/src/main/java/art/arcane/iris/engine/object/procedural/tree/TreeRootBuilder.java deleted file mode 100644 index 7ae8c976f..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/tree/TreeRootBuilder.java +++ /dev/null @@ -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 . - */ - -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 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 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 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))); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/tree/TreeSupport.java b/src/main/java/art/arcane/iris/engine/object/procedural/tree/TreeSupport.java deleted file mode 100644 index c6ef85c91..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/tree/TreeSupport.java +++ /dev/null @@ -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 . - */ - -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 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())); - } -} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/tree/TreeTrunkBuilder.java b/src/main/java/art/arcane/iris/engine/object/procedural/tree/TreeTrunkBuilder.java deleted file mode 100644 index b66b10e5a..000000000 --- a/src/main/java/art/arcane/iris/engine/object/procedural/tree/TreeTrunkBuilder.java +++ /dev/null @@ -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 . - */ - -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 build(TreeBlockCanvas canvas, Tree tree, int height) { - boolean hasSecondary = hasSecondaryTrunk(tree); - double[][] mainOffsets = leanPath(tree, height); - int forks = Math.max(1, tree.trunkForks()); - - List 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 squarePositions(double cx, double cz, int width) { - List 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); - } -} diff --git a/src/main/java/art/arcane/iris/engine/procedural/BakeProfile.java b/src/main/java/art/arcane/iris/engine/procedural/BakeProfile.java new file mode 100644 index 000000000..75e37ba1c --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/procedural/BakeProfile.java @@ -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 . + */ +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; + } +} diff --git a/src/main/java/art/arcane/iris/engine/procedural/IrisProceduralBlocks.java b/src/main/java/art/arcane/iris/engine/procedural/IrisProceduralBlocks.java new file mode 100644 index 000000000..8328b8d65 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/procedural/IrisProceduralBlocks.java @@ -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 . + */ + +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 blocks) { + if (blocks == null || blocks.isEmpty()) { + return null; + } + + Anchor anchor = Anchor.of(blocks.keySet()); + List placed = new ArrayList<>(blocks.size()); + for (Map.Entry 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 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); + } + } +} diff --git a/src/main/java/art/arcane/iris/engine/procedural/ProceduralObjectCatalog.java b/src/main/java/art/arcane/iris/engine/procedural/ProceduralObjectCatalog.java new file mode 100644 index 000000000..6cd8dd9a2 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/procedural/ProceduralObjectCatalog.java @@ -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 . + */ + +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/.json} and placed from any object placement + * as {@code procedural/}, or one variant as {@code procedural/#}. 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 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> 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 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 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 variants(String key) { + return variantsNamedBy(ObjectKey.parse(key)); + } + + /** Every variant {@code key} may place: the one it pins, or the whole pool. */ + public List 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 variantsNamedBy(ObjectKey key) { + return variantsByPath.computeIfAbsent(key.path(), this::resolve); + } + + private Optional resolve(String path) { + ResourceId id = resources.idOf(path); + Optional 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; + } + } +} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/ProceduralShape.java b/src/main/java/art/arcane/iris/engine/procedural/ProceduralShape.java similarity index 95% rename from src/main/java/art/arcane/iris/engine/object/procedural/ProceduralShape.java rename to src/main/java/art/arcane/iris/engine/procedural/ProceduralShape.java index 4443833b8..65876b4bf 100644 --- a/src/main/java/art/arcane/iris/engine/object/procedural/ProceduralShape.java +++ b/src/main/java/art/arcane/iris/engine/procedural/ProceduralShape.java @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package art.arcane.iris.engine.object.procedural; +package art.arcane.iris.engine.procedural; import com.volmit.object.ObjectBlock; diff --git a/src/main/java/art/arcane/iris/engine/procedural/ProceduralVariants.java b/src/main/java/art/arcane/iris/engine/procedural/ProceduralVariants.java new file mode 100644 index 000000000..044833df0 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/procedural/ProceduralVariants.java @@ -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 . + */ + +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/}: a + * placement picks one variant per object it places, or always the same one with {@code procedural/#}. + */ +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 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 variants() { + List 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 variant(RNG rng) { + List 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 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 bake(ObjectBuilder blocks, BakeProfile profile) { + List 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; + } +} diff --git a/src/main/java/art/arcane/iris/engine/procedural/part/BlobShape.java b/src/main/java/art/arcane/iris/engine/procedural/part/BlobShape.java new file mode 100644 index 000000000..106884a81 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/procedural/part/BlobShape.java @@ -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 . + */ +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; + } +} diff --git a/src/main/java/art/arcane/iris/engine/procedural/part/BlockChoice.java b/src/main/java/art/arcane/iris/engine/procedural/part/BlockChoice.java new file mode 100644 index 000000000..77b1704c9 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/procedural/part/BlockChoice.java @@ -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 . + */ +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()); + } +} diff --git a/src/main/java/art/arcane/iris/modules/objects/coral/CoralBranchAzimuth.java b/src/main/java/art/arcane/iris/engine/procedural/part/BranchAzimuth.java similarity index 57% rename from src/main/java/art/arcane/iris/modules/objects/coral/CoralBranchAzimuth.java rename to src/main/java/art/arcane/iris/engine/procedural/part/BranchAzimuth.java index ec607d0d2..2342eaad0 100644 --- a/src/main/java/art/arcane/iris/modules/objects/coral/CoralBranchAzimuth.java +++ b/src/main/java/art/arcane/iris/engine/procedural/part/BranchAzimuth.java @@ -15,19 +15,22 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - -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 } diff --git a/src/main/java/art/arcane/iris/modules/objects/tree/TreeRootStyle.java b/src/main/java/art/arcane/iris/engine/procedural/part/ClusterLayout.java similarity index 62% rename from src/main/java/art/arcane/iris/modules/objects/tree/TreeRootStyle.java rename to src/main/java/art/arcane/iris/engine/procedural/part/ClusterLayout.java index ff9afcae9..6f9d99d50 100644 --- a/src/main/java/art/arcane/iris/modules/objects/tree/TreeRootStyle.java +++ b/src/main/java/art/arcane/iris/engine/procedural/part/ClusterLayout.java @@ -15,17 +15,18 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - -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 } diff --git a/src/main/java/art/arcane/iris/modules/objects/ruin/RuinDecoratorTarget.java b/src/main/java/art/arcane/iris/engine/procedural/part/DecorationSpot.java similarity index 56% rename from src/main/java/art/arcane/iris/modules/objects/ruin/RuinDecoratorTarget.java rename to src/main/java/art/arcane/iris/engine/procedural/part/DecorationSpot.java index 9f8021004..578d10932 100644 --- a/src/main/java/art/arcane/iris/modules/objects/ruin/RuinDecoratorTarget.java +++ b/src/main/java/art/arcane/iris/engine/procedural/part/DecorationSpot.java @@ -15,17 +15,24 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - -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 } diff --git a/src/main/java/art/arcane/iris/engine/procedural/part/Decorator.java b/src/main/java/art/arcane/iris/engine/procedural/part/Decorator.java new file mode 100644 index 000000000..fc2b5210d --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/procedural/part/Decorator.java @@ -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 . + */ +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 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 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 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 spots(ProceduralDecoration decoration, RNG rng) { + List 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 decoratedBlocks(ProceduralDecoration decoration) { + Set roles = new HashSet<>(); + for (String role : decoration.on()) { + roles.add(canvas.role(role)); + } + List 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 besideEach(List decorated, BlockFace... faces) { + List spots = new ArrayList<>(); + Set 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 columnEnds(List decorated, boolean top) { + Map 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 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 tips(ProceduralDecoration decoration) { + Set roles = new HashSet<>(); + for (String role : decoration.on()) { + roles.add(canvas.role(role)); + } + List 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 ground(double radius) { + int reach = (int) Math.ceil(radius); + Set 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 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 footprint() { + Set 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) { + } +} diff --git a/src/main/java/art/arcane/iris/engine/procedural/part/LeafDecay.java b/src/main/java/art/arcane/iris/engine/procedural/part/LeafDecay.java new file mode 100644 index 000000000..1357f3602 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/procedural/part/LeafDecay.java @@ -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 . + */ + +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 blocks; + private final ObjectBuilder builder; + private final Set leaves = new LinkedHashSet<>(); + + private LeafDecay(Map blocks, ObjectBuilder builder) { + this.blocks = blocks; + this.builder = builder; + List 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 blocks, ObjectBuilder builder) { + LeafDecay decay = new LeafDecay(blocks, builder); + if (decay.leaves.isEmpty()) { + return; + } + decay.markDistances(); + } + + /** Leaves that never decay. */ + static void persistLeaves(Map blocks, ObjectBuilder builder) { + LeafDecay decay = new LeafDecay(blocks, builder); + for (long leaf : decay.leaves) { + decay.setLeafState(leaf, true, 1); + } + } + + private void markDistances() { + Map 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 distances() { + Map distance = new HashMap<>(); + ArrayDeque 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"); + } +} diff --git a/src/main/java/art/arcane/iris/engine/procedural/part/MaterialPainter.java b/src/main/java/art/arcane/iris/engine/procedural/part/MaterialPainter.java new file mode 100644 index 000000000..994c0f759 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/procedural/part/MaterialPainter.java @@ -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 . + */ +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 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 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 paint() { + Map painted = new HashMap<>(); + for (Map.Entry 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 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()); + } +} diff --git a/src/main/java/art/arcane/iris/engine/procedural/part/MaterialRule.java b/src/main/java/art/arcane/iris/engine/procedural/part/MaterialRule.java new file mode 100644 index 000000000..08cce07fe --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/procedural/part/MaterialRule.java @@ -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 . + */ +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; + } +} diff --git a/src/main/java/art/arcane/iris/engine/procedural/part/ObjectBaker.java b/src/main/java/art/arcane/iris/engine/procedural/part/ObjectBaker.java new file mode 100644 index 000000000..c417bd9d0 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/procedural/part/ObjectBaker.java @@ -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 . + */ +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 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 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 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 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 painted, int sinkDepth) { + Map placed() { + Map 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)); + } + } +} diff --git a/src/main/java/art/arcane/iris/engine/procedural/part/PartBlob.java b/src/main/java/art/arcane/iris/engine/procedural/part/PartBlob.java new file mode 100644 index 000000000..a67ba8348 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/procedural/part/PartBlob.java @@ -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 . + */ +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; + } +} diff --git a/src/main/java/art/arcane/iris/engine/procedural/part/PartBranches.java b/src/main/java/art/arcane/iris/engine/procedural/part/PartBranches.java new file mode 100644 index 000000000..c2432bfad --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/procedural/part/PartBranches.java @@ -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 . + */ +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; + } +} diff --git a/src/main/java/art/arcane/iris/engine/procedural/part/PartCanvas.java b/src/main/java/art/arcane/iris/engine/procedural/part/PartCanvas.java new file mode 100644 index 000000000..72e6a8d9f --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/procedural/part/PartCanvas.java @@ -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 . + */ +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 cells = new HashMap<>(); + private final List tips = new ArrayList<>(); + private final List 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 cells() { + return Collections.unmodifiableMap(cells); + } + + void addTip(Tip tip) { + tips.add(tip); + } + + List 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; + } +} diff --git a/src/main/java/art/arcane/iris/engine/procedural/part/PartCluster.java b/src/main/java/art/arcane/iris/engine/procedural/part/PartCluster.java new file mode 100644 index 000000000..f2fd488d7 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/procedural/part/PartCluster.java @@ -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 . + */ +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; + } +} diff --git a/src/main/java/art/arcane/iris/engine/procedural/part/PartFill.java b/src/main/java/art/arcane/iris/engine/procedural/part/PartFill.java new file mode 100644 index 000000000..fff683b1f --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/procedural/part/PartFill.java @@ -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 . + */ +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)); + } +} diff --git a/src/main/java/art/arcane/iris/engine/procedural/part/PartGrower.java b/src/main/java/art/arcane/iris/engine/procedural/part/PartGrower.java new file mode 100644 index 000000000..af93ea4e1 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/procedural/part/PartGrower.java @@ -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 . + */ +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 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 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 positions = branchPositions(branches, parent, rng); + List 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 branchPositions(PartBranches branches, PartShape parent, RNG rng) { + ProceduralSpan along = branches.along(); + List 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) { + } +} diff --git a/src/main/java/art/arcane/iris/modules/objects/crystal/CrystalDistribution.java b/src/main/java/art/arcane/iris/engine/procedural/part/PartMode.java similarity index 59% rename from src/main/java/art/arcane/iris/modules/objects/crystal/CrystalDistribution.java rename to src/main/java/art/arcane/iris/engine/procedural/part/PartMode.java index e4dbc5517..83b978c04 100644 --- a/src/main/java/art/arcane/iris/modules/objects/crystal/CrystalDistribution.java +++ b/src/main/java/art/arcane/iris/engine/procedural/part/PartMode.java @@ -15,16 +15,16 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - -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 } diff --git a/src/main/java/art/arcane/iris/engine/procedural/part/PartNoise.java b/src/main/java/art/arcane/iris/engine/procedural/part/PartNoise.java new file mode 100644 index 000000000..1ba2ac509 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/procedural/part/PartNoise.java @@ -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 . + */ +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; + } +} diff --git a/src/main/java/art/arcane/iris/engine/procedural/part/PartOffset.java b/src/main/java/art/arcane/iris/engine/procedural/part/PartOffset.java new file mode 100644 index 000000000..d7a564cf0 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/procedural/part/PartOffset.java @@ -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 . + */ +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); + } +} diff --git a/src/main/java/art/arcane/iris/engine/procedural/part/PartOutline.java b/src/main/java/art/arcane/iris/engine/procedural/part/PartOutline.java new file mode 100644 index 000000000..bd467f82a --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/procedural/part/PartOutline.java @@ -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 . + */ +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 children) { + } + + private final Map idsByPart = new IdentityHashMap<>(); + private final List 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 roots() { + return roots; + } + + public int nodeCount() { + return nodeCount; + } + + public int idOf(ProceduralPart part) { + return idsByPart.getOrDefault(part, NO_PART); + } + + private List nodesFor(List parts, String parentRole) { + List 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 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; + } +} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/crystal/CrystalRole.java b/src/main/java/art/arcane/iris/engine/procedural/part/PartPattern.java similarity index 70% rename from src/main/java/art/arcane/iris/engine/object/procedural/crystal/CrystalRole.java rename to src/main/java/art/arcane/iris/engine/procedural/part/PartPattern.java index 14413beac..a28c83017 100644 --- a/src/main/java/art/arcane/iris/engine/object/procedural/crystal/CrystalRole.java +++ b/src/main/java/art/arcane/iris/engine/procedural/part/PartPattern.java @@ -15,11 +15,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +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 } diff --git a/src/main/java/art/arcane/iris/engine/procedural/part/PartSection.java b/src/main/java/art/arcane/iris/engine/procedural/part/PartSection.java new file mode 100644 index 000000000..ef53618e6 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/procedural/part/PartSection.java @@ -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 . + */ +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 +} diff --git a/src/main/java/art/arcane/iris/engine/procedural/part/PartShape.java b/src/main/java/art/arcane/iris/engine/procedural/part/PartShape.java new file mode 100644 index 000000000..caed199d6 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/procedural/part/PartShape.java @@ -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 . + */ +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; + } + }; +} diff --git a/src/main/java/art/arcane/iris/engine/procedural/part/PartSpot.java b/src/main/java/art/arcane/iris/engine/procedural/part/PartSpot.java new file mode 100644 index 000000000..b43384f90 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/procedural/part/PartSpot.java @@ -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 . + */ +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); + } +} diff --git a/src/main/java/art/arcane/iris/engine/procedural/part/PartStem.java b/src/main/java/art/arcane/iris/engine/procedural/part/PartStem.java new file mode 100644 index 000000000..da289a09e --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/procedural/part/PartStem.java @@ -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 . + */ +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; + } +} diff --git a/src/main/java/art/arcane/iris/engine/procedural/part/PartTrace.java b/src/main/java/art/arcane/iris/engine/procedural/part/PartTrace.java new file mode 100644 index 000000000..c64ff5a2b --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/procedural/part/PartTrace.java @@ -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 . + */ +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 partsByBlock; + + PartTrace(Map 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); + } +} diff --git a/src/main/java/art/arcane/iris/engine/procedural/part/ProceduralDecoration.java b/src/main/java/art/arcane/iris/engine/procedural/part/ProceduralDecoration.java new file mode 100644 index 000000000..1cd6223ba --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/procedural/part/ProceduralDecoration.java @@ -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 . + */ +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 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 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; + } +} diff --git a/src/main/java/art/arcane/iris/engine/procedural/part/ProceduralMaterial.java b/src/main/java/art/arcane/iris/engine/procedural/part/ProceduralMaterial.java new file mode 100644 index 000000000..a21611c28 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/procedural/part/ProceduralMaterial.java @@ -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 . + */ +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 rules = List.of(); + + public String role() { + return role == null ? "main" : role; + } + + public BlockChoice choice() { + return new BlockChoice(block, palette, bands); + } + + public List rules() { + return rules == null ? List.of() : Collections.unmodifiableList(rules); + } +} diff --git a/src/main/java/art/arcane/iris/engine/procedural/part/ProceduralObject.java b/src/main/java/art/arcane/iris/engine/procedural/part/ProceduralObject.java new file mode 100644 index 000000000..34f231309 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/procedural/part/ProceduralObject.java @@ -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 . + */ +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/, or a single variant as procedural/#.") +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 materials = List.of(); + + @MinItems(1) + @Desc("The parts the object grows from, each starting at the object's base.") + private List parts = List.of(); + + @MinItems(1) + @Desc("Blocks placed against the finished object, such as vines, moss or fruit.") + private List 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 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 parts() { + return parts == null ? List.of() : Collections.unmodifiableList(parts); + } + + public List decorations() { + return decorations == null ? List.of() : Collections.unmodifiableList(decorations); + } + + public boolean leafDecay() { + return leafDecay; + } + + public boolean waterlogged() { + return waterlogged; + } + + public double sink() { + return sink; + } +} diff --git a/src/main/java/art/arcane/iris/engine/procedural/part/ProceduralPart.java b/src/main/java/art/arcane/iris/engine/procedural/part/ProceduralPart.java new file mode 100644 index 000000000..814e67fd9 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/procedural/part/ProceduralPart.java @@ -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 . + */ +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 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 children() { + return children == null ? List.of() : Collections.unmodifiableList(children); + } +} diff --git a/src/main/java/art/arcane/iris/engine/procedural/part/ProceduralSpan.java b/src/main/java/art/arcane/iris/engine/procedural/part/ProceduralSpan.java new file mode 100644 index 000000000..417d46d19 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/procedural/part/ProceduralSpan.java @@ -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 . + */ +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; + } +} diff --git a/src/main/java/art/arcane/iris/engine/procedural/part/ProceduralValue.java b/src/main/java/art/arcane/iris/engine/procedural/part/ProceduralValue.java new file mode 100644 index 000000000..1aa8688be --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/procedural/part/ProceduralValue.java @@ -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 . + */ +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 parameters; + + CurveShape(List 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 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 { + 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 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); + } + } +} diff --git a/src/main/java/art/arcane/iris/engine/procedural/part/ResolvedProceduralObject.java b/src/main/java/art/arcane/iris/engine/procedural/part/ResolvedProceduralObject.java new file mode 100644 index 000000000..6e5f5e0a4 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/procedural/part/ResolvedProceduralObject.java @@ -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 . + */ +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()); + } +} diff --git a/src/main/java/art/arcane/iris/engine/object/procedural/fungi/FungusCellRole.java b/src/main/java/art/arcane/iris/engine/procedural/part/RuleFace.java similarity index 69% rename from src/main/java/art/arcane/iris/engine/object/procedural/fungi/FungusCellRole.java rename to src/main/java/art/arcane/iris/engine/procedural/part/RuleFace.java index 2dac80c8c..c4adeb49a 100644 --- a/src/main/java/art/arcane/iris/engine/object/procedural/fungi/FungusCellRole.java +++ b/src/main/java/art/arcane/iris/engine/procedural/part/RuleFace.java @@ -15,12 +15,18 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +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 } diff --git a/src/main/java/art/arcane/iris/engine/procedural/part/Sections.java b/src/main/java/art/arcane/iris/engine/procedural/part/Sections.java new file mode 100644 index 000000000..ef25078a8 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/procedural/part/Sections.java @@ -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 . + */ +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); + }; + } +} diff --git a/src/main/java/art/arcane/iris/engine/procedural/part/StemShape.java b/src/main/java/art/arcane/iris/engine/procedural/part/StemShape.java new file mode 100644 index 000000000..d9040a79e --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/procedural/part/StemShape.java @@ -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 . + */ +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); + } + } +} diff --git a/src/main/java/art/arcane/iris/engine/procedural/part/Vectors.java b/src/main/java/art/arcane/iris/engine/procedural/part/Vectors.java new file mode 100644 index 000000000..06b044985 --- /dev/null +++ b/src/main/java/art/arcane/iris/engine/procedural/part/Vectors.java @@ -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 . + */ +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); + } +} diff --git a/src/main/java/art/arcane/iris/modules/objects/EffectiveSettings.java b/src/main/java/art/arcane/iris/modules/objects/EffectiveSettings.java index f4dbbab50..68cb05bda 100644 --- a/src/main/java/art/arcane/iris/modules/objects/EffectiveSettings.java +++ b/src/main/java/art/arcane/iris/modules/objects/EffectiveSettings.java @@ -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 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), diff --git a/src/main/java/art/arcane/iris/modules/objects/ObjectBuilder.java b/src/main/java/art/arcane/iris/modules/objects/ObjectBuilder.java index 7fd89c85a..dc0cb9cc7 100644 --- a/src/main/java/art/arcane/iris/modules/objects/ObjectBuilder.java +++ b/src/main/java/art/arcane/iris/modules/objects/ObjectBuilder.java @@ -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); diff --git a/src/main/java/art/arcane/iris/modules/objects/ObjectPool.java b/src/main/java/art/arcane/iris/modules/objects/ObjectPool.java index ec6d049c9..014b5ef01 100644 --- a/src/main/java/art/arcane/iris/modules/objects/ObjectPool.java +++ b/src/main/java/art/arcane/iris/modules/objects/ObjectPool.java @@ -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 object(String key) { + /** The pack object {@code key} names; for a procedural pool, the variant {@code rng} picks. */ + public Optional 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) { diff --git a/src/main/java/art/arcane/iris/modules/objects/ProceduralObjectSettings.java b/src/main/java/art/arcane/iris/modules/objects/ProceduralObjectSettings.java deleted file mode 100644 index b313539ed..000000000 --- a/src/main/java/art/arcane/iris/modules/objects/ProceduralObjectSettings.java +++ /dev/null @@ -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 . - */ - -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 trees = List.of(); - - @MinItems(1) - @Desc("Procedurally generated ruins (crumbling pillars, walls, arches, rubble).") - private List ruins = List.of(); - - @MinItems(1) - @Desc("Procedurally generated natural rock formations (spires, hoodoos, arches, sea stacks, boulders, basalt columns).") - private List formations = List.of(); - - @MinItems(1) - @Desc("Procedurally generated underwater coral structures.") - private List coral = List.of(); - - @MinItems(1) - @Desc("Procedurally generated mushrooms and shelf fungi.") - private List fungi = List.of(); - - @MinItems(1) - @Desc("Procedurally generated crystal clusters (usually placed in caves).") - private List crystals = List.of(); - - public ProceduralObjectSettings() { - } - - public List trees() { - return view(trees); - } - - public List ruins() { - return view(ruins); - } - - public List formations() { - return view(formations); - } - - public List coral() { - return view(coral); - } - - public List fungi() { - return view(fungi); - } - - public List crystals() { - return view(crystals); - } - - private static List view(List list) { - return list == null ? List.of() : Collections.unmodifiableList(list); - } -} diff --git a/src/main/java/art/arcane/iris/modules/objects/ProceduralPlacement.java b/src/main/java/art/arcane/iris/modules/objects/ProceduralPlacement.java deleted file mode 100644 index c8be43476..000000000 --- a/src/main/java/art/arcane/iris/modules/objects/ProceduralPlacement.java +++ /dev/null @@ -1,97 +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 . - */ - -package art.arcane.iris.modules.objects; - -import art.arcane.iris.builtin.anchor.ObjectPlaceMode; -import art.arcane.iris.builtin.objects.PlacementSource; -import com.volmit.object.PlaceableObject; -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.volmlib.util.math.RNG; - -import java.util.List; -import java.util.Optional; - -/** - * A procedural object of a region or biome made placeable: a pool of variants Iris bakes once from its settings, and - * the options it is scattered with, like an object placement. - */ -public interface ProceduralPlacement extends PlacementSource { - String name(); - - @Override - double chance(); - - int density(); - - /** Whether the variants are meant to look like the real thing, so leaves decay. */ - boolean plausible(); - - /** Whether the variants are trees. */ - boolean tree(); - - @Override - ObjectPlaceMode mode(); - - @Override - CarvingMode carvingSupport(); - - @Override - CaveAnchorMode caveAnchorMode(); - - @Override - boolean underwater(); - - @Override - default boolean requireSurfaceSupport() { - return true; - } - - @Override - default int surfaceSupportBuffer() { - return 2; - } - - @Override - default boolean isDolphinTarget() { - return false; - } - - ObjectRotation rotation(); - - ObjectTranslate translate(); - - Optional vacuumSettings(); - - /** The heights the variants may sit between. */ - ObjectLimit clamp(); - - Optional stiltSettings(); - - /** One of the variants, picked with {@code rng}; empty when none baked. */ - Optional variant(RNG rng); - - /** Every variant, baked on first use. */ - List variants(); -} diff --git a/src/main/java/art/arcane/iris/modules/objects/coral/Coral.java b/src/main/java/art/arcane/iris/modules/objects/coral/Coral.java deleted file mode 100644 index 31dc9f77f..000000000 --- a/src/main/java/art/arcane/iris/modules/objects/coral/Coral.java +++ /dev/null @@ -1,344 +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 . - */ - -package art.arcane.iris.modules.objects.coral; - -import art.arcane.iris.builtin.anchor.ObjectPlaceMode; -import art.arcane.iris.builtin.carve.CarvingMode; -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 com.volmit.block.PaletteSpec; -import com.volmit.config.Desc; -import com.volmit.config.Snippet; -import com.volmit.config.MaxNumber; -import com.volmit.config.MinNumber; -import com.volmit.config.Ref; -import com.volmit.config.Reference; -import com.volmit.config.Required; - -import java.util.Optional; - -@Snippet("iris/objects/coral") -@Desc("A single procedurally generated coral reef structure. Iris bakes a pool of deterministic variants from these settings and scatters them across the seafloor at world-gen time, exactly like an object placement but generated from scratch instead of loaded from an iob file. Mirrors the procedural tree system but tuned for underwater reefs: structural blocks are waterlogged so the coral stays alive, and placement defaults to anchoring on the terrain beneath the water surface.") -public final class Coral { - @Desc("A human readable name used in logs and as the variant load key.") - private String name = "coral"; - - @MinNumber(0) - @MaxNumber(1) - @Desc("The chance per chunk for this coral to attempt placement. Use density for multiple per chunk.") - private double chance = 0.4; - - @MinNumber(1) - @Desc("If the chance check passes, attempt this many placements in the chunk.") - private int density = 1; - - @MinNumber(1) - @MaxNumber(64) - @Desc("How many distinct variants to pre-bake for this coral. Higher means more variety at a small memory cost.") - private int variants = 6; - - @Desc("The base seed for deterministic generation. The same seed and settings always bake the same variants.") - private long seed = 1337; - - @Desc("The placement mode used to anchor the coral to the seafloor.") - private ObjectPlaceMode mode = ObjectPlaceMode.CENTER_HEIGHT; - - @Desc("Rotate this coral's placement.") - private ObjectRotation rotation = new ObjectRotation(); - - @Desc("Limit the max or min height of placement.") - private ObjectLimit clamp = new ObjectLimit(); - - @Desc("Whether this coral may place on the terrain surface, under carvings, or both.") - private CarvingMode carvingSupport = CarvingMode.SURFACE_ONLY; - - @Desc("If true (default for coral), the coral anchors on the terrain height beneath the water, so it grows up from the seafloor rather than floating at the water surface.") - private boolean underwater = true; - - @Desc("Translate (offset) this placement along each axis; for example set a negative y to sink it into the seafloor.") - private ObjectTranslate translate = new ObjectTranslate(); - - @Desc("Settings for the stilt place modes (STILT, MIN_STILT, FAST_STILT, CENTER_STILT, ERODE_STILT, ORGANIC_STILT).") - private StiltSettings stiltSettings; - - @Desc("Settings for the vacuum place modes (VACUUM, VACUUM_HIGH, VACUUM_FAST, VACUUM_ORGANIC).") - private VacuumSettings vacuumSettings; - - @Desc("If true (default), every resolved coral block that is waterloggable is forced waterlogged so the coral does not die in water (coral fans, sea pickles and kelp also waterlog). Set false to place dead/dry coral.") - private boolean waterlogged = true; - - @Desc("The overall silhouette this coral grows into (branching, fan, brain, pillar, tendril). Each form runs a different generation routine.") - private CoralForm form = CoralForm.BRANCHING; - - @Required - @Desc("The structural coral block (the living wood of the reef), e.g. minecraft:tube_coral_block. Ignored when blockPalette is set.") - @Ref(Reference.BLOCK) - private String block = "minecraft:tube_coral_block"; - - @Desc("A noise-driven palette for the structural coral block. When set this overrides the single block, letting the reef mix tube/brain/bubble/fire/horn coral_block tones across its body.") - private PaletteSpec blockPalette; - - @Desc("Optional tip block placed at branch tips and at the very top of the structure, e.g. coral fans or minecraft:sea_pickle. Ignored when tipPalette is set. Null disables tips.") - @Ref(Reference.BLOCK) - private String tipBlock = null; - - @Desc("A noise-driven palette for the tip block. When set this overrides the single tipBlock, letting tips mix fan / pickle decorations.") - private PaletteSpec tipPalette; - - @MinNumber(0) - @MaxNumber(1) - @Desc("The chance per eligible tip position to place a tip block (coral fan / sea pickle).") - private double tipChance = 0.6; - - @MinNumber(1) - @Desc("Minimum overall height of the coral in blocks.") - private int heightMin = 4; - - @MinNumber(1) - @Desc("Maximum overall height of the coral in blocks.") - private int heightMax = 8; - - @MinNumber(0) - @Desc("Horizontal spread of the structure in blocks. For BRANCHING this is how far arms reach out, for BRAIN/PILLAR/FAN it widens the base footprint.") - private double spread = 3; - - @MinNumber(0) - @MaxNumber(1) - @Desc("Lateral noise wobble (0-1) applied to branches and tendrils so they are not ruler-straight. 0 is perfectly straight, 1 is heavily wandering.") - private double sway = 0.5; - - @MinNumber(1) - @MaxNumber(12) - @Desc("BRANCHING only: how many arms sprout from the central stalk.") - private int branchCount = 4; - - @MinNumber(1) - @Desc("BRANCHING only: the length of each arm in blocks before reaching its tip.") - private double branchLength = 3; - - @MinNumber(0) - @MaxNumber(90) - @Desc("BRANCHING only: the upward elevation in degrees of each arm from horizontal. 90 is straight up, 0 is flat out.") - private double branchElevation = 55; - - @Desc("BRANCHING only: how the arms are distributed around the stalk by azimuth.") - private CoralBranchAzimuth branchAzimuth = CoralBranchAzimuth.GOLDEN_ANGLE; - - @Desc("BRANCHING only: if true, each arm splits once into a small fan of sub-arms for a bushier reef.") - private boolean subBranches = true; - - @MinNumber(1) - @MaxNumber(5) - @Desc("BRANCHING only: how many sub-arms each arm splits into when subBranches is true.") - private int subBranchCount = 2; - - @MinNumber(0) - @MaxNumber(1) - @Desc("BRANCHING only: the length of each sub-arm as a fraction of its parent arm.") - private double subBranchScale = 0.5; - - @MinNumber(0) - @MaxNumber(4) - @Desc("BRANCHING and PILLAR only: the radius of the small coral tip cluster grown at each tip.") - private int tipClusterRadius = 1; - - @MinNumber(1) - @MaxNumber(8) - @Desc("BRAIN only: the horizontal radius of the brain-coral blob in blocks.") - private int brainRadius = 3; - - @MinNumber(0) - @MaxNumber(1) - @Desc("BRAIN only: how strongly 3D value noise perturbs the ellipsoid surface, for a wrinkled organic blob. 0 is a smooth dome.") - private double brainRoughness = 0.35; - - @MinNumber(1) - @MaxNumber(12) - @Desc("PILLAR only: the radius of the stout vertical column in blocks.") - private int pillarRadius = 1; - - @MinNumber(1) - @MaxNumber(8) - @Desc("FAN only: the half-width of the upright fan plane in blocks (the disc widens toward its mid-height).") - private int fanWidth = 3; - - @MinNumber(1) - @MaxNumber(12) - @Desc("TENDRIL only: how many thin wavy stalks rise from the base.") - private int tendrilCount = 4; - - public Coral() { - } - - public String name() { - return name; - } - - public double chance() { - return chance; - } - - public int density() { - return density; - } - - public int variants() { - return variants; - } - - public long seed() { - return seed; - } - - public ObjectPlaceMode mode() { - return mode == null ? ObjectPlaceMode.CENTER_HEIGHT : mode; - } - - public ObjectRotation rotation() { - return rotation; - } - - public ObjectLimit clamp() { - return clamp; - } - - public CarvingMode carvingSupport() { - return carvingSupport == null ? CarvingMode.SURFACE_ONLY : carvingSupport; - } - - public boolean underwater() { - return underwater; - } - - public ObjectTranslate translate() { - return translate; - } - - /** Empty where the pack sets none. */ - public Optional stiltSettings() { - return Optional.ofNullable(stiltSettings); - } - - /** Empty where the pack sets none. */ - public Optional vacuumSettings() { - return Optional.ofNullable(vacuumSettings); - } - - public boolean waterlogged() { - return waterlogged; - } - - public CoralForm form() { - return form == null ? CoralForm.BRANCHING : form; - } - - public String block() { - return block; - } - - /** Empty where the pack sets none. */ - public Optional blockPalette() { - return Optional.ofNullable(blockPalette); - } - - /** Empty where the pack sets none. */ - public Optional tipBlock() { - return Optional.ofNullable(tipBlock); - } - - /** Empty where the pack sets none. */ - public Optional tipPalette() { - return Optional.ofNullable(tipPalette); - } - - public double tipChance() { - return tipChance; - } - - public int heightMin() { - return heightMin; - } - - public int heightMax() { - return heightMax; - } - - public double spread() { - return spread; - } - - public double sway() { - return sway; - } - - public int branchCount() { - return branchCount; - } - - public double branchLength() { - return branchLength; - } - - public double branchElevation() { - return branchElevation; - } - - public CoralBranchAzimuth branchAzimuth() { - return branchAzimuth == null ? CoralBranchAzimuth.GOLDEN_ANGLE : branchAzimuth; - } - - public boolean subBranches() { - return subBranches; - } - - public int subBranchCount() { - return subBranchCount; - } - - public double subBranchScale() { - return subBranchScale; - } - - public int tipClusterRadius() { - return tipClusterRadius; - } - - public int brainRadius() { - return brainRadius; - } - - public double brainRoughness() { - return brainRoughness; - } - - public int pillarRadius() { - return pillarRadius; - } - - public int fanWidth() { - return fanWidth; - } - - public int tendrilCount() { - return tendrilCount; - } -} diff --git a/src/main/java/art/arcane/iris/modules/objects/coral/CoralForm.java b/src/main/java/art/arcane/iris/modules/objects/coral/CoralForm.java deleted file mode 100644 index 46d645872..000000000 --- a/src/main/java/art/arcane/iris/modules/objects/coral/CoralForm.java +++ /dev/null @@ -1,39 +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 . - */ - -package art.arcane.iris.modules.objects.coral; - -import com.volmit.config.Desc; - -@Desc("The overall silhouette a procedural coral grows into. Each form drives a completely different generation routine in the coral generator, from tree-like branching arms to rounded brain blobs and thin wavy tendrils.") -public enum CoralForm { - @Desc("A tree-like coral built from a stout central stalk that sprouts several upward-leaning arms (distributed by golden angle or randomly), each optionally splitting once into sub-arms, with small coral tip clusters (fans / sea pickles) at the ends. The most structurally complex form and the closest analogue to a procedural tree.") - BRANCHING, - - @Desc("A thin, single-block-thick vertical fan plane that rises and widens with height like a sheet of fire or horn coral. Reads as a flat decorative blade rather than a volume.") - FAN, - - @Desc("A rounded, noise-perturbed ellipsoid blob of brain coral that bulges out of the seafloor like a boulder, with an irregular wrinkled surface driven by 3D value noise.") - BRAIN, - - @Desc("A stout, thick vertical column of coral block topped with a dense tip cluster. Wider and blunter than a tendril, reading as a solid coral pillar or stack.") - PILLAR, - - @Desc("Several very thin (one block wide) wavy stalks that rise upward and wander laterally using value noise, like a clump of swaying coral whips or kelp-thin growths.") - TENDRIL -} diff --git a/src/main/java/art/arcane/iris/modules/objects/crystal/Crystal.java b/src/main/java/art/arcane/iris/modules/objects/crystal/Crystal.java deleted file mode 100644 index f954a4e79..000000000 --- a/src/main/java/art/arcane/iris/modules/objects/crystal/Crystal.java +++ /dev/null @@ -1,314 +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 . - */ - -package art.arcane.iris.modules.objects.crystal; - -import art.arcane.iris.builtin.anchor.ObjectPlaceMode; -import art.arcane.iris.builtin.carve.CarvingMode; -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 com.volmit.block.PaletteSpec; -import com.volmit.config.Desc; -import com.volmit.config.Snippet; -import com.volmit.config.MaxNumber; -import com.volmit.config.MinNumber; -import com.volmit.config.Ref; -import com.volmit.config.Reference; -import com.volmit.config.Required; - -import java.util.Optional; - -@Snippet("iris/objects/crystal") -@Desc("A single procedurally generated crystal cluster: a budding base blob with faceted, tapered shards radiating from it (geode / amethyst-style). Iris bakes a pool of deterministic variants from these settings and scatters them at world-gen time, exactly like an object placement but generated from scratch instead of loaded from an iob file. Built for caves.") -public final class Crystal { - @Desc("A human readable name used in logs and as the variant load key.") - private String name = "crystal"; - - @MinNumber(0) - @MaxNumber(1) - @Desc("The chance per chunk for this crystal cluster to attempt placement. Use density for multiple per chunk.") - private double chance = 0.2; - - @MinNumber(1) - @Desc("If the chance check passes, attempt this many placements in the chunk.") - private int density = 1; - - @MinNumber(1) - @MaxNumber(64) - @Desc("How many distinct variants to pre-bake for this crystal cluster. Higher means more variety at a small memory cost.") - private int variants = 6; - - @Desc("The base seed for deterministic generation. The same seed and settings always bake the same variants.") - private long seed = 1337; - - @Desc("The placement mode used to anchor the crystal cluster to the terrain.") - private ObjectPlaceMode mode = ObjectPlaceMode.CENTER_HEIGHT; - - @Desc("Rotate this crystal cluster's placement.") - private ObjectRotation rotation = new ObjectRotation(); - - @Desc("Limit the max or min height of placement.") - private ObjectLimit clamp = new ObjectLimit(); - - @Desc("Whether this crystal cluster may place on the terrain surface, under carvings, or both. Crystals are meant for caves, so this defaults to CARVING_ONLY.") - private CarvingMode carvingSupport = CarvingMode.CARVING_ONLY; - - @Desc("If true, the crystal cluster anchors on the terrain height ignoring the water surface.") - private boolean underwater = false; - - @Desc("Translate (offset) this placement along each axis; for example set a negative y to sink it into the ground.") - private ObjectTranslate translate = new ObjectTranslate(); - - @Desc("Settings for the stilt place modes (STILT, MIN_STILT, FAST_STILT, CENTER_STILT, ERODE_STILT, ORGANIC_STILT).") - private StiltSettings stiltSettings; - - @Desc("Settings for the vacuum place modes (VACUUM, VACUUM_HIGH, VACUUM_FAST, VACUUM_ORGANIC).") - private VacuumSettings vacuumSettings; - - @Desc("The surface this crystal grows from (FLOOR shards up, CEILING shards down, WALL shards outward). This orients the baked geometry only.") - private CrystalSurface growthSurface = CrystalSurface.FLOOR; - - @Required - @Desc("The primary crystal shard block, e.g. minecraft:amethyst_block. Ignored when blockPalette is set.") - @Ref(Reference.BLOCK) - private String block = "minecraft:amethyst_block"; - - @Desc("A noise-driven palette for the crystal shards (a prismatic mix, e.g. amethyst_block, calcite, tinted_glass). When set this overrides the single block, letting the shards mix blocks by noise. Palette wins.") - private PaletteSpec blockPalette; - - @Desc("Optional block placed at the very tip of each shard for a different colored or sparkling point (e.g. minecraft:amethyst_cluster or glowstone). Ignored when tipPalette is set. If unset and glow is true, a light-emitting block is sprinkled among the tips instead.") - @Ref(Reference.BLOCK) - private String tipBlock = null; - - @Desc("A noise-driven palette for the shard tips. When set this overrides the single tipBlock. Palette wins.") - private PaletteSpec tipPalette; - - @MinNumber(0) - @MaxNumber(1) - @Desc("The chance per shard that its very tip is replaced by the tip block (or glow block).") - private double tipChance = 0.6; - - @Desc("If true and no tipBlock/tipPalette is set, sprinkle a light-emitting block (the glowBlock) among the shard tips for a sparkling geode.") - private boolean glow = false; - - @Desc("The light-emitting block sprinkled among the tips when glow is true and no tip block is configured.") - @Ref(Reference.BLOCK) - private String glowBlock = "minecraft:glowstone"; - - @Desc("Optional block for the budding base blob the shards grow from, e.g. minecraft:budding_amethyst or calcite. Ignored when basePalette is set. If unset, the base is built from the primary shard block.") - @Ref(Reference.BLOCK) - private String baseBlock = "minecraft:budding_amethyst"; - - @Desc("A noise-driven palette for the budding base blob. When set this overrides the single baseBlock. Palette wins.") - private PaletteSpec basePalette; - - @MinNumber(0) - @Desc("Radius in blocks of the budding base blob the shards radiate from. 0 places no base blob (shards spring from a single point).") - private double baseRadius = 1.6; - - @MinNumber(0) - @MaxNumber(1) - @Desc("How strongly value noise perturbs the surface of the base blob, for a lumpy organic budding base rather than a clean sphere.") - private double baseNoise = 0.35; - - @MinNumber(1) - @Desc("Minimum number of shards radiating from the base.") - private int shardCountMin = 5; - - @MinNumber(1) - @Desc("Maximum number of shards radiating from the base.") - private int shardCountMax = 11; - - @MinNumber(1) - @Desc("Minimum length in blocks of a shard, measured from the base out to its pointed tip.") - private int shardLengthMin = 3; - - @MinNumber(1) - @Desc("Maximum length in blocks of a shard, measured from the base out to its pointed tip.") - private int shardLengthMax = 8; - - @MinNumber(0.5) - @Desc("Starting radius in blocks of a shard at its thick base end. The shard tapers from this down to a single block at the tip.") - private double shardBaseRadius = 1.4; - - @MinNumber(0) - @MaxNumber(1) - @Desc("How aggressively each shard narrows from base to tip. 0 keeps a near-constant column; 1 tapers fully to a sharp point at the very tip. Each shard always ends in a single pointed block.") - private double shardTaper = 0.85; - - @MinNumber(0) - @MaxNumber(90) - @Desc("The half-angle in degrees of the cone the shards fan within around the surface normal. 0 makes all shards parallel to the normal; larger values splay them outward into a starburst.") - private double spreadAngle = 45; - - @Desc("How the shard azimuths are distributed around the normal (RANDOM for a chaotic clump, GOLDEN_ANGLE for an evenly spaced rosette).") - private CrystalDistribution distribution = CrystalDistribution.GOLDEN_ANGLE; - - @MinNumber(0) - @MaxNumber(1) - @Desc("Per-shard angular randomness (0-1) added on top of the chosen distribution so the cluster never looks mechanically regular. 0 is perfectly distributed; 1 is heavily jittered.") - private double jitter = 0.25; - - public Crystal() { - } - - public String name() { - return name; - } - - public double chance() { - return chance; - } - - public int density() { - return density; - } - - public int variants() { - return variants; - } - - public long seed() { - return seed; - } - - public ObjectPlaceMode mode() { - return mode == null ? ObjectPlaceMode.CENTER_HEIGHT : mode; - } - - public ObjectRotation rotation() { - return rotation; - } - - public ObjectLimit clamp() { - return clamp; - } - - public CarvingMode carvingSupport() { - return carvingSupport == null ? CarvingMode.CARVING_ONLY : carvingSupport; - } - - public boolean underwater() { - return underwater; - } - - public ObjectTranslate translate() { - return translate; - } - - /** Empty where the pack sets none. */ - public Optional stiltSettings() { - return Optional.ofNullable(stiltSettings); - } - - /** Empty where the pack sets none. */ - public Optional vacuumSettings() { - return Optional.ofNullable(vacuumSettings); - } - - public CrystalSurface growthSurface() { - return growthSurface == null ? CrystalSurface.FLOOR : growthSurface; - } - - public String block() { - return block; - } - - /** Empty where the pack sets none. */ - public Optional blockPalette() { - return Optional.ofNullable(blockPalette); - } - - /** Empty where the pack sets none. */ - public Optional tipBlock() { - return Optional.ofNullable(tipBlock); - } - - /** Empty where the pack sets none. */ - public Optional tipPalette() { - return Optional.ofNullable(tipPalette); - } - - public double tipChance() { - return tipChance; - } - - public boolean glow() { - return glow; - } - - public String glowBlock() { - return glowBlock; - } - - public String baseBlock() { - return baseBlock; - } - - /** Empty where the pack sets none. */ - public Optional basePalette() { - return Optional.ofNullable(basePalette); - } - - public double baseRadius() { - return baseRadius; - } - - public double baseNoise() { - return baseNoise; - } - - public int shardCountMin() { - return shardCountMin; - } - - public int shardCountMax() { - return shardCountMax; - } - - public int shardLengthMin() { - return shardLengthMin; - } - - public int shardLengthMax() { - return shardLengthMax; - } - - public double shardBaseRadius() { - return shardBaseRadius; - } - - public double shardTaper() { - return shardTaper; - } - - public double spreadAngle() { - return spreadAngle; - } - - public CrystalDistribution distribution() { - return distribution == null ? CrystalDistribution.GOLDEN_ANGLE : distribution; - } - - public double jitter() { - return jitter; - } -} diff --git a/src/main/java/art/arcane/iris/modules/objects/crystal/CrystalSurface.java b/src/main/java/art/arcane/iris/modules/objects/crystal/CrystalSurface.java deleted file mode 100644 index 66d456e8d..000000000 --- a/src/main/java/art/arcane/iris/modules/objects/crystal/CrystalSurface.java +++ /dev/null @@ -1,33 +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 . - */ - -package art.arcane.iris.modules.objects.crystal; - -import com.volmit.config.Desc; - -@Desc("The surface a crystal cluster grows from. This only orients the baked geometry (which way the shards point); placement of the object into a cave is handled by the placement system, not here.") -public enum CrystalSurface { - @Desc("Grows from a cave floor. The budding base sits at the bottom and the shards point upward, fanning within the spread cone around the up axis. Built with positive py so the cluster grows up from the base layer.") - FLOOR, - - @Desc("Grows from a cave ceiling. The budding base sits at the top and the shards point downward like stalactites, fanning within the spread cone around the down axis. Built with negative py so the cluster grows down from the ceiling.") - CEILING, - - @Desc("Grows from a cave wall. The budding base hugs the wall and the shards point outward and slightly upward, fanning within the spread cone around a tilted normal so the cluster reads as a wall sconce of shards.") - WALL -} diff --git a/src/main/java/art/arcane/iris/modules/objects/formation/Formation.java b/src/main/java/art/arcane/iris/modules/objects/formation/Formation.java deleted file mode 100644 index eeb8b93db..000000000 --- a/src/main/java/art/arcane/iris/modules/objects/formation/Formation.java +++ /dev/null @@ -1,447 +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 . - */ - -package art.arcane.iris.modules.objects.formation; - -import art.arcane.iris.builtin.anchor.ObjectPlaceMode; -import art.arcane.iris.builtin.carve.CarvingMode; -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 com.volmit.block.PaletteSpec; -import com.volmit.config.Desc; -import com.volmit.config.Snippet; -import com.volmit.config.MaxNumber; -import com.volmit.config.MinNumber; -import com.volmit.config.Ref; -import com.volmit.config.Reference; -import com.volmit.config.Required; - -import java.util.Optional; - -@Snippet("iris/objects/formation") -@Desc("A single procedurally generated natural formation, including rock landmarks and magical glacial silhouettes. Iris bakes a pool of deterministic variants from these settings and scatters them at world-gen time, exactly like an object placement but generated from scratch instead of loaded from an iob file.") -public final class Formation { - @Desc("A human readable name used in logs and as the variant load key.") - private String name = "formation"; - - @MinNumber(0) - @MaxNumber(1) - @Desc("The chance per chunk for this formation to attempt placement. Use density for multiple per chunk.") - private double chance = 0.02; - - @MinNumber(1) - @Desc("If the chance check passes, attempt this many placements in the chunk.") - private int density = 1; - - @MinNumber(1) - @MaxNumber(64) - @Desc("How many distinct variants to pre-bake for this formation. Higher means more variety at a small memory cost.") - private int variants = 6; - - @Desc("The base seed for deterministic generation. The same seed and settings always bake the same variants.") - private long seed = 1337; - - @Desc("The placement mode used to anchor the formation to the terrain.") - private ObjectPlaceMode mode = ObjectPlaceMode.CENTER_HEIGHT; - - @Desc("Rotate this formation's placement.") - private ObjectRotation rotation = new ObjectRotation(); - - @Desc("Limit the max or min height of placement.") - private ObjectLimit clamp = new ObjectLimit(); - - @Desc("Whether this formation may place on the terrain surface, under carvings, or both.") - private CarvingMode carvingSupport = CarvingMode.SURFACE_ONLY; - - @MinNumber(0) - @MaxNumber(16) - @Desc("Horizontal buffer, in blocks, beyond each lowest solid foundation block that must also be solid, un-carved ground.") - private int surfaceSupportBuffer = 3; - - @Desc("If true, the formation anchors on the terrain height ignoring the water surface.") - private boolean underwater = false; - - @Desc("Translate (offset) this placement along each axis; for example set a negative y to sink it into the ground.") - private ObjectTranslate translate = new ObjectTranslate(); - - @Desc("Settings for the stilt place modes (STILT, MIN_STILT, FAST_STILT, CENTER_STILT, ERODE_STILT, ORGANIC_STILT).") - private StiltSettings stiltSettings; - - @Desc("Settings for the vacuum place modes (VACUUM, VACUUM_HIGH, VACUUM_FAST, VACUUM_ORGANIC).") - private VacuumSettings vacuumSettings; - - @Desc("The overall silhouette of the formation. Drives which sculpting routine the generator uses.") - private FormationForm form = FormationForm.SPIRE; - - @Required - @Desc("The main rock block, e.g. minecraft:stone. Ignored when blockPalette is set.") - @Ref(Reference.BLOCK) - private String block = "minecraft:stone"; - - @Desc("A noise-driven palette for the main rock body. When set this overrides the single block, letting the body mix blocks by noise.") - private PaletteSpec blockPalette; - - @Desc("Optional caprock block placed on the top crown of the formation (and the wide overhanging cap for HOODOO). Ignored when capPalette is set. When null and capPalette is unset, the formation uses its main rock everywhere.") - @Ref(Reference.BLOCK) - private String capBlock = null; - - @Desc("A noise-driven palette for the caprock. When set this overrides the single capBlock.") - private PaletteSpec capPalette; - - @Desc("Optional palette of strata (horizontal colored bands) blended into the rock body by y level. When set, every strataThickness blocks of height switches to the next strata block, producing the signature banded look. Falls back to the main block where unset.") - private PaletteSpec strataPalette; - - @MinNumber(1) - @MaxNumber(32) - @Desc("The thickness in blocks of each horizontal strata band when strataPalette is set.") - private int strataThickness = 3; - - @MinNumber(1) - @Desc("Minimum total height of the formation in blocks.") - private int heightMin = 14; - - @MinNumber(1) - @Desc("Maximum total height of the formation in blocks.") - private int heightMax = 26; - - @MinNumber(1) - @Desc("Minimum base radius (half-width) of the formation in blocks.") - private int baseWidthMin = 3; - - @MinNumber(1) - @Desc("Maximum base radius (half-width) of the formation in blocks.") - private int baseWidthMax = 6; - - @MinNumber(0) - @Desc("The target radius (half-width) at the very top of the formation in blocks, before the profile is applied. 0 means taper to a point.") - private int topWidth = 0; - - @Desc("The function used to shape the formation radius over its height.") - private FormationProfile profile = FormationProfile.TAPER; - - @MinNumber(0) - @MaxNumber(1) - @Desc("The normalized height (0 base, 1 top) of the pinched waist for the PARABOLIC profile (used by HOODOO).") - private double profileWaist = 0.55; - - @MinNumber(0) - @MaxNumber(1) - @Desc("The minimum radius fraction at the waist for the PARABOLIC profile. Lower values pinch the waist tighter.") - private double profileWaistFloor = 0.35; - - @MinNumber(0) - @Desc("How far the formation leans, in degrees from vertical. 0 is perfectly upright. The whole body is sheared by this amount over its height.") - private double lean = 0; - - @Desc("Compass direction in degrees the formation leans toward when lean is non-zero.") - private double leanAzimuth = 0; - - @MinNumber(0) - @MaxNumber(1) - @Desc("Surface roughness from 0 (a clean smooth solid) to 1 (heavily eroded and pitted). Driven by 3D value noise that perturbs the radius so the formation never reads as a clean cylinder.") - private double roughness = 0.3; - - @MinNumber(0) - @MaxNumber(1) - @Desc("Per-block surface jitter from 0 (none) to 1 (maximum). Randomly carves and adds isolated edge blocks to break up the silhouette.") - private double jitter = 0.15; - - @MinNumber(0) - @Desc("Extra wide cap radius in blocks added on top for the HOODOO form, producing the overhanging mushroom caprock. 0 disables the overhang.") - private int hoodooCapRadius = 3; - - @MinNumber(1) - @MaxNumber(6) - @Desc("The height in blocks of the HOODOO overhanging caprock slab.") - private int hoodooCapHeight = 3; - - @MinNumber(0) - @Desc("How wide the ARCH opening is in blocks (the gap between the two legs). The arch span is rasterized over this width.") - private int archSpan = 10; - - @MinNumber(1) - @Desc("The thickness in blocks of the ARCH legs and spanning curve.") - private int archThickness = 3; - - @MinNumber(0) - @MaxNumber(1) - @Desc("How strongly an ARCH varies its leg steepness, crown position, depth bow and tube width between deterministic variants. 0 is symmetric and 1 is highly organic.") - private double archAsymmetry = 0.35; - - @MinNumber(2) - @MaxNumber(12) - @Desc("How many separate columns make up a BASALT_COLUMN cluster. Each column gets a randomized height around the formation height range.") - private int basaltColumns = 5; - - @MinNumber(1) - @Desc("The radius (half-width) in blocks of each individual column in a BASALT_COLUMN cluster.") - private int basaltColumnRadius = 1; - - @MinNumber(0) - @MaxNumber(1) - @Desc("How much the heights of individual BASALT_COLUMN columns vary from each other, from 0 (all equal) to 1 (highly varied).") - private double basaltHeightVariance = 0.45; - - @MinNumber(1) - @MaxNumber(12) - @Desc("How many tapered summits crown an ICEBERG formation.") - private int icebergPeaks = 3; - - @MinNumber(2) - @MaxNumber(8) - @Desc("How many separated shards form a FISSURE.") - private int fractureCount = 3; - - @MinNumber(1) - @MaxNumber(16) - @Desc("Open-air separation in blocks between the shards of a FISSURE.") - private int fractureSeparation = 2; - - @MinNumber(0.25) - @MaxNumber(6) - @Desc("How many complete turns a SPIRAL makes from base to tip.") - private double spiralTurns = 1.5; - - @MinNumber(1) - @MaxNumber(32) - @Desc("The starting distance in blocks between a SPIRAL and its open center.") - private int spiralRadius = 4; - - @MinNumber(1) - @MaxNumber(8) - @Desc("The radius in blocks of the tube swept along a SPIRAL.") - private int spiralThickness = 2; - - @MinNumber(1) - @MaxNumber(32) - @Desc("How far the hooked arm of an OVERHANG projects from its base.") - private int overhangReach = 8; - - @MinNumber(0) - @MaxNumber(16) - @Desc("How many blocks the tip of an OVERHANG curls downward.") - private int overhangDrop = 3; - - public Formation() { - } - - public String name() { - return name; - } - - public double chance() { - return chance; - } - - public int density() { - return density; - } - - public int variants() { - return variants; - } - - public long seed() { - return seed; - } - - public ObjectPlaceMode mode() { - return mode == null ? ObjectPlaceMode.CENTER_HEIGHT : mode; - } - - public ObjectRotation rotation() { - return rotation; - } - - public ObjectLimit clamp() { - return clamp; - } - - public CarvingMode carvingSupport() { - return carvingSupport == null ? CarvingMode.SURFACE_ONLY : carvingSupport; - } - - public int surfaceSupportBuffer() { - return surfaceSupportBuffer; - } - - public boolean underwater() { - return underwater; - } - - public ObjectTranslate translate() { - return translate; - } - - /** Empty where the pack sets none. */ - public Optional stiltSettings() { - return Optional.ofNullable(stiltSettings); - } - - /** Empty where the pack sets none. */ - public Optional vacuumSettings() { - return Optional.ofNullable(vacuumSettings); - } - - public FormationForm form() { - return form == null ? FormationForm.SPIRE : form; - } - - public String block() { - return block; - } - - /** Empty where the pack sets none. */ - public Optional blockPalette() { - return Optional.ofNullable(blockPalette); - } - - /** Empty where the pack sets none. */ - public Optional capBlock() { - return Optional.ofNullable(capBlock); - } - - /** Empty where the pack sets none. */ - public Optional capPalette() { - return Optional.ofNullable(capPalette); - } - - /** Empty where the pack sets none. */ - public Optional strataPalette() { - return Optional.ofNullable(strataPalette); - } - - public int strataThickness() { - return strataThickness; - } - - public int heightMin() { - return heightMin; - } - - public int heightMax() { - return heightMax; - } - - public int baseWidthMin() { - return baseWidthMin; - } - - public int baseWidthMax() { - return baseWidthMax; - } - - public int topWidth() { - return topWidth; - } - - public FormationProfile profile() { - return profile == null ? FormationProfile.TAPER : profile; - } - - public double profileWaist() { - return profileWaist; - } - - public double profileWaistFloor() { - return profileWaistFloor; - } - - public double lean() { - return lean; - } - - public double leanAzimuth() { - return leanAzimuth; - } - - public double roughness() { - return roughness; - } - - public double jitter() { - return jitter; - } - - public int hoodooCapRadius() { - return hoodooCapRadius; - } - - public int hoodooCapHeight() { - return hoodooCapHeight; - } - - public int archSpan() { - return archSpan; - } - - public int archThickness() { - return archThickness; - } - - public double archAsymmetry() { - return archAsymmetry; - } - - public int basaltColumns() { - return basaltColumns; - } - - public int basaltColumnRadius() { - return basaltColumnRadius; - } - - public double basaltHeightVariance() { - return basaltHeightVariance; - } - - public int icebergPeaks() { - return icebergPeaks; - } - - public int fractureCount() { - return fractureCount; - } - - public int fractureSeparation() { - return fractureSeparation; - } - - public double spiralTurns() { - return spiralTurns; - } - - public int spiralRadius() { - return spiralRadius; - } - - public int spiralThickness() { - return spiralThickness; - } - - public int overhangReach() { - return overhangReach; - } - - public int overhangDrop() { - return overhangDrop; - } -} diff --git a/src/main/java/art/arcane/iris/modules/objects/formation/FormationForm.java b/src/main/java/art/arcane/iris/modules/objects/formation/FormationForm.java deleted file mode 100644 index 6ffbefc54..000000000 --- a/src/main/java/art/arcane/iris/modules/objects/formation/FormationForm.java +++ /dev/null @@ -1,45 +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 . - */ - -package art.arcane.iris.modules.objects.formation; - -import com.volmit.config.Desc; - -@Desc("The overall silhouette of a procedural natural formation. Each form drives a distinct sculpting routine in the formation generator.") -public enum FormationForm { - @Desc("A tall, slender needle of rock that tapers smoothly to a point at the top (a sharp pinnacle or stone spire).") - SPIRE, - @Desc("A column with a pinched, eroded waist and a wide overhanging caprock balanced on top (the classic desert hoodoo / mushroom rock).") - HOODOO, - @Desc("Two stout legs joined by a spanning curved bridge of rock overhead (a natural stone arch).") - ARCH, - @Desc("A chunky, blocky stack that tapers gently as it rises, like an isolated pillar of rock standing in water (a sea stack).") - SEA_STACK, - @Desc("A rounded, lumpy boulder formed from a noise-perturbed ellipsoid that sits low on the terrain.") - BOULDER, - @Desc("A tightly packed cluster of several vertical, near-hexagonal columns of varying height (a basalt column formation / giant's causeway).") - BASALT_COLUMN, - @Desc("A broad, faceted mound crowned by several irregular tapered peaks, suitable for icebergs and glacial outcrops.") - ICEBERG, - @Desc("Several separated, outward-leaning shards divided by open cracks.") - FISSURE, - @Desc("A tapered tube swept around a tightening helix, leaving open air through its curled center.") - SPIRAL, - @Desc("A grounded pillar that bends into a long hooked cantilever and curls downward at its tip.") - OVERHANG -} diff --git a/src/main/java/art/arcane/iris/modules/objects/formation/FormationProfile.java b/src/main/java/art/arcane/iris/modules/objects/formation/FormationProfile.java deleted file mode 100644 index c63462b8f..000000000 --- a/src/main/java/art/arcane/iris/modules/objects/formation/FormationProfile.java +++ /dev/null @@ -1,35 +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 . - */ - -package art.arcane.iris.modules.objects.formation; - -import com.volmit.config.Desc; - -@Desc("A width-shaping function evaluated over normalized height (0 at the base, 1 at the top). Controls how the formation radius scales between baseWidth at the bottom and topWidth at the top.") -public enum FormationProfile { - @Desc("Same radius at every height (a straight cylinder of constant baseWidth).") - CONSTANT, - @Desc("Radius ramps straight from baseWidth at the bottom to topWidth at the top.") - LINEAR, - @Desc("Radius shrinks smoothly toward a point as height increases (an ease that drives the SPIRE needle and gentle SEA_STACK taper).") - TAPER, - @Desc("Radius pinches to a narrow waist near profileWaist then widens again toward the top (the eroded waist used by HOODOO columns).") - PARABOLIC, - @Desc("Radius bulges out to its maximum in the middle of the height range and narrows at both ends (a barrel / bulged column).") - BULGE -} diff --git a/src/main/java/art/arcane/iris/modules/objects/fungi/Fungus.java b/src/main/java/art/arcane/iris/modules/objects/fungi/Fungus.java deleted file mode 100644 index 8098f9d59..000000000 --- a/src/main/java/art/arcane/iris/modules/objects/fungi/Fungus.java +++ /dev/null @@ -1,355 +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 . - */ - -package art.arcane.iris.modules.objects.fungi; - -import art.arcane.iris.builtin.anchor.ObjectPlaceMode; -import art.arcane.iris.builtin.carve.CarvingMode; -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 com.volmit.block.PaletteSpec; -import com.volmit.config.Desc; -import com.volmit.config.Snippet; -import com.volmit.config.MaxNumber; -import com.volmit.config.MinNumber; -import com.volmit.config.Ref; -import com.volmit.config.Reference; -import com.volmit.config.Required; - -import java.util.Optional; - -@Snippet("iris/objects/fungus") -@Desc("A single procedurally generated fungus (giant mushroom or shelf fungus). Iris bakes a pool of deterministic variants from these settings and scatters them at world-gen time, exactly like an object placement but generated from scratch instead of loaded from an iob file. The fungus is built as a stem column with a cap dome grown on top, mirroring the trunk-and-canopy model used by procedural trees.") -public final class Fungus { - @Desc("A human readable name used in logs and as the variant load key.") - private String name = "fungus"; - - @MinNumber(0) - @MaxNumber(1) - @Desc("The chance per chunk for this fungus to attempt placement. Use density for multiple per chunk.") - private double chance = 0.4; - - @MinNumber(1) - @Desc("If the chance check passes, attempt this many placements in the chunk.") - private int density = 1; - - @MinNumber(1) - @MaxNumber(64) - @Desc("How many distinct variants to pre-bake for this fungus. Higher means more variety at a small memory cost.") - private int variants = 6; - - @Desc("The base seed for deterministic generation. The same seed and settings always bake the same variants.") - private long seed = 1337; - - @Desc("The placement mode used to anchor the fungus to the terrain.") - private ObjectPlaceMode mode = ObjectPlaceMode.CENTER_HEIGHT; - - @Desc("Rotate this fungus's placement.") - private ObjectRotation rotation = new ObjectRotation(); - - @Desc("Limit the max or min height of placement.") - private ObjectLimit clamp = new ObjectLimit(); - - @Desc("Whether this fungus may place on the terrain surface, under carvings, or both.") - private CarvingMode carvingSupport = CarvingMode.SURFACE_ONLY; - - @Desc("If true, the fungus anchors on the terrain height ignoring the water surface.") - private boolean underwater = false; - - @Desc("Translate (offset) this placement along each axis; for example set a negative y to sink it into the ground.") - private ObjectTranslate translate = new ObjectTranslate(); - - @Desc("Settings for the stilt place modes (STILT, MIN_STILT, FAST_STILT, CENTER_STILT, ERODE_STILT, ORGANIC_STILT).") - private StiltSettings stiltSettings; - - @Desc("Settings for the vacuum place modes (VACUUM, VACUUM_HIGH, VACUUM_FAST, VACUUM_ORGANIC).") - private VacuumSettings vacuumSettings; - - @Required - @Desc("The stem block, e.g. minecraft:mushroom_stem. Ignored when stemPalette is set.") - @Ref(Reference.BLOCK) - private String stem = "minecraft:mushroom_stem"; - - @Desc("A noise-driven palette for the stem. When set this overrides the single stem block, letting the stem mix blocks by noise.") - private PaletteSpec stemPalette; - - @Required - @Desc("The cap block, e.g. minecraft:red_mushroom_block. Ignored when capPalette is set.") - @Ref(Reference.BLOCK) - private String cap = "minecraft:red_mushroom_block"; - - @Desc("A noise-driven palette for the cap. When set this overrides the single cap block, letting the cap mix blocks by noise.") - private PaletteSpec capPalette; - - @MinNumber(1) - @Desc("Minimum total stem height in blocks. Variants spread between this and stemHeightMax.") - private int stemHeightMin = 5; - - @MinNumber(1) - @Desc("Maximum total stem height in blocks. Variants spread between stemHeightMin and this.") - private int stemHeightMax = 9; - - @MinNumber(1) - @MaxNumber(3) - @Desc("Base stem width in blocks. 1 is a single column, 2 is a 2x2 stem, 3 is a chunky 3x3 trunk.") - private int stemWidth = 1; - - @Desc("How far the stem leans away from vertical, in degrees. 0 is perfectly upright; small values give an organic tilt.") - private double stemCurve = 0; - - @Desc("Compass direction in degrees the stem leans toward when stemCurve is non-zero.") - private double stemLeanAzimuth = 0; - - @MinNumber(0) - @Desc("Amplitude in blocks of a gentle sideways wave applied up the stem so it is not a perfectly straight ruler.") - private double stemWaveAmplitude = 0.4; - - @MinNumber(0.0001) - @Desc("The number of full sine wobbles applied over the stem height for the stem wave.") - private double stemWavePeriods = 1; - - @Desc("The silhouette of the cap (dome, flat umbrella, funnel, cone, or wide shallow slab).") - private FungusCapShape capShape = FungusCapShape.DOME; - - @MinNumber(1) - @Desc("Minimum cap radius in blocks (measured from the cap center to its rim).") - private int capRadiusMin = 3; - - @MinNumber(1) - @Desc("Maximum cap radius in blocks (measured from the cap center to its rim).") - private int capRadiusMax = 5; - - @MinNumber(1) - @MaxNumber(3) - @Desc("How many blocks thick the cap shell is. 1 is a thin skin, 3 is a fleshy slab.") - private int capThickness = 1; - - @MinNumber(0) - @MaxNumber(1) - @Desc("Vertical flatten factor for the cap. 0 leaves the cap at full height, 1 squashes it flat into a disc.") - private double capSquish = 0.4; - - @MinNumber(0) - @Desc("How far the cap rim droops downward, in degrees, curling the edge of the cap toward the ground.") - private double capDroop = 20; - - @MinNumber(0) - @Desc("How far the cap radius extends past the stem before the rim begins, in blocks. Larger values make the cap overhang the stem more.") - private double capOverhang = 2; - - @Desc("Optional block forming the gill layer on the underside of the cap (gills or a glow layer), e.g. minecraft:brown_mushroom_block or minecraft:shroomlight. Ignored when gillPalette is set or left null.") - @Ref(Reference.BLOCK) - private String gillBlock = null; - - @Desc("A noise-driven palette for the underside gill layer. When set this overrides the single gillBlock.") - private PaletteSpec gillPalette; - - @MinNumber(0) - @MaxNumber(1) - @Desc("The fraction of underside cap blocks replaced by the gill block when a gill block or palette is set.") - private double gillChance = 0.85; - - @Desc("Optional block speckled across the top of the cap by noise (white toadstool dots, warts, glowing spots), e.g. minecraft:bone_block or minecraft:white_concrete. Ignored when spotPalette is set or left null.") - @Ref(Reference.BLOCK) - private String spotBlock = null; - - @Desc("A noise-driven palette for the cap top spots. When set this overrides the single spotBlock.") - private PaletteSpec spotPalette; - - @MinNumber(0) - @MaxNumber(1) - @Desc("The fraction of top cap blocks replaced by the spot block, selected by value noise so spots cluster naturally.") - private double spotChance = 0.18; - - @Desc("If true, generate a bracket / shelf fungus instead of an upright mushroom: a small flat fan that grows sideways off a very short or absent stem, like a polypore clinging to a trunk.") - private boolean shelf = false; - - @MinNumber(1) - @Desc("The radius in blocks of the sideways fan when shelf is true.") - private int shelfRadius = 3; - - public Fungus() { - } - - public String name() { - return name; - } - - public double chance() { - return chance; - } - - public int density() { - return density; - } - - public int variants() { - return variants; - } - - public long seed() { - return seed; - } - - public ObjectPlaceMode mode() { - return mode == null ? ObjectPlaceMode.CENTER_HEIGHT : mode; - } - - public ObjectRotation rotation() { - return rotation; - } - - public ObjectLimit clamp() { - return clamp; - } - - public CarvingMode carvingSupport() { - return carvingSupport == null ? CarvingMode.SURFACE_ONLY : carvingSupport; - } - - public boolean underwater() { - return underwater; - } - - public ObjectTranslate translate() { - return translate; - } - - /** Empty where the pack sets none. */ - public Optional stiltSettings() { - return Optional.ofNullable(stiltSettings); - } - - /** Empty where the pack sets none. */ - public Optional vacuumSettings() { - return Optional.ofNullable(vacuumSettings); - } - - public String stem() { - return stem; - } - - /** Empty where the pack sets none. */ - public Optional stemPalette() { - return Optional.ofNullable(stemPalette); - } - - public String cap() { - return cap; - } - - /** Empty where the pack sets none. */ - public Optional capPalette() { - return Optional.ofNullable(capPalette); - } - - public int stemHeightMin() { - return stemHeightMin; - } - - public int stemHeightMax() { - return stemHeightMax; - } - - public int stemWidth() { - return stemWidth; - } - - public double stemCurve() { - return stemCurve; - } - - public double stemLeanAzimuth() { - return stemLeanAzimuth; - } - - public double stemWaveAmplitude() { - return stemWaveAmplitude; - } - - public double stemWavePeriods() { - return stemWavePeriods; - } - - public FungusCapShape capShape() { - return capShape == null ? FungusCapShape.DOME : capShape; - } - - public int capRadiusMin() { - return capRadiusMin; - } - - public int capRadiusMax() { - return capRadiusMax; - } - - public int capThickness() { - return capThickness; - } - - public double capSquish() { - return capSquish; - } - - public double capDroop() { - return capDroop; - } - - public double capOverhang() { - return capOverhang; - } - - /** Empty where the pack sets none. */ - public Optional gillBlock() { - return Optional.ofNullable(gillBlock); - } - - /** Empty where the pack sets none. */ - public Optional gillPalette() { - return Optional.ofNullable(gillPalette); - } - - public double gillChance() { - return gillChance; - } - - /** Empty where the pack sets none. */ - public Optional spotBlock() { - return Optional.ofNullable(spotBlock); - } - - /** Empty where the pack sets none. */ - public Optional spotPalette() { - return Optional.ofNullable(spotPalette); - } - - public double spotChance() { - return spotChance; - } - - public boolean shelf() { - return shelf; - } - - public int shelfRadius() { - return shelfRadius; - } -} diff --git a/src/main/java/art/arcane/iris/modules/objects/fungi/FungusCapShape.java b/src/main/java/art/arcane/iris/modules/objects/fungi/FungusCapShape.java deleted file mode 100644 index b57ec317e..000000000 --- a/src/main/java/art/arcane/iris/modules/objects/fungi/FungusCapShape.java +++ /dev/null @@ -1,35 +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 . - */ - -package art.arcane.iris.modules.objects.fungi; - -import com.volmit.config.Desc; - -@Desc("The silhouette of the mushroom cap. Each shape drives how the cap radius and thickness vary from its apex down to the rim, giving the fungus a distinct profile.") -public enum FungusCapShape { - @Desc("A rounded hemisphere cap that bulges up and curls slightly under at the rim, the classic red toadstool dome.") - DOME, - @Desc("A wide, nearly flat umbrella that holds its full radius almost to the edge before dropping, the brown-mushroom plate look.") - FLAT, - @Desc("An upturned bowl whose rim lifts higher than its center, cupping upward like a chanterelle or funnel mushroom.") - FUNNEL, - @Desc("A tall pointed cone that tapers from a broad base to a sharp apex, the witch-hat parasol silhouette.") - CONICAL, - @Desc("A very wide but shallow slab, a low overhanging shelf-like roof that spreads far past the stem with minimal vertical rise.") - FLAT_WIDE -} diff --git a/src/main/java/art/arcane/iris/modules/objects/ruin/Ruin.java b/src/main/java/art/arcane/iris/modules/objects/ruin/Ruin.java deleted file mode 100644 index 3de150eef..000000000 --- a/src/main/java/art/arcane/iris/modules/objects/ruin/Ruin.java +++ /dev/null @@ -1,286 +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 . - */ - -package art.arcane.iris.modules.objects.ruin; - -import art.arcane.iris.builtin.anchor.ObjectPlaceMode; -import art.arcane.iris.builtin.carve.CarvingMode; -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 com.volmit.block.PaletteSpec; -import com.volmit.config.Desc; -import com.volmit.config.Snippet; -import com.volmit.config.MaxNumber; -import com.volmit.config.MinItems; -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; -import java.util.Optional; - -@Snippet("iris/objects/ruin") -@Desc("A single procedurally generated ruin: a crumbling man-made structure (pillar, wall, arch, foundation slab, or rubble pile). Iris bakes a pool of deterministic variants from these settings and scatters them at world-gen time, exactly like an object placement but generated from scratch instead of loaded from an iob file. Weathering swaps blocks for mossy or cracked variants by noise, erosion deletes blocks so the shape reads as collapsed, and a buried fraction sinks the ruin into the terrain.") -public final class Ruin { - @Desc("A human readable name used in logs and as the variant load key (procedural/#).") - private String name = "ruin"; - - @MinNumber(0) - @MaxNumber(1) - @Desc("The chance (0-1) per chunk for this ruin to attempt placement. Use density to attempt more than one per chunk once the chance check passes.") - private double chance = 0.05; - - @MinNumber(1) - @Desc("If the chance check passes, attempt this many placements in the chunk. Defaults to a single ruin per qualifying chunk.") - private int density = 1; - - @MinNumber(1) - @MaxNumber(64) - @Desc("How many distinct variants to pre-bake for this ruin. Higher means more variety (different heights, gap patterns, erosion seeds) at a small memory cost.") - private int variants = 6; - - @Desc("The base seed for deterministic generation. The same seed and settings always bake the same variants. Every random choice (size, weathering mask, erosion mask, accents) is derived from this.") - private long seed = 1337; - - @Desc("The placement mode used to anchor the ruin to the terrain. MIN_HEIGHT plants the lowest footprint corner on the ground (good for slabs and rubble on slopes); CENTER_HEIGHT averages the footprint (good for tall pillars and arches).") - private ObjectPlaceMode mode = ObjectPlaceMode.MIN_HEIGHT; - - @Desc("Rotate this ruin's placement so variants do not all face the same way.") - private ObjectRotation rotation = new ObjectRotation(); - - @Desc("Limit the max or min terrain height at which this ruin may place.") - private ObjectLimit clamp = new ObjectLimit(); - - @Desc("Whether this ruin may place on the terrain surface, under carvings (caves), or both. SURFACE_ONLY keeps ruins above ground.") - private CarvingMode carvingSupport = CarvingMode.SURFACE_ONLY; - - @Desc("If true the ruin anchors on the terrain height ignoring the water surface, so it can sit submerged. If false (default) it anchors to the surface and avoids water.") - private boolean underwater = false; - - @Desc("Translate (offset) this placement along each axis; for example set a negative y to sink it into the ground.") - private ObjectTranslate translate = new ObjectTranslate(); - - @Desc("Settings for the stilt place modes (STILT, MIN_STILT, FAST_STILT, CENTER_STILT, ERODE_STILT, ORGANIC_STILT).") - private StiltSettings stiltSettings; - - @Desc("Settings for the vacuum place modes (VACUUM, VACUUM_HIGH, VACUUM_FAST, VACUUM_ORGANIC).") - private VacuumSettings vacuumSettings; - - @Required - @Desc("The primary structural block, e.g. minecraft:cobblestone or minecraft:stone_bricks. Ignored when blockPalette is set. This is the bulk material of the ruin before weathering swaps some of it out.") - @Ref(Reference.BLOCK) - private String block = "minecraft:cobblestone"; - - @Desc("A noise-driven palette for the primary block. When set this overrides the single block, letting the structure mix materials by noise. Palette wins over the block string via IrisProceduralBlocks.resolve.") - private PaletteSpec blockPalette; - - @Desc("The overall silhouette of the ruin: PILLAR (broken column), WALL (gapped segment), ARCH (two legs plus a curved span), FLOOR_SLAB (foundation patch), or RUBBLE (low scattered pile).") - private RuinForm form = RuinForm.PILLAR; - - @MinNumber(1) - @Desc("Minimum structure height in blocks (PILLAR/WALL/ARCH height, slab thickness for FLOOR_SLAB, mound height for RUBBLE). Variants interpolate between this and heightMax.") - private int heightMin = 4; - - @MinNumber(1) - @Desc("Maximum structure height in blocks. Variants interpolate between heightMin and this so taller and shorter ruins coexist.") - private int heightMax = 9; - - @MinNumber(1) - @Desc("Minimum footprint width (X axis) in blocks: column/leg thickness for PILLAR/ARCH, wall thickness for WALL, slab width for FLOOR_SLAB, blob width for RUBBLE.") - private int widthMin = 1; - - @MinNumber(1) - @Desc("Maximum footprint width (X axis) in blocks. Variants interpolate between widthMin and this.") - private int widthMax = 3; - - @MinNumber(1) - @Desc("Minimum footprint length (Z axis) in blocks: wall run length, arch leg spacing, slab length, rubble blob length.") - private int lengthMin = 3; - - @MinNumber(1) - @Desc("Maximum footprint length (Z axis) in blocks. Variants interpolate between lengthMin and this.") - private int lengthMax = 7; - - @Desc("A palette of weathered variants (mossy/cracked block ids) blended over the structure by noise. When set this drives weathering; otherwise weatheredBlock is used.") - private PaletteSpec weatheringPalette; - - @Desc("A single weathered block id used when weatheringPalette is not set, e.g. minecraft:mossy_cobblestone. Applied to a noise-selected fraction of the structure, biased toward the lower rows.") - @Ref(Reference.BLOCK) - private String weatheredBlock = "minecraft:mossy_cobblestone"; - - @MinNumber(0) - @MaxNumber(1) - @Desc("How much of the structure is replaced by weathered blocks (0 none, 1 nearly all). The replacement mask is value-noise driven and weighted so lower rows weather more than upper rows, mimicking moss climbing from the ground.") - private double mossiness = 0.45; - - @MinNumber(0) - @MaxNumber(8) - @Desc("The scale of the weathering noise. Higher values produce smaller, busier moss/crack patches; lower values produce broad continuous weathered zones.") - private double weatheringScale = 1.0; - - @MinNumber(0) - @MaxNumber(1) - @Desc("How crumbled the ruin is (0 intact, 1 mostly gone). Blocks whose value-noise falls below this threshold are deleted, so the shape reads as collapsed. Structural integrity is preserved: the bottom row and core legs are never eroded away.") - private double erosion = 0.25; - - @MinNumber(0) - @MaxNumber(8) - @Desc("The scale of the erosion noise. Higher values knock out small speckled holes; lower values carve larger missing chunks out of the silhouette.") - private double erosionScale = 1.5; - - @MinNumber(0) - @MaxNumber(1) - @Desc("How far the structure extends below the surface as a fraction of its height (0 sits fully on top, 1 sinks it a full height into the ground). The buried rows live at negative y so the ruin reads as settled and partly swallowed by the terrain.") - private double buriedFraction = 0.2; - - @MinItems(1) - @Desc("Accent decorators applied after the ruin is built and eroded (moss carpets and lanterns on broken tops, vines and lichen on the faces, rubble and growth scattered around the base).") - private List accents = List.of(); - - public Ruin() { - } - - public String name() { - return name; - } - - public double chance() { - return chance; - } - - public int density() { - return density; - } - - public int variants() { - return variants; - } - - public long seed() { - return seed; - } - - public ObjectPlaceMode mode() { - return mode == null ? ObjectPlaceMode.MIN_HEIGHT : mode; - } - - public ObjectRotation rotation() { - return rotation; - } - - public ObjectLimit clamp() { - return clamp; - } - - public CarvingMode carvingSupport() { - return carvingSupport == null ? CarvingMode.SURFACE_ONLY : carvingSupport; - } - - public boolean underwater() { - return underwater; - } - - public ObjectTranslate translate() { - return translate; - } - - /** Empty where the pack sets none. */ - public Optional stiltSettings() { - return Optional.ofNullable(stiltSettings); - } - - /** Empty where the pack sets none. */ - public Optional vacuumSettings() { - return Optional.ofNullable(vacuumSettings); - } - - public String block() { - return block; - } - - /** Empty where the pack sets none. */ - public Optional blockPalette() { - return Optional.ofNullable(blockPalette); - } - - public RuinForm form() { - return form == null ? RuinForm.PILLAR : form; - } - - public int heightMin() { - return heightMin; - } - - public int heightMax() { - return heightMax; - } - - public int widthMin() { - return widthMin; - } - - public int widthMax() { - return widthMax; - } - - public int lengthMin() { - return lengthMin; - } - - public int lengthMax() { - return lengthMax; - } - - /** Empty where the pack sets none. */ - public Optional weatheringPalette() { - return Optional.ofNullable(weatheringPalette); - } - - public String weatheredBlock() { - return weatheredBlock; - } - - public double mossiness() { - return mossiness; - } - - public double weatheringScale() { - return weatheringScale; - } - - public double erosion() { - return erosion; - } - - public double erosionScale() { - return erosionScale; - } - - public double buriedFraction() { - return buriedFraction; - } - - public List accents() { - return accents == null ? List.of() : Collections.unmodifiableList(accents); - } -} diff --git a/src/main/java/art/arcane/iris/modules/objects/ruin/RuinDecorator.java b/src/main/java/art/arcane/iris/modules/objects/ruin/RuinDecorator.java deleted file mode 100644 index 5c77731b2..000000000 --- a/src/main/java/art/arcane/iris/modules/objects/ruin/RuinDecorator.java +++ /dev/null @@ -1,78 +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 . - */ - -package art.arcane.iris.modules.objects.ruin; - -import com.volmit.block.PaletteSpec; -import com.volmit.config.Desc; -import com.volmit.config.Snippet; -import com.volmit.config.MaxNumber; -import com.volmit.config.MinNumber; -import com.volmit.config.Ref; -import com.volmit.config.Reference; -import com.volmit.config.Required; - -import java.util.Optional; - -@Snippet("iris/objects/ruin-decorator") -@Desc("An accent block applied to a generated ruin after it is built and eroded, such as moss carpets on broken tops, vines on the faces, or rubble scattered around the base.") -public final class RuinDecorator { - @Desc("Where on the ruin this accent is placed. TOP sits on the highest block of each column, SURFACE clings to air-facing vertical faces, BASE_SCATTER rings the ground footprint around the base.") - private RuinDecoratorTarget target = RuinDecoratorTarget.TOP; - - @Required - @Desc("The block id to place, e.g. minecraft:moss_carpet or minecraft:vine. Ignored when palette is set.") - @Ref(Reference.BLOCK) - private String block = ""; - - @Desc("A noise-driven palette for this decorator. When set this overrides the single block, letting the accent mix blocks by noise. Resolved through IrisProceduralBlocks.resolve so the palette wins over the string.") - private PaletteSpec palette; - - @MinNumber(0) - @MaxNumber(1) - @Desc("The chance (0-1) per candidate position for this decorator to actually place. 1 covers every candidate, lower values leave sparse, patchy accents.") - private double chance = 0.4; - - @MinNumber(1) - @Desc("For the BASE_SCATTER target, how many blocks beyond the ruin footprint the scatter ring extends outward in each direction. Higher values fling rubble and growth further from the structure.") - private int scatterRadius = 2; - - public RuinDecorator() { - } - - public RuinDecoratorTarget target() { - return target == null ? RuinDecoratorTarget.TOP : target; - } - - public String block() { - return block; - } - - /** Empty where the pack sets none. */ - public Optional palette() { - return Optional.ofNullable(palette); - } - - public double chance() { - return chance; - } - - public int scatterRadius() { - return scatterRadius; - } -} diff --git a/src/main/java/art/arcane/iris/modules/objects/ruin/RuinForm.java b/src/main/java/art/arcane/iris/modules/objects/ruin/RuinForm.java deleted file mode 100644 index 9b469e02f..000000000 --- a/src/main/java/art/arcane/iris/modules/objects/ruin/RuinForm.java +++ /dev/null @@ -1,35 +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 . - */ - -package art.arcane.iris.modules.objects.ruin; - -import com.volmit.config.Desc; - -@Desc("The overall silhouette of a procedural ruin. Each form rasterizes a different crumbling man-made shape from the same size, weathering, and erosion settings.") -public enum RuinForm { - @Desc("A broken vertical column. A square trunk (widthMin..widthMax footprint) rises to a randomized height then snaps off with a jagged crown, leaving a toppled stub. Use for ancient pillars and obelisk stumps.") - PILLAR, - @Desc("A standing wall segment. A flat slab spanning lengthMin..lengthMax long and heightMin..heightMax tall, thickness widthMin..widthMax, punched through with noise-driven gaps and a ragged top edge. Use for collapsed building sides and fortifications.") - WALL, - @Desc("A freestanding arch. Two legs spaced by lengthMin..lengthMax joined at the top by a rasterized semicircular span (the lintel), so the structure literally arches. Use for gateways, aqueduct bays, and ruined doorways.") - ARCH, - @Desc("A flat foundation patch. A single (or few) block-thick slab covering a widthMin..lengthMax footprint at ground level, heavily eroded into an irregular outline. Use for floor remnants, plazas, and building foundations.") - FLOOR_SLAB, - @Desc("A low scattered debris pile. A noise blob of partial blocks mounded near the ground, tallest at the center and thinning toward the edges. Use for collapsed-structure rubble and scree.") - RUBBLE -} diff --git a/src/main/java/art/arcane/iris/modules/objects/tree/Tree.java b/src/main/java/art/arcane/iris/modules/objects/tree/Tree.java deleted file mode 100644 index 49d18a983..000000000 --- a/src/main/java/art/arcane/iris/modules/objects/tree/Tree.java +++ /dev/null @@ -1,511 +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 . - */ - -package art.arcane.iris.modules.objects.tree; - -import art.arcane.iris.builtin.anchor.ObjectPlaceMode; -import art.arcane.iris.builtin.carve.CarvingMode; -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 com.volmit.block.PaletteSpec; -import com.volmit.config.Desc; -import com.volmit.config.MaxNumber; -import com.volmit.config.MinItems; -import com.volmit.config.MinNumber; -import com.volmit.config.Ref; -import com.volmit.config.Reference; -import com.volmit.config.Required; -import com.volmit.config.Snippet; - -import java.util.Collections; -import java.util.List; -import java.util.Optional; - -@Snippet("iris/objects/procedural-tree") -@Desc("A single procedurally generated tree. Iris bakes a pool of deterministic variants from these settings and scatters them at world-gen time, exactly like an object placement but generated from scratch instead of loaded from an iob file.") -public final class Tree { - @Desc("A human readable name used in logs and as the variant load key.") - private String name = "procedural-tree"; - - @MinNumber(0) - @MaxNumber(1) - @Desc("The chance per chunk for this tree to attempt placement. Use density for multiple per chunk.") - private double chance = 0.4; - - @MinNumber(1) - @Desc("If the chance check passes, attempt this many placements in the chunk.") - private int density = 1; - - @MinNumber(1) - @MaxNumber(64) - @Desc("How many distinct variants to pre-bake for this tree. Higher means more variety at a small memory cost.") - private int variants = 8; - - @Desc("The base seed for deterministic generation. The same seed and settings always bake the same variants.") - private long seed = 1337; - - @Desc("If true (default) leaves are placed with vanilla distance-from-wood values and persistent=false so leaf decay behaves naturally and the tree reads as plausible. If false, leaves are forced persistent and never decay (a raw object dump).") - private boolean plausible = true; - - @Desc("The placement mode used to anchor the tree to the terrain.") - private ObjectPlaceMode mode = ObjectPlaceMode.CENTER_HEIGHT; - - @Desc("Rotate this tree's placement.") - private ObjectRotation rotation = new ObjectRotation(); - - @Desc("Limit the max or min height of placement.") - private ObjectLimit clamp = new ObjectLimit(); - - @Desc("Whether this tree may place on the terrain surface, under carvings, or both.") - private CarvingMode carvingSupport = CarvingMode.SURFACE_ONLY; - - @Desc("If true, the tree anchors on the terrain height ignoring the water surface.") - private boolean underwater = false; - - @Desc("Translate (offset) this placement along each axis; for example set a negative y to sink it into the ground.") - private ObjectTranslate translate = new ObjectTranslate(); - - @Desc("Settings for the stilt place modes (STILT, MIN_STILT, FAST_STILT, CENTER_STILT, ERODE_STILT, ORGANIC_STILT).") - private StiltSettings stiltSettings; - - @Desc("Settings for the vacuum place modes (VACUUM, VACUUM_HIGH, VACUUM_FAST, VACUUM_ORGANIC).") - private VacuumSettings vacuumSettings; - - @Required - @Desc("The trunk (log) block, e.g. minecraft:oak_log. Ignored when trunkPalette is set.") - @Ref(Reference.BLOCK) - private String trunk = "minecraft:oak_log"; - - @Desc("A noise-driven palette for the trunk. When set this overrides the single trunk block, letting the trunk mix blocks by noise.") - private PaletteSpec trunkPalette; - - @Required - @Desc("The leaf block, e.g. minecraft:oak_leaves. Ignored when leavesPalette is set.") - @Ref(Reference.BLOCK) - private String leaves = "minecraft:oak_leaves"; - - @Desc("A noise-driven palette for the leaves. When set this overrides the single leaf block, letting the canopy mix leaf (or other) blocks by noise. Only blocks that are actually leaves get vanilla decay distances.") - private PaletteSpec leavesPalette; - - @Desc("The named canopy profile that drives default crown radii and shape.") - private TreeProfile profile = TreeProfile.OAK; - - @MinNumber(1) - @Desc("Minimum trunk height in blocks.") - private int heightMin = 8; - - @MinNumber(1) - @Desc("Maximum trunk height in blocks.") - private int heightMax = 12; - - @MinNumber(1) - @Desc("Base trunk width in blocks. 1 is a single column, 2 is a 2x2 trunk, etc.") - private int trunkWidth = 1; - - @Desc("The function used to shape trunk width over height.") - private TreeFunction trunkShape = TreeFunction.CONSTANT; - - @Desc("Width multiplier at the base for the LINEAR trunk shape.") - private double shapeStart = 1; - - @Desc("Width multiplier at the top for the LINEAR trunk shape.") - private double shapeEnd = 1; - - @Desc("Steepness for the SIGMOID trunk shape.") - private double shapeSteepness = 5; - - @Desc("Base for the LOG trunk shape.") - private double shapeBase = 2.718281828; - - @Desc("Period for the SINE trunk shape.") - private double shapePeriod = 1; - - @Desc("Amplitude for the SINE trunk shape.") - private double shapeAmplitude = 0.2; - - @Desc("Pinch position (0-1) for the PARABOLIC trunk shape.") - private double shapePeakOffset = 0.5; - - @Desc("Minimum width fraction at the waist for the PARABOLIC trunk shape.") - private double shapeFloor = 0.5; - - @Desc("Compass direction in degrees the trunk leans toward.") - private double leanAzimuth = 0; - - @Desc("How far the trunk leans, in degrees from vertical. 0 is perfectly upright.") - private double leanAngle = 0; - - @Desc("How the lean accumulates over height.") - private TreeFunction trunkCurve = TreeFunction.LINEAR; - - @Desc("Steepness for the SIGMOID trunk curve.") - private double curveSteepness = 8; - - @Desc("How the lean azimuth itself changes over height (for spiraling or wandering trunks).") - private TreeAzimuthMode leanAzimuthMode = TreeAzimuthMode.CONSTANT; - - @Desc("Azimuth at the base for the LINEAR azimuth mode.") - private double azimuthStart = 0; - - @Desc("Azimuth at the top for the LINEAR azimuth mode.") - private double azimuthEnd = 0; - - @Desc("Number of full turns for the SPIRAL azimuth mode.") - private double azimuthTurns = 1; - - @Desc("Amplitude for the SINE azimuth mode.") - private double azimuthAmplitude = 90; - - @Desc("Period for the SINE azimuth mode.") - private double azimuthPeriod = 1; - - @Desc("Offset for the SINE azimuth mode.") - private double azimuthOffset = 0; - - @Desc("Scale for the NOISE azimuth mode.") - private double azimuthScale = 1; - - @MinNumber(1) - @Desc("Number of branches per whorl ring for the WHORL branch azimuth mode.") - private int azimuthWhorlCount = 5; - - @Desc("Optional accent leaf block scattered through the canopy (blossoms, shroomlight).") - @Ref(Reference.BLOCK) - private String secondaryLeaves; - - @MinNumber(0) - @MaxNumber(1) - @Desc("The fraction of leaves replaced by the secondary leaf block(s).") - private double secondaryLeafFraction = 0.35; - - @MinItems(1) - @Desc("Optional weighted set of accent leaf blocks. When set this overrides the single secondaryLeaves block.") - private List weightedSecondaryLeaves = List.of(); - - @Desc("A noise-driven palette for the secondary (accent) leaves. When set this overrides both secondaryLeaves and weightedSecondaryLeaves.") - private PaletteSpec secondaryLeavesPalette; - - @Desc("Optional secondary trunk block used over a height band (for color-banded trunks). Ignored when secondaryTrunkPalette is set.") - @Ref(Reference.BLOCK) - private String secondaryTrunk; - - @Desc("A noise-driven palette for the secondary trunk band. When set this overrides the single secondaryTrunk block.") - private PaletteSpec secondaryTrunkPalette; - - @MinNumber(0) - @MaxNumber(1) - @Desc("The normalized height where the secondary trunk band starts.") - private double secondaryTrunkStart = 0.5; - - @MinNumber(0) - @MaxNumber(1) - @Desc("The normalized height where the secondary trunk band ends.") - private double secondaryTrunkEnd = 1; - - @Desc("If true, a root system extends below (and around) the base so the tree connects to the ground on uneven terrain.") - private boolean roots = true; - - @Desc("How the root system is built when roots is true.") - private TreeRootStyle rootStyle = TreeRootStyle.BUTTRESS; - - @MinNumber(0) - @Desc("Override the root depth/reach in blocks. 0 means auto (scales with tree height).") - private int rootDepth = 0; - - @MinNumber(0) - @Desc("Override the root flare radius in blocks. 0 means auto.") - private double rootFlare = 0; - - @MinNumber(1) - @MaxNumber(6) - @Desc("How many separate trunks the tree splits into above forkHeight. 1 is a single trunk.") - private int trunkForks = 1; - - @MinNumber(0) - @MaxNumber(1) - @Desc("The normalized height where the trunk splits into forks.") - private double forkHeight = 0.5; - - @Desc("The outward lean angle in degrees of each fork.") - private double forkAngle = 25; - - @Desc("The leaf crown configuration.") - private TreeCanopy canopy = new TreeCanopy(); - - @MinItems(1) - @Desc("Accent decorators applied after the tree is built (fruit, vines, snow, glow).") - private List decorators = List.of(); - - public Tree() { - } - - /** The key the variant {@code index} of the tree named {@code name} is loaded under, which placement markers and the sapling tree list name. */ - public static String variantLoadKey(String name, int index) { - if (index < 0) { - throw new IllegalArgumentException("index must not be negative"); - } - return "procedural/tree/" + name + "#" + index; - } - - public String name() { - return name; - } - - public double chance() { - return chance; - } - - public int density() { - return density; - } - - public int variants() { - return variants; - } - - public long seed() { - return seed; - } - - public boolean plausible() { - return plausible; - } - - public ObjectPlaceMode mode() { - return mode; - } - - public ObjectRotation rotation() { - return rotation; - } - - public ObjectLimit clamp() { - return clamp; - } - - public CarvingMode carvingSupport() { - return carvingSupport; - } - - public boolean underwater() { - return underwater; - } - - public ObjectTranslate translate() { - return translate; - } - - public Optional stiltSettings() { - return Optional.ofNullable(stiltSettings); - } - - public Optional vacuumSettings() { - return Optional.ofNullable(vacuumSettings); - } - - public String trunk() { - return trunk; - } - - public Optional trunkPalette() { - return Optional.ofNullable(trunkPalette); - } - - public String leaves() { - return leaves; - } - - public Optional leavesPalette() { - return Optional.ofNullable(leavesPalette); - } - - public TreeProfile profile() { - return profile; - } - - public int heightMin() { - return heightMin; - } - - public int heightMax() { - return heightMax; - } - - public int trunkWidth() { - return trunkWidth; - } - - public TreeFunction trunkShape() { - return trunkShape; - } - - public double shapeStart() { - return shapeStart; - } - - public double shapeEnd() { - return shapeEnd; - } - - public double shapeSteepness() { - return shapeSteepness; - } - - public double shapeBase() { - return shapeBase; - } - - public double shapePeriod() { - return shapePeriod; - } - - public double shapeAmplitude() { - return shapeAmplitude; - } - - public double shapePeakOffset() { - return shapePeakOffset; - } - - public double shapeFloor() { - return shapeFloor; - } - - public double leanAzimuth() { - return leanAzimuth; - } - - public double leanAngle() { - return leanAngle; - } - - public TreeFunction trunkCurve() { - return trunkCurve; - } - - public double curveSteepness() { - return curveSteepness; - } - - public TreeAzimuthMode leanAzimuthMode() { - return leanAzimuthMode; - } - - public double azimuthStart() { - return azimuthStart; - } - - public double azimuthEnd() { - return azimuthEnd; - } - - public double azimuthTurns() { - return azimuthTurns; - } - - public double azimuthAmplitude() { - return azimuthAmplitude; - } - - public double azimuthPeriod() { - return azimuthPeriod; - } - - public double azimuthOffset() { - return azimuthOffset; - } - - public double azimuthScale() { - return azimuthScale; - } - - public int azimuthWhorlCount() { - return azimuthWhorlCount; - } - - public Optional secondaryLeaves() { - return Optional.ofNullable(secondaryLeaves); - } - - public double secondaryLeafFraction() { - return secondaryLeafFraction; - } - - public List weightedSecondaryLeaves() { - return weightedSecondaryLeaves == null ? List.of() : Collections.unmodifiableList(weightedSecondaryLeaves); - } - - public Optional secondaryLeavesPalette() { - return Optional.ofNullable(secondaryLeavesPalette); - } - - public Optional secondaryTrunk() { - return Optional.ofNullable(secondaryTrunk); - } - - public Optional secondaryTrunkPalette() { - return Optional.ofNullable(secondaryTrunkPalette); - } - - public double secondaryTrunkStart() { - return secondaryTrunkStart; - } - - public double secondaryTrunkEnd() { - return secondaryTrunkEnd; - } - - public boolean roots() { - return roots; - } - - public TreeRootStyle rootStyle() { - return rootStyle; - } - - public int rootDepth() { - return rootDepth; - } - - public double rootFlare() { - return rootFlare; - } - - public int trunkForks() { - return trunkForks; - } - - public double forkHeight() { - return forkHeight; - } - - public double forkAngle() { - return forkAngle; - } - - public TreeCanopy canopy() { - return canopy; - } - - public List decorators() { - return decorators == null ? List.of() : Collections.unmodifiableList(decorators); - } -} diff --git a/src/main/java/art/arcane/iris/modules/objects/tree/TreeAzimuthMode.java b/src/main/java/art/arcane/iris/modules/objects/tree/TreeAzimuthMode.java deleted file mode 100644 index 92ffc4a19..000000000 --- a/src/main/java/art/arcane/iris/modules/objects/tree/TreeAzimuthMode.java +++ /dev/null @@ -1,45 +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 . - */ - -package art.arcane.iris.modules.objects.tree; - -import com.volmit.config.Desc; - -@Desc("Controls the compass direction (azimuth) of trunk lean as it rises, or the direction each branch is thrown.") -public enum TreeAzimuthMode { - @Desc("A single fixed azimuth.") - CONSTANT, - @Desc("Azimuth ramps straight from start to end with height.") - LINEAR, - @Desc("Azimuth winds around the trunk a number of turns (corkscrew).") - SPIRAL, - @Desc("Azimuth oscillates with a sine wave.") - SINE, - @Desc("Azimuth wanders using deterministic noise.") - NOISE, - @Desc("Each branch picks a uniformly random azimuth (falls back to constant for trunk lean).") - RANDOM, - @Desc("Phyllotaxis: each successive branch is offset by the 137.5 degree golden angle for the most natural spiral packing (branches).") - GOLDEN_ANGLE, - @Desc("Each successive branch is thrown to the opposite side (180 degrees apart).") - ALTERNATING, - @Desc("Branches are grouped into evenly spaced whorls of azimuthWhorlCount around each ring.") - WHORL, - @Desc("Azimuth zigzags by +/- amplitude on alternating branches.") - ZIGZAG -} diff --git a/src/main/java/art/arcane/iris/modules/objects/tree/TreeBranchProbability.java b/src/main/java/art/arcane/iris/modules/objects/tree/TreeBranchProbability.java deleted file mode 100644 index d0b680898..000000000 --- a/src/main/java/art/arcane/iris/modules/objects/tree/TreeBranchProbability.java +++ /dev/null @@ -1,47 +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 . - */ - -package art.arcane.iris.modules.objects.tree; - -import com.volmit.config.Desc; - -@Desc("Controls how the chance of spawning a branch varies with trunk height (0 at the base, 1 at the top).") -public enum TreeBranchProbability { - @Desc("Same branch chance at every height.") - CONSTANT, - @Desc("Ramps straight from base chance to crown chance.") - LINEAR, - @Desc("S-curve that switches on around a midpoint height.") - SIGMOID, - @Desc("Chance rises with height raised to an exponent, clustering branches near the crown.") - TOP_HEAVY, - @Desc("Bell curve peaking in a height band.") - GAUSSIAN, - @Desc("Irregular organic branching from deterministic noise.") - NOISE, - @Desc("Chance falls with height (1-t)^exponent, clustering branches near the base.") - BOTTOM_HEAVY, - @Desc("Regular whorl rings of branches at evenly spaced heights (periods controls count).") - PERIODIC, - @Desc("Branches only within a height window around mean +/- std.") - BAND, - @Desc("Inverse of GAUSSIAN: branches avoid the mean band and favor base and crown.") - INVERSE_GAUSSIAN, - @Desc("Exponential decay from the base upward (constant * e^-exponent*t).") - EXPONENTIAL_DECAY -} diff --git a/src/main/java/art/arcane/iris/modules/objects/tree/TreeBranches.java b/src/main/java/art/arcane/iris/modules/objects/tree/TreeBranches.java deleted file mode 100644 index 62ff4bf6b..000000000 --- a/src/main/java/art/arcane/iris/modules/objects/tree/TreeBranches.java +++ /dev/null @@ -1,237 +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 . - */ - -package art.arcane.iris.modules.objects.tree; - -import com.volmit.config.Desc; -import com.volmit.config.Snippet; -import com.volmit.config.MaxNumber; -import com.volmit.config.MinNumber; - -import java.util.Optional; - -@Snippet("iris/objects/tree-branches") -@Desc("A branch system that throws limbs out of the trunk and places a leaf ball at each tip. When present, branches drive the canopy and only the topmost crown disc of the profile is still placed.") -public final class TreeBranches { - @Desc("How branch spawn chance varies over trunk height.") - private TreeBranchProbability probabilityFunction = TreeBranchProbability.TOP_HEAVY; - - @MinNumber(0) - @Desc("Branch chance for the CONSTANT probability function.") - private double probabilityConstant = 0.5; - - @MinNumber(0) - @Desc("Branch chance at the base for the LINEAR probability function.") - private double probabilityBase = 0; - - @MinNumber(0) - @Desc("Branch chance at the crown for the LINEAR probability function.") - private double probabilityCrown = 1; - - @Desc("Steepness for the SIGMOID probability function.") - private double probabilitySteepness = 10; - - @Desc("Midpoint height (0-1) for the SIGMOID probability function.") - private double probabilityMidpoint = 0.7; - - @Desc("Exponent for the TOP_HEAVY probability function.") - private double probabilityExponent = 2; - - @Desc("Mean height (0-1) for the GAUSSIAN probability function.") - private double probabilityMean = 0.7; - - @Desc("Standard deviation for the GAUSSIAN probability function.") - private double probabilityStd = 0.15; - - @Desc("Noise scale for the NOISE probability function.") - private double probabilityScale = 1; - - @MinNumber(0) - @Desc("Number of whorl rings over the trunk height for the PERIODIC probability function.") - private double probabilityPeriods = 5; - - @Desc("How branch length varies over trunk height.") - private TreeFunction lengthFunction = TreeFunction.LINEAR; - - @MinNumber(0) - @Desc("Branch length at the base for the LINEAR length function.") - private double lengthBase = 1; - - @MinNumber(0) - @Desc("Branch length at the crown for the LINEAR length function.") - private double lengthCrown = 4; - - @MinNumber(0) - @Desc("Branch length for the CONSTANT length function.") - private double lengthConstant = 3; - - @MinNumber(0) - @Desc("Maximum branch length for the SIGMOID, LOG and PARABOLIC length functions.") - private double lengthMax = 4; - - @Desc("Steepness for the SIGMOID length function.") - private double lengthSteepness = 5; - - @Desc("How the compass direction of each branch is chosen.") - private TreeAzimuthMode azimuthMode = TreeAzimuthMode.RANDOM; - - @Desc("Fixed azimuth in degrees when azimuthMode is CONSTANT.") - private double azimuth = 0; - - @Desc("Elevation angle in degrees from horizontal. 0 is flat, positive points up, negative droops down.") - private double elevation = 0; - - @MinNumber(0) - @MaxNumber(1) - @Desc("How much each branch sags/droops along its length (catenary). 0 is a straight branch; higher values arc the branch and its tip downward.") - private double sag = 0; - - @MinNumber(0) - @MaxNumber(6) - @Desc("How many recursive levels of sub-branches to grow. 0 is none, 1 is a single level, 2+ produces fractal branching.") - private int branchDepth = 1; - - @Desc("If true, branches are clamped to never droop below horizontal (useful for upright species).") - private boolean leafStartUp = false; - - @MinNumber(0) - @Desc("Leaf ball radius placed at each branch tip.") - private int clusterRadius = 2; - - @Desc("How the branch tip leaf cluster fills.") - private TreeLeafMode clusterMode = TreeLeafMode.TRIMMED; - - @MinNumber(0) - @Desc("Fill density for the branch tip leaf cluster when clusterMode is density or noise.") - private double clusterDensity = 0.85; - - @Desc("Optional one level of recursive sub-branches sprouting from each branch tip.") - private TreeSubBranches subBranches = null; - - public TreeBranches() { - } - - public TreeBranchProbability probabilityFunction() { - return probabilityFunction == null ? TreeBranchProbability.TOP_HEAVY : probabilityFunction; - } - - public double probabilityConstant() { - return probabilityConstant; - } - - public double probabilityBase() { - return probabilityBase; - } - - public double probabilityCrown() { - return probabilityCrown; - } - - public double probabilitySteepness() { - return probabilitySteepness; - } - - public double probabilityMidpoint() { - return probabilityMidpoint; - } - - public double probabilityExponent() { - return probabilityExponent; - } - - public double probabilityMean() { - return probabilityMean; - } - - public double probabilityStd() { - return probabilityStd; - } - - public double probabilityScale() { - return probabilityScale; - } - - public double probabilityPeriods() { - return probabilityPeriods; - } - - public TreeFunction lengthFunction() { - return lengthFunction == null ? TreeFunction.LINEAR : lengthFunction; - } - - public double lengthBase() { - return lengthBase; - } - - public double lengthCrown() { - return lengthCrown; - } - - public double lengthConstant() { - return lengthConstant; - } - - public double lengthMax() { - return lengthMax; - } - - public double lengthSteepness() { - return lengthSteepness; - } - - public TreeAzimuthMode azimuthMode() { - return azimuthMode == null ? TreeAzimuthMode.RANDOM : azimuthMode; - } - - public double azimuth() { - return azimuth; - } - - public double elevation() { - return elevation; - } - - public double sag() { - return sag; - } - - public int branchDepth() { - return branchDepth; - } - - public boolean leafStartUp() { - return leafStartUp; - } - - public int clusterRadius() { - return clusterRadius; - } - - public TreeLeafMode clusterMode() { - return clusterMode == null ? TreeLeafMode.TRIMMED : clusterMode; - } - - public double clusterDensity() { - return clusterDensity; - } - - /** Empty where the pack sets none. */ - public Optional subBranches() { - return Optional.ofNullable(subBranches); - } -} diff --git a/src/main/java/art/arcane/iris/modules/objects/tree/TreeCanopy.java b/src/main/java/art/arcane/iris/modules/objects/tree/TreeCanopy.java deleted file mode 100644 index 2d8fc1e7e..000000000 --- a/src/main/java/art/arcane/iris/modules/objects/tree/TreeCanopy.java +++ /dev/null @@ -1,102 +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 . - */ - -package art.arcane.iris.modules.objects.tree; - -import com.volmit.config.Desc; -import com.volmit.config.Snippet; -import com.volmit.config.MaxNumber; -import com.volmit.config.MinItems; -import com.volmit.config.MinNumber; - -import java.util.Collections; -import java.util.List; -import java.util.Optional; - -@Snippet("iris/objects/tree-canopy") -@Desc("The leaf crown of a procedural tree. Built from stacked dome-shaped discs (driven by the profile or by explicit layers) and optionally a branch system.") -public final class TreeCanopy { - @MinNumber(0) - @MaxNumber(180) - @Desc("Elevation angle in degrees from vertical for each leaf dome. 90 is a flat disc, below 90 domes downward into a sphere, above 90 flares outward into an umbrella.") - private double startAngle = 90; - - @MinNumber(0) - @MaxNumber(1) - @Desc("Vertical scale of the canopy volume. Lower values flatten the crown.") - private double squish = 1; - - @Desc("How leaves fill each canopy disc.") - private TreeLeafMode mode = TreeLeafMode.TRIMMED; - - @MinNumber(0) - @MaxNumber(1) - @Desc("Fill probability used by the density and noise leaf modes.") - private double leafDensity = 0.85; - - @MinNumber(0.1) - @Desc("Horizontal X stretch of the crown for elliptical or wind-blown shapes. 1 is circular.") - private double crownStretchX = 1; - - @MinNumber(0.1) - @Desc("Horizontal Z stretch of the crown for elliptical or wind-blown shapes. 1 is circular.") - private double crownStretchZ = 1; - - @MinItems(1) - @Desc("Optional explicit crown discs. When provided these replace the profile-driven layers and let you sculpt the silhouette by hand.") - private List layers = List.of(); - - @Desc("Optional branch system. When present, branches build most of the canopy and only the topmost profile disc is still placed as a crown.") - private TreeBranches branches = null; - - public TreeCanopy() { - } - - public double startAngle() { - return startAngle; - } - - public double squish() { - return squish; - } - - public TreeLeafMode mode() { - return mode == null ? TreeLeafMode.TRIMMED : mode; - } - - public double leafDensity() { - return leafDensity; - } - - public double crownStretchX() { - return crownStretchX; - } - - public double crownStretchZ() { - return crownStretchZ; - } - - public List layers() { - return layers == null ? List.of() : Collections.unmodifiableList(layers); - } - - /** Empty where the pack sets none. */ - public Optional branches() { - return Optional.ofNullable(branches); - } -} diff --git a/src/main/java/art/arcane/iris/modules/objects/tree/TreeDecorator.java b/src/main/java/art/arcane/iris/modules/objects/tree/TreeDecorator.java deleted file mode 100644 index 926a23ad6..000000000 --- a/src/main/java/art/arcane/iris/modules/objects/tree/TreeDecorator.java +++ /dev/null @@ -1,85 +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 . - */ - -package art.arcane.iris.modules.objects.tree; - -import com.volmit.block.PaletteSpec; -import com.volmit.config.Desc; -import com.volmit.config.Snippet; -import com.volmit.config.MaxNumber; -import com.volmit.config.MinNumber; -import com.volmit.config.Ref; -import com.volmit.config.Reference; -import com.volmit.config.Required; - -import java.util.Optional; - -@Snippet("iris/objects/tree-decorator") -@Desc("An accent block applied to a generated tree such as fruit on branch tips, vines on the trunk, snow on the crown, or a glowing underside.") -public final class TreeDecorator { - @Desc("Where this decorator is placed on the tree.") - private TreeDecoratorTarget target = TreeDecoratorTarget.BRANCH_TIP; - - @Required - @Desc("The block id to place, e.g. minecraft:magma_block. Ignored when palette is set.") - @Ref(Reference.BLOCK) - private String block = ""; - - @Desc("A noise-driven palette for this decorator. When set this overrides the single block.") - private PaletteSpec palette; - - @MinNumber(0) - @MaxNumber(1) - @Desc("The chance per candidate position for this decorator to place.") - private double chance = 0.5; - - @MinNumber(1) - @Desc("Maximum strand length downward for the CANOPY_HANG target (random 1..length per column).") - private int length = 1; - - @Desc("If true the block's facing is oriented away from the trunk (for trunk-mounted fences/gates/banners).") - private boolean axisAware = false; - - public TreeDecorator() { - } - - public TreeDecoratorTarget target() { - return target == null ? TreeDecoratorTarget.BRANCH_TIP : target; - } - - public String block() { - return block; - } - - /** Empty where the pack sets none. */ - public Optional palette() { - return Optional.ofNullable(palette); - } - - public double chance() { - return chance; - } - - public int length() { - return length; - } - - public boolean axisAware() { - return axisAware; - } -} diff --git a/src/main/java/art/arcane/iris/modules/objects/tree/TreeDecoratorTarget.java b/src/main/java/art/arcane/iris/modules/objects/tree/TreeDecoratorTarget.java deleted file mode 100644 index 87137f3ec..000000000 --- a/src/main/java/art/arcane/iris/modules/objects/tree/TreeDecoratorTarget.java +++ /dev/null @@ -1,45 +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 . - */ - -package art.arcane.iris.modules.objects.tree; - -import com.volmit.config.Desc; - -@Desc("Where a tree decorator block is placed.") -public enum TreeDecoratorTarget { - @Desc("At the tip of each generated branch (vines, fruit, lanterns).") - BRANCH_TIP, - @Desc("On air-facing sides of trunk and branch blocks (vines, moss).") - TRUNK_SURFACE, - @Desc("On top of the highest block in each column (snow, sculk).") - CANOPY_TOP, - @Desc("One block below the lowest leaf in each column (glowing underside).") - CANOPY_BOTTOM, - @Desc("Around the y=0 ring at the base of the trunk (roots, mushrooms).") - TRUNK_BASE, - @Desc("On air-facing sides of leaf blocks (berries, lights nestled in the foliage).") - LEAF_SURFACE, - @Desc("Hanging strands of up to 'length' blocks below the lowest leaf in each column (vines, icicles).") - CANOPY_HANG, - @Desc("On the top face of trunk and branch blocks (moss, snow on limbs).") - BRANCH_SURFACE, - @Desc("One block above the very top of the trunk (nest, beehive, beacon).") - TRUNK_TOP, - @Desc("Scattered across the ground footprint around the base, wider than the trunk-base ring.") - GROUND_SCATTER -} diff --git a/src/main/java/art/arcane/iris/modules/objects/tree/TreeFunction.java b/src/main/java/art/arcane/iris/modules/objects/tree/TreeFunction.java deleted file mode 100644 index 7dd34331a..000000000 --- a/src/main/java/art/arcane/iris/modules/objects/tree/TreeFunction.java +++ /dev/null @@ -1,47 +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 . - */ - -package art.arcane.iris.modules.objects.tree; - -import com.volmit.config.Desc; - -@Desc("A shaping function evaluated over normalized height (0 at the base, 1 at the top). Used for trunk width, trunk curve and branch length.") -public enum TreeFunction { - @Desc("Same value at every height.") - CONSTANT, - @Desc("Ramps straight from start to end.") - LINEAR, - @Desc("S-curve transition controlled by steepness.") - SIGMOID, - @Desc("Logarithmic falloff controlled by base.") - LOG, - @Desc("Sine ripple controlled by period and amplitude.") - SINE, - @Desc("Parabolic pinch, narrowest at peakOffset.") - PARABOLIC, - @Desc("Geometric (exponential) interpolation from start to end.") - EXPONENTIAL, - @Desc("Square-root ease: fast change low, slow high.") - SQRT, - @Desc("Hard step that jumps from start to end at the threshold (peakOffset).") - STEP, - @Desc("Bell bulge peaking in the middle of the height range.") - BELL, - @Desc("Smoothstep ease-in-out (3t^2 - 2t^3).") - EASE_IN_OUT -} diff --git a/src/main/java/art/arcane/iris/modules/objects/tree/TreeLayer.java b/src/main/java/art/arcane/iris/modules/objects/tree/TreeLayer.java deleted file mode 100644 index 0a6e03fdc..000000000 --- a/src/main/java/art/arcane/iris/modules/objects/tree/TreeLayer.java +++ /dev/null @@ -1,45 +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 . - */ - -package art.arcane.iris.modules.objects.tree; - -import com.volmit.config.Desc; -import com.volmit.config.Snippet; -import com.volmit.config.MinNumber; - -@Snippet("iris/objects/tree-layer") -@Desc("An explicit canopy disc at a given vertical offset and radius. Define a list of these to bypass the profile and sculpt the crown by hand.") -public final class TreeLayer { - @Desc("The vertical offset of this disc, measured in blocks above the trunk base.") - private int yOffset = 0; - - @MinNumber(0.5) - @Desc("The radius of this leaf disc in blocks.") - private double radius = 2; - - public TreeLayer() { - } - - public int yOffset() { - return yOffset; - } - - public double radius() { - return radius; - } -} diff --git a/src/main/java/art/arcane/iris/modules/objects/tree/TreeLeafMode.java b/src/main/java/art/arcane/iris/modules/objects/tree/TreeLeafMode.java deleted file mode 100644 index 40bfebcc8..000000000 --- a/src/main/java/art/arcane/iris/modules/objects/tree/TreeLeafMode.java +++ /dev/null @@ -1,43 +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 . - */ - -package art.arcane.iris.modules.objects.tree; - -import com.volmit.config.Desc; - -@Desc("How leaves fill a disc or cluster.") -public enum TreeLeafMode { - @Desc("Corner-trimmed disc/sphere for a rounded silhouette.") - TRIMMED, - @Desc("Completely filled disc/sphere.") - FILLED, - @Desc("Seeded probabilistic falloff toward the edge controlled by leafDensity.") - DENSITY, - @Desc("Seeded value-noise mask controlled by leafDensity.") - NOISE, - @Desc("Only the outer shell is placed, leaving the interior hollow.") - HOLLOW, - @Desc("Quadratic radial gradient: dense at the center, thinning sharply toward the edge.") - GRADIENT, - @Desc("Coarse low-frequency noise that forms clumps and gaps of foliage.") - CLUMPED, - @Desc("Trimmed with heavy random erosion of the outer ring for a ragged, weathered look.") - TATTERED, - @Desc("Very thin scattering of leaves across the volume.") - SPARSE -} diff --git a/src/main/java/art/arcane/iris/modules/objects/tree/TreeProfile.java b/src/main/java/art/arcane/iris/modules/objects/tree/TreeProfile.java deleted file mode 100644 index d079823ff..000000000 --- a/src/main/java/art/arcane/iris/modules/objects/tree/TreeProfile.java +++ /dev/null @@ -1,53 +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 . - */ - -package art.arcane.iris.modules.objects.tree; - -import com.volmit.config.Desc; - -@Desc("Named canopy presets that drive default layer radii and shape, scaled to the tree height.") -public enum TreeProfile { - @Desc("Rounded broadleaf crown.") - OAK, - @Desc("Slim upright broadleaf crown.") - BIRCH, - @Desc("Narrow conifer cone.") - SPRUCE, - @Desc("Tall thin crown concentrated near the very top.") - JUNGLE, - @Desc("Flat shallow umbrella crown.") - ACACIA, - @Desc("Dense rounded broadleaf crown.") - DARK_OAK, - @Desc("Flat wide umbrella crown compressed into the top quarter (vanilla dark oak look).") - DARK_OAK_FLAT, - @Desc("Extra wide flat umbrella that overlaps into a continuous roofed canopy.") - DARK_OAK_FLAT_WIDE, - @Desc("Broad rounded blossom crown.") - CHERRY, - @Desc("Bare trunk with a small tuft of fronds only at the very top.") - PALM, - @Desc("Broad crown with wide drooping radii, ideal with a low startAngle to make a weeping skirt.") - WILLOW, - @Desc("Very narrow tall crown hugging the trunk (cypress / lombardy poplar).") - COLUMNAR, - @Desc("Squat, wide, low crown for shrubs and saplings.") - BUSH, - @Desc("Giant conifer cone for 2x2 mega spruce trunks.") - MEGA_SPRUCE -} diff --git a/src/main/java/art/arcane/iris/modules/objects/tree/TreeSecondaryLeaf.java b/src/main/java/art/arcane/iris/modules/objects/tree/TreeSecondaryLeaf.java deleted file mode 100644 index a11d7f0f0..000000000 --- a/src/main/java/art/arcane/iris/modules/objects/tree/TreeSecondaryLeaf.java +++ /dev/null @@ -1,50 +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 . - */ - -package art.arcane.iris.modules.objects.tree; - -import com.volmit.config.Desc; -import com.volmit.config.Snippet; -import com.volmit.config.MinNumber; -import com.volmit.config.Ref; -import com.volmit.config.Reference; -import com.volmit.config.Required; - -@Snippet("iris/objects/tree-secondary-leaf") -@Desc("A weighted accent leaf or foliage block scattered through the canopy (blossoms, shroomlight, berries).") -public final class TreeSecondaryLeaf { - @Required - @Desc("The block id to scatter, e.g. minecraft:shroomlight") - @Ref(Reference.BLOCK) - private String block = ""; - - @MinNumber(0) - @Desc("The relative weight of this block among the secondary leaves.") - private int weight = 1; - - public TreeSecondaryLeaf() { - } - - public String block() { - return block; - } - - public int weight() { - return weight; - } -} diff --git a/src/main/java/art/arcane/iris/modules/objects/tree/TreeSubBranches.java b/src/main/java/art/arcane/iris/modules/objects/tree/TreeSubBranches.java deleted file mode 100644 index f9471a229..000000000 --- a/src/main/java/art/arcane/iris/modules/objects/tree/TreeSubBranches.java +++ /dev/null @@ -1,93 +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 . - */ - -package art.arcane.iris.modules.objects.tree; - -import com.volmit.config.Desc; -import com.volmit.config.Snippet; -import com.volmit.config.MaxNumber; -import com.volmit.config.MinNumber; - -@Snippet("iris/objects/tree-sub-branches") -@Desc("One recursive level of sub-branches sprouting from each primary branch tip.") -public final class TreeSubBranches { - @MinNumber(1) - @Desc("How many sub-branches sprout from each primary branch tip.") - private int count = 1; - - @Desc("Pitch deflection in degrees applied to each sub-branch relative to its parent. Positive bends up, negative droops down. Cumulative pitch past 90 makes sub-branches point downward.") - private double pitchDelta = 0; - - @Desc("Yaw (horizontal) spread in degrees fanned between sub-branches.") - private double yawDelta = 45; - - @MinNumber(0) - @Desc("Sub-branch length as a fraction of its parent branch length.") - private double lengthScale = 0.5; - - @MinNumber(0) - @MaxNumber(1) - @Desc("How much each sub-branch sags/droops along its length (catenary).") - private double sag = 0; - - @MinNumber(0) - @Desc("Leaf ball radius placed at each sub-branch tip.") - private int clusterRadius = 1; - - @Desc("How the sub-branch tip leaf cluster fills.") - private TreeLeafMode clusterMode = TreeLeafMode.TRIMMED; - - @MinNumber(0) - @Desc("Fill density for the sub-branch leaf cluster when clusterMode is density or noise.") - private double clusterDensity = 0.85; - - public TreeSubBranches() { - } - - public int count() { - return count; - } - - public double pitchDelta() { - return pitchDelta; - } - - public double yawDelta() { - return yawDelta; - } - - public double lengthScale() { - return lengthScale; - } - - public double sag() { - return sag; - } - - public int clusterRadius() { - return clusterRadius; - } - - public TreeLeafMode clusterMode() { - return clusterMode == null ? TreeLeafMode.TRIMMED : clusterMode; - } - - public double clusterDensity() { - return clusterDensity; - } -}