mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-29 17:23:59 +00:00
Disable mantle stages by flag or stage id in disabledComponents, warn about names that match nothing, offer pack stage ids in studio
This commit is contained in:
1 parent
2cfb6f0d93
commit
22df943860
6 files changed
+171
-47
No files matched your search
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import com.volmit.host.ResolvedStage;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* The names in a dimension's {@code disabledComponents}: the flag of one of Iris's own mantle stages
|
||||
* ({@code CARVED}) or the id of any mantle stage ({@code example:moss/veins}).
|
||||
*/
|
||||
final class DisabledComponents {
|
||||
private final Set<String> names;
|
||||
|
||||
DisabledComponents(Collection<String> names) {
|
||||
this.names = Set.copyOf(names);
|
||||
}
|
||||
|
||||
boolean disables(ResolvedStage stage) {
|
||||
return names.stream().anyMatch(name -> isNamed(stage, name));
|
||||
}
|
||||
|
||||
/** The names that match none of {@code stages}, sorted. */
|
||||
List<String> unknown(List<ResolvedStage> stages) {
|
||||
return names.stream().filter(name -> stages.stream().noneMatch(stage -> isNamed(stage, name))).sorted().toList();
|
||||
}
|
||||
|
||||
void warnAboutUnknown(List<ResolvedStage> stages) {
|
||||
for (String name : unknown(stages)) {
|
||||
IrisLogging.warn("disabledComponents names \"%s\", which is neither a mantle flag of Iris (%s) nor the id of a mantle stage of the pack; ignored.",
|
||||
name, MantleStageFlags.builtIn());
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isNamed(ResolvedStage stage, String name) {
|
||||
return stage.stage().id().toString().equals(name)
|
||||
|| MantleStageFlags.builtInFlag(stage.stage().id()).filter(flag -> flag.name().equals(name)).isPresent();
|
||||
}
|
||||
}
|
||||
@@ -33,9 +33,10 @@ import java.util.Optional;
|
||||
|
||||
/**
|
||||
* The mantle flag of each mantle stage: it marks a mantle chunk whose stage has run, and names the stage in a
|
||||
* dimension's {@code disabledComponents}. Iris's own mantle stages keep the flags their mantle components had,
|
||||
* so packs that disable {@code CARVED} keep doing so and existing worlds stay marked. Every other stage gets a
|
||||
* custom flag in resolved order, so adding or removing a pack mantle stage can renumber the stages after it.
|
||||
* dimension's {@code disabledComponents} when it is one of Iris's own. Iris's own mantle stages keep the flags
|
||||
* their mantle components had, so packs that disable {@code CARVED} keep doing so and existing worlds stay
|
||||
* marked. Every other stage gets a custom flag in resolved order, so adding or removing a pack mantle stage can
|
||||
* renumber the stages after it; those flags stay internal and a dimension names such a stage by its id.
|
||||
*/
|
||||
public final class MantleStageFlags {
|
||||
private static final List<BuiltIn> BUILT_IN = List.of(
|
||||
@@ -52,6 +53,15 @@ public final class MantleStageFlags {
|
||||
return BUILT_IN.stream().map(BuiltIn::flag).toList();
|
||||
}
|
||||
|
||||
/** The ids of the mantle stages that have no flag of their own, which a dimension names by id in {@code disabledComponents}. */
|
||||
public static List<String> packStageIds(List<ResolvedStage> stages) {
|
||||
return stages.stream()
|
||||
.map(stage -> stage.stage().id())
|
||||
.filter(id -> builtInFlag(id).isEmpty())
|
||||
.map(ResourceId::toString)
|
||||
.toList();
|
||||
}
|
||||
|
||||
/** One flag per stage, in the order of {@code stages}. */
|
||||
static List<MantleFlag> assign(List<ResolvedStage> stages) {
|
||||
List<MantleFlag> flags = new ArrayList<>(stages.size());
|
||||
@@ -71,7 +81,7 @@ public final class MantleStageFlags {
|
||||
return List.copyOf(flags);
|
||||
}
|
||||
|
||||
private static Optional<MantleFlag> builtInFlag(ResourceId stage) {
|
||||
static Optional<MantleFlag> builtInFlag(ResourceId stage) {
|
||||
return BUILT_IN.stream().filter(builtIn -> builtIn.stage().equals(stage)).map(BuiltIn::flag).findFirst();
|
||||
}
|
||||
|
||||
|
||||
@@ -29,14 +29,14 @@ import com.volmit.host.ResolvedGraph;
|
||||
import com.volmit.host.ResolvedStage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Runs one mantle stage of the pack, Iris's built-in ones included, as a mantle component of its own: a pass of
|
||||
* Iris's mantle at the stage's place in the resolved order, so the stage sees everything earlier stages wrote
|
||||
* into the chunks around it. Its radius is the stage's reach, worked out from the pack when the components are
|
||||
* built; its flag comes from {@link MantleStageFlags}, so a dimension's {@code disabledComponents} turns it off.
|
||||
* built; a dimension's {@code disabledComponents} turns it off, by its flag when it is one of Iris's own, or by its id.
|
||||
*/
|
||||
public final class ModuleMantleComponent implements MantleComponent {
|
||||
private final Engine engine;
|
||||
@@ -61,15 +61,17 @@ public final class ModuleMantleComponent implements MantleComponent {
|
||||
}
|
||||
|
||||
/**
|
||||
* One component per mantle stage of the engine's pack, in resolved order, each its own pass. A stage whose
|
||||
* flag is in {@code disabled} is turned off.
|
||||
* One component per mantle stage of the engine's pack, in resolved order, each its own pass. A stage named in
|
||||
* {@code disabledComponents} is turned off; a name that matches no stage is warned about.
|
||||
*/
|
||||
public static List<ModuleMantleComponent> forPack(Engine engine, Set<MantleFlag> disabled) {
|
||||
return forPack(engine, engine.getData().getModules().pack(), disabled);
|
||||
public static List<ModuleMantleComponent> forPack(Engine engine, Collection<String> disabledComponents) {
|
||||
return forPack(engine, engine.getData().getModules().pack(), disabledComponents);
|
||||
}
|
||||
|
||||
static List<ModuleMantleComponent> forPack(Engine engine, LoadedPack pack, Set<MantleFlag> disabled) {
|
||||
static List<ModuleMantleComponent> forPack(Engine engine, LoadedPack pack, Collection<String> disabledComponents) {
|
||||
ResolvedGraph graph = pack.mantle();
|
||||
DisabledComponents disabled = new DisabledComponents(disabledComponents);
|
||||
disabled.warnAboutUnknown(graph.stages());
|
||||
MantleRunner runner = new MantleRunner(graph);
|
||||
IrisPackSettings settings = new IrisPackSettings(engine);
|
||||
List<MantleFlag> flags = MantleStageFlags.assign(graph.stages());
|
||||
@@ -78,7 +80,7 @@ public final class ModuleMantleComponent implements MantleComponent {
|
||||
ResolvedStage stage = graph.stages().get(position);
|
||||
MantleFlag flag = flags.get(position);
|
||||
components.add(new ModuleMantleComponent(engine, pack, runner, stage, flag, position,
|
||||
stage.reachBlocks(settings), !disabled.contains(flag)));
|
||||
stage.reachBlocks(settings), !disabled.disables(stage)));
|
||||
}
|
||||
return List.copyOf(components);
|
||||
}
|
||||
|
||||
@@ -58,7 +58,6 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@Data
|
||||
@@ -118,7 +117,7 @@ public class IrisEngineMantle implements EngineMantle {
|
||||
}
|
||||
|
||||
private List<ModuleMantleComponent> stageComponents() {
|
||||
return stageComponents.aquire(() -> ModuleMantleComponent.forPack(engine, Set.copyOf(getDimension().getDisabledComponents())));
|
||||
return stageComponents.aquire(() -> ModuleMantleComponent.forPack(engine, getDimension().getDisabledComponents()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user