Write typed markers with an exhaustive switch; drop MantleMarkerTypes

The marker ids no longer need a copy in core or a test keeping it equal
to the module's.
This commit is contained in:
piexel committed 2026-11-06 06:37:34 +01:00
1 parent 0c2aefef20
commit 7bc9f21f50
3 files changed
+4 -89

No files matched your search

@@ -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 <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.core.modules;
import com.volmit.placement.PlacedMarker;
import com.volmit.resource.ResourceId;
/**
* The marker types Iris keeps in its mantle when a placement marks a block ({@link PlacedMarker#type()}); a marker of
* any other type is rejected. The built-in modules mark with these ids, and Iris knows them as ids only.
*/
final class MantleMarkerTypes {
/** A marker the pack declares by name, kept as a pack marker; its name is the {@link #PACK_MARKER_NAME} attribute. */
static final ResourceId PACK_MARKER = ResourceId.parse("iris:marker");
static final String PACK_MARKER_NAME = "marker";
/** A block of a tree, kept as the block's tree material for felling and growth. */
static final ResourceId TREE_MATERIAL = ResourceId.parse("iris:tree_material");
/** A buried treasure chest, kept as a structure point of interest. */
static final ResourceId BURIED_TREASURE = ResourceId.parse("iris:buried_treasure");
private MantleMarkerTypes() {
}
/** The name of the pack marker {@code marker} is. */
static String packMarkerName(PlacedMarker marker) {
String name = marker.attributes().get(PACK_MARKER_NAME);
if (!marker.type().equals(PACK_MARKER) || name == null) {
throw new IllegalArgumentException("Iris keeps markers of type " + PACK_MARKER + " with a \"" + PACK_MARKER_NAME
+ "\" attribute, " + TREE_MATERIAL + " and " + BURIED_TREASURE + " only, not " + marker.type() + " "
+ marker.attributes());
}
return name;
}
}
@@ -187,15 +187,11 @@ final class PlacerTerrain implements PlacementTerrain {
int x = position.x();
int y = position.y();
int z = position.z();
if (marker.type().equals(MantleMarkerTypes.TREE_MATERIAL)) {
placer.setData(x, y, z, TreeBlockMaterial.of(placer.get(x, y, z)));
return;
switch (marker) {
case PlacedMarker.TreeMaterial ignored -> placer.setData(x, y, z, TreeBlockMaterial.of(placer.get(x, y, z)));
case PlacedMarker.BuriedTreasure ignored -> placer.setData(x, y, z, MatterStructurePOI.BURIED_TREASURE);
case PlacedMarker.PackMarker pack -> placer.setData(x, y, z, new MatterMarker(pack.key()));
}
if (marker.type().equals(MantleMarkerTypes.BURIED_TREASURE)) {
placer.setData(x, y, z, MatterStructurePOI.BURIED_TREASURE);
return;
}
placer.setData(x, y, z, new MatterMarker(MantleMarkerTypes.packMarkerName(marker)));
}
/** Resolved by the platform bound now, so a rebound platform never answers with another's states. */
@@ -1,31 +0,0 @@
package art.arcane.iris.core.modules;
import art.arcane.iris.builtin.blocks.ObjectMarkers;
import com.volmit.geometry.BlockPosition;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
/** Iris keeps the marker ids the built-in modules mark with, without reading their classes. */
public class MantleMarkerTypesTest {
private static final BlockPosition SPOT = new BlockPosition(1, 2, 3);
@Test
public void theTypesAreTheOnesTheBuiltInModulesMarkWith() {
assertEquals(ObjectMarkers.TYPE, MantleMarkerTypes.PACK_MARKER);
assertEquals(ObjectMarkers.MARKER_ATTRIBUTE, MantleMarkerTypes.PACK_MARKER_NAME);
assertEquals(ObjectMarkers.TREE_MATERIAL, MantleMarkerTypes.TREE_MATERIAL);
assertEquals(ObjectMarkers.BURIED_TREASURE, MantleMarkerTypes.BURIED_TREASURE);
}
@Test
public void aPackMarkerGivesItsName() {
assertEquals("spawn/zombie", MantleMarkerTypes.packMarkerName(ObjectMarkers.of(SPOT, "spawn/zombie")));
}
@Test
public void aMarkerOfAnotherTypeIsRejected() {
assertThrows(IllegalArgumentException.class, () -> MantleMarkerTypes.packMarkerName(ObjectMarkers.treeMaterial(SPOT)));
}
}