mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-30 09:44:24 +00:00
Let the object model stand on the api: turn, scale, paste, records
Core turns objects with ObjectTurn and BlockTurn and scales with ScaleMethod, so the object model no longer reads the modules' ObjectRotation and ScaleInterpolation; /iris object paste writes the turned blocks with IrisObject.paste instead of running a placement. IrisObject takes no ObjectPlacement; the structure placers call ModuleObjectPlacement directly. IrisPlacements reads the run's name and JSON, the placement type comes from the module, placements are stored as PlacementMarkers texts and read back as PlacementRecords, the marker ids are Iris's own, the loot shuffle seed and the protected floor come from the modules, entity knobs are EntitySpec fields, and entity key completion is one handler by kind id. The entity pin is retaken with the old print proven to hash to the old number.
This commit is contained in:
1 parent
3022c54a43
commit
40436352bf
68 files changed
+1190
-427
No files matched your search
@@ -18,7 +18,6 @@
|
||||
|
||||
package art.arcane.iris.core.content;
|
||||
|
||||
import art.arcane.iris.builtin.spawn.IrisEntityExtras;
|
||||
import art.arcane.iris.core.modules.IrisPackResources;
|
||||
import art.arcane.iris.core.modules.ModuleServices;
|
||||
import art.arcane.iris.core.modules.PlatformBlockStates;
|
||||
@@ -161,18 +160,18 @@ public final class ContentServices {
|
||||
* {@link #tableItems} for them again.
|
||||
*/
|
||||
private static ContentEntity entityOf(EntitySpec spec) {
|
||||
IrisEntityExtras extras = spec.extension(IrisEntityExtras.class).orElse(IrisEntityExtras.NONE);
|
||||
String type = spec.type() instanceof ContentKey.Registered registered ? registered.id().toString() : "";
|
||||
String provided = spec.type() instanceof ContentKey.Provided mob ? mob.toString() : "";
|
||||
return new ContentEntity(type, provided, extras.reason().orElse(null),
|
||||
return new ContentEntity(type, provided, spec.arrival().reason().orElse(null),
|
||||
spec.appearance().customName().orElse(""), flagsOf(spec),
|
||||
equipmentOf(spec.equipment()), spec.company().passengers().stream().map(ContentServices::entityOf).toList(),
|
||||
spec.attributes().stream().map(ContentServices::attributeOf).toList(),
|
||||
spec.drops().lootTables().stream().map(ResourceId::path).toList(), spec.drops().shuffleSeed(),
|
||||
spec.company().leashHolder().map(ContentServices::entityOf).orElse(null),
|
||||
spec.arrival().effect().map(ContentServices::spawnEffectOf).orElse(null),
|
||||
extras.riseOutOfGround(), extras.pandaMainGene().orElse(null), extras.pandaHiddenGene().orElse(null),
|
||||
extras.applySettingsToProvidedMob(), spec.arrival().commands().stream().map(ContentServices::commandOf).toList());
|
||||
spec.arrival().risesFromGround(), spec.appearance().pandaMainGene().orElse(null),
|
||||
spec.appearance().pandaHiddenGene().orElse(null),
|
||||
spec.adjustsProvidedMob(), spec.arrival().commands().stream().map(ContentServices::commandOf).toList());
|
||||
}
|
||||
|
||||
private static ContentEntity.Flags flagsOf(EntitySpec spec) {
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
import art.arcane.iris.engine.object.prefab.BlockStateRotation;
|
||||
import art.arcane.iris.engine.object.prefab.ObjectTurn;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.volmlib.util.math.IrisBlockVector;
|
||||
@@ -37,7 +37,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Transforms geometry with the rotation Iris places objects with ({@link ObjectRotation}, its axis order
|
||||
* Transforms geometry with the rotation Iris places objects with ({@link ObjectTurn}, its axis order
|
||||
* included) about the anchor, turning block states with the object so stairs and logs face the way it does.
|
||||
* Mirrors come first, as {@link ObjectTransform} says: an X or Z mirror flips positions about the anchor and
|
||||
* mirrors block states through the platform's own mirror, so stairs and doors face the mirrored way. A Y mirror
|
||||
@@ -48,7 +48,6 @@ import java.util.Map;
|
||||
*/
|
||||
final class IrisObjectTransformer implements ObjectTransformer {
|
||||
private static final double NO_SCALE = 1D;
|
||||
private static final int NO_SPIN = 0;
|
||||
|
||||
@Override
|
||||
public GeneratedObject transform(GeneratedObject object, ObjectTransform transform) {
|
||||
@@ -101,7 +100,7 @@ final class IrisObjectTransformer implements ObjectTransformer {
|
||||
private final boolean mirrorX;
|
||||
private final boolean mirrorY;
|
||||
private final boolean mirrorZ;
|
||||
private final ObjectRotation rotation;
|
||||
private final ObjectTurn rotation;
|
||||
private final PlatformBlockStates states = new PlatformBlockStates(key -> IrisPlatforms.get().registries().block(key));
|
||||
|
||||
Turn(BlockPosition anchor, ObjectTransform transform) {
|
||||
@@ -109,7 +108,7 @@ final class IrisObjectTransformer implements ObjectTransformer {
|
||||
this.mirrorX = transform.mirrorX();
|
||||
this.mirrorY = transform.mirrorY();
|
||||
this.mirrorZ = transform.mirrorZ();
|
||||
this.rotation = ObjectRotation.of(transform.rotationX(), transform.rotationY(), transform.rotationZ());
|
||||
this.rotation = ObjectTurn.of(transform.rotationX(), transform.rotationY(), transform.rotationZ());
|
||||
}
|
||||
|
||||
BlockPosition position(BlockPosition local) {
|
||||
@@ -123,13 +122,13 @@ final class IrisObjectTransformer implements ObjectTransformer {
|
||||
if (mirrorZ) {
|
||||
offset.setZ(-offset.getZ());
|
||||
}
|
||||
IrisBlockVector turned = rotation.rotate(offset, NO_SPIN, NO_SPIN, NO_SPIN);
|
||||
IrisBlockVector turned = rotation.rotate(offset);
|
||||
return new BlockPosition(anchor.x() + (int) Math.round(turned.getX()), anchor.y() + (int) Math.round(turned.getY()),
|
||||
anchor.z() + (int) Math.round(turned.getZ()));
|
||||
}
|
||||
|
||||
com.volmit.block.BlockState state(ObjectBlock block) {
|
||||
return states.toApi(BlockStateRotation.rotate(rotation, mirrored(states.toPlatform(block.state())), NO_SPIN, NO_SPIN, NO_SPIN));
|
||||
return states.toApi(BlockStateRotation.rotate(rotation, mirrored(states.toPlatform(block.state()))));
|
||||
}
|
||||
|
||||
private PlatformBlockState mirrored(PlatformBlockState state) {
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.objects.ScaleInterpolation;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
@@ -80,7 +79,7 @@ final class IrisPackObjects implements PackObjects {
|
||||
if (engine == null) {
|
||||
throw new IllegalStateException("Scaling " + object.name() + " needs the world the pack generates, and it has none");
|
||||
}
|
||||
return ScaledObjects.scaled(irisObject(object), factor, ScaleInterpolation.valueOf(method.name()), engine);
|
||||
return ScaledObjects.scaled(irisObject(object), factor, method, engine);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,10 +18,8 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.objects.ObjectRun;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.placement.IrisPlacementForm;
|
||||
import com.volmit.config.FeatureSettings;
|
||||
import com.volmit.geometry.BlockBox;
|
||||
import com.volmit.host.LoadedPack;
|
||||
@@ -42,12 +40,11 @@ import java.util.function.Supplier;
|
||||
* blocks as the stages' inputs. Without an engine, such as for a studio paste, the stages have no terrain to sample and
|
||||
* no mantle.
|
||||
* <p>
|
||||
* The placement settings the stages read are those of the placed object's placement when the run's input is an
|
||||
* {@link ObjectRun}, which Iris's built-in stages and Iris's own placements pass; other inputs place with none.
|
||||
* The placement-level settings the stages read are those the run's {@link PlacementRun#settings()} declares, and the run's
|
||||
* name names their source.
|
||||
*/
|
||||
final class IrisPlacements implements Placements {
|
||||
private static final String OBJECT_KIND = "object";
|
||||
private static final String UNNAMED_PLACEMENT = "placement";
|
||||
|
||||
private final IrisData data;
|
||||
private final Engine engine;
|
||||
@@ -66,8 +63,10 @@ final class IrisPlacements implements Placements {
|
||||
ResolvedGraph graph = pack.placement();
|
||||
BlockBox area = widened(run.area(), graph.reach().blocks());
|
||||
PackResourceIds ids = new PackResourceIds(data.getDataFolder());
|
||||
ResourceId source = ids.of(OBJECT_KIND, placedName(run));
|
||||
ModuleSettings placementSettings = placementSettingsOf(run);
|
||||
ResourceId source = ids.of(OBJECT_KIND, run.name());
|
||||
ModuleSettings placementSettings = run.settings()
|
||||
.map(json -> data.getModules().settings().decodePlacement(json))
|
||||
.orElse(ModuleSettings.NONE);
|
||||
TerrainEdit edit = new TerrainEdit(run.terrain(), area, () -> mantle(area, pack));
|
||||
IrisPlacementInputs inputs = new IrisPlacementInputs(terrain(ids, area),
|
||||
new PlacementModuleSettings(worldSettings(ids), placementSettings, source),
|
||||
@@ -81,17 +80,6 @@ final class IrisPlacements implements Placements {
|
||||
area.maxZ() + blocks);
|
||||
}
|
||||
|
||||
private static String placedName(PlacementRun run) {
|
||||
return run.input() instanceof ObjectRun objectRun ? objectRun.object().name() : UNNAMED_PLACEMENT;
|
||||
}
|
||||
|
||||
private ModuleSettings placementSettingsOf(PlacementRun run) {
|
||||
if (!(run.input() instanceof ObjectRun objectRun)) {
|
||||
return ModuleSettings.NONE;
|
||||
}
|
||||
return IrisPlacementForm.of(objectRun.settings(), data).moduleSettings();
|
||||
}
|
||||
|
||||
private TerrainSampler terrain(PackResourceIds ids, BlockBox area) {
|
||||
if (engine == null) {
|
||||
return IrisPlacementInputs.noTerrain(area);
|
||||
|
||||
@@ -27,6 +27,7 @@ import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.volmlib.util.matter.slices.MarkerMatter;
|
||||
import com.volmit.config.FeatureSettings;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
import com.volmit.placement.PlacementRecord;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.RunningWorld;
|
||||
import com.volmit.world.TerrainSampler;
|
||||
@@ -113,11 +114,11 @@ final class IrisRunningWorld implements RunningWorld {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> placementAt(int worldX, int y, int worldZ) {
|
||||
public Optional<PlacementRecord> placementAt(int worldX, int y, int worldZ) {
|
||||
MantleChunk<Matter> chunk = engine.getMantle().getMantle().getChunk(worldX >> 4, worldZ >> 4).use();
|
||||
try {
|
||||
String recorded = chunk.get(worldX & 15, y, worldZ & 15, String.class);
|
||||
return recorded == null || recorded.isEmpty() ? Optional.empty() : Optional.of(recorded);
|
||||
return PlacementMarkers.recordOf(recorded, engine.getData().getPackResources());
|
||||
} finally {
|
||||
chunk.release();
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import art.arcane.iris.engine.mantle.components.StructurePlacing;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructure;
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.generation.InvocationContext;
|
||||
import com.volmit.resource.ResourceId;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -51,8 +52,9 @@ final class IrisStructureHost implements StructureHost {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<List<String>> lootTables(String structureKey) {
|
||||
IrisStructure structure = StructureResources.structure(engine.getData().getPackResources(), structureKey);
|
||||
public Optional<List<String>> lootTables(ResourceId structureId) {
|
||||
IrisPackResources resources = engine.getData().getPackResources();
|
||||
IrisStructure structure = StructureResources.structure(resources, resources.keyOf(structureId));
|
||||
if (structure == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,7 @@ import com.volmit.service.EntitySpawns;
|
||||
import com.volmit.service.LocateResult;
|
||||
import com.volmit.service.Loot;
|
||||
import com.volmit.service.ObjectsAt;
|
||||
import com.volmit.service.ProtectedFloor;
|
||||
import com.volmit.service.SaplingGrowth;
|
||||
import com.volmit.service.StructureLocator;
|
||||
import com.volmit.service.VanillaFeatures;
|
||||
@@ -43,6 +44,7 @@ import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalLong;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
@@ -88,6 +90,19 @@ public final class ModuleServices {
|
||||
.orElseGet(() -> new CaveBiomeAnswers(owner, null, owner.getGeneration().world())));
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the module that shapes the terrain keeps the lowest layer of the engine's world for itself, so the engine
|
||||
* discards the blocks others write there. Asked once for the world and kept; no provider keeps nothing.
|
||||
*/
|
||||
public static boolean protectsFloor(Engine engine) {
|
||||
return engine.getGeneration().state(FloorProtection.class, owner -> new FloorProtection(
|
||||
providers(owner, ProtectedFloor.class).stream()
|
||||
.anyMatch(provider -> provider.service().protectsFloor(provider.world())))).protectsFloor();
|
||||
}
|
||||
|
||||
private record FloorProtection(boolean protectsFloor) {
|
||||
}
|
||||
|
||||
/** What the modules say about the platform's own placed features in the engine's world, kept for the world. */
|
||||
public static VanillaFeatureAnswers vanillaFeatures(Engine engine) {
|
||||
return engine.getGeneration().state(VanillaFeatureAnswers.class, owner -> new VanillaFeatureAnswers(
|
||||
@@ -136,6 +151,17 @@ public final class ModuleServices {
|
||||
return tables;
|
||||
}
|
||||
|
||||
/** The seed to shuffle the slots of the container at {@code site} with: the first the modules give; empty when none does. */
|
||||
public static OptionalLong lootShuffleSeed(Engine engine, Loot.Site site) {
|
||||
for (Provider<Loot> provider : providers(engine, Loot.class)) {
|
||||
OptionalLong seed = provider.service().shuffleSeed(provider.world(), site);
|
||||
if (seed.isPresent()) {
|
||||
return seed;
|
||||
}
|
||||
}
|
||||
return OptionalLong.empty();
|
||||
}
|
||||
|
||||
/** The items loot table {@code table} gives at {@code site}, from the module that knows the table. */
|
||||
public static List<ItemDrop> lootItems(Engine engine, Loot.Site site, ResourceId table) {
|
||||
List<ItemDrop> items = new ArrayList<>();
|
||||
|
||||
@@ -52,6 +52,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
@@ -73,9 +74,11 @@ public final class ModuleSettingsDecoder {
|
||||
private static final String SNIPPET_PREFIX = "snippet/";
|
||||
private static final String SNIPPET_FOLDER = "snippet";
|
||||
private static final String JSON_EXTENSION = ".json";
|
||||
private static final String PLACEMENT_RESOURCE = "object placement";
|
||||
|
||||
private final Map<Level, List<FeatureDescriptor<?>>> settings = new EnumMap<>(Level.class);
|
||||
private final Map<Level, Set<String>> keys = new EnumMap<>(Level.class);
|
||||
private final Map<String, ModuleSettings> placementSettings = new ConcurrentHashMap<>();
|
||||
private final Path packFolder;
|
||||
private final Gson gson;
|
||||
private final Supplier<Gson> irisGson;
|
||||
@@ -123,6 +126,16 @@ public final class ModuleSettingsDecoder {
|
||||
return ModuleSettings.of(values);
|
||||
}
|
||||
|
||||
/**
|
||||
* The settings the object placement written as {@code json} declares at {@link Level#PLACEMENT}. A placement is placed
|
||||
* many times and always reads the same, so each text is decoded once for as long as the decoder lives.
|
||||
*
|
||||
* @throws IllegalArgumentException when a value does not decode into its settings type
|
||||
*/
|
||||
public ModuleSettings decodePlacement(String json) {
|
||||
return placementSettings.computeIfAbsent(json, text -> decode(Level.PLACEMENT, new JSONObject(text), PLACEMENT_RESOURCE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the JSON of a module resource file into a new {@code type}, created with its no-argument constructor so an
|
||||
* omitted option keeps its default. Iris's own classes, which built-in resource kinds may read into, are read by
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.core.loader.JsonFieldNames;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
@@ -31,14 +30,15 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Which Iris class holds the JSON of each attachment target that module settings can appear in.
|
||||
* Which Iris class holds the JSON of each attachment target that module settings can appear in. The JSON of an object
|
||||
* placement is held by the type the module that places objects declares ({@code FeatureRegistry.registerPlacementType}),
|
||||
* not by a class of Iris.
|
||||
*/
|
||||
public final class ModuleTargets {
|
||||
private static final Map<Level, Class<?>> HOLDERS = Map.of(
|
||||
Level.DIMENSION, IrisDimension.class,
|
||||
Level.REGION, IrisRegion.class,
|
||||
Level.BIOME, IrisBiome.class,
|
||||
Level.PLACEMENT, ObjectPlacement.class);
|
||||
Level.BIOME, IrisBiome.class);
|
||||
|
||||
private ModuleTargets() {
|
||||
}
|
||||
@@ -51,14 +51,6 @@ public final class ModuleTargets {
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
/** The target whose JSON an object of the class named {@code typeName} is, for module types such as a placement. */
|
||||
public static Optional<Level> ofTypeName(String typeName) {
|
||||
return HOLDERS.entrySet().stream()
|
||||
.filter(entry -> entry.getValue().getName().equals(typeName))
|
||||
.map(Map.Entry::getKey)
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
/** Iris's own JSON fields per target, which no settings key may take. */
|
||||
static Map<Level, Set<String>> reservedFields() {
|
||||
Map<Level, Set<String>> fields = new EnumMap<>(Level.class);
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* 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.PlacementRecord;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* The text Iris keeps beside a placed block in its mantle to say which placement the block belongs to: {@code key@id}
|
||||
* for an object placed on its own, and a delimiter-safe {@code @iris-structure:v1:...} form for a piece of a structure.
|
||||
* Worlds already generated hold these texts, so the forms never change. A module hands Iris a {@link PlacementRecord},
|
||||
* and Iris reads one back from the text with the pack's keys and ids.
|
||||
*/
|
||||
public final class PlacementMarkers {
|
||||
private static final String FAMILY_PREFIX = "@iris-structure:";
|
||||
private static final String VERSION_PREFIX = FAMILY_PREFIX + "v1:";
|
||||
private static final char PLACEMENT_SEPARATOR = '@';
|
||||
|
||||
private PlacementMarkers() {
|
||||
}
|
||||
|
||||
/** The text of an object placed on its own. */
|
||||
public static String encode(String objectKey, int placementId) {
|
||||
return requireKey(objectKey, "objectKey") + PLACEMENT_SEPARATOR + placementId;
|
||||
}
|
||||
|
||||
/** The text of a piece of a structure. */
|
||||
public static String encodeStructure(String objectKey, int placementId, String structureKey) {
|
||||
String normalizedObjectKey = requireKey(objectKey, "objectKey");
|
||||
String normalizedStructureKey = requireKey(structureKey, "structureKey");
|
||||
return VERSION_PREFIX
|
||||
+ encodeKey(normalizedObjectKey)
|
||||
+ ":" + placementId
|
||||
+ ":" + encodeKey(normalizedStructureKey);
|
||||
}
|
||||
|
||||
/** The text of {@code record}, with the pack keys of its object and structure. */
|
||||
public static String encode(PlacementRecord record, IrisPackResources resources) {
|
||||
String objectKey = resources.keyOf(PackResources.OBJECTS, record.object());
|
||||
if (record.structure().isEmpty()) {
|
||||
return encode(objectKey, record.placementId());
|
||||
}
|
||||
return encodeStructure(objectKey, record.placementId(), resources.keyOf(record.structure().get()));
|
||||
}
|
||||
|
||||
/** What the text says, or empty for a text that names no placement. */
|
||||
public static Optional<PlacementRecord> recordOf(String marker, IrisPackResources resources) {
|
||||
Decoded decoded = decode(marker);
|
||||
if (decoded == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
ResourceId object = resources.idOf(decoded.objectKey());
|
||||
Optional<ResourceId> structure = decoded.structureAware()
|
||||
? Optional.of(resources.idOf(decoded.structureKey()))
|
||||
: Optional.empty();
|
||||
return Optional.of(new PlacementRecord(object, decoded.placementId(), structure));
|
||||
}
|
||||
|
||||
public static Decoded decode(String marker) {
|
||||
if (marker == null || marker.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
if (marker.startsWith(FAMILY_PREFIX)) {
|
||||
return decodeStructure(marker);
|
||||
}
|
||||
return decodeLegacy(marker);
|
||||
}
|
||||
|
||||
private static Decoded decodeStructure(String marker) {
|
||||
if (!marker.startsWith(VERSION_PREFIX)) {
|
||||
return null;
|
||||
}
|
||||
String[] fields = marker.split(":", -1);
|
||||
if (fields.length != 5 || !fields[0].equals("@iris-structure") || !fields[1].equals("v1")) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
String objectKey = decodeCanonicalKey(fields[2]);
|
||||
int placementId = Integer.parseInt(fields[3]);
|
||||
String structureKey = decodeCanonicalKey(fields[4]);
|
||||
if (objectKey.isBlank() || structureKey.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
return new Decoded(objectKey, placementId, structureKey);
|
||||
} catch (IllegalArgumentException exception) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static Decoded decodeLegacy(String marker) {
|
||||
int separator = marker.indexOf(PLACEMENT_SEPARATOR);
|
||||
if (separator <= 0 || separator != marker.lastIndexOf(PLACEMENT_SEPARATOR) || separator == marker.length() - 1) {
|
||||
return null;
|
||||
}
|
||||
String objectKey = marker.substring(0, separator);
|
||||
if (objectKey.isEmpty() || objectKey.equals("null")) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return new Decoded(objectKey, Integer.parseInt(marker.substring(separator + 1)), null);
|
||||
} catch (NumberFormatException exception) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static String requireKey(String key, String name) {
|
||||
String required = Objects.requireNonNull(key, name);
|
||||
if (required.isBlank()) {
|
||||
throw new IllegalArgumentException(name + " must not be blank");
|
||||
}
|
||||
return required;
|
||||
}
|
||||
|
||||
private static String encodeKey(String key) {
|
||||
return Base64.getUrlEncoder().withoutPadding().encodeToString(key.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
private static String decodeCanonicalKey(String key) {
|
||||
String decoded = new String(Base64.getUrlDecoder().decode(key), StandardCharsets.UTF_8);
|
||||
if (!encodeKey(decoded).equals(key)) {
|
||||
throw new IllegalArgumentException("Non-canonical marker key");
|
||||
}
|
||||
return decoded;
|
||||
}
|
||||
|
||||
/** A placement text read as pack keys; {@code structureKey} is null for an object placed on its own. */
|
||||
public record Decoded(String objectKey, int placementId, String structureKey) {
|
||||
public boolean structureAware() {
|
||||
return structureKey != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.blocks.ObjectMarkers;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.NativeStructureVolume;
|
||||
@@ -34,6 +33,7 @@ import com.volmit.block.BlockState;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
import com.volmit.object.BlockEntityData;
|
||||
import com.volmit.placement.PlacedMarker;
|
||||
import com.volmit.placement.PlacementRecord;
|
||||
import com.volmit.placement.PlacementTerrain;
|
||||
import com.volmit.placement.StructureVolumes;
|
||||
|
||||
@@ -66,8 +66,6 @@ final class PlacerTerrain implements PlacementTerrain {
|
||||
}
|
||||
};
|
||||
|
||||
private static final char PLACEMENT_ID_SEPARATOR = '@';
|
||||
|
||||
private final IObjectPlacer placer;
|
||||
private final IrisData data;
|
||||
private final PlatformBlockStates states = new PlatformBlockStates(PlacerTerrain::platformState);
|
||||
@@ -148,8 +146,8 @@ final class PlacerTerrain implements PlacementTerrain {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordPlacement(int x, int y, int z, String placement) {
|
||||
placer.setData(x, y, z, placement);
|
||||
public void recordPlacement(int x, int y, int z, PlacementRecord placement) {
|
||||
placer.setData(x, y, z, PlacementMarkers.encode(placement, data.getPackResources()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -158,7 +156,7 @@ final class PlacerTerrain implements PlacementTerrain {
|
||||
* procedural object's, read as no placement, so placements collide with what they collided with before.
|
||||
*/
|
||||
@Override
|
||||
public Optional<String> placementAt(int x, int y, int z) {
|
||||
public Optional<PlacementRecord> placementAt(int x, int y, int z) {
|
||||
Engine engine = data.getEngine();
|
||||
if (engine == null) {
|
||||
throw new IllegalStateException("Object placement requires active Iris data for collision settings.");
|
||||
@@ -167,7 +165,7 @@ final class PlacerTerrain implements PlacementTerrain {
|
||||
if (placed == null || placed.getObject() == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(placed.getObject().getLoadKey() + PLACEMENT_ID_SEPARATOR + placed.getId());
|
||||
return Optional.of(PlacementRecord.of(data.getPackResources().idOf(placed.getObject().getLoadKey()), placed.getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -189,15 +187,15 @@ final class PlacerTerrain implements PlacementTerrain {
|
||||
int x = position.x();
|
||||
int y = position.y();
|
||||
int z = position.z();
|
||||
if (marker.type().equals(ObjectMarkers.TREE_MATERIAL)) {
|
||||
if (marker.type().equals(MantleMarkerTypes.TREE_MATERIAL)) {
|
||||
placer.setData(x, y, z, TreeBlockMaterial.of(placer.get(x, y, z)));
|
||||
return;
|
||||
}
|
||||
if (marker.type().equals(ObjectMarkers.BURIED_TREASURE)) {
|
||||
if (marker.type().equals(MantleMarkerTypes.BURIED_TREASURE)) {
|
||||
placer.setData(x, y, z, MatterStructurePOI.BURIED_TREASURE);
|
||||
return;
|
||||
}
|
||||
placer.setData(x, y, z, new MatterMarker(ObjectMarkers.markerKey(marker)));
|
||||
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. */
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package art.arcane.iris.core.project;
|
||||
|
||||
import art.arcane.iris.core.modules.ModuleTargets;
|
||||
import art.arcane.volmlib.util.json.JSONArray;
|
||||
import art.arcane.volmlib.util.json.JSONObject;
|
||||
import com.volmit.config.Level;
|
||||
@@ -181,7 +180,9 @@ final class ModuleSchemaRenderer {
|
||||
required.put(option.name());
|
||||
}
|
||||
}
|
||||
ModuleTargets.ofTypeName(type.name()).ifPresent(target -> addFeatures(target, properties));
|
||||
if (schema.placementType().filter(type.name()::equals).isPresent()) {
|
||||
addFeatures(Level.PLACEMENT, properties);
|
||||
}
|
||||
object.put("properties", properties);
|
||||
if (required.length() > 0) {
|
||||
object.put("required", required);
|
||||
|
||||
@@ -3,7 +3,7 @@ package art.arcane.iris.core.service;
|
||||
import art.arcane.iris.engine.framework.PlacedStructurePiece;
|
||||
import art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawConnector;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
import art.arcane.iris.engine.object.prefab.ObjectTurn;
|
||||
import art.arcane.iris.engine.object.prefab.BlockStateRotation;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
@@ -193,10 +193,10 @@ public final class JigsawStudioPreviewRenderer {
|
||||
PlacedStructurePiece piece
|
||||
) throws IOException {
|
||||
IrisObject object = piece.getObject();
|
||||
ObjectRotation rotation = piece.getRotation();
|
||||
ObjectTurn rotation = piece.getRotation();
|
||||
for (Map.Entry<IrisBlockVector, PlatformBlockState> entry : object.getBlocks()) {
|
||||
IrisBlockVector rotated = rotation.rotate(entry.getKey());
|
||||
PlatformBlockState state = BlockStateRotation.rotate(rotation, entry.getValue(), 0, 0, 0);
|
||||
PlatformBlockState state = BlockStateRotation.rotate(rotation, entry.getValue());
|
||||
putState(
|
||||
blocks,
|
||||
new BlockPosition(
|
||||
@@ -213,7 +213,7 @@ public final class JigsawStudioPreviewRenderer {
|
||||
PlacedStructurePiece piece
|
||||
) throws IOException {
|
||||
IrisObject object = piece.getObject();
|
||||
ObjectRotation rotation = piece.getRotation();
|
||||
ObjectTurn rotation = piece.getRotation();
|
||||
if (piece.getPiece().getConnectors() == null) {
|
||||
return;
|
||||
}
|
||||
@@ -227,7 +227,7 @@ public final class JigsawStudioPreviewRenderer {
|
||||
connector.getPosition().getZ() - object.getCenter().getBlockZ());
|
||||
IrisBlockVector rotated = rotation.rotate(signed);
|
||||
PlatformBlockState source = B.getStateOrNull(connector.getFinalState(), false);
|
||||
PlatformBlockState state = source == null ? null : BlockStateRotation.rotate(rotation, source, 0, 0, 0);
|
||||
PlatformBlockState state = source == null ? null : BlockStateRotation.rotate(rotation, source);
|
||||
putState(
|
||||
blocks,
|
||||
new BlockPosition(
|
||||
|
||||
@@ -47,7 +47,7 @@ import art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawConnector;
|
||||
import art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawPiece;
|
||||
import art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawThemeSet;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
import art.arcane.iris.engine.object.prefab.ObjectTurn;
|
||||
import art.arcane.iris.engine.object.prefab.BlockStateRotation;
|
||||
import art.arcane.iris.engine.object.value.IrisPosition;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructure;
|
||||
@@ -6287,7 +6287,7 @@ public final class JigsawStudioService implements IrisService, JigsawStudioMenuC
|
||||
int sourceDepth = (quarterTurns & 1) == 0
|
||||
? displayDimensions.depth()
|
||||
: displayDimensions.width();
|
||||
ObjectRotation rotation = ObjectRotation.of(0, -90.0D * quarterTurns, 0);
|
||||
ObjectTurn rotation = ObjectTurn.of(0, -90.0D * quarterTurns, 0);
|
||||
Map<LocalPosition, IrisJigsawConnector> displayed = new HashMap<>(source.getConnectors().size());
|
||||
for (IrisJigsawConnector sourceConnector : source.getConnectors()) {
|
||||
LocalPosition sourcePosition = connectorPosition(sourceConnector, "source piece");
|
||||
@@ -6395,7 +6395,7 @@ public final class JigsawStudioService implements IrisService, JigsawStudioMenuC
|
||||
sourceWidth,
|
||||
captureBounds.dimensions().height(),
|
||||
sourceDepth);
|
||||
ObjectRotation inverseRotation = ObjectRotation.of(0, 90.0D * quarterTurns, 0);
|
||||
ObjectTurn inverseRotation = ObjectTurn.of(0, 90.0D * quarterTurns, 0);
|
||||
List<IrisJigsawConnector> connectors = new ArrayList<>();
|
||||
Set<LocalPosition> capturedBlocks = new HashSet<>();
|
||||
Set<LocalPosition> capturedConnectors = new HashSet<>();
|
||||
@@ -6417,7 +6417,7 @@ public final class JigsawStudioService implements IrisService, JigsawStudioMenuC
|
||||
}
|
||||
PlatformBlockState sourceState = quarterTurns == 0
|
||||
? block.state()
|
||||
: BlockStateRotation.rotate(inverseRotation, block.state(), 0, 0, 0);
|
||||
: BlockStateRotation.rotate(inverseRotation, block.state());
|
||||
if (sourceState == null) {
|
||||
throw new IOException("Captured block state cannot be inverse-rotated at "
|
||||
+ block.x() + "," + block.y() + "," + block.z());
|
||||
@@ -6459,7 +6459,7 @@ public final class JigsawStudioService implements IrisService, JigsawStudioMenuC
|
||||
+ capturedConnector.x() + "," + capturedConnector.y() + ","
|
||||
+ capturedConnector.z());
|
||||
}
|
||||
PlatformBlockState sourceFinalState = BlockStateRotation.rotate(inverseRotation, finalState, 0, 0, 0);
|
||||
PlatformBlockState sourceFinalState = BlockStateRotation.rotate(inverseRotation, finalState);
|
||||
if (sourceFinalState == null) {
|
||||
throw new IOException("Captured connector final state cannot be inverse-rotated at "
|
||||
+ capturedConnector.x() + "," + capturedConnector.y() + ","
|
||||
@@ -6963,7 +6963,7 @@ public final class JigsawStudioService implements IrisService, JigsawStudioMenuC
|
||||
sourceWidth,
|
||||
sourceDepth,
|
||||
quarterTurns);
|
||||
ObjectRotation inverseRotation = ObjectRotation.of(0, 90.0D * quarterTurns, 0);
|
||||
ObjectTurn inverseRotation = ObjectTurn.of(0, 90.0D * quarterTurns, 0);
|
||||
IrisJigsawConnector sourceOriented = CapturedConnector.from(captured).toConnector()
|
||||
.setPosition(new IrisPosition(position.x(), position.y(), position.z()))
|
||||
.setDirection(inverseRotation.rotate(captured.getDirection()))
|
||||
|
||||
@@ -2,7 +2,7 @@ package art.arcane.iris.core.service.tree;
|
||||
|
||||
import art.arcane.iris.core.modules.ModuleServices;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.builtin.structure.StructurePlacementMarker;
|
||||
import art.arcane.iris.core.modules.PlacementMarkers;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.service.SaplingGrowth;
|
||||
@@ -28,7 +28,7 @@ public final class TreeDefinitionIndex {
|
||||
}
|
||||
|
||||
public boolean isTreeMarker(String marker) {
|
||||
StructurePlacementMarker.Decoded decoded = StructurePlacementMarker.decode(marker);
|
||||
PlacementMarkers.Decoded decoded = PlacementMarkers.decode(marker);
|
||||
if (decoded == null || decoded.structureAware()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
package art.arcane.iris.engine.framework;
|
||||
|
||||
import art.arcane.iris.builtin.structure.StructurePlacementMarker;
|
||||
import art.arcane.iris.core.modules.PlacementMarkers;
|
||||
|
||||
|
||||
import art.arcane.iris.core.IrisSettings;
|
||||
@@ -437,7 +437,7 @@ public interface Engine extends DataProvider, Fallible, BlockUpdater, Renderer,
|
||||
return null;
|
||||
}
|
||||
|
||||
StructurePlacementMarker.Decoded marker = StructurePlacementMarker.decode(objectAt);
|
||||
PlacementMarkers.Decoded marker = PlacementMarkers.decode(objectAt);
|
||||
if (marker == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ package art.arcane.iris.engine.framework;
|
||||
|
||||
import art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawPiece;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
import art.arcane.iris.engine.object.prefab.ObjectTurn;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@@ -32,7 +32,7 @@ public class PlacedStructurePiece {
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
private final ObjectRotation rotation;
|
||||
private final ObjectTurn rotation;
|
||||
private final int minX;
|
||||
private final int minY;
|
||||
private final int minZ;
|
||||
|
||||
@@ -38,7 +38,7 @@ import art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawPieceEntry;
|
||||
import art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawPool;
|
||||
import art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawWorkcellArchetype;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
import art.arcane.iris.engine.object.prefab.ObjectTurn;
|
||||
import art.arcane.iris.engine.object.value.IrisPosition;
|
||||
import art.arcane.iris.engine.object.structure.IrisStructure;
|
||||
import art.arcane.iris.engine.object.structure.jigsaw.JigsawJoint;
|
||||
@@ -186,7 +186,7 @@ public final class StructureAssembler {
|
||||
}
|
||||
|
||||
int startRotY = startPiece.isRotatable() ? Y_DEGREES[rng.i(Y_DEGREES.length)] : 0;
|
||||
ObjectRotation startRot = ObjectRotation.of(0, startRotY, 0);
|
||||
ObjectTurn startRot = ObjectTurn.of(0, startRotY, 0);
|
||||
PlacedStructurePiece start = build(startPiece, startObject, originX, originY, originZ, startRot);
|
||||
placed.add(start);
|
||||
registerPlacedPiece(consumedConnectors, start, null);
|
||||
@@ -407,7 +407,7 @@ public final class StructureAssembler {
|
||||
IrisDirection needed = connector.facing.reverse();
|
||||
int[] rotations = piece.isRotatable() ? rotationCandidates(connector.joint, rng) : NO_ROTATION;
|
||||
for (int yDeg : rotations) {
|
||||
ObjectRotation rot = ObjectRotation.of(0, yDeg, 0);
|
||||
ObjectTurn rot = ObjectTurn.of(0, yDeg, 0);
|
||||
IrisDirection rotatedFace = rot.rotate(cb.getDirection());
|
||||
if (rotatedFace != needed) {
|
||||
continue;
|
||||
@@ -717,7 +717,7 @@ public final class StructureAssembler {
|
||||
}
|
||||
int[] rotations = piece.isRotatable() ? Y_DEGREES : NO_ROTATION;
|
||||
for (int yDegrees : rotations) {
|
||||
ObjectRotation rotation = ObjectRotation.of(0, yDegrees, 0);
|
||||
ObjectTurn rotation = ObjectTurn.of(0, yDegrees, 0);
|
||||
if (rotation.rotate(connector.getDirection()) != source.facing().reverse()
|
||||
|| source.joint() == JigsawJoint.ALIGNED
|
||||
&& rotation.rotate(connector.getTop()) != source.top()) {
|
||||
@@ -968,7 +968,7 @@ public final class StructureAssembler {
|
||||
throw assemblyFailure("piece expansion queue was unexpectedly empty");
|
||||
}
|
||||
|
||||
private PlacedStructurePiece build(IrisJigsawPiece piece, IrisObject object, int x, int y, int z, ObjectRotation rot) {
|
||||
private PlacedStructurePiece build(IrisJigsawPiece piece, IrisObject object, int x, int y, int z, ObjectTurn rot) {
|
||||
int width = Math.max(1, object.getW());
|
||||
int height = Math.max(1, object.getH());
|
||||
int depth = Math.max(1, object.getD());
|
||||
@@ -998,8 +998,8 @@ public final class StructureAssembler {
|
||||
int localMaxX = localMinX + width - 1;
|
||||
int localMaxY = localMinY + height - 1;
|
||||
int localMaxZ = localMinZ + depth - 1;
|
||||
IrisPosition rotatedMin = rot.rotate(new IrisPosition(localMinX, localMinY, localMinZ), 0, 0, 0);
|
||||
IrisPosition rotatedMax = rot.rotate(new IrisPosition(localMaxX, localMaxY, localMaxZ), 0, 0, 0);
|
||||
IrisPosition rotatedMin = rot.rotate(new IrisPosition(localMinX, localMinY, localMinZ));
|
||||
IrisPosition rotatedMax = rot.rotate(new IrisPosition(localMaxX, localMaxY, localMaxZ));
|
||||
int minX = Math.min(rotatedMin.getX(), rotatedMax.getX());
|
||||
int minY = Math.min(rotatedMin.getY(), rotatedMax.getY());
|
||||
int minZ = Math.min(rotatedMin.getZ(), rotatedMax.getZ());
|
||||
@@ -1048,7 +1048,7 @@ public final class StructureAssembler {
|
||||
private IrisPosition connectorOffset(
|
||||
IrisObject object,
|
||||
IrisJigsawConnector connector,
|
||||
ObjectRotation rotation
|
||||
ObjectTurn rotation
|
||||
) {
|
||||
if (structure.resolvedMode() == IrisJigsawMode.PLANAR_JIGSAW) {
|
||||
IrisPosition dimensions = rotatedDimensions(object, rotation);
|
||||
@@ -1065,7 +1065,7 @@ public final class StructureAssembler {
|
||||
connector.getPosition().getX() - center.getX(),
|
||||
connector.getPosition().getY() - center.getY(),
|
||||
connector.getPosition().getZ() - center.getZ());
|
||||
return rotation.rotate(relative, 0, 0, 0);
|
||||
return rotation.rotate(relative);
|
||||
}
|
||||
|
||||
private IrisPosition logicalCenter(PlacedStructurePiece piece) {
|
||||
@@ -1079,7 +1079,7 @@ public final class StructureAssembler {
|
||||
piece.getZ() - offset.getZ());
|
||||
}
|
||||
|
||||
private IrisPosition rotatedDimensions(IrisObject object, ObjectRotation rotation) {
|
||||
private IrisPosition rotatedDimensions(IrisObject object, ObjectTurn rotation) {
|
||||
int width = Math.max(1, object.getW());
|
||||
int height = Math.max(1, object.getH());
|
||||
int depth = Math.max(1, object.getD());
|
||||
@@ -1088,7 +1088,7 @@ public final class StructureAssembler {
|
||||
: new IrisPosition(depth, height, width);
|
||||
}
|
||||
|
||||
private IrisPosition planarPlacementOffset(IrisObject object, ObjectRotation rotation) {
|
||||
private IrisPosition planarPlacementOffset(IrisObject object, ObjectTurn rotation) {
|
||||
int width = Math.max(1, object.getW());
|
||||
int depth = Math.max(1, object.getD());
|
||||
return switch (quarterTurns(rotation)) {
|
||||
@@ -1103,7 +1103,7 @@ public final class StructureAssembler {
|
||||
};
|
||||
}
|
||||
|
||||
private int quarterTurns(ObjectRotation rotation) {
|
||||
private int quarterTurns(ObjectTurn rotation) {
|
||||
return switch (rotation.rotate(IrisDirection.NORTH_NEGATIVE_Z)) {
|
||||
case NORTH_NEGATIVE_Z -> 0;
|
||||
case WEST_NEGATIVE_X -> 1;
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
package art.arcane.iris.engine.mantle;
|
||||
|
||||
|
||||
import art.arcane.iris.builtin.terrain.BedrockSettings;
|
||||
import art.arcane.iris.core.modules.ModuleServices;
|
||||
import art.arcane.iris.engine.object.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.util.project.matter.TileWrapper;
|
||||
@@ -43,7 +43,10 @@ import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import art.arcane.volmlib.util.matter.MatterSlice;
|
||||
import art.arcane.iris.util.project.noise.CNG;
|
||||
import art.arcane.iris.util.common.scheduling.J;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.common.data.B;
|
||||
import org.bukkit.util.Vector;
|
||||
@@ -64,6 +67,9 @@ public class MantleWriter implements IObjectPlacer, AutoCloseable {
|
||||
private final int z;
|
||||
private final int windowSide;
|
||||
private final AtomicReferenceArray<MantleChunk<Matter>> window;
|
||||
@Getter(AccessLevel.NONE)
|
||||
@Setter(AccessLevel.NONE)
|
||||
private transient volatile Boolean floorProtected;
|
||||
|
||||
public MantleWriter(EngineMantle engineMantle, Mantle<Matter> mantle, int x, int z, int radius, boolean multicore) {
|
||||
this(engineMantle, mantle, x, z, radius, radius * 2, multicore);
|
||||
@@ -187,6 +193,16 @@ public class MantleWriter implements IObjectPlacer, AutoCloseable {
|
||||
(int) Math.round(style.warp(rng, data, z, -y, z, x)), t);
|
||||
}
|
||||
|
||||
/** Whether the terrain module keeps the lowest layer, asked of the modules the first time a block lands there. */
|
||||
private boolean isFloorProtected() {
|
||||
Boolean known = floorProtected;
|
||||
if (known == null) {
|
||||
known = ModuleServices.protectsFloor(engineMantle.getEngine());
|
||||
floorProtected = known;
|
||||
}
|
||||
return known;
|
||||
}
|
||||
|
||||
public <T> void setData(int x, int y, int z, T t) {
|
||||
if (t == null) {
|
||||
return;
|
||||
@@ -199,7 +215,7 @@ public class MantleWriter implements IObjectPlacer, AutoCloseable {
|
||||
return;
|
||||
}
|
||||
|
||||
if (y == 0 && t instanceof PlatformBlockState && engineMantle.getEngine().getDimension().getModuleSettings().find(BedrockSettings.class).map(BedrockSettings::bedrock).orElse(true)) {
|
||||
if (y == 0 && t instanceof PlatformBlockState && isFloorProtected()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@ package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.engine.framework.PlacedStructurePiece;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
import art.arcane.iris.engine.object.prefab.ObjectTurn;
|
||||
import art.arcane.iris.util.common.data.B;
|
||||
import art.arcane.volmlib.util.math.IrisBlockVector;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
@@ -191,7 +191,7 @@ public final class StructureCarvingFootprint {
|
||||
continue;
|
||||
}
|
||||
IrisObject object = piece.getObject();
|
||||
ObjectRotation rotation = piece.getRotation();
|
||||
ObjectTurn rotation = piece.getRotation();
|
||||
if (object == null || rotation == null || object.getBlocks() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -22,12 +22,15 @@ import art.arcane.iris.builtin.anchor.PlaceTrait;
|
||||
import art.arcane.iris.builtin.anchor.ObjectPlaceMode;
|
||||
import art.arcane.iris.engine.framework.structure.StructureResources;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
import art.arcane.iris.core.IrisSettings;
|
||||
import art.arcane.iris.core.modules.ModuleObjectPlacement;
|
||||
import art.arcane.iris.engine.object.prefab.ObjectTurn;
|
||||
import art.arcane.volmlib.util.cache.CacheKey;
|
||||
import art.arcane.iris.engine.framework.IrisStructureLocator;
|
||||
import art.arcane.iris.engine.framework.PlacedStructurePiece;
|
||||
import art.arcane.iris.engine.framework.StructurePlacementScope;
|
||||
import art.arcane.iris.builtin.structure.StructurePlacementMarker;
|
||||
import art.arcane.iris.core.modules.PlacementMarkers;
|
||||
import art.arcane.iris.engine.framework.TreeBlockMaterial;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.builtin.loot.ObjectLoot;
|
||||
@@ -455,7 +458,7 @@ public class StructurePlacing {
|
||||
|
||||
private void clearMarkerOwnedObject(MantleWriter writer, String marker,
|
||||
ObjectMarkerBounds intersections, int worldHeight) {
|
||||
StructurePlacementMarker.Decoded decoded = StructurePlacementMarker.decode(marker);
|
||||
PlacementMarkers.Decoded decoded = PlacementMarkers.decode(marker);
|
||||
if (decoded == null) {
|
||||
return;
|
||||
}
|
||||
@@ -498,7 +501,7 @@ public class StructurePlacing {
|
||||
}
|
||||
|
||||
static boolean isOrdinaryObjectMarker(String marker) {
|
||||
StructurePlacementMarker.Decoded decoded = StructurePlacementMarker.decode(marker);
|
||||
PlacementMarkers.Decoded decoded = PlacementMarkers.decode(marker);
|
||||
return decoded != null && !decoded.structureAware();
|
||||
}
|
||||
|
||||
@@ -562,7 +565,7 @@ public class StructurePlacing {
|
||||
boolean supportNonOccluding) {
|
||||
IrisObject object = p.getObject();
|
||||
String objectKey = object.getLoadKey();
|
||||
ObjectPlacement.Builder builder = lootPlacementBuilder(structure, objectKey).mode(mode).rotation(p.getRotation());
|
||||
ObjectPlacement.Builder builder = lootPlacementBuilder(structure, objectKey).mode(mode).rotation(moduleRotation(p.getRotation()));
|
||||
if (!structure.getEdit().isEmpty()) {
|
||||
builder.edit(structure.getEdit());
|
||||
}
|
||||
@@ -572,14 +575,19 @@ public class StructurePlacing {
|
||||
ObjectPlacement config = builder.build();
|
||||
int placeY = (y == -1) ? -1 : y - engine.getMinHeight();
|
||||
String marker = structurePlacementMarker(structure, p, objectKey);
|
||||
return object.place(p.getX(), placeY, p.getZ(), writer, config, rng, (position, state) -> {
|
||||
return ModuleObjectPlacement.place(object, p.getX(), placeY, p.getZ(), writer, config, rng, (position, state) -> {
|
||||
StructureFoundationPlanner.recordBaseCell(
|
||||
foundationColumns, position.getX(), position.getY(), position.getZ(), state,
|
||||
supportNonOccluding);
|
||||
if (marker != null && shouldWriteStructureMarker(state)) {
|
||||
writer.setData(position.getX(), position.getY(), position.getZ(), marker);
|
||||
}
|
||||
}, null, engine.getData());
|
||||
}, null, engine.getData()).heightOrRejected();
|
||||
}
|
||||
|
||||
/** The placement rotation that turns a placed piece the way {@code turn} does. */
|
||||
public static ObjectRotation moduleRotation(ObjectTurn turn) {
|
||||
return ObjectRotation.of(turn.xDegrees(), turn.yDegrees(), turn.zDegrees());
|
||||
}
|
||||
|
||||
static boolean shouldWriteStructureMarker(PlatformBlockState state) {
|
||||
@@ -602,7 +610,7 @@ public class StructurePlacing {
|
||||
return null;
|
||||
}
|
||||
int placementId = structurePlacementId(structureKey, objectKey, piece.getX(), piece.getY(), piece.getZ());
|
||||
return StructurePlacementMarker.encodeStructure(objectKey, placementId, structureKey);
|
||||
return PlacementMarkers.encodeStructure(objectKey, placementId, structureKey);
|
||||
}
|
||||
|
||||
/** How far, in blocks along X and Z, placements may write beyond their chunk. */
|
||||
|
||||
@@ -29,9 +29,7 @@ import art.arcane.iris.engine.object.noise.IrisNoiseGenerator;
|
||||
import art.arcane.iris.engine.object.noise.IrisStyledRange;
|
||||
import art.arcane.iris.util.project.noise.CNG;
|
||||
import art.arcane.volmlib.util.cache.LazyBoundedCache;
|
||||
import art.arcane.volmlib.util.json.JSONObject;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.config.Level;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
@@ -79,7 +77,7 @@ public final class IrisPlacementForm {
|
||||
if (placement.json() == null) {
|
||||
return ModuleSettings.NONE;
|
||||
}
|
||||
return data.getModules().settings().decode(Level.PLACEMENT, new JSONObject(placement.json()), "object placement");
|
||||
return data.getModules().settings().decodePlacement(placement.json());
|
||||
}
|
||||
|
||||
/** The settings the pack's modules declare on the placement. */
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package art.arcane.iris.engine.object.prefab;
|
||||
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
import art.arcane.iris.platform.bukkit.BukkitBlockState;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
@@ -44,12 +43,10 @@ import java.util.Set;
|
||||
|
||||
/**
|
||||
* Turns a platform block state with an object: the facing, axis and connections of stairs, logs, walls and wires follow
|
||||
* the {@link BlockTurn} that turns the object's directions, such as an {@link ObjectRotation}'s. A platform other than
|
||||
* the {@link BlockTurn} that turns the object's directions, such as an {@link ObjectTurn}'s. A platform other than
|
||||
* Bukkit binds its own {@link StateRotator}.
|
||||
*/
|
||||
public final class BlockStateRotation {
|
||||
private static final double QUARTER_TURN_DEGREES = 90D;
|
||||
private static final double FULL_TURN_DEGREES = 360D;
|
||||
private static volatile StateRotator platformRotator = null;
|
||||
|
||||
/** How a platform turns its own block states. */
|
||||
@@ -76,15 +73,12 @@ public final class BlockStateRotation {
|
||||
platformRotator = rotator;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code state} turned by {@code rotation}, spun by the given degrees counted in whole quarter turns; null when a
|
||||
* block that cannot face the new way is dropped.
|
||||
*/
|
||||
public static PlatformBlockState rotate(ObjectRotation rotation, PlatformBlockState state, int spinX, int spinY, int spinZ) {
|
||||
if (!rotation.canRotate()) {
|
||||
/** {@code state} turned by {@code turn}; null when a block that cannot face the new way is dropped. */
|
||||
public static PlatformBlockState rotate(ObjectTurn turn, PlatformBlockState state) {
|
||||
if (!turn.canRotate()) {
|
||||
return state;
|
||||
}
|
||||
return rotate(turnOf(rotation, spinX, spinY, spinZ), state);
|
||||
return rotate(turn.blockTurn(), state);
|
||||
}
|
||||
|
||||
/** {@code state} turned by {@code turn}; null when a block that cannot face the new way is dropped. */
|
||||
@@ -104,17 +98,6 @@ public final class BlockStateRotation {
|
||||
return rotated == null ? null : BukkitBlockState.of(rotated);
|
||||
}
|
||||
|
||||
/** The directions {@code rotation} turns, spun by the given degrees counted in whole quarter turns. */
|
||||
public static BlockTurn turnOf(ObjectRotation rotation, int spinXDegrees, int spinYDegrees, int spinZDegrees) {
|
||||
int spinX = wholeQuarterTurns(spinXDegrees);
|
||||
int spinY = wholeQuarterTurns(spinYDegrees);
|
||||
int spinZ = wholeQuarterTurns(spinZDegrees);
|
||||
return (x, y, z) -> {
|
||||
IrisBlockVector turned = rotation.rotate(new IrisBlockVector(x, y, z), spinX, spinY, spinZ);
|
||||
return new BlockTurn.Direction(turned.getX(), turned.getY(), turned.getZ());
|
||||
};
|
||||
}
|
||||
|
||||
/** {@code direction} turned by {@code turn}. */
|
||||
public static IrisBlockVector turned(BlockTurn turn, double x, double y, double z) {
|
||||
BlockTurn.Direction direction = turn.turn(x, y, z);
|
||||
@@ -130,14 +113,6 @@ public final class BlockStateRotation {
|
||||
|| data instanceof RedstoneWire;
|
||||
}
|
||||
|
||||
/** {@code data}, changed in place, turned by {@code rotation} in whole quarter turns; null when it cannot face the new way. */
|
||||
public static BlockData rotate(ObjectRotation rotation, BlockData data, int spinXDegrees, int spinYDegrees, int spinZDegrees) {
|
||||
if (!rotation.canRotate()) {
|
||||
return data;
|
||||
}
|
||||
return rotate(turnOf(rotation, spinXDegrees, spinYDegrees, spinZDegrees), data);
|
||||
}
|
||||
|
||||
/** {@code data}, changed in place, turned by {@code turn}; null when it cannot face the new way. */
|
||||
public static BlockData rotate(BlockTurn turn, BlockData data) {
|
||||
BlockData d = data;
|
||||
@@ -222,10 +197,6 @@ public final class BlockStateRotation {
|
||||
return d;
|
||||
}
|
||||
|
||||
private static int wholeQuarterTurns(int degrees) {
|
||||
return (int) (QUARTER_TURN_DEGREES * (Math.ceil(Math.abs((degrees % FULL_TURN_DEGREES) / QUARTER_TURN_DEGREES))));
|
||||
}
|
||||
|
||||
private static BlockFace faceOf(IrisBlockVector v) {
|
||||
int x = (int) Math.round(v.getX());
|
||||
int y = (int) Math.round(v.getY());
|
||||
|
||||
@@ -19,14 +19,9 @@
|
||||
package art.arcane.iris.engine.object.prefab;
|
||||
|
||||
import com.volmit.object.PlaceableObject;
|
||||
import art.arcane.iris.builtin.objects.ScaleInterpolation;
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
import com.volmit.object.ScaleMethod;
|
||||
import art.arcane.iris.engine.object.placement.IObjectPlacer;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.engine.object.terrain.carving.CarveResult;
|
||||
import art.arcane.iris.engine.object.value.IrisPosition;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.ModuleObjectPlacement;
|
||||
import art.arcane.iris.core.modules.ObjectGeometry;
|
||||
import art.arcane.iris.core.loader.IrisRegistrant;
|
||||
import art.arcane.volmlib.util.cache.AtomicCache;
|
||||
@@ -41,8 +36,6 @@ import art.arcane.volmlib.util.math.IrisVector;
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
import art.arcane.iris.util.common.plugin.VolmitSender;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.BlockPosition;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.object.GeneratedObject;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
@@ -60,7 +53,6 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
/**
|
||||
* A voxel volume loaded from a .iob file. Instances are loader cached and shared across generation threads, so all
|
||||
@@ -68,8 +60,8 @@ import java.util.function.BiConsumer;
|
||||
* <p>
|
||||
* The heavy behaviour lives in package-private collaborators that read this state directly:
|
||||
* {@link IrisObjectIO} (binary persistence), {@link IrisObjectShaping} (boring, shrinkwrap, block classification),
|
||||
* {@link IrisObjectTransforms} (rotation, scaling, interpolated upscaling) and {@link ModuleObjectPlacement}
|
||||
* (world placement).
|
||||
* {@link IrisObjectTransforms} (rotation, scaling, interpolated upscaling). Placing an object in a world with the
|
||||
* pack's placement rules is the placement stages' job, not this class's.
|
||||
*/
|
||||
@Accessors(chain = true)
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@@ -260,25 +252,37 @@ public class IrisObject extends IrisRegistrant implements PlaceableObject {
|
||||
forgetDerivedShapes();
|
||||
}
|
||||
|
||||
public int place(int x, int z, IObjectPlacer placer, ObjectPlacement config, RNG rng, IrisData rdata) {
|
||||
return place(x, -1, z, placer, config, rng, rdata);
|
||||
}
|
||||
|
||||
public int place(int x, int z, IObjectPlacer placer, ObjectPlacement config, RNG rng, CarveResult c, IrisData rdata) {
|
||||
return place(x, -1, z, placer, config, rng, null, c, rdata);
|
||||
}
|
||||
|
||||
public int place(int x, int yv, int z, IObjectPlacer placer, ObjectPlacement config, RNG rng, IrisData rdata) {
|
||||
return place(x, yv, z, placer, config, rng, null, null, rdata);
|
||||
}
|
||||
|
||||
public int place(Location loc, IObjectPlacer placer, ObjectPlacement config, RNG rng, IrisData rdata) {
|
||||
return place(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), placer, config, rng, rdata);
|
||||
}
|
||||
|
||||
/** The height the object was placed at, or -1 when the placement rejected it. */
|
||||
public int place(int x, int yv, int z, IObjectPlacer oplacer, ObjectPlacement config, RNG rng, BiConsumer<BlockPosition, PlatformBlockState> listener, CarveResult c, IrisData rdata) {
|
||||
return ModuleObjectPlacement.place(this, x, yv, z, oplacer, config, rng, listener, c, rdata).heightOrRejected();
|
||||
/**
|
||||
* Writes the object's blocks and their block entities around ({@code x}, {@code y}, {@code z}) turned by {@code turn},
|
||||
* with no placement rule: the object's own offsets count from that spot, air is left out, and a block that cannot
|
||||
* face the new way is dropped. This is what a paste does; placement rules belong to the placement stages.
|
||||
*
|
||||
* @return how many blocks were written
|
||||
*/
|
||||
public int paste(int x, int y, int z, IObjectPlacer placer, ObjectTurn turn) {
|
||||
int written = 0;
|
||||
readLock.lock();
|
||||
try {
|
||||
for (var entry : blocks) {
|
||||
PlatformBlockState state = BlockStateRotation.rotate(turn, entry.getValue());
|
||||
if (state == null || state.isAir()) {
|
||||
continue;
|
||||
}
|
||||
IrisBlockVector turned = turn.rotate(entry.getKey());
|
||||
int blockX = x + (int) Math.round(turned.getX());
|
||||
int blockY = y + (int) Math.round(turned.getY());
|
||||
int blockZ = z + (int) Math.round(turned.getZ());
|
||||
placer.set(blockX, blockY, blockZ, state);
|
||||
TileData tile = states.get(entry.getKey());
|
||||
if (tile != null) {
|
||||
placer.setTile(blockX, blockY, blockZ, tile);
|
||||
}
|
||||
written++;
|
||||
}
|
||||
} finally {
|
||||
readLock.unlock();
|
||||
}
|
||||
return written;
|
||||
}
|
||||
|
||||
/** This object as IrisApi geometry, read once until its blocks change. */
|
||||
@@ -320,11 +324,11 @@ public class IrisObject extends IrisRegistrant implements PlaceableObject {
|
||||
});
|
||||
}
|
||||
|
||||
public IrisObject rotateCopy(ObjectRotation rt) {
|
||||
return IrisObjectTransforms.rotateCopy(this, rt);
|
||||
public IrisObject rotateCopy(ObjectTurn turn) {
|
||||
return IrisObjectTransforms.rotateCopy(this, turn);
|
||||
}
|
||||
|
||||
public IrisObject scaled(double scale, ScaleInterpolation interpolation) {
|
||||
public IrisObject scaled(double scale, ScaleMethod interpolation) {
|
||||
return IrisObjectTransforms.scaled(this, scale, interpolation);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,7 @@
|
||||
|
||||
package art.arcane.iris.engine.object.prefab;
|
||||
|
||||
import art.arcane.iris.builtin.objects.ScaleInterpolation;
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
import com.volmit.object.ScaleMethod;
|
||||
import art.arcane.iris.engine.object.value.IrisPosition;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.common.data.B;
|
||||
@@ -40,25 +39,25 @@ final class IrisObjectTransforms {
|
||||
private IrisObjectTransforms() {
|
||||
}
|
||||
|
||||
static IrisObject rotateCopy(IrisObject self, ObjectRotation rt) {
|
||||
static IrisObject rotateCopy(IrisObject self, ObjectTurn turn) {
|
||||
IrisObject copy = self.copy();
|
||||
rotate(copy, rt, 0, 0, 0);
|
||||
rotate(copy, turn);
|
||||
return copy;
|
||||
}
|
||||
|
||||
static void rotate(IrisObject self, ObjectRotation r, int spinx, int spiny, int spinz) {
|
||||
static void rotate(IrisObject self, ObjectTurn turn) {
|
||||
self.writeLock.lock();
|
||||
try {
|
||||
VectorMap<PlatformBlockState> d = new VectorMap<>();
|
||||
|
||||
for (var entry : self.blocks) {
|
||||
d.put(r.rotate(entry.getKey(), spinx, spiny, spinz), BlockStateRotation.rotate(r, entry.getValue(), spinx, spiny, spinz));
|
||||
d.put(turn.rotate(entry.getKey()), BlockStateRotation.rotate(turn, entry.getValue()));
|
||||
}
|
||||
|
||||
VectorMap<TileData> dx = new VectorMap<>();
|
||||
|
||||
for (var entry : self.states) {
|
||||
dx.put(r.rotate(entry.getKey(), spinx, spiny, spinz), entry.getValue());
|
||||
dx.put(turn.rotate(entry.getKey()), entry.getValue());
|
||||
}
|
||||
|
||||
self.blocks = d;
|
||||
@@ -70,9 +69,9 @@ final class IrisObjectTransforms {
|
||||
}
|
||||
}
|
||||
|
||||
static IrisObject scaled(IrisObject self, double scale, ScaleInterpolation interpolation) {
|
||||
static IrisObject scaled(IrisObject self, double scale, ScaleMethod interpolation) {
|
||||
if (interpolation == null) {
|
||||
interpolation = ScaleInterpolation.NONE;
|
||||
interpolation = ScaleMethod.NONE;
|
||||
}
|
||||
IrisVector sm1 = new IrisVector(scale - 1, scale - 1, scale - 1);
|
||||
scale = Math.max(0.001, Math.min(50, scale));
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* 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.prefab;
|
||||
|
||||
import art.arcane.iris.engine.object.value.IrisDirection;
|
||||
import art.arcane.iris.engine.object.value.IrisPosition;
|
||||
import art.arcane.volmlib.util.math.IrisBlockVector;
|
||||
import com.volmit.block.BlockTurn;
|
||||
|
||||
/**
|
||||
* How Iris's object model turns an object by fixed angles: positions turn around X, then Z, then Y, and an axis turned by
|
||||
* a multiple of a quarter turn swaps coordinates exactly instead of turning by an angle. The same turn as the built-in
|
||||
* modules' placement rotation locked to these angles, kept in core so the object model does not read module settings.
|
||||
*
|
||||
* @param xDegrees degrees around X; 0 for none
|
||||
* @param yDegrees degrees around Y; 0 for none
|
||||
* @param zDegrees degrees around Z; 0 for none
|
||||
*/
|
||||
public record ObjectTurn(double xDegrees, double yDegrees, double zDegrees) {
|
||||
public static final ObjectTurn NONE = new ObjectTurn(0, 0, 0);
|
||||
|
||||
private static final double QUARTER_TURN_DEGREES = 90;
|
||||
private static final double HALF_TURN_DEGREES = 180;
|
||||
private static final double THREE_QUARTER_TURN_DEGREES = 270;
|
||||
private static final double FULL_TURN_DEGREES = 360;
|
||||
|
||||
public static ObjectTurn of(double xDegrees, double yDegrees, double zDegrees) {
|
||||
return new ObjectTurn(xDegrees, yDegrees, zDegrees);
|
||||
}
|
||||
|
||||
public boolean canRotate() {
|
||||
return xDegrees != 0 || yDegrees != 0 || zDegrees != 0;
|
||||
}
|
||||
|
||||
/** The directions this turn turns, for the facing, axis and connections of block states. */
|
||||
public BlockTurn blockTurn() {
|
||||
return (x, y, z) -> {
|
||||
IrisBlockVector turned = rotate(new IrisBlockVector(x, y, z));
|
||||
return new BlockTurn.Direction(turned.getX(), turned.getY(), turned.getZ());
|
||||
};
|
||||
}
|
||||
|
||||
/** {@code position} turned around X, then Z, then Y; a copy unless nothing turns. */
|
||||
public IrisBlockVector rotate(IrisBlockVector position) {
|
||||
if (!canRotate()) {
|
||||
return position;
|
||||
}
|
||||
IrisBlockVector turned = position.clone();
|
||||
if (xDegrees != 0) {
|
||||
turnAroundX(turned);
|
||||
}
|
||||
if (zDegrees != 0) {
|
||||
turnAroundZ(turned);
|
||||
}
|
||||
if (yDegrees != 0) {
|
||||
turnAroundY(turned);
|
||||
}
|
||||
return turned;
|
||||
}
|
||||
|
||||
public IrisPosition rotate(IrisPosition position) {
|
||||
IrisBlockVector turned = rotate(new IrisBlockVector(position.getX(), position.getY(), position.getZ()));
|
||||
return new IrisPosition(turned.getBlockX(), turned.getBlockY(), turned.getBlockZ());
|
||||
}
|
||||
|
||||
/** The direction closest to {@code direction} turned by this turn. */
|
||||
public IrisDirection rotate(IrisDirection direction) {
|
||||
IrisBlockVector turned = rotate(new IrisBlockVector(direction.x(), direction.y(), direction.z()));
|
||||
double closestDistance = Double.MAX_VALUE;
|
||||
IrisDirection closest = null;
|
||||
for (IrisDirection candidate : IrisDirection.values()) {
|
||||
double distance = new IrisBlockVector(candidate.x(), candidate.y(), candidate.z()).distance(turned);
|
||||
if (distance < closestDistance) {
|
||||
closestDistance = distance;
|
||||
closest = candidate;
|
||||
}
|
||||
}
|
||||
return closest;
|
||||
}
|
||||
|
||||
private void turnAroundX(IrisBlockVector v) {
|
||||
if (Math.abs(xDegrees) % FULL_TURN_DEGREES == HALF_TURN_DEGREES) {
|
||||
v.setZ(-v.getZ());
|
||||
v.setY(-v.getY());
|
||||
} else if (isQuarterTurn(xDegrees)) {
|
||||
double z = v.getZ();
|
||||
v.setZ(v.getY());
|
||||
v.setY(-z);
|
||||
} else if (isThreeQuarterTurn(xDegrees)) {
|
||||
double z = v.getZ();
|
||||
v.setZ(-v.getY());
|
||||
v.setY(z);
|
||||
} else {
|
||||
v.rotateAroundX(radians(xDegrees));
|
||||
}
|
||||
}
|
||||
|
||||
private void turnAroundZ(IrisBlockVector v) {
|
||||
if (Math.abs(zDegrees) % FULL_TURN_DEGREES == HALF_TURN_DEGREES) {
|
||||
v.setY(-v.getY());
|
||||
v.setX(-v.getX());
|
||||
} else if (isQuarterTurn(zDegrees)) {
|
||||
double y = v.getY();
|
||||
v.setY(v.getX());
|
||||
v.setX(-y);
|
||||
} else if (isThreeQuarterTurn(zDegrees)) {
|
||||
double y = v.getY();
|
||||
v.setY(-v.getX());
|
||||
v.setX(y);
|
||||
} else {
|
||||
v.rotateAroundZ(radians(zDegrees));
|
||||
}
|
||||
}
|
||||
|
||||
private void turnAroundY(IrisBlockVector v) {
|
||||
if (Math.abs(yDegrees) % FULL_TURN_DEGREES == HALF_TURN_DEGREES) {
|
||||
v.setX(-v.getX());
|
||||
v.setZ(-v.getZ());
|
||||
} else if (isQuarterTurn(yDegrees)) {
|
||||
double x = v.getX();
|
||||
v.setX(v.getZ());
|
||||
v.setZ(-x);
|
||||
} else if (isThreeQuarterTurn(yDegrees)) {
|
||||
double x = v.getX();
|
||||
v.setX(-v.getZ());
|
||||
v.setZ(x);
|
||||
} else {
|
||||
v.rotateAroundY(radians(yDegrees));
|
||||
}
|
||||
}
|
||||
|
||||
/** The angle in radians a turn by {@code degrees} not on a quarter turn uses: whole degrees, rounded up, without the sign. */
|
||||
private static double radians(double degrees) {
|
||||
return Math.toRadians(Math.ceil(Math.abs(degrees % FULL_TURN_DEGREES)));
|
||||
}
|
||||
|
||||
private static boolean isQuarterTurn(double angle) {
|
||||
return angle % FULL_TURN_DEGREES == QUARTER_TURN_DEGREES || angle % FULL_TURN_DEGREES == -THREE_QUARTER_TURN_DEGREES;
|
||||
}
|
||||
|
||||
private static boolean isThreeQuarterTurn(double angle) {
|
||||
return angle == -QUARTER_TURN_DEGREES || angle % FULL_TURN_DEGREES == THREE_QUARTER_TURN_DEGREES;
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@
|
||||
package art.arcane.iris.engine.object.prefab;
|
||||
|
||||
import art.arcane.iris.builtin.objects.ObjectScale;
|
||||
import art.arcane.iris.builtin.objects.ScaleInterpolation;
|
||||
import com.volmit.object.ScaleMethod;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
@@ -50,7 +50,7 @@ public final class ScaledObjects {
|
||||
* {@code origin} scaled by {@code factor} with {@code interpolation}, even by a factor of 1, which interpolation may
|
||||
* still change; built once per origin, factor and interpolation.
|
||||
*/
|
||||
public static IrisObject scaled(IrisObject origin, double factor, ScaleInterpolation interpolation, Engine engine) {
|
||||
public static IrisObject scaled(IrisObject origin, double factor, ScaleMethod interpolation, Engine engine) {
|
||||
return cachedVariant(new ScaleRequest(factor, factor, factor, NO_VARIATIONS, interpolation), 0, origin, engine);
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ public final class ScaledObjects {
|
||||
}
|
||||
|
||||
record ScaleRequest(double size, double minimumScale, double maximumScale, int variations,
|
||||
ScaleInterpolation interpolation) {
|
||||
ScaleMethod interpolation) {
|
||||
boolean shouldScale() {
|
||||
if (size != 1D) {
|
||||
return true;
|
||||
|
||||
@@ -38,7 +38,6 @@ import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.M;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.volmlib.util.scheduling.PrecisionStopwatch;
|
||||
import art.arcane.iris.builtin.spawn.IrisEntityExtras;
|
||||
import com.volmit.entity.EntitySpec;
|
||||
import com.volmit.item.ItemAttribute;
|
||||
import com.volmit.resource.ContentKey;
|
||||
@@ -104,18 +103,18 @@ public final class BukkitEntitySpawner {
|
||||
if (!Chunks.isSafe(at)) {
|
||||
return null;
|
||||
}
|
||||
IrisEntityExtras extras = spec.extension(IrisEntityExtras.class).orElse(IrisEntityExtras.NONE);
|
||||
if (extras.riseOutOfGround()) {
|
||||
boolean risesFromGround = spec.arrival().risesFromGround();
|
||||
if (risesFromGround) {
|
||||
at = startBelowGroundWhenWatched(at);
|
||||
}
|
||||
|
||||
Entity ee = doSpawn(spec, extras, at);
|
||||
Entity ee = doSpawn(spec, at);
|
||||
|
||||
if (ee == null && !Chunks.isSafe(at)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (spec.type() instanceof ContentKey.Provided && !extras.applySettingsToProvidedMob()) {
|
||||
if (spec.type() instanceof ContentKey.Provided && !spec.adjustsProvidedMob()) {
|
||||
return ee;
|
||||
}
|
||||
|
||||
@@ -146,8 +145,8 @@ public final class BukkitEntitySpawner {
|
||||
}
|
||||
|
||||
if (e instanceof Panda panda) {
|
||||
panda.setMainGene(resolveGene(extras.pandaMainGene().orElse(null)));
|
||||
panda.setHiddenGene(resolveGene(extras.pandaHiddenGene().orElse(null)));
|
||||
panda.setMainGene(resolveGene(spec.appearance().pandaMainGene().orElse(null)));
|
||||
panda.setHiddenGene(resolveGene(spec.appearance().pandaHiddenGene().orElse(null)));
|
||||
}
|
||||
|
||||
if (e instanceof Villager villager) {
|
||||
@@ -165,7 +164,7 @@ public final class BukkitEntitySpawner {
|
||||
|
||||
Location riseFrom = at;
|
||||
J.runEntity(e, () -> {
|
||||
if (extras.riseOutOfGround() && e instanceof LivingEntity living && Chunks.hasPlayersNearby(riseFrom)) {
|
||||
if (risesFromGround && e instanceof LivingEntity living && Chunks.hasPlayersNearby(riseFrom)) {
|
||||
riseOutOfGround(e, living, riseFrom);
|
||||
}
|
||||
});
|
||||
@@ -293,7 +292,7 @@ public final class BukkitEntitySpawner {
|
||||
EntityRiseSVC.clearStamp(entity);
|
||||
}
|
||||
|
||||
private static Entity doSpawn(EntitySpec spec, IrisEntityExtras extras, Location at) {
|
||||
private static Entity doSpawn(EntitySpec spec, Location at) {
|
||||
if (!Chunks.isSafe(at)) {
|
||||
return null;
|
||||
}
|
||||
@@ -308,7 +307,7 @@ public final class BukkitEntitySpawner {
|
||||
AtomicReference<Entity> ae = new AtomicReference<>();
|
||||
|
||||
try {
|
||||
if (!J.runAt(at, () -> ae.set(doSpawn(spec, extras, at)))) {
|
||||
if (!J.runAt(at, () -> ae.set(doSpawn(spec, at)))) {
|
||||
return null;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
@@ -331,7 +330,7 @@ public final class BukkitEntitySpawner {
|
||||
return IrisServices.get(ExternalDataSVC.class).spawnMob(at, new Identifier(mob.provider(), mob.name()));
|
||||
}
|
||||
|
||||
return BukkitPlatform.spawnEntity(at, bukkitType(spec), bukkitReason(extras));
|
||||
return BukkitPlatform.spawnEntity(at, bukkitType(spec), bukkitReason(spec));
|
||||
}
|
||||
|
||||
/** The platform's entity type of the spec, unknown for a provider's mob or a type the platform lacks. */
|
||||
@@ -343,8 +342,8 @@ public final class BukkitEntitySpawner {
|
||||
return entityType == null ? EntityType.UNKNOWN : entityType;
|
||||
}
|
||||
|
||||
private static CreatureSpawnEvent.SpawnReason bukkitReason(IrisEntityExtras extras) {
|
||||
String reason = extras.reason().orElse("");
|
||||
private static CreatureSpawnEvent.SpawnReason bukkitReason(EntitySpec spec) {
|
||||
String reason = spec.arrival().reason().orElse("");
|
||||
if (reason.isBlank()) {
|
||||
return CreatureSpawnEvent.SpawnReason.NATURAL;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ import art.arcane.iris.engine.framework.GenerationSessionLease;
|
||||
import art.arcane.iris.engine.framework.Locator;
|
||||
import art.arcane.iris.core.modules.ModuleServices;
|
||||
import art.arcane.iris.core.modules.PlatformBlockStates;
|
||||
import art.arcane.iris.builtin.loot.LootResolver;
|
||||
import art.arcane.iris.platform.bukkit.BukkitItemStacks;
|
||||
import art.arcane.iris.engine.framework.WrongEngineBroException;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
@@ -444,7 +443,7 @@ public final class EngineBukkitOps {
|
||||
inv.addItem(i);
|
||||
}
|
||||
|
||||
scramble(engine, inv, LootResolver.containerRng(engine.getSeedManager().getLoot(), x, y, z));
|
||||
scrambleAsModulesSay(engine, inv, x, y, z);
|
||||
};
|
||||
|
||||
LootMutationTask task = new LootMutationTask(world, x >> 4, z >> 4, mutation);
|
||||
@@ -468,10 +467,16 @@ public final class EngineBukkitOps {
|
||||
inv.addItem(i);
|
||||
}
|
||||
|
||||
scramble(engine, inv, LootResolver.containerRng(engine.getSeedManager().getLoot(), x, y, z));
|
||||
scrambleAsModulesSay(engine, inv, x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
/** Shuffles the container's slots with the seed the modules give for the container at the spot; unshuffled when none does. */
|
||||
private static void scrambleAsModulesSay(Engine engine, Inventory inv, int x, int y, int z) {
|
||||
Loot.Site site = new Loot.Site(new BlockPosition(x, y - engine.getMinHeight(), z), Optional.empty(), false, false);
|
||||
ModuleServices.lootShuffleSeed(engine, site).ifPresent(seed -> scramble(engine, inv, new RNG(seed)));
|
||||
}
|
||||
|
||||
/** The items of {@code tables} at the spot, in the tables' order: the modules' for pack tables, the platform's own for platform tables. */
|
||||
private static List<ItemStack> lootItems(Engine engine, boolean debug, List<Loot.Source> tables, World world, int x, int y, int z) {
|
||||
Loot.Site site = new Loot.Site(new BlockPosition(x, y - engine.getMinHeight(), z), Optional.empty(), false, debug);
|
||||
|
||||
+8
-8
@@ -20,7 +20,7 @@ import art.arcane.iris.engine.object.value.IrisDirection;
|
||||
import art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawConnector;
|
||||
import art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawPiece;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
import art.arcane.iris.engine.object.prefab.ObjectTurn;
|
||||
import art.arcane.iris.engine.object.prefab.BlockStateRotation;
|
||||
import art.arcane.iris.engine.object.value.IrisPosition;
|
||||
import art.arcane.iris.engine.object.structure.jigsaw.JigsawJoint;
|
||||
@@ -463,7 +463,7 @@ public final class JigsawStudioGenerator extends EnginedStudioGenerator {
|
||||
"object '" + variant.objectKey() + "' does not fit workcell '" + workcell.stableId() + "'");
|
||||
}
|
||||
|
||||
ObjectRotation rotation = ObjectRotation.of(0, -90.0D * quarterTurns, 0);
|
||||
ObjectTurn rotation = ObjectTurn.of(0, -90.0D * quarterTurns, 0);
|
||||
List<RenderedBlock> blocks = renderBlocks(object, dimensions, quarterTurns, rotation);
|
||||
if (blocks == null) {
|
||||
return RenderedBay.invalid(
|
||||
@@ -482,7 +482,7 @@ public final class JigsawStudioGenerator extends EnginedStudioGenerator {
|
||||
IrisObject object,
|
||||
JigsawStudioCellDimensions dimensions,
|
||||
int quarterTurns,
|
||||
ObjectRotation rotation
|
||||
ObjectTurn rotation
|
||||
) {
|
||||
VectorMap<PlatformBlockState> sourceBlocks = object.getBlocks();
|
||||
VectorMap<TileData> sourceTiles = object.getStates();
|
||||
@@ -514,7 +514,7 @@ public final class JigsawStudioGenerator extends EnginedStudioGenerator {
|
||||
}
|
||||
PlatformBlockState blockState = quarterTurns == 0
|
||||
? entry.getValue()
|
||||
: BlockStateRotation.rotate(rotation, entry.getValue(), 0, 0, 0);
|
||||
: BlockStateRotation.rotate(rotation, entry.getValue());
|
||||
if (blockState == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -534,7 +534,7 @@ public final class JigsawStudioGenerator extends EnginedStudioGenerator {
|
||||
IrisObject object,
|
||||
JigsawStudioCellDimensions dimensions,
|
||||
int quarterTurns,
|
||||
ObjectRotation rotation
|
||||
ObjectTurn rotation
|
||||
) {
|
||||
KList<IrisJigsawConnector> sourceConnectors = piece.getConnectors();
|
||||
if (sourceConnectors == null) {
|
||||
@@ -603,7 +603,7 @@ public final class JigsawStudioGenerator extends EnginedStudioGenerator {
|
||||
|
||||
private static String rotatedFinalState(
|
||||
String finalState,
|
||||
ObjectRotation rotation,
|
||||
ObjectTurn rotation,
|
||||
int quarterTurns
|
||||
) {
|
||||
PlatformBlockState state = B.getStateOrNull(finalState, false);
|
||||
@@ -613,7 +613,7 @@ public final class JigsawStudioGenerator extends EnginedStudioGenerator {
|
||||
if (quarterTurns == 0) {
|
||||
return state.key();
|
||||
}
|
||||
PlatformBlockState rotated = BlockStateRotation.rotate(rotation, state, 0, 0, 0);
|
||||
PlatformBlockState rotated = BlockStateRotation.rotate(rotation, state);
|
||||
return rotated == null ? null : rotated.key();
|
||||
}
|
||||
|
||||
@@ -922,7 +922,7 @@ public final class JigsawStudioGenerator extends EnginedStudioGenerator {
|
||||
|
||||
@FunctionalInterface
|
||||
interface FinalStateRenderer {
|
||||
String render(String finalState, ObjectRotation rotation, int quarterTurns);
|
||||
String render(String finalState, ObjectTurn rotation, int quarterTurns);
|
||||
}
|
||||
|
||||
record RotatedPosition(int x, int y, int z) {
|
||||
|
||||
+5
-56
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Servers
|
||||
* Copyright (c) 2026 Arcane Arts (Volmit Software)
|
||||
* 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
|
||||
@@ -18,64 +18,13 @@
|
||||
|
||||
package art.arcane.iris.util.common.director.specialhandlers;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.PackModulesException;
|
||||
import art.arcane.iris.core.pack.PackDirectoryResolver;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.util.common.director.DirectorParameterHandler;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.director.exceptions.DirectorParsingException;
|
||||
import com.volmit.resource.ResourceId;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/** The key of an entity of a pack: the open pack's, then those of the packs in the packs folder. */
|
||||
public final class EntityKeyHandler implements DirectorParameterHandler<String> {
|
||||
// iris:spawn's entity kind, named by id: its constant and its class ship only in the built-ins jar, which the
|
||||
// plugin's own classes cannot reach.
|
||||
public final class EntityKeyHandler extends PackResourceKeyHandler {
|
||||
private static final ResourceId ENTITIES = ResourceId.parse("iris:spawn/entity");
|
||||
|
||||
@Override
|
||||
public KList<String> getPossibilities() {
|
||||
Set<String> keys = new LinkedHashSet<>();
|
||||
IrisData activeData = data();
|
||||
if (activeData != null) {
|
||||
addEntityKeys(keys, activeData);
|
||||
}
|
||||
for (File pack : PackDirectoryResolver.listVisiblePackDirectories(
|
||||
IrisPlatforms.get().packsFolder())) {
|
||||
addEntityKeys(keys, IrisData.get(pack));
|
||||
}
|
||||
return new KList<>(keys);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(String value) {
|
||||
return value == null ? "" : value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parse(String input, boolean force) throws DirectorParsingException {
|
||||
for (String option : getPossibilities(input)) {
|
||||
if (option.equalsIgnoreCase(input)) {
|
||||
return option;
|
||||
}
|
||||
}
|
||||
throw new DirectorParsingException("Unable to find Entity \"" + input + "\"");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(Class<?> type) {
|
||||
return type == String.class;
|
||||
}
|
||||
|
||||
/** A pack whose modules fail to load has no entities to offer; its failure was reported when it loaded. */
|
||||
private static void addEntityKeys(Set<String> keys, IrisData data) {
|
||||
try {
|
||||
data.getPackResources().ids(ENTITIES).forEach(id -> keys.add(id.path()));
|
||||
} catch (PackModulesException ignored) {
|
||||
}
|
||||
public EntityKeyHandler() {
|
||||
super(ENTITIES, "Entity");
|
||||
}
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package art.arcane.iris.util.common.director.specialhandlers;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.PackModulesException;
|
||||
import art.arcane.iris.core.pack.PackDirectoryResolver;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.util.common.director.DirectorParameterHandler;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.director.exceptions.DirectorParsingException;
|
||||
import com.volmit.resource.ResourceId;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* The keys of one kind of pack resources a module declares, named by the kind's id, offered to a command parameter: the
|
||||
* open pack's, then those of the packs in the packs folder. A subclass names the kind and what a command calls one of
|
||||
* its resources; Iris needs no class of the module for it.
|
||||
*/
|
||||
public abstract class PackResourceKeyHandler implements DirectorParameterHandler<String> {
|
||||
private final ResourceId kind;
|
||||
private final String noun;
|
||||
|
||||
/**
|
||||
* @param kind the kind's id, such as {@code iris:spawn/entity}
|
||||
* @param noun what the kind's resources are called in the error for a key that no pack has, such as {@code Entity}
|
||||
*/
|
||||
protected PackResourceKeyHandler(ResourceId kind, String noun) {
|
||||
this.kind = kind;
|
||||
this.noun = noun;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KList<String> getPossibilities() {
|
||||
Set<String> keys = new LinkedHashSet<>();
|
||||
IrisData activeData = data();
|
||||
if (activeData != null) {
|
||||
addKeys(keys, activeData);
|
||||
}
|
||||
for (File pack : PackDirectoryResolver.listVisiblePackDirectories(
|
||||
IrisPlatforms.get().packsFolder())) {
|
||||
addKeys(keys, IrisData.get(pack));
|
||||
}
|
||||
return new KList<>(keys);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(String value) {
|
||||
return value == null ? "" : value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parse(String input, boolean force) throws DirectorParsingException {
|
||||
for (String option : getPossibilities(input)) {
|
||||
if (option.equalsIgnoreCase(input)) {
|
||||
return option;
|
||||
}
|
||||
}
|
||||
throw new DirectorParsingException("Unable to find " + noun + " \"" + input + "\"");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(Class<?> type) {
|
||||
return type == String.class;
|
||||
}
|
||||
|
||||
/** A pack whose modules fail to load has no resources to offer; its failure was reported when it loaded. */
|
||||
private void addKeys(Set<String> keys, IrisData data) {
|
||||
try {
|
||||
data.getPackResources().ids(kind).forEach(id -> keys.add(id.path()));
|
||||
} catch (PackModulesException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user