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:
piexel committed 2026-10-08 13:09:03 +02:00
1 parent 2cfb6f0d93
commit 22df943860
6 files changed
+171 -47

No files matched your search

@@ -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));
}
}
}
@@ -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));
}
}
}