diff --git a/core/src/main/java/com/volmit/iris/engine/IrisEngineMantle.java b/core/src/main/java/com/volmit/iris/engine/IrisEngineMantle.java index 71a412290..665897e71 100644 --- a/core/src/main/java/com/volmit/iris/engine/IrisEngineMantle.java +++ b/core/src/main/java/com/volmit/iris/engine/IrisEngineMantle.java @@ -24,6 +24,7 @@ import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.mantle.EngineMantle; import com.volmit.iris.engine.mantle.MantleComponent; import com.volmit.iris.engine.mantle.components.MantleCarvingComponent; +import com.volmit.iris.engine.mantle.components.MantleNoiseCarvingComponent; import com.volmit.iris.engine.mantle.components.MantleFluidBodyComponent; import com.volmit.iris.engine.mantle.components.MantleJigsawComponent; import com.volmit.iris.engine.mantle.components.MantleObjectComponent; @@ -58,6 +59,7 @@ public class IrisEngineMantle implements EngineMantle { this.mantle = new Mantle(new File(engine.getWorld().worldFolder(), "mantle"), engine.getTarget().getHeight()); components = new KMap<>(); registerComponent(new MantleCarvingComponent(this)); + registerComponent(new MantleNoiseCarvingComponent(this)); registerComponent(new MantleFluidBodyComponent(this)); jigsaw = new MantleJigsawComponent(this); registerComponent(jigsaw); diff --git a/core/src/main/java/com/volmit/iris/engine/mantle/components/MantleCarvingComponent.java b/core/src/main/java/com/volmit/iris/engine/mantle/components/MantleCarvingComponent.java index 53b0d0933..dcaf50bee 100644 --- a/core/src/main/java/com/volmit/iris/engine/mantle/components/MantleCarvingComponent.java +++ b/core/src/main/java/com/volmit/iris/engine/mantle/components/MantleCarvingComponent.java @@ -45,7 +45,6 @@ public class MantleCarvingComponent extends IrisMantleComponent { IrisRegion region = getComplex().getRegionStream().get(xxx, zzz); IrisBiome biome = getComplex().getTrueBiomeStream().get(xxx, zzz); carve(writer, rng, x, z, region, biome); - new NoiseTerrainCarver(getEngineMantle().getEngine()).carve(writer, x, z); } @ChunkCoordinates diff --git a/core/src/main/java/com/volmit/iris/engine/mantle/components/MantleNoiseCarvingComponent.java b/core/src/main/java/com/volmit/iris/engine/mantle/components/MantleNoiseCarvingComponent.java new file mode 100644 index 000000000..c7de1f724 --- /dev/null +++ b/core/src/main/java/com/volmit/iris/engine/mantle/components/MantleNoiseCarvingComponent.java @@ -0,0 +1,66 @@ +/* + * 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 com.volmit.iris.engine.mantle.components; + +import com.volmit.iris.engine.data.cache.AtomicCache; +import com.volmit.iris.engine.mantle.ComponentFlag; +import com.volmit.iris.engine.mantle.EngineMantle; +import com.volmit.iris.engine.mantle.IrisMantleComponent; +import com.volmit.iris.engine.mantle.MantleWriter; +import com.volmit.iris.util.context.ChunkContext; +import com.volmit.iris.util.mantle.flag.ReservedFlag; + +/** + * Runs noise carving last and only for the chunk being generated: it never reaches into other chunks, and sampling + * every column's biome and height is too expensive to repeat across the reach of the other components. + */ +@ComponentFlag(ReservedFlag.NOISE_CARVED) +public class MantleNoiseCarvingComponent extends IrisMantleComponent { + private static final int RUNS_AFTER_OBJECTS = 2; + + private final AtomicCache packUsesNoiseCarving = new AtomicCache<>(); + + public MantleNoiseCarvingComponent(EngineMantle engineMantle) { + super(engineMantle, ReservedFlag.NOISE_CARVED, RUNS_AFTER_OBJECTS); + } + + @Override + public void generateLayer(MantleWriter writer, int x, int z, ChunkContext context) { + if (!packUsesNoiseCarving()) { + return; + } + new NoiseTerrainCarver(getEngineMantle().getEngine()).carve(writer, x, z); + } + + @Override + public void hotload() { + super.hotload(); + packUsesNoiseCarving.reset(); + } + + private boolean packUsesNoiseCarving() { + return packUsesNoiseCarving.aquire(() -> getDimension().getAllBiomes(this::getData).stream() + .anyMatch(biome -> biome.getNoiseCarving() != null)); + } + + @Override + protected int computeRadius() { + return 0; + } +} diff --git a/core/src/main/java/com/volmit/iris/util/mantle/flag/MantleFlag.java b/core/src/main/java/com/volmit/iris/util/mantle/flag/MantleFlag.java index 77aaa8e89..f687999e9 100644 --- a/core/src/main/java/com/volmit/iris/util/mantle/flag/MantleFlag.java +++ b/core/src/main/java/com/volmit/iris/util/mantle/flag/MantleFlag.java @@ -41,6 +41,7 @@ public sealed interface MantleFlag permits CustomFlag, ReservedFlag { MantleFlag DISCOVERED = ReservedFlag.DISCOVERED; MantleFlag CUSTOM_ACTIVE = ReservedFlag.CUSTOM_ACTIVE; MantleFlag SCRIPT = ReservedFlag.SCRIPT; + MantleFlag NOISE_CARVED = ReservedFlag.NOISE_CARVED; int RESERVED_FLAGS = ReservedFlag.values().length; diff --git a/core/src/main/java/com/volmit/iris/util/mantle/flag/ReservedFlag.java b/core/src/main/java/com/volmit/iris/util/mantle/flag/ReservedFlag.java index 6fb0c97b9..4844269a4 100644 --- a/core/src/main/java/com/volmit/iris/util/mantle/flag/ReservedFlag.java +++ b/core/src/main/java/com/volmit/iris/util/mantle/flag/ReservedFlag.java @@ -17,7 +17,8 @@ public enum ReservedFlag implements MantleFlag { CUSTOM, DISCOVERED, CUSTOM_ACTIVE, - SCRIPT; + SCRIPT, + NOISE_CARVED; @Override public boolean isCustom() {