mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 16:25:36 +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()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,6 +23,7 @@ import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.EngineGeneration;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.volmlib.util.mantle.flag.MantleFlag;
|
||||
import art.arcane.volmlib.util.mantle.flag.ReservedFlag;
|
||||
import com.volmit.IrisModule;
|
||||
@@ -30,16 +31,23 @@ import com.volmit.ModuleInfo;
|
||||
import com.volmit.host.LoadedPack;
|
||||
import com.volmit.stage.Stage;
|
||||
import com.volmit.stage.StageGraph;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.mockito.MockedStatic;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.contains;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/** Every mantle stage is a mantle pass of its own, in the stage graph's order. */
|
||||
@@ -49,22 +57,28 @@ public class ModuleMantleComponentTest {
|
||||
@Rule
|
||||
public TemporaryFolder folder = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void everyMantleStageIsAPassOfItsOwnWithItsFlagAndThePacksReach() throws IOException {
|
||||
IrisModule marks = new IrisModule() {
|
||||
public ModuleInfo info() { return ModuleInfo.of("test:marks", "Marks", "1"); }
|
||||
public void install(StageGraph graph) {
|
||||
graph.define(Stage.mantle("test:marks/mark")).requires(StructureStages.PLACE).reach(settings -> MARK_REACH).run(context -> { });
|
||||
}
|
||||
};
|
||||
IrisData data = mock(IrisData.class);
|
||||
Engine engine = mock(Engine.class);
|
||||
private static final String MARK_STAGE = "test:marks/mark";
|
||||
|
||||
private final IrisModule marks = new IrisModule() {
|
||||
public ModuleInfo info() { return ModuleInfo.of("test:marks", "Marks", "1"); }
|
||||
public void install(StageGraph graph) {
|
||||
graph.define(Stage.mantle(MARK_STAGE)).requires(StructureStages.PLACE).reach(settings -> MARK_REACH).run(context -> { });
|
||||
}
|
||||
};
|
||||
private final IrisData data = mock(IrisData.class);
|
||||
private final Engine engine = mock(Engine.class);
|
||||
|
||||
@Before
|
||||
public void bindEngine() {
|
||||
when(engine.getData()).thenReturn(data);
|
||||
when(engine.getDimension()).thenReturn(new IrisDimension());
|
||||
when(engine.getGeneration()).thenReturn(new EngineGeneration(engine));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void everyMantleStageIsAPassOfItsOwnWithItsFlagAndThePacksReach() throws IOException {
|
||||
try (LoadedPack ignored = BuiltInPack.serve(data, folder, List.of(marks))) {
|
||||
List<ModuleMantleComponent> components = ModuleMantleComponent.forPack(engine, Set.of(ReservedFlag.CARVED));
|
||||
List<ModuleMantleComponent> components = ModuleMantleComponent.forPack(engine, List.of("CARVED"));
|
||||
|
||||
assertEquals(List.of("iris:carve/caves", "iris:objects/place", "iris:floating/objects", "iris:structure/place", "test:marks/mark"),
|
||||
components.stream().map(component -> component.stage().stage().id().toString()).toList());
|
||||
@@ -77,4 +91,39 @@ public class ModuleMantleComponentTest {
|
||||
components.stream().map(ModuleMantleComponent::isEnabled).toList());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aPackStageIsDisabledByItsIdAndNoOtherStageIs() throws IOException {
|
||||
try (LoadedPack ignored = BuiltInPack.serve(data, folder, List.of(marks))) {
|
||||
List<ModuleMantleComponent> components = ModuleMantleComponent.forPack(engine, List.of(MARK_STAGE));
|
||||
|
||||
assertEquals(List.of(true, true, true, true, false), components.stream().map(ModuleMantleComponent::isEnabled).toList());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anIrisStageIsDisabledByItsIdAsWellAsByItsFlag() throws IOException {
|
||||
try (LoadedPack ignored = BuiltInPack.serve(data, folder, List.of(marks))) {
|
||||
List<ModuleMantleComponent> byId = ModuleMantleComponent.forPack(engine, List.of("iris:objects/place"));
|
||||
List<ModuleMantleComponent> byFlag = ModuleMantleComponent.forPack(engine, List.of("OBJECT"));
|
||||
|
||||
assertEquals(List.of(true, false, true, true, true), byId.stream().map(ModuleMantleComponent::isEnabled).toList());
|
||||
assertEquals(List.of(true, false, true, true, true), byFlag.stream().map(ModuleMantleComponent::isEnabled).toList());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aNameThatIsNoStageIsWarnedAboutAndDisablesNothing() throws IOException {
|
||||
try (LoadedPack ignored = BuiltInPack.serve(data, folder, List.of(marks));
|
||||
MockedStatic<IrisLogging> logging = mockStatic(IrisLogging.class)) {
|
||||
List<String> names = List.of("test:marks/missing", "CUSTOM:64", "CARVED");
|
||||
|
||||
List<ModuleMantleComponent> components = ModuleMantleComponent.forPack(engine, names);
|
||||
|
||||
assertEquals(List.of(false, true, true, true, true), components.stream().map(ModuleMantleComponent::isEnabled).toList());
|
||||
logging.verify(() -> IrisLogging.warn(contains("disabledComponents names"), eq("CUSTOM:64"), any()), times(1));
|
||||
logging.verify(() -> IrisLogging.warn(contains("disabledComponents names"), eq("test:marks/missing"), any()), times(1));
|
||||
logging.verify(() -> IrisLogging.warn(anyString(), any(Object[].class)), times(2));
|
||||
}
|
||||
}
|
||||
}
|
||||
+26
-21
@@ -1,35 +1,40 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.engine.object.annotations.functions;
|
||||
|
||||
import art.arcane.iris.builtin.structure.StructureStages;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.BuiltInPack;
|
||||
import com.volmit.IrisModule;
|
||||
import com.volmit.ModuleInfo;
|
||||
import com.volmit.host.LoadedPack;
|
||||
import com.volmit.stage.Stage;
|
||||
import com.volmit.stage.StageGraph;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/** Studio offers the flags of Iris's own mantle stages for a dimension's disabledComponents, caves included. */
|
||||
/** Studio offers the flags of Iris's own mantle stages for a dimension's disabledComponents, then the pack's mantle stage ids. */
|
||||
public class ComponentFlagFunctionTest {
|
||||
@Rule
|
||||
public TemporaryFolder folder = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void offersTheFlagsOfIrisMantleStagesInTheirOrder() {
|
||||
assertEquals(List.of("CARVED", "OBJECT", "FLOATING_OBJECT", "JIGSAW"), new ComponentFlagFunction().apply(mock(IrisData.class)));
|
||||
public void offersTheFlagsOfIrisMantleStagesInTheirOrderThenThePacksMantleStageIds() throws IOException {
|
||||
IrisModule moss = new IrisModule() {
|
||||
public ModuleInfo info() { return ModuleInfo.of("test:moss", "Moss", "1"); }
|
||||
public void install(StageGraph graph) {
|
||||
graph.define(Stage.mantle("test:moss/veins")).requires(StructureStages.PLACE).reach(8).run(context -> { });
|
||||
}
|
||||
};
|
||||
IrisData data = mock(IrisData.class);
|
||||
|
||||
try (LoadedPack ignored = BuiltInPack.serve(data, folder, List.of(moss))) {
|
||||
assertEquals(List.of("CARVED", "OBJECT", "FLOATING_OBJECT", "JIGSAW", "test:moss/veins"), new ComponentFlagFunction().apply(data));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user