mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-30 01:34:04 +00:00
Place with iris:objects placement settings
IrisObjectPlacement, IrisObjectTranslate and IPostBlockAccess are gone; Iris places with the module's ObjectPlacement. IrisPlacementForm keeps what Iris makes of a placement (its module settings decoded from the placement's JSON, its noise as Iris generators, the surface warp cache) on the placement's host slot. The placement reader decodes through the module decoder. IrisObjectRotation becomes BlockStateRotation (state turning only) and IrisObjectScale becomes ScaledObjects. Studio adds placement-level module settings to the module's ObjectPlacement schema. The procedural golden digests change only because the hashed options JSON no longer carries the Iris-only warp cacheSize; a probe on the previous commit and this one gave identical block digests and identical option values otherwise.
This commit is contained in:
1 parent
74b129e105
commit
e47acc847d
90 files changed
+1375
-2154
No files matched your search
@@ -23,6 +23,8 @@ import art.arcane.iris.builtin.floating.IslandAnchor;
|
||||
import art.arcane.iris.builtin.floating.IslandFootprint;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.PlaceableObject;
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
import art.arcane.iris.builtin.prepare.ObjectTranslate;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.mantle.MantleWriter;
|
||||
@@ -30,13 +32,9 @@ import art.arcane.iris.engine.mantle.components.FloatingObjectPlacementTransacti
|
||||
import art.arcane.iris.engine.mantle.components.IslandAnchorPlacer;
|
||||
import art.arcane.iris.engine.object.placement.FloatingObjectFootprint;
|
||||
import art.arcane.iris.engine.object.placement.IObjectPlacer;
|
||||
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
|
||||
import art.arcane.iris.engine.object.placement.ObjectPlacements;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectRotation;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectScale;
|
||||
import art.arcane.iris.engine.object.prefab.ScaledObjects;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectShaping;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectTranslate;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.biome.custom.IrisBiomeCustom;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
@@ -49,21 +47,19 @@ import com.volmit.ModuleLog;
|
||||
import com.volmit.generation.InvocationContext;
|
||||
import com.volmit.resource.ResourceId;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Iris's answers to {@code iris:floating}: a biome's terrain height by its generators, sky biomes into the engine's
|
||||
* mantle, and floating objects placed by Iris's own object placement into the mantle chunk being generated.
|
||||
*/
|
||||
final class IrisFloatingHost implements FloatingHost {
|
||||
private static final IrisObjectRotation NO_ROTATION = IrisObjectRotation.of(0, 0, 0);
|
||||
private static final ObjectRotation NO_ROTATION = ObjectRotation.of(0, 0, 0);
|
||||
private static final int FLOATING_OBJECT_Y = -1;
|
||||
|
||||
private final Engine engine;
|
||||
private final ModuleLog log;
|
||||
private final Map<Double, IrisObjectScale> shrinkScales = new ConcurrentHashMap<>();
|
||||
|
||||
IrisFloatingHost(Engine engine, ModuleLog log) {
|
||||
this.engine = engine;
|
||||
@@ -104,14 +100,7 @@ final class IrisFloatingHost implements FloatingHost {
|
||||
|
||||
@Override
|
||||
public Optional<PlaceableObject> shrink(PlaceableObject object, double factor, RNG random) {
|
||||
IrisObjectScale scale = shrinkScales.computeIfAbsent(factor, IrisFloatingHost::scaleOf);
|
||||
return Optional.ofNullable(scale.get(random, (IrisObject) object, engine));
|
||||
}
|
||||
|
||||
private static IrisObjectScale scaleOf(double factor) {
|
||||
IrisObjectScale scale = new IrisObjectScale();
|
||||
scale.setSize(factor);
|
||||
return scale;
|
||||
return Optional.ofNullable(ScaledObjects.resized((IrisObject) object, factor, random, engine));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -119,7 +108,7 @@ final class IrisFloatingHost implements FloatingHost {
|
||||
RNG random) {
|
||||
IrisObject placed = (IrisObject) object;
|
||||
IrisData data = engine.getData();
|
||||
IrisObjectPlacement floating = ObjectPlacements.host(placement, data).toPlacement(placed.getLoadKey());
|
||||
ObjectPlacement floating = placement.toBuilder().place(List.of(placed.getLoadKey())).build();
|
||||
MantleWriter writer = writerOf(context);
|
||||
int id = random.i(0, Integer.MAX_VALUE);
|
||||
try {
|
||||
@@ -139,7 +128,7 @@ final class IrisFloatingHost implements FloatingHost {
|
||||
@Override
|
||||
public void placeUnder(InvocationContext context, PlaceableObject object, int worldX, int y, int worldZ, int yRotation,
|
||||
ObjectPlacement placement, IslandAnchor anchor, RNG random) {
|
||||
placeAgainstIsland(writerOf(context), (IrisObject) object, worldX, y, worldZ, placement, IrisObjectRotation.xFlip180WithY(yRotation),
|
||||
placeAgainstIsland(writerOf(context), (IrisObject) object, worldX, y, worldZ, placement, ObjectRotation.xFlip180WithY(yRotation),
|
||||
anchor, random, "inverted");
|
||||
}
|
||||
|
||||
@@ -149,14 +138,16 @@ final class IrisFloatingHost implements FloatingHost {
|
||||
|
||||
/** Places the object through a transaction that writes nothing unless every block lands where the anchor allows. */
|
||||
private void placeAgainstIsland(MantleWriter writer, IrisObject object, int worldX, int y, int worldZ, ObjectPlacement placement,
|
||||
IrisObjectRotation rotation, IslandAnchor anchor, RNG random, String kind) {
|
||||
ObjectRotation rotation, IslandAnchor anchor, RNG random, String kind) {
|
||||
IrisData data = engine.getData();
|
||||
IrisObjectPlacement anchored = ObjectPlacements.host(placement, data).toPlacement(object.getLoadKey());
|
||||
anchored.setMode(anchored.getMode().onFloatingIsland());
|
||||
anchored.setTranslate(new IrisObjectTranslate());
|
||||
anchored.setRotation(rotation);
|
||||
anchored.setForcePlace(true);
|
||||
anchored.setBottom(false);
|
||||
ObjectPlacement anchored = placement.toBuilder()
|
||||
.place(List.of(object.getLoadKey()))
|
||||
.mode(placement.mode().onFloatingIsland())
|
||||
.translate(new ObjectTranslate())
|
||||
.rotation(rotation)
|
||||
.forcePlace(true)
|
||||
.bottom(false)
|
||||
.build();
|
||||
|
||||
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(
|
||||
new IslandAnchorPlacer(writer, anchor));
|
||||
|
||||
@@ -30,6 +30,7 @@ import art.arcane.iris.builtin.objects.PlacementSource;
|
||||
import art.arcane.iris.builtin.objects.PlacementTags;
|
||||
import art.arcane.iris.builtin.objects.ProceduralPlacement;
|
||||
import art.arcane.iris.builtin.prepare.AxisRotationClamp;
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.TreeBlockMaterial;
|
||||
import art.arcane.iris.engine.mantle.MantleWriter;
|
||||
@@ -37,10 +38,7 @@ import art.arcane.iris.engine.mantle.components.CaveObjectPlacementTransaction;
|
||||
import art.arcane.iris.engine.mantle.components.GoldenDebugObjectPlacer;
|
||||
import art.arcane.iris.engine.object.placement.DecayControlPlacer;
|
||||
import art.arcane.iris.engine.object.placement.IObjectPlacer;
|
||||
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
|
||||
import art.arcane.iris.engine.object.placement.ObjectPlacements;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectRotation;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.common.data.B;
|
||||
import art.arcane.volmlib.util.math.BlockPosition;
|
||||
@@ -61,9 +59,9 @@ final class IrisObjectChunk implements ObjectChunk {
|
||||
private final Engine engine;
|
||||
private final MantleWriter writer;
|
||||
private final ModuleLog log;
|
||||
private final Function<ProceduralPlacement, IrisObjectPlacement> proceduralOptions;
|
||||
private final Function<ProceduralPlacement, ObjectPlacement> proceduralOptions;
|
||||
|
||||
IrisObjectChunk(Engine engine, MantleWriter writer, ModuleLog log, Function<ProceduralPlacement, IrisObjectPlacement> proceduralOptions) {
|
||||
IrisObjectChunk(Engine engine, MantleWriter writer, ModuleLog log, Function<ProceduralPlacement, ObjectPlacement> proceduralOptions) {
|
||||
this.engine = engine;
|
||||
this.writer = writer;
|
||||
this.log = log;
|
||||
@@ -102,7 +100,7 @@ final class IrisObjectChunk implements ObjectChunk {
|
||||
@Override
|
||||
public int placeOnSurface(PlaceableObject object, int x, int z, PlacementSource placement, PlacementChanges changes,
|
||||
PlacementTags tags, RNG rng, String goldenTag) {
|
||||
IrisObjectPlacement effective = effective(placement, changes);
|
||||
ObjectPlacement effective = effective(placement, changes);
|
||||
IObjectPlacer base = placement instanceof ProceduralPlacement procedural && procedural.plausible()
|
||||
? new DecayControlPlacer(writer) : writer;
|
||||
IObjectPlacer placer = goldenTag == null ? base : new GoldenDebugObjectPlacer(base, goldenTag, log);
|
||||
@@ -113,12 +111,12 @@ final class IrisObjectChunk implements ObjectChunk {
|
||||
@Override
|
||||
public CavePlacement placeInCave(PlaceableObject object, int x, int anchorY, int z, PlacementSource placement, PlacementChanges changes,
|
||||
int minDepthBelowSurface, PlacementTags tags, RNG rng, String goldenTag) {
|
||||
IrisObjectPlacement effective = effective(placement, changes);
|
||||
ObjectPlacement effective = effective(placement, changes);
|
||||
IrisObject irisObject = (IrisObject) object;
|
||||
IObjectPlacer placer = caveBase(placement, goldenTag);
|
||||
CaveObjectPlacementTransaction transaction = new CaveObjectPlacementTransaction(placer, anchorY, minDepthBelowSurface);
|
||||
int placeY = anchorY;
|
||||
if (effective.getMode().placeMode().has(PlaceTrait.UPSIDE_DOWN)) {
|
||||
if (effective.mode().placeMode().has(PlaceTrait.UPSIDE_DOWN)) {
|
||||
placeY = Math.max(1, transaction.getCaveCeiling(x, z) - 1 - Math.floorDiv(irisObject.getH(), 2));
|
||||
}
|
||||
int result = irisObject.place(x, placeY, z, transaction, effective, rng, taggedBlocks(transaction, tags), null, engine.getData());
|
||||
@@ -132,7 +130,7 @@ final class IrisObjectChunk implements ObjectChunk {
|
||||
@Override
|
||||
public int placeUpper(PlaceableObject object, int x, int anchorY, int z, ObjectPlacement placement, PlacementChanges changes,
|
||||
PlacementTags tags, RNG rng) {
|
||||
IrisObjectPlacement effective = effective(placement, changes);
|
||||
ObjectPlacement effective = effective(placement, changes);
|
||||
return ((IrisObject) object).place(x, anchorY, z, writer, effective, rng, taggedBlocks(writer, tags), null, engine.getData());
|
||||
}
|
||||
|
||||
@@ -167,48 +165,48 @@ final class IrisObjectChunk implements ObjectChunk {
|
||||
};
|
||||
}
|
||||
|
||||
/** Iris's placement for {@code placement}, with {@code changes} made to a copy of it. */
|
||||
private IrisObjectPlacement effective(PlacementSource placement, PlacementChanges changes) {
|
||||
IrisObjectPlacement base = placement instanceof ObjectPlacement settings
|
||||
? ObjectPlacements.host(settings, engine.getData())
|
||||
/** The placement {@code placement} places with, with {@code changes} made to a copy of it. */
|
||||
private ObjectPlacement effective(PlacementSource placement, PlacementChanges changes) {
|
||||
ObjectPlacement base = placement instanceof ObjectPlacement settings
|
||||
? settings
|
||||
: proceduralOptions.apply((ProceduralPlacement) placement);
|
||||
return withChanges(base, changes);
|
||||
}
|
||||
|
||||
/** {@code base} with {@code changes} made to a copy of it; {@code base} itself when there are none. */
|
||||
static IrisObjectPlacement withChanges(IrisObjectPlacement base, PlacementChanges changes) {
|
||||
static ObjectPlacement withChanges(ObjectPlacement base, PlacementChanges changes) {
|
||||
if (changes.isNone()) {
|
||||
return base;
|
||||
}
|
||||
String[] keys = (changes.place() == null ? base.getPlace() : changes.place()).toArray(new String[0]);
|
||||
IrisObjectPlacement changed = base.toPlacement(keys);
|
||||
ObjectPlacement.Builder changed = base.toBuilder();
|
||||
if (changes.place() != null) {
|
||||
changed.place(changes.place());
|
||||
}
|
||||
if (changes.mode() != null) {
|
||||
changed.setMode(changes.mode());
|
||||
changed.mode(changes.mode());
|
||||
}
|
||||
if (changes.upsideDown() != null && changes.upsideDown()) {
|
||||
changed.setRotation(upsideDownRotation());
|
||||
changed.rotation(upsideDownRotation());
|
||||
}
|
||||
if (changes.carvingSupport() != null) {
|
||||
changed.setCarvingSupport(changes.carvingSupport());
|
||||
changed.carvingSupport(changes.carvingSupport());
|
||||
}
|
||||
if (changes.requireSurfaceSupport() != null) {
|
||||
changed.setRequireSurfaceSupport(changes.requireSurfaceSupport());
|
||||
changed.requireSurfaceSupport(changes.requireSurfaceSupport());
|
||||
}
|
||||
if (changes.surfaceSupportBuffer() != null) {
|
||||
changed.setSurfaceSupportBuffer(changes.surfaceSupportBuffer());
|
||||
changed.surfaceSupportBuffer(changes.surfaceSupportBuffer());
|
||||
}
|
||||
if (changes.forcePlace() != null) {
|
||||
changed.setForcePlace(changes.forcePlace());
|
||||
changed.forcePlace(changes.forcePlace());
|
||||
}
|
||||
return changed;
|
||||
return changed.build();
|
||||
}
|
||||
|
||||
private static IrisObjectRotation upsideDownRotation() {
|
||||
IrisObjectRotation rotation = new IrisObjectRotation();
|
||||
rotation.setEnabled(true);
|
||||
rotation.setXAxis(AxisRotationClamp.of(true, true, UPSIDE_DOWN_TURN_DEGREES, UPSIDE_DOWN_TURN_DEGREES, QUARTER_TURN_DEGREES));
|
||||
rotation.setYAxis(AxisRotationClamp.of(true, false, 0D, 0D, QUARTER_TURN_DEGREES));
|
||||
rotation.setZAxis(new AxisRotationClamp());
|
||||
return rotation;
|
||||
private static ObjectRotation upsideDownRotation() {
|
||||
return ObjectRotation.of(true,
|
||||
AxisRotationClamp.of(true, true, UPSIDE_DOWN_TURN_DEGREES, UPSIDE_DOWN_TURN_DEGREES, QUARTER_TURN_DEGREES),
|
||||
AxisRotationClamp.of(true, false, 0D, 0D, QUARTER_TURN_DEGREES),
|
||||
new AxisRotationClamp());
|
||||
}
|
||||
}
|
||||
@@ -31,9 +31,10 @@ import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.loader.IrisRegistrant;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.PlacedObject;
|
||||
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
|
||||
import art.arcane.iris.engine.object.placement.IrisPlacementForm;
|
||||
import art.arcane.iris.engine.object.placement.ObjectPlacements;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.engine.object.prefab.ScaledObjects;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
import art.arcane.iris.util.project.noise.CNG;
|
||||
@@ -62,7 +63,7 @@ final class IrisObjectHost implements ObjectHost {
|
||||
private final Engine engine;
|
||||
private final ModuleLog log;
|
||||
private volatile PackResourceIds ids;
|
||||
private final Map<ProceduralPlacement, IrisObjectPlacement> proceduralOptions = new ConcurrentHashMap<>();
|
||||
private final Map<ProceduralPlacement, ObjectPlacement> proceduralOptions = new ConcurrentHashMap<>();
|
||||
|
||||
IrisObjectHost(Engine engine, ModuleLog log) {
|
||||
this.engine = engine;
|
||||
@@ -103,14 +104,13 @@ final class IrisObjectHost implements ObjectHost {
|
||||
|
||||
@Override
|
||||
public Optional<PlaceableObject> pickScaled(ObjectPlacement placement, RNG rng) {
|
||||
IrisObjectPlacement host = hostPlacement(placement);
|
||||
IrisObject picked = host.getObject(engine.getComplex(), rng);
|
||||
return Optional.ofNullable(host.getScale().get(rng, picked, engine));
|
||||
IrisObject picked = ObjectPlacements.pickObject(placement, engine.getData(), rng);
|
||||
return Optional.ofNullable(ScaledObjects.variant(placement.scale(), rng, picked, engine));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int density(ObjectPlacement placement, RNG rng, double x, double z) {
|
||||
return hostPlacement(placement).getDensity(rng, x, z, engine.getData());
|
||||
return formOf(placement).density(placement, rng, x, z, engine.getData());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -129,9 +129,9 @@ final class IrisObjectHost implements ObjectHost {
|
||||
|
||||
@Override
|
||||
public void warm(ObjectPlacement placement, RNG rng) {
|
||||
IrisObjectPlacement host = hostPlacement(placement);
|
||||
host.getSurfaceWarp(rng, engine.getData(), engine);
|
||||
host.getDensity(rng, 0, 0, engine.getData());
|
||||
IrisPlacementForm form = formOf(placement);
|
||||
form.surfaceWarp(rng, engine.getData(), engine);
|
||||
form.density(placement, rng, 0, 0, engine.getData());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -139,25 +139,25 @@ final class IrisObjectHost implements ObjectHost {
|
||||
return new IrisObjectBuilder(engine.getData());
|
||||
}
|
||||
|
||||
/** The options {@code placement} is scattered with, as Iris's own placement, made once per placement. */
|
||||
IrisObjectPlacement options(ProceduralPlacement placement) {
|
||||
/** The options {@code placement} is scattered with, as an object placement, made once per placement. */
|
||||
ObjectPlacement options(ProceduralPlacement placement) {
|
||||
return proceduralOptions.computeIfAbsent(placement, ProceduralOptions::of);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int placeInto(PlaceableObject object, int x, int y, int z, ObjectPlacement placement, ObjectSink sink, RNG rng) {
|
||||
IrisData data = engine.getData();
|
||||
return ((IrisObject) object).place(x, y, z, new SinkPlacer(engine, sink), hostPlacement(placement), rng, data);
|
||||
return ((IrisObject) object).place(x, y, z, new SinkPlacer(engine, sink), placement, rng, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ObjectLoots> placedLoot(int x, int y, int z) {
|
||||
PlacedObject placed = engine.getObjectPlacement(x, y, z);
|
||||
IrisObjectPlacement placement = placed == null ? null : placed.getPlacement();
|
||||
ObjectPlacement placement = placed == null ? null : placed.getPlacement();
|
||||
if (placement == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(new ObjectLoots(placement.getLoot(), placement.getVanillaLoot(), placement.isOverrideGlobalLoot()));
|
||||
return Optional.of(new ObjectLoots(placement.loot(), placement.vanillaLoot(), placement.overrideGlobalLoot()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -179,7 +179,7 @@ final class IrisObjectHost implements ObjectHost {
|
||||
owner.getModuleSettings().find(type).ifPresent(settings -> found.add(new Declaration<>(level, ids().of(owner.getLoadKey()), settings)));
|
||||
}
|
||||
|
||||
private IrisObjectPlacement hostPlacement(ObjectPlacement placement) {
|
||||
return ObjectPlacements.host(placement, engine.getData());
|
||||
private IrisPlacementForm formOf(ObjectPlacement placement) {
|
||||
return IrisPlacementForm.of(placement, engine.getData());
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,8 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectRotation;
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
import art.arcane.iris.engine.object.prefab.BlockStateRotation;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.volmlib.util.math.IrisBlockVector;
|
||||
@@ -36,7 +37,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Transforms geometry with the rotation Iris places objects with ({@link IrisObjectRotation}, its axis order
|
||||
* Transforms geometry with the rotation Iris places objects with ({@link ObjectRotation}, 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
|
||||
@@ -100,7 +101,7 @@ final class IrisObjectTransformer implements ObjectTransformer {
|
||||
private final boolean mirrorX;
|
||||
private final boolean mirrorY;
|
||||
private final boolean mirrorZ;
|
||||
private final IrisObjectRotation rotation;
|
||||
private final ObjectRotation rotation;
|
||||
private final PlatformBlockStates states = new PlatformBlockStates(key -> IrisPlatforms.get().registries().block(key));
|
||||
|
||||
Turn(BlockPosition anchor, ObjectTransform transform) {
|
||||
@@ -108,7 +109,7 @@ final class IrisObjectTransformer implements ObjectTransformer {
|
||||
this.mirrorX = transform.mirrorX();
|
||||
this.mirrorY = transform.mirrorY();
|
||||
this.mirrorZ = transform.mirrorZ();
|
||||
this.rotation = IrisObjectRotation.of(transform.rotationX(), transform.rotationY(), transform.rotationZ());
|
||||
this.rotation = ObjectRotation.of(transform.rotationX(), transform.rotationY(), transform.rotationZ());
|
||||
}
|
||||
|
||||
BlockPosition position(BlockPosition local) {
|
||||
@@ -128,7 +129,7 @@ final class IrisObjectTransformer implements ObjectTransformer {
|
||||
}
|
||||
|
||||
com.volmit.block.BlockState state(ObjectBlock block) {
|
||||
return states.toApi(rotation.rotate(mirrored(states.toPlatform(block.state())), NO_SPIN, NO_SPIN, NO_SPIN));
|
||||
return states.toApi(BlockStateRotation.rotate(rotation, mirrored(states.toPlatform(block.state())), NO_SPIN, NO_SPIN, NO_SPIN));
|
||||
}
|
||||
|
||||
private PlatformBlockState mirrored(PlatformBlockState state) {
|
||||
|
||||
@@ -30,9 +30,9 @@ import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.placer.HeightmapObjectPlacer;
|
||||
import art.arcane.iris.engine.object.material.BlockDataMergeSupport;
|
||||
import art.arcane.iris.engine.object.placement.IObjectPlacer;
|
||||
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
|
||||
import art.arcane.iris.engine.object.placement.IrisPlacementForm;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectRotation;
|
||||
import art.arcane.iris.engine.object.prefab.BlockStateRotation;
|
||||
import art.arcane.iris.engine.object.terrain.carving.CarveResult;
|
||||
import art.arcane.iris.util.project.noise.CNG;
|
||||
import art.arcane.iris.util.project.noise.SimplexNoise;
|
||||
@@ -53,7 +53,7 @@ public final class IrisPlacement implements ObjectPlacement {
|
||||
private static final int NOT_ANCHORED = Integer.MIN_VALUE;
|
||||
|
||||
private final IrisObject object;
|
||||
private final IrisObjectPlacement config;
|
||||
private final IrisPlacementForm form;
|
||||
private final IObjectPlacer placer;
|
||||
private final CarveResult cave;
|
||||
private final int x;
|
||||
@@ -65,14 +65,13 @@ public final class IrisPlacement implements ObjectPlacement {
|
||||
private final IrisObjectShape shape;
|
||||
private final IrisPlacementSettings settings;
|
||||
private final IrisPlacementTerrain terrain;
|
||||
private ObjectRotation derivedRotation;
|
||||
private IrisObjectRotation derivedIrisRotation;
|
||||
private int anchorY = NOT_ANCHORED;
|
||||
|
||||
IrisPlacement(IrisObject object, IrisObjectPlacement config, IObjectPlacer placer, CarveResult cave,
|
||||
int x, int requestedY, int z, IrisData data, PlatformBlockStates states, ObjectPlacerEdit edit) {
|
||||
IrisPlacement(IrisObject object, art.arcane.iris.builtin.objects.ObjectPlacement config, IrisPlacementForm form,
|
||||
IObjectPlacer placer, CarveResult cave, int x, int requestedY, int z, IrisData data, PlatformBlockStates states,
|
||||
ObjectPlacerEdit edit) {
|
||||
this.object = object;
|
||||
this.config = config;
|
||||
this.form = form;
|
||||
this.placer = placer;
|
||||
this.cave = cave;
|
||||
this.x = x;
|
||||
@@ -82,7 +81,7 @@ public final class IrisPlacement implements ObjectPlacement {
|
||||
this.states = states;
|
||||
this.edit = edit;
|
||||
this.shape = new IrisObjectShape(object, data.getPackResources());
|
||||
this.settings = new IrisPlacementSettings(config, data, states);
|
||||
this.settings = new IrisPlacementSettings(config, data);
|
||||
this.terrain = new IrisPlacementTerrain(placer, object.getLoader(), data);
|
||||
}
|
||||
|
||||
@@ -125,19 +124,20 @@ public final class IrisPlacement implements ObjectPlacement {
|
||||
|
||||
@Override
|
||||
public PlacementTerrain terrainFor(RNG rng) {
|
||||
if (config.getHeightmap() == null) {
|
||||
if (form.heightmap() == null) {
|
||||
return terrain;
|
||||
}
|
||||
return new IrisPlacementTerrain(new HeightmapObjectPlacer(rng, x, requestedY, z, config, placer), object.getLoader(), data);
|
||||
return new IrisPlacementTerrain(new HeightmapObjectPlacer(rng, x, requestedY, z, form.heightmap(), placer), object.getLoader(), data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<SurfaceWarp> surfaceWarp(RNG rng) {
|
||||
if (config.getWarp().isFlat()) {
|
||||
if (form.warp().isFlat()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
CNG warp = config.getSurfaceWarp(rng, object.getLoader());
|
||||
double multiplier = config.getWarp().getMultiplier();
|
||||
IrisData loader = object.getLoader();
|
||||
CNG warp = form.surfaceWarp(rng, loader, loader.getEngine());
|
||||
double multiplier = form.warp().getMultiplier();
|
||||
return Optional.of(new SurfaceWarp() {
|
||||
@Override
|
||||
public double multiplier() {
|
||||
@@ -159,24 +159,7 @@ public final class IrisPlacement implements ObjectPlacement {
|
||||
|
||||
@Override
|
||||
public BlockState rotate(BlockState state, ObjectRotation rotation, int spinX, int spinY, int spinZ) {
|
||||
return states.toApi(irisRotation(rotation).rotate(states.toPlatform(state), spinX, spinY, spinZ));
|
||||
}
|
||||
|
||||
/** The rotation model that turns blocks for the rotation the stages chose, which is the settings' own or one derived from it. */
|
||||
private IrisObjectRotation irisRotation(ObjectRotation rotation) {
|
||||
if (settings.gaveRotation(rotation)) {
|
||||
return settings.irisRotation();
|
||||
}
|
||||
if (rotation != derivedRotation) {
|
||||
IrisObjectRotation converted = new IrisObjectRotation();
|
||||
converted.setEnabled(rotation.enabled());
|
||||
converted.setXAxis(rotation.xAxis());
|
||||
converted.setYAxis(rotation.yAxis());
|
||||
converted.setZAxis(rotation.zAxis());
|
||||
derivedIrisRotation = converted;
|
||||
derivedRotation = rotation;
|
||||
}
|
||||
return derivedIrisRotation;
|
||||
return states.toApi(BlockStateRotation.rotate(rotation, states.toPlatform(state), spinX, spinY, spinZ));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,6 +21,7 @@ package art.arcane.iris.core.modules;
|
||||
import art.arcane.iris.builtin.anchor.ObjectPlaceMode;
|
||||
import art.arcane.iris.builtin.blocks.ObjectReplace;
|
||||
import art.arcane.iris.builtin.carve.CarvingMode;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.placement.MarkerRule;
|
||||
import art.arcane.iris.builtin.spawn.PlacementMarker;
|
||||
import art.arcane.iris.builtin.placement.PlacementSettings;
|
||||
@@ -31,9 +32,6 @@ import art.arcane.iris.builtin.stilt.StiltSettings;
|
||||
import art.arcane.iris.builtin.vacuum.VacuumSettings;
|
||||
import art.arcane.iris.builtin.validate.ObjectLimit;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectRotation;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectTranslate;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.resource.ResourceId;
|
||||
|
||||
@@ -43,164 +41,149 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/** An Iris object placement's settings as the placement stages read them. */
|
||||
/** An object placement's settings as the placement stages read them, its markers and collisions resolved in the pack. */
|
||||
final class IrisPlacementSettings implements PlacementSettings {
|
||||
private final IrisObjectPlacement config;
|
||||
private final ObjectPlacement config;
|
||||
private final IrisData data;
|
||||
private final PlatformBlockStates states;
|
||||
private final ObjectRotation rotation;
|
||||
|
||||
IrisPlacementSettings(IrisObjectPlacement config, IrisData data, PlatformBlockStates states) {
|
||||
IrisPlacementSettings(ObjectPlacement config, IrisData data) {
|
||||
this.config = config;
|
||||
this.data = data;
|
||||
this.states = states;
|
||||
IrisObjectRotation requested = config.getRotation();
|
||||
this.rotation = ObjectRotation.of(requested.isEnabled(), requested.getXAxis(), requested.getYAxis(), requested.getZAxis());
|
||||
}
|
||||
|
||||
/** The Iris rotation the settings were read from, if {@code rotation} is the one they gave. */
|
||||
boolean gaveRotation(ObjectRotation candidate) {
|
||||
return candidate == rotation;
|
||||
}
|
||||
|
||||
IrisObjectRotation irisRotation() {
|
||||
return config.getRotation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forcePlace() {
|
||||
return config.isForcePlace();
|
||||
return config.forcePlace();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SlopeClip slopeCondition() {
|
||||
return config.getSlopeCondition();
|
||||
return config.slopeCondition();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean rotateTowardsSlope() {
|
||||
return config.isRotateTowardsSlope();
|
||||
return config.rotateTowardsSlope();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectRotation rotation() {
|
||||
return rotation;
|
||||
return config.rotation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectTranslate translate() {
|
||||
IrisObjectTranslate translate = config.getTranslate();
|
||||
return ObjectTranslate.of(translate.getX(), translate.getY(), translate.getYRandom(), translate.getZ());
|
||||
return config.translate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectPlaceMode mode() {
|
||||
return config.getMode();
|
||||
return config.mode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fromBottom() {
|
||||
return config.isFromBottom();
|
||||
return config.fromBottom();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean bottom() {
|
||||
return config.isBottom();
|
||||
return config.bottom();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CarvingMode carvingSupport() {
|
||||
return config.getCarvingSupport();
|
||||
return config.carvingSupport();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean underwater() {
|
||||
return config.isUnderwater();
|
||||
return config.underwater();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onwater() {
|
||||
return config.isOnwater();
|
||||
return config.onwater();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requireSurfaceSupport() {
|
||||
return config.isRequireSurfaceSupport();
|
||||
return config.requireSurfaceSupport();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int surfaceSupportBuffer() {
|
||||
return config.getSurfaceSupportBuffer();
|
||||
return config.surfaceSupportBuffer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int surfaceSupportDepth() {
|
||||
return config.getSurfaceSupportDepth();
|
||||
return config.surfaceSupportDepth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectLimit clamp() {
|
||||
return config.getClamp();
|
||||
return config.clamp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean bore() {
|
||||
return config.isBore();
|
||||
return config.bore();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int boreExtendMinY() {
|
||||
return config.getBoreExtendMinY();
|
||||
return config.boreExtendMinY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int boreExtendMaxY() {
|
||||
return config.getBoreExtendMaxY();
|
||||
return config.boreExtendMaxY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ObjectReplace> edit() {
|
||||
return config.getEdit();
|
||||
return config.edit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean waterloggable() {
|
||||
return config.isWaterloggable();
|
||||
return config.waterloggable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean meld() {
|
||||
return config.isMeld();
|
||||
return config.meld();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MarkerRule> markers() {
|
||||
return config.getMarkers().stream().<MarkerRule>map(marker -> new Marker(marker, data)).toList();
|
||||
return config.markers().stream().<MarkerRule>map(marker -> new Marker(marker, data)).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<StiltSettings> stilt() {
|
||||
return Optional.ofNullable(config.getStiltSettings());
|
||||
return config.stiltSettings();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<VacuumSettings> vacuum() {
|
||||
return Optional.ofNullable(config.getVacuumSettings());
|
||||
return config.vacuumSettings();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double snow() {
|
||||
return config.getSnow();
|
||||
return config.snow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ResourceId> allowedCollisions() {
|
||||
return objectIds(config.getAllowedCollisions());
|
||||
return objectIds(config.allowedCollisions());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ResourceId> forbiddenCollisions() {
|
||||
return objectIds(config.getForbiddenCollisions());
|
||||
return objectIds(config.forbiddenCollisions());
|
||||
}
|
||||
|
||||
private Set<ResourceId> objectIds(List<String> keys) {
|
||||
|
||||
@@ -22,7 +22,9 @@ import art.arcane.iris.builtin.terrain.LayerLoad;
|
||||
import art.arcane.iris.builtin.terrain.LayersSettings;
|
||||
import art.arcane.iris.engine.object.material.IrisBlockData;
|
||||
import art.arcane.iris.engine.object.material.IrisMaterialPalette;
|
||||
import art.arcane.iris.builtin.objects.HeightmapNoise;
|
||||
import art.arcane.iris.engine.object.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.engine.object.noise.IrisNoiseGenerator;
|
||||
import art.arcane.iris.engine.object.noise.IrisStyledRange;
|
||||
import art.arcane.iris.engine.object.noise.NoiseStyle;
|
||||
import art.arcane.iris.engine.object.value.IrisPosition;
|
||||
@@ -119,6 +121,27 @@ public final class IrisValues {
|
||||
.map(layer -> irisStyle(layer.style().style())).toList();
|
||||
}
|
||||
|
||||
/** {@code noise} as the noise generator Iris reads the same JSON into. */
|
||||
public static IrisNoiseGenerator noiseGenerator(HeightmapNoise noise, IrisPackResources resources) {
|
||||
IrisNoiseGenerator generator = new IrisNoiseGenerator();
|
||||
generator.setZoom(noise.zoom());
|
||||
generator.setNegative(noise.negative());
|
||||
generator.setOpacity(noise.opacity());
|
||||
generator.setOffsetX(noise.offsetX());
|
||||
generator.setOffsetY(noise.offsetY());
|
||||
generator.setOffsetZ(noise.offsetZ());
|
||||
generator.setSeed(noise.seed());
|
||||
generator.setParametric(noise.parametric());
|
||||
generator.setBezier(noise.bezier());
|
||||
generator.setSinCentered(noise.sinCentered());
|
||||
generator.setExponent(noise.exponent());
|
||||
generator.setEnabled(noise.enabled());
|
||||
generator.setStyle(generatorStyle(noise.style(), resources));
|
||||
generator.setOctaves(noise.octaves());
|
||||
generator.setFracture(new KList<>(noise.fracture().stream().map(child -> noiseGenerator(child, resources)).toList()));
|
||||
return generator;
|
||||
}
|
||||
|
||||
/** {@code range} as the range Iris reads the same JSON into. */
|
||||
public static IrisRange range(Range range) {
|
||||
return new IrisRange(range.min(), range.max());
|
||||
|
||||
@@ -18,10 +18,11 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.placement.IObjectPlacer;
|
||||
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
|
||||
import art.arcane.iris.engine.object.placement.IrisPlacementForm;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectShaping;
|
||||
import art.arcane.iris.engine.object.terrain.carving.CarveResult;
|
||||
@@ -64,7 +65,7 @@ public final class ModuleObjectPlacement {
|
||||
* @param cave the cave the object is placed in, or null outside caves
|
||||
*/
|
||||
public static ObjectPlacementResult place(IrisObject object, int x, int requestedY, int z, IObjectPlacer placer,
|
||||
IrisObjectPlacement config, RNG rng,
|
||||
ObjectPlacement config, RNG rng,
|
||||
BiConsumer<art.arcane.volmlib.util.math.BlockPosition, PlatformBlockState> listener,
|
||||
CarveResult cave, IrisData data) {
|
||||
Objects.requireNonNull(placer, "Object placer is required.");
|
||||
@@ -73,11 +74,12 @@ public final class ModuleObjectPlacement {
|
||||
Objects.requireNonNull(data, "Object placement data is required.");
|
||||
LoadedPack pack = data.getModules().pack();
|
||||
ResolvedGraph graph = pack.placement();
|
||||
IrisPlacementForm form = IrisPlacementForm.of(config, data);
|
||||
GeneratedObject geometry = geometryOf(object, config);
|
||||
BlockBox area = PlacementArea.around(object, geometry, config, x, z, graph.reach().blocks());
|
||||
BlockBox area = PlacementArea.around(object, geometry, config.translate(), form.warp(), x, z, graph.reach().blocks());
|
||||
PlatformBlockStates states = new PlatformBlockStates(ModuleObjectPlacement::platformState);
|
||||
ObjectPlacerEdit edit = new ObjectPlacerEdit(placer, area, states, listener, () -> mantle(placer.getEngine(), area, pack));
|
||||
IrisPlacement placement = new IrisPlacement(object, config, placer, cave, x, requestedY, z, data, states, edit);
|
||||
IrisPlacement placement = new IrisPlacement(object, config, form, placer, cave, x, requestedY, z, data, states, edit);
|
||||
PackResourceIds ids = new PackResourceIds(data.getDataFolder());
|
||||
String objectKey = keyOf(object);
|
||||
Engine engine = placer.getEngine();
|
||||
@@ -88,11 +90,11 @@ public final class ModuleObjectPlacement {
|
||||
StageMetrics metrics = new StageMetrics(engine != null ? engine.getMetrics() : null);
|
||||
try (ToolWorld toolWorld = engine == null ? new ToolWorld(worldSeed, data.getPackResources(), new PackDeclaredSettings(data)) : null) {
|
||||
IrisPlacementInputs inputs = new IrisPlacementInputs(terrain(engine, ids, area),
|
||||
new PlacementModuleSettings(worldSettings(engine, ids), config.getModuleSettings(), source),
|
||||
new PlacementModuleSettings(worldSettings(engine, ids), form.moduleSettings(), source),
|
||||
new PlacerBlockView(placer, area, states), engine != null ? IrisPlacementInputs.worldOf(engine) : () -> toolWorld,
|
||||
placement);
|
||||
PlacementOutcome outcome = new PlacementRunner(graph)
|
||||
.place(request, edit, inputs, seed, config.getModuleSettings().placement(source), metrics);
|
||||
.place(request, edit, inputs, seed, form.moduleSettings().placement(source), metrics);
|
||||
return outcome.isPlaced()
|
||||
? ObjectPlacementResult.placed(placement.anchorY())
|
||||
: ObjectPlacementResult.rejected(outcome.rejection().orElseThrow());
|
||||
@@ -100,8 +102,8 @@ public final class ModuleObjectPlacement {
|
||||
}
|
||||
|
||||
/** Smart boring adds the object's bored air, so it has to happen before the geometry is read. */
|
||||
private static GeneratedObject geometryOf(IrisObject object, IrisObjectPlacement config) {
|
||||
if (config.isSmartBore()) {
|
||||
private static GeneratedObject geometryOf(IrisObject object, ObjectPlacement config) {
|
||||
if (config.smartBore()) {
|
||||
IrisObjectShaping.ensureSmartBored(object);
|
||||
}
|
||||
return object.getGeometry();
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
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.placement.IrisObjectPlacement;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
@@ -38,7 +38,7 @@ public final class ModuleTargets {
|
||||
Level.DIMENSION, IrisDimension.class,
|
||||
Level.REGION, IrisRegion.class,
|
||||
Level.BIOME, IrisBiome.class,
|
||||
Level.PLACEMENT, IrisObjectPlacement.class);
|
||||
Level.PLACEMENT, ObjectPlacement.class);
|
||||
|
||||
private ModuleTargets() {
|
||||
}
|
||||
@@ -51,6 +51,14 @@ 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);
|
||||
|
||||
+18
-20
@@ -18,8 +18,7 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
|
||||
import art.arcane.volmlib.util.json.JSONObject;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.TypeAdapter;
|
||||
@@ -27,16 +26,15 @@ import com.google.gson.TypeAdapterFactory;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import com.volmit.config.Level;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Decodes the module settings of every object placement Gson reads, wherever pack JSON nests one, into
|
||||
* {@link IrisObjectPlacement#getModuleSettings()}. Register it before the factory that resolves snippets:
|
||||
* Gson asks later registrations first, so that factory reads a snippet reference and this one decodes the
|
||||
* snippet's JSON.
|
||||
* Reads the object placements an Iris resource nests, such as a mod's placement injectors, the way {@code iris:objects}
|
||||
* reads its own: with the modules' Gson, keeping the JSON that declares the placement's module settings. Register it
|
||||
* before the factory that resolves snippets: Gson asks later registrations first, so that factory reads a snippet
|
||||
* reference and this one decodes the snippet's JSON.
|
||||
*/
|
||||
public final class ObjectPlacementSettingsReader implements TypeAdapterFactory {
|
||||
private final Supplier<ModuleSettingsDecoder> decoder;
|
||||
@@ -47,29 +45,29 @@ public final class ObjectPlacementSettingsReader implements TypeAdapterFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked") // The type is checked to be IrisObjectPlacement.
|
||||
@SuppressWarnings("unchecked") // The type is checked to be ObjectPlacement.
|
||||
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
|
||||
if (type.getRawType() != IrisObjectPlacement.class) {
|
||||
if (type.getRawType() != ObjectPlacement.class) {
|
||||
return null;
|
||||
}
|
||||
TypeAdapter<IrisObjectPlacement> placements = gson.getDelegateAdapter(this, (TypeToken<IrisObjectPlacement>) type);
|
||||
TypeAdapter<JsonElement> elements = gson.getAdapter(JsonElement.class);
|
||||
return (TypeAdapter<T>) new TypeAdapter<IrisObjectPlacement>() {
|
||||
return (TypeAdapter<T>) new TypeAdapter<ObjectPlacement>() {
|
||||
@Override
|
||||
public void write(JsonWriter out, IrisObjectPlacement placement) throws IOException {
|
||||
placements.write(out, placement);
|
||||
public void write(JsonWriter out, ObjectPlacement placement) throws IOException {
|
||||
if (placement == null || placement.json() == null) {
|
||||
out.nullValue();
|
||||
return;
|
||||
}
|
||||
out.jsonValue(placement.json());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IrisObjectPlacement read(JsonReader in) throws IOException {
|
||||
String path = in.getPath();
|
||||
public ObjectPlacement read(JsonReader in) throws IOException {
|
||||
JsonElement json = elements.read(in);
|
||||
IrisObjectPlacement placement = placements.fromJsonTree(json);
|
||||
if (placement != null && json.isJsonObject()) {
|
||||
placement.setModuleSettings(decoder.get().decode(Level.PLACEMENT,
|
||||
new JSONObject(json.toString()), "object placement at " + path));
|
||||
if (json == null || json.isJsonNull()) {
|
||||
return null;
|
||||
}
|
||||
return placement;
|
||||
return decoder.get().decodeResource(ObjectPlacement.class, json.toString());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -18,10 +18,9 @@
|
||||
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.prepare.ObjectTranslate;
|
||||
import art.arcane.iris.engine.object.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectTranslate;
|
||||
import com.volmit.geometry.BlockBox;
|
||||
import com.volmit.object.GeneratedObject;
|
||||
|
||||
@@ -38,11 +37,11 @@ final class PlacementArea {
|
||||
private PlacementArea() {
|
||||
}
|
||||
|
||||
static BlockBox around(IrisObject object, GeneratedObject geometry, IrisObjectPlacement config, int x, int z,
|
||||
int pipelineReachBlocks) {
|
||||
static BlockBox around(IrisObject object, GeneratedObject geometry, ObjectTranslate translate, IrisGeneratorStyle warp,
|
||||
int x, int z, int pipelineReachBlocks) {
|
||||
int objectRadius = Math.max(rotationRadius(geometry.bounds()), rotationRadius(declaredBox(object)));
|
||||
int reach = objectRadius + translationLength(config.getTranslate())
|
||||
+ warpMargin(config.getWarp()) + NEIGHBOR_READ_BLOCKS + pipelineReachBlocks;
|
||||
int reach = objectRadius + translationLength(translate)
|
||||
+ warpMargin(warp) + NEIGHBOR_READ_BLOCKS + pipelineReachBlocks;
|
||||
return new BlockBox(x - reach, Integer.MIN_VALUE, z - reach, x + reach + 1, Integer.MAX_VALUE, z + reach + 1);
|
||||
}
|
||||
|
||||
@@ -67,10 +66,10 @@ final class PlacementArea {
|
||||
return Math.max(Math.abs((long) min), Math.abs((long) maxExclusive - 1));
|
||||
}
|
||||
|
||||
private static int translationLength(IrisObjectTranslate translate) {
|
||||
long x = translate.getX();
|
||||
long y = translate.getY();
|
||||
long z = translate.getZ();
|
||||
private static int translationLength(ObjectTranslate translate) {
|
||||
long x = translate.x();
|
||||
long y = translate.y();
|
||||
long z = translate.z();
|
||||
return (int) Math.ceil(Math.sqrt(x * x + y * y + z * z));
|
||||
}
|
||||
|
||||
|
||||
@@ -17,43 +17,27 @@
|
||||
*/
|
||||
package art.arcane.iris.core.modules;
|
||||
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.ProceduralPlacement;
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
import art.arcane.iris.builtin.prepare.ObjectTranslate;
|
||||
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectRotation;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectTranslate;
|
||||
|
||||
/** The options a procedural object is scattered with, as Iris's own placement. */
|
||||
/** The options a procedural object is scattered with, as an object placement. */
|
||||
public final class ProceduralOptions {
|
||||
private ProceduralOptions() {
|
||||
}
|
||||
|
||||
public static IrisObjectPlacement of(ProceduralPlacement procedural) {
|
||||
IrisObjectPlacement placement = new IrisObjectPlacement();
|
||||
placement.setMode(procedural.mode());
|
||||
placement.setRotation(irisRotation(procedural.rotation()));
|
||||
placement.setClamp(procedural.clamp());
|
||||
placement.setCarvingSupport(procedural.carvingSupport());
|
||||
placement.setUnderwater(procedural.underwater());
|
||||
placement.setTranslate(irisTranslate(procedural.translate()));
|
||||
placement.setStiltSettings(procedural.stiltSettings().orElse(null));
|
||||
placement.setVacuumSettings(procedural.vacuumSettings().orElse(null));
|
||||
placement.setChance(procedural.chance());
|
||||
placement.setDensity(procedural.density());
|
||||
placement.setSurfaceSupportBuffer(procedural.surfaceSupportBuffer());
|
||||
return placement;
|
||||
}
|
||||
|
||||
private static IrisObjectRotation irisRotation(ObjectRotation rotation) {
|
||||
return new IrisObjectRotation()
|
||||
.setEnabled(rotation.enabled())
|
||||
.setXAxis(rotation.xAxis())
|
||||
.setYAxis(rotation.yAxis())
|
||||
.setZAxis(rotation.zAxis());
|
||||
}
|
||||
|
||||
private static IrisObjectTranslate irisTranslate(ObjectTranslate translate) {
|
||||
return new IrisObjectTranslate(translate.x(), translate.y(), translate.yRandom(), translate.z());
|
||||
public static ObjectPlacement of(ProceduralPlacement procedural) {
|
||||
return ObjectPlacement.builder()
|
||||
.mode(procedural.mode())
|
||||
.rotation(procedural.rotation())
|
||||
.clamp(procedural.clamp())
|
||||
.carvingSupport(procedural.carvingSupport())
|
||||
.underwater(procedural.underwater())
|
||||
.translate(procedural.translate())
|
||||
.stiltSettings(procedural.stiltSettings().orElse(null))
|
||||
.vacuumSettings(procedural.vacuumSettings().orElse(null))
|
||||
.chance(procedural.chance())
|
||||
.density(procedural.density())
|
||||
.surfaceSupportBuffer(procedural.surfaceSupportBuffer())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
package art.arcane.iris.core.pack;
|
||||
|
||||
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.volmlib.util.collection.KSet;
|
||||
|
||||
/**
|
||||
@@ -31,16 +31,16 @@ public final class PackExportClosure {
|
||||
private PackExportClosure() {
|
||||
}
|
||||
|
||||
public static KSet<String> collectObjectKeys(Iterable<IrisObjectPlacement> placements) {
|
||||
public static KSet<String> collectObjectKeys(Iterable<ObjectPlacement> placements) {
|
||||
KSet<String> objectKeys = new KSet<>();
|
||||
if (placements == null) {
|
||||
return objectKeys;
|
||||
}
|
||||
for (IrisObjectPlacement placement : placements) {
|
||||
if (placement == null || placement.getPlace() == null) {
|
||||
for (ObjectPlacement placement : placements) {
|
||||
if (placement == null) {
|
||||
continue;
|
||||
}
|
||||
for (String key : placement.getPlace()) {
|
||||
for (String key : placement.place()) {
|
||||
if (key == null || key.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
package art.arcane.iris.core.project;
|
||||
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.engine.object.placement.ObjectPlacements;
|
||||
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
|
||||
import com.google.gson.Gson;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.loader.IrisRegistrant;
|
||||
@@ -54,6 +54,7 @@ import org.zeroturnaround.zip.ZipUtil;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
@SuppressWarnings("ALL")
|
||||
@@ -121,34 +122,32 @@ public class IrisPackageCompiler {
|
||||
regions.forEach(moduleResources::followSettingsOf);
|
||||
biomes.forEach((i) -> i.getGenerators().forEach((j) -> addIfPresent(generators, j.getCachedGenerator(() -> dm))));
|
||||
biomes.forEach(moduleResources::followSettingsOf);
|
||||
KList<IrisObjectPlacement> allPlacements = new KList<>();
|
||||
KList<ObjectPlacement> allPlacements = new KList<>();
|
||||
regions.forEach((r) -> allPlacements.addAll(ObjectPlacements.all(r)));
|
||||
biomes.forEach((i) -> allPlacements.addAll(ObjectPlacements.all(i)));
|
||||
moduleResources.follow(allPlacements);
|
||||
List<String> structureKeys = moduleResources.keysOf(IrisStructure.class);
|
||||
KMap<String, String> renameObjects = new KMap<>();
|
||||
KList<String> exportedObjectNames = new KList<>();
|
||||
String a;
|
||||
StringBuilder b = new StringBuilder();
|
||||
StringBuilder c = new StringBuilder();
|
||||
sender.sendMessage(IrisLanguage.text(BukkitRuntimeMessages.IRIS_PROJECT_SERIALIZING_OBJECTS));
|
||||
|
||||
for (IrisObjectPlacement j : allPlacements) {
|
||||
b.append(j.hashCode());
|
||||
KList<String> newNames = new KList<>();
|
||||
for (ObjectPlacement j : allPlacements) {
|
||||
b.append(Objects.hashCode(j.json()));
|
||||
|
||||
for (String k : j.getPlace()) {
|
||||
for (String k : j.place()) {
|
||||
if (renameObjects.containsKey(k)) {
|
||||
newNames.add(renameObjects.get(k));
|
||||
exportedObjectNames.add(renameObjects.get(k));
|
||||
continue;
|
||||
}
|
||||
|
||||
String name = !obfuscate ? k : UUID.randomUUID().toString().replaceAll("-", "");
|
||||
b.append(name);
|
||||
newNames.add(name);
|
||||
exportedObjectNames.add(name);
|
||||
renameObjects.put(k, name);
|
||||
}
|
||||
|
||||
j.setPlace(newNames);
|
||||
}
|
||||
|
||||
KMap<String, KList<String>> lookupObjects = renameObjects.flip();
|
||||
@@ -158,7 +157,7 @@ public class IrisPackageCompiler {
|
||||
ggg.set(0);
|
||||
O<Integer> missingObjects = new O<>();
|
||||
missingObjects.set(0);
|
||||
allPlacements.forEach((j) -> j.getPlace().forEach((k) ->
|
||||
exportedObjectNames.forEach((k) ->
|
||||
{
|
||||
try {
|
||||
KList<String> sources = lookupObjects.get(k);
|
||||
@@ -181,7 +180,7 @@ public class IrisPackageCompiler {
|
||||
missingObjects.set(missingObjects.get() + 1);
|
||||
IrisLogging.reportError(e);
|
||||
}
|
||||
}));
|
||||
});
|
||||
if (missingObjects.get() > 0) {
|
||||
// A package missing objects must fail loudly, not ship as a clean "compiled".
|
||||
throw new IllegalStateException(missingObjects.get()
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
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;
|
||||
@@ -180,6 +181,7 @@ final class ModuleSchemaRenderer {
|
||||
required.put(option.name());
|
||||
}
|
||||
}
|
||||
ModuleTargets.ofTypeName(type.name()).ifPresent(target -> addFeatures(target, properties));
|
||||
object.put("properties", properties);
|
||||
if (required.length() > 0) {
|
||||
object.put("required", required);
|
||||
|
||||
@@ -3,7 +3,8 @@ 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.engine.object.prefab.IrisObjectRotation;
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
import art.arcane.iris.engine.object.prefab.BlockStateRotation;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.common.data.B;
|
||||
@@ -192,10 +193,10 @@ public final class JigsawStudioPreviewRenderer {
|
||||
PlacedStructurePiece piece
|
||||
) throws IOException {
|
||||
IrisObject object = piece.getObject();
|
||||
IrisObjectRotation rotation = piece.getRotation();
|
||||
ObjectRotation rotation = piece.getRotation();
|
||||
for (Map.Entry<IrisBlockVector, PlatformBlockState> entry : object.getBlocks()) {
|
||||
IrisBlockVector rotated = rotation.rotate(entry.getKey());
|
||||
PlatformBlockState state = rotation.rotate(entry.getValue(), 0, 0, 0);
|
||||
PlatformBlockState state = BlockStateRotation.rotate(rotation, entry.getValue(), 0, 0, 0);
|
||||
putState(
|
||||
blocks,
|
||||
new BlockPosition(
|
||||
@@ -212,7 +213,7 @@ public final class JigsawStudioPreviewRenderer {
|
||||
PlacedStructurePiece piece
|
||||
) throws IOException {
|
||||
IrisObject object = piece.getObject();
|
||||
IrisObjectRotation rotation = piece.getRotation();
|
||||
ObjectRotation rotation = piece.getRotation();
|
||||
if (piece.getPiece().getConnectors() == null) {
|
||||
return;
|
||||
}
|
||||
@@ -226,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 : rotation.rotate(source, 0, 0, 0);
|
||||
PlatformBlockState state = source == null ? null : BlockStateRotation.rotate(rotation, source, 0, 0, 0);
|
||||
putState(
|
||||
blocks,
|
||||
new BlockPosition(
|
||||
|
||||
@@ -47,7 +47,8 @@ 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.engine.object.prefab.IrisObjectRotation;
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
import art.arcane.iris.engine.object.prefab.BlockStateRotation;
|
||||
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;
|
||||
@@ -6286,7 +6287,7 @@ public final class JigsawStudioService implements IrisService, JigsawStudioMenuC
|
||||
int sourceDepth = (quarterTurns & 1) == 0
|
||||
? displayDimensions.depth()
|
||||
: displayDimensions.width();
|
||||
IrisObjectRotation rotation = IrisObjectRotation.of(0, -90.0D * quarterTurns, 0);
|
||||
ObjectRotation rotation = ObjectRotation.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");
|
||||
@@ -6394,7 +6395,7 @@ public final class JigsawStudioService implements IrisService, JigsawStudioMenuC
|
||||
sourceWidth,
|
||||
captureBounds.dimensions().height(),
|
||||
sourceDepth);
|
||||
IrisObjectRotation inverseRotation = IrisObjectRotation.of(0, 90.0D * quarterTurns, 0);
|
||||
ObjectRotation inverseRotation = ObjectRotation.of(0, 90.0D * quarterTurns, 0);
|
||||
List<IrisJigsawConnector> connectors = new ArrayList<>();
|
||||
Set<LocalPosition> capturedBlocks = new HashSet<>();
|
||||
Set<LocalPosition> capturedConnectors = new HashSet<>();
|
||||
@@ -6416,7 +6417,7 @@ public final class JigsawStudioService implements IrisService, JigsawStudioMenuC
|
||||
}
|
||||
PlatformBlockState sourceState = quarterTurns == 0
|
||||
? block.state()
|
||||
: inverseRotation.rotate(block.state(), 0, 0, 0);
|
||||
: BlockStateRotation.rotate(inverseRotation, block.state(), 0, 0, 0);
|
||||
if (sourceState == null) {
|
||||
throw new IOException("Captured block state cannot be inverse-rotated at "
|
||||
+ block.x() + "," + block.y() + "," + block.z());
|
||||
@@ -6458,7 +6459,7 @@ public final class JigsawStudioService implements IrisService, JigsawStudioMenuC
|
||||
+ capturedConnector.x() + "," + capturedConnector.y() + ","
|
||||
+ capturedConnector.z());
|
||||
}
|
||||
PlatformBlockState sourceFinalState = inverseRotation.rotate(finalState, 0, 0, 0);
|
||||
PlatformBlockState sourceFinalState = BlockStateRotation.rotate(inverseRotation, finalState, 0, 0, 0);
|
||||
if (sourceFinalState == null) {
|
||||
throw new IOException("Captured connector final state cannot be inverse-rotated at "
|
||||
+ capturedConnector.x() + "," + capturedConnector.y() + ","
|
||||
@@ -6962,7 +6963,7 @@ public final class JigsawStudioService implements IrisService, JigsawStudioMenuC
|
||||
sourceWidth,
|
||||
sourceDepth,
|
||||
quarterTurns);
|
||||
IrisObjectRotation inverseRotation = IrisObjectRotation.of(0, 90.0D * quarterTurns, 0);
|
||||
ObjectRotation inverseRotation = ObjectRotation.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()))
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
package art.arcane.iris.engine;
|
||||
|
||||
import art.arcane.iris.engine.object.placement.ObjectPlacements;
|
||||
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.EngineRuntime.BiomeMaxes;
|
||||
import art.arcane.iris.engine.IrisEngine.LifecycleState;
|
||||
@@ -200,8 +200,8 @@ final class EngineRuntimeBuilder {
|
||||
for (IrisBiome i : engine.getDimension().getReachableBiomes(engine)) {
|
||||
double density = 0;
|
||||
|
||||
for (IrisObjectPlacement j : ObjectPlacements.all(i)) {
|
||||
density += j.getDensity() * j.getChance();
|
||||
for (ObjectPlacement j : ObjectPlacements.all(i)) {
|
||||
density += j.middleDensity() * j.chance();
|
||||
}
|
||||
|
||||
objectDensity = Math.max(objectDensity, density);
|
||||
|
||||
@@ -23,7 +23,7 @@ import art.arcane.iris.builtin.structure.StructurePlacementMarker;
|
||||
|
||||
import art.arcane.iris.engine.object.placement.ObjectPlacements;
|
||||
import art.arcane.iris.engine.framework.structure.StructureResources;
|
||||
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.core.IrisSettings;
|
||||
import art.arcane.iris.engine.framework.render.RenderType;
|
||||
import art.arcane.iris.engine.framework.render.Renderer;
|
||||
@@ -461,7 +461,7 @@ public interface Engine extends DataProvider, Fallible, BlockUpdater, Renderer,
|
||||
if (marker.structureAware()) {
|
||||
IrisObject placedObject = getData().getObjectLoader().load(object);
|
||||
IrisStructure structure = StructureResources.structure(getData().getPackResources(), marker.structureKey());
|
||||
IrisObjectPlacement placement = placedObject == null || structure == null
|
||||
ObjectPlacement placement = placedObject == null || structure == null
|
||||
? null
|
||||
: StructurePlacing.lootPlacement(structure, object);
|
||||
return new PlacedObject(placement, placedObject, id, x, z);
|
||||
@@ -470,16 +470,16 @@ public interface Engine extends DataProvider, Fallible, BlockUpdater, Renderer,
|
||||
|
||||
IrisRegion region = getRegion(x, z);
|
||||
|
||||
for (IrisObjectPlacement i : ObjectPlacements.all(region)) {
|
||||
if (i.getPlace().contains(object)) {
|
||||
for (ObjectPlacement i : ObjectPlacements.all(region)) {
|
||||
if (i.place().contains(object)) {
|
||||
return new PlacedObject(i, getData().getObjectLoader().load(object), id, x, z);
|
||||
}
|
||||
}
|
||||
|
||||
IrisBiome biome = getSurfaceBiome(x, z);
|
||||
|
||||
for (IrisObjectPlacement i : ObjectPlacements.all(biome)) {
|
||||
if (i.getPlace().contains(object)) {
|
||||
for (ObjectPlacement i : ObjectPlacements.all(biome)) {
|
||||
if (i.place().contains(object)) {
|
||||
return new PlacedObject(i, getData().getObjectLoader().load(object), id, x, z);
|
||||
}
|
||||
}
|
||||
@@ -507,17 +507,17 @@ public interface Engine extends DataProvider, Fallible, BlockUpdater, Renderer,
|
||||
return !regionKeys.isEmpty();
|
||||
}
|
||||
|
||||
private static boolean containsObjectPlacement(KList<IrisObjectPlacement> placements, String normalizedObjectKey) {
|
||||
private static boolean containsObjectPlacement(KList<ObjectPlacement> placements, String normalizedObjectKey) {
|
||||
if (placements == null || placements.isEmpty() || normalizedObjectKey.isBlank()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (IrisObjectPlacement placement : placements) {
|
||||
if (placement == null || placement.getPlace() == null || placement.getPlace().isEmpty()) {
|
||||
for (ObjectPlacement placement : placements) {
|
||||
if (placement == null || placement.place().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (String placedObject : placement.getPlace()) {
|
||||
for (String placedObject : placement.place()) {
|
||||
String normalizedPlacedObject = normalizeObjectPlacementKey(placedObject);
|
||||
if (!normalizedPlacedObject.isBlank() && normalizedPlacedObject.equals(normalizedObjectKey)) {
|
||||
return true;
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
package art.arcane.iris.engine.framework;
|
||||
|
||||
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
@@ -28,7 +28,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
@AllArgsConstructor
|
||||
public class PlacedObject {
|
||||
@Nullable
|
||||
private IrisObjectPlacement placement;
|
||||
private ObjectPlacement placement;
|
||||
@Nullable
|
||||
private IrisObject object;
|
||||
private int id;
|
||||
|
||||
@@ -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.engine.object.prefab.IrisObjectRotation;
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
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 IrisObjectRotation rotation;
|
||||
private final ObjectRotation 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.engine.object.prefab.IrisObjectRotation;
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
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;
|
||||
IrisObjectRotation startRot = IrisObjectRotation.of(0, startRotY, 0);
|
||||
ObjectRotation startRot = ObjectRotation.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) {
|
||||
IrisObjectRotation rot = IrisObjectRotation.of(0, yDeg, 0);
|
||||
ObjectRotation rot = ObjectRotation.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) {
|
||||
IrisObjectRotation rotation = IrisObjectRotation.of(0, yDegrees, 0);
|
||||
ObjectRotation rotation = ObjectRotation.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, IrisObjectRotation rot) {
|
||||
private PlacedStructurePiece build(IrisJigsawPiece piece, IrisObject object, int x, int y, int z, ObjectRotation rot) {
|
||||
int width = Math.max(1, object.getW());
|
||||
int height = Math.max(1, object.getH());
|
||||
int depth = Math.max(1, object.getD());
|
||||
@@ -1048,7 +1048,7 @@ public final class StructureAssembler {
|
||||
private IrisPosition connectorOffset(
|
||||
IrisObject object,
|
||||
IrisJigsawConnector connector,
|
||||
IrisObjectRotation rotation
|
||||
ObjectRotation rotation
|
||||
) {
|
||||
if (structure.resolvedMode() == IrisJigsawMode.PLANAR_JIGSAW) {
|
||||
IrisPosition dimensions = rotatedDimensions(object, rotation);
|
||||
@@ -1079,7 +1079,7 @@ public final class StructureAssembler {
|
||||
piece.getZ() - offset.getZ());
|
||||
}
|
||||
|
||||
private IrisPosition rotatedDimensions(IrisObject object, IrisObjectRotation rotation) {
|
||||
private IrisPosition rotatedDimensions(IrisObject object, ObjectRotation 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, IrisObjectRotation rotation) {
|
||||
private IrisPosition planarPlacementOffset(IrisObject object, ObjectRotation 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(IrisObjectRotation rotation) {
|
||||
private int quarterTurns(ObjectRotation rotation) {
|
||||
return switch (rotation.rotate(IrisDirection.NORTH_NEGATIVE_Z)) {
|
||||
case NORTH_NEGATIVE_Z -> 0;
|
||||
case WEST_NEGATIVE_X -> 1;
|
||||
|
||||
+6
-6
@@ -18,9 +18,9 @@
|
||||
|
||||
package art.arcane.iris.engine.framework.placer;
|
||||
|
||||
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.noise.IrisNoiseGenerator;
|
||||
import art.arcane.iris.engine.object.placement.IObjectPlacer;
|
||||
import art.arcane.iris.engine.object.prefab.TileData;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
@@ -28,21 +28,21 @@ import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
public class HeightmapObjectPlacer implements IObjectPlacer {
|
||||
private final long s;
|
||||
private final IrisObjectPlacement config;
|
||||
private final IrisNoiseGenerator heightmap;
|
||||
private final IObjectPlacer oplacer;
|
||||
|
||||
public HeightmapObjectPlacer(RNG rng, int x, int yv, int z, IrisObjectPlacement config, IObjectPlacer oplacer) {
|
||||
public HeightmapObjectPlacer(RNG rng, int x, int yv, int z, IrisNoiseGenerator heightmap, IObjectPlacer oplacer) {
|
||||
s = rng.nextLong() + yv + z - x;
|
||||
this.config = config;
|
||||
this.heightmap = heightmap;
|
||||
this.oplacer = oplacer;
|
||||
}
|
||||
|
||||
public int getHighest(int param1Int1, int param1Int2, IrisData data) {
|
||||
return (int) Math.round(config.getHeightmap().getNoise(this.s, param1Int1, param1Int2, data));
|
||||
return (int) Math.round(heightmap.getNoise(this.s, param1Int1, param1Int2, data));
|
||||
}
|
||||
|
||||
public int getHighest(int param1Int1, int param1Int2, IrisData data, boolean param1Boolean) {
|
||||
return (int) Math.round(config.getHeightmap().getNoise(this.s, param1Int1, param1Int2, data));
|
||||
return (int) Math.round(heightmap.getNoise(this.s, param1Int1, param1Int2, data));
|
||||
}
|
||||
|
||||
public void set(int param1Int1, int param1Int2, int param1Int3, PlatformBlockState param1BlockData) {
|
||||
|
||||
+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.engine.object.prefab.IrisObjectRotation;
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
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();
|
||||
IrisObjectRotation rotation = piece.getRotation();
|
||||
ObjectRotation rotation = piece.getRotation();
|
||||
if (object == null || rotation == null || object.getBlocks() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ package art.arcane.iris.engine.mantle.components;
|
||||
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.engine.object.placement.IrisObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.core.IrisSettings;
|
||||
import art.arcane.volmlib.util.cache.CacheKey;
|
||||
import art.arcane.iris.engine.framework.IrisStructureLocator;
|
||||
@@ -61,6 +61,7 @@ import art.arcane.volmlib.util.math.RNG;
|
||||
import it.unimi.dsi.fastutil.longs.Long2IntMap;
|
||||
import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -538,19 +539,22 @@ public class StructurePlacing {
|
||||
}
|
||||
|
||||
/** A placement of the piece object {@code objectKey} whose containers draw from the structure's loot tables. */
|
||||
public static IrisObjectPlacement lootPlacement(IrisStructure structure, String objectKey) {
|
||||
IrisObjectPlacement placement = new IrisObjectPlacement();
|
||||
placement.getPlace().add(objectKey);
|
||||
placement.setOverrideGlobalLoot(false);
|
||||
public static ObjectPlacement lootPlacement(IrisStructure structure, String objectKey) {
|
||||
return lootPlacementBuilder(structure, objectKey).build();
|
||||
}
|
||||
|
||||
private static ObjectPlacement.Builder lootPlacementBuilder(IrisStructure structure, String objectKey) {
|
||||
ObjectPlacement.Builder placement = ObjectPlacement.builder().place(List.of(objectKey));
|
||||
if (structure.getLoot() == null) {
|
||||
return placement;
|
||||
}
|
||||
List<ObjectLoot> loot = new ArrayList<>();
|
||||
for (String lootTable : structure.getLoot()) {
|
||||
if (lootTable != null && !lootTable.isBlank()) {
|
||||
placement.getLoot().add(new ObjectLoot(lootTable, 1));
|
||||
loot.add(new ObjectLoot(lootTable, 1));
|
||||
}
|
||||
}
|
||||
return placement;
|
||||
return placement.loot(loot);
|
||||
}
|
||||
|
||||
private int placeObject(MantleWriter writer, IrisStructure structure, PlacedStructurePiece p,
|
||||
@@ -558,15 +562,14 @@ public class StructurePlacing {
|
||||
boolean supportNonOccluding) {
|
||||
IrisObject object = p.getObject();
|
||||
String objectKey = object.getLoadKey();
|
||||
IrisObjectPlacement config = lootPlacement(structure, objectKey);
|
||||
config.setMode(mode);
|
||||
config.setRotation(p.getRotation());
|
||||
ObjectPlacement.Builder builder = lootPlacementBuilder(structure, objectKey).mode(mode).rotation(p.getRotation());
|
||||
if (!structure.getEdit().isEmpty()) {
|
||||
config.setEdit(structure.getEdit());
|
||||
builder.edit(structure.getEdit());
|
||||
}
|
||||
if (!mode.placeMode().has(PlaceTrait.FREE_HEIGHT)) {
|
||||
config.setForcePlace(true);
|
||||
builder.forcePlace(true);
|
||||
}
|
||||
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) -> {
|
||||
|
||||
+3
-3
@@ -18,7 +18,7 @@
|
||||
|
||||
package art.arcane.iris.engine.object.mod;
|
||||
|
||||
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||
import art.arcane.iris.engine.object.annotations.ArrayType;
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
@@ -45,6 +45,6 @@ public class IrisModObjectPlacementBiomeInjector {
|
||||
|
||||
@Required
|
||||
@Desc("Object placements to inject into the biome")
|
||||
@ArrayType(type = IrisObjectPlacement.class, min = 1)
|
||||
private KList<IrisObjectPlacement> place = new KList<>();
|
||||
@ArrayType(type = ObjectPlacement.class, min = 1)
|
||||
private KList<ObjectPlacement> place = new KList<>();
|
||||
}
|
||||
+3
-3
@@ -18,7 +18,7 @@
|
||||
|
||||
package art.arcane.iris.engine.object.mod;
|
||||
|
||||
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||
import art.arcane.iris.engine.object.annotations.ArrayType;
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
@@ -45,6 +45,6 @@ public class IrisModObjectPlacementRegionInjector {
|
||||
|
||||
@Required
|
||||
@Desc("Object placements to inject into the region")
|
||||
@ArrayType(type = IrisObjectPlacement.class, min = 1)
|
||||
private KList<IrisObjectPlacement> place = new KList<>();
|
||||
@ArrayType(type = ObjectPlacement.class, min = 1)
|
||||
private KList<ObjectPlacement> place = new KList<>();
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* 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.engine.object.placement;
|
||||
|
||||
import art.arcane.iris.engine.object.terrain.carving.CaveResult;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import org.bukkit.generator.ChunkGenerator.ChunkData;
|
||||
|
||||
public interface IPostBlockAccess {
|
||||
PlatformBlockState getPostBlock(int x, int y, int z, int currentPostX, int currentPostZ, ChunkData currentData);
|
||||
|
||||
void setPostBlock(int x, int y, int z, PlatformBlockState d, int currentPostX, int currentPostZ, ChunkData currentData);
|
||||
|
||||
int highestTerrainOrFluidBlock(int x, int z);
|
||||
|
||||
int highestTerrainBlock(int x, int z);
|
||||
|
||||
void updateHeight(int x, int z, int h);
|
||||
|
||||
KList<CaveResult> caveFloors(int x, int z);
|
||||
}
|
||||
@@ -1,325 +0,0 @@
|
||||
/*
|
||||
* 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.engine.object.placement;
|
||||
|
||||
import art.arcane.iris.builtin.carve.CarvingMode;
|
||||
import art.arcane.iris.builtin.objects.TreeOverride;
|
||||
import art.arcane.iris.builtin.carve.CaveAnchorMode;
|
||||
import art.arcane.iris.builtin.anchor.ObjectPlaceMode;
|
||||
import art.arcane.iris.builtin.blocks.ObjectReplace;
|
||||
import art.arcane.iris.builtin.stilt.StiltSettings;
|
||||
import art.arcane.iris.builtin.prepare.SlopeClip;
|
||||
import art.arcane.iris.builtin.vacuum.VacuumSettings;
|
||||
import art.arcane.iris.builtin.validate.ObjectLimit;
|
||||
import art.arcane.iris.core.modules.ModuleSettings;
|
||||
import art.arcane.iris.builtin.loot.ObjectLoot;
|
||||
import art.arcane.iris.builtin.loot.ObjectVanillaLoot;
|
||||
import art.arcane.iris.builtin.spawn.PlacementMarker;
|
||||
import art.arcane.iris.engine.object.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.engine.object.noise.IrisNoiseGenerator;
|
||||
import art.arcane.iris.engine.object.noise.IrisStyledRange;
|
||||
import art.arcane.iris.engine.object.noise.NoiseStyle;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectRotation;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectScale;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObjectTranslate;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.volmlib.util.cache.LazyBoundedCache;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.annotations.ArrayType;
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
import art.arcane.iris.engine.object.annotations.MaxNumber;
|
||||
import art.arcane.iris.engine.object.annotations.MinNumber;
|
||||
import art.arcane.iris.engine.object.annotations.RegistryListResource;
|
||||
import art.arcane.iris.engine.object.annotations.Required;
|
||||
import art.arcane.iris.engine.object.annotations.Snippet;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.iris.util.common.data.DataProvider;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.iris.util.project.noise.CNG;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
||||
@Snippet("object-placer")
|
||||
@EqualsAndHashCode()
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Desc("Represents an iris object placer. It places objects.")
|
||||
@Data
|
||||
public class IrisObjectPlacement {
|
||||
private static final int SURFACE_WARP_CACHE_SIZE = 8;
|
||||
@Getter(AccessLevel.NONE)
|
||||
@Setter(AccessLevel.NONE)
|
||||
private final transient LazyBoundedCache<SurfaceWarpCacheKey, CNG> surfaceWarpCache =
|
||||
new LazyBoundedCache<>(SURFACE_WARP_CACHE_SIZE);
|
||||
@RegistryListResource(IrisObject.class)
|
||||
@Required
|
||||
@ArrayType(min = 1, type = String.class)
|
||||
@Desc("List of objects to place")
|
||||
private KList<String> place = new KList<>();
|
||||
@Desc("Rotate this objects placement")
|
||||
private IrisObjectRotation rotation = new IrisObjectRotation();
|
||||
@Desc("Limit the max height or min height of placement.")
|
||||
private ObjectLimit clamp = new ObjectLimit();
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Desc("The maximum layer level of a snow filter overtop of this placement. Set to 0 to disable. Max of 1.")
|
||||
private double snow = 0;
|
||||
@Desc("Whether or not this object can be targeted by a dolphin.")
|
||||
private boolean isDolphinTarget = false;
|
||||
@Desc("The slope at which this object can be placed. Range from 0 to 10 by default. Calculated from a 3-block radius from the center of the object placement.")
|
||||
private SlopeClip slopeCondition = new SlopeClip();
|
||||
@Desc("Set to true to add the rotation of the direction of the slope of the terrain (wherever the slope is going down) to the y-axis rotation of the object." +
|
||||
"Rounded to 90 degrees. Adds the *min* rotation of the y axis as well (to still allow you to rotate objects nicely). Discards *max* and *interval* on *yaxis*")
|
||||
private boolean rotateTowardsSlope = false;
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Desc("The chance for this to place in a chunk. If you need multiple per chunk, set this to 1 and use density.")
|
||||
private double chance = 1;
|
||||
@MinNumber(1)
|
||||
@Desc("If the chance check passes, place this many in a single chunk")
|
||||
private int density = 1;
|
||||
@Desc("If the chance check passes, and you specify this, it picks a number in the range based on noise, and 'density' is ignored.")
|
||||
private IrisStyledRange densityStyle = null;
|
||||
@Desc("When stilting is enabled, this object will define various properties related to it.")
|
||||
private StiltSettings stiltSettings;
|
||||
@Desc("When a VACUUM place mode is used, this defines the deformation radius and falloff.")
|
||||
private VacuumSettings vacuumSettings;
|
||||
@MaxNumber(64)
|
||||
@MinNumber(0)
|
||||
@Desc("When bore is enabled, expand max-y of the cuboid it removes")
|
||||
private int boreExtendMaxY = 0;
|
||||
@ArrayType(min = 1, type = PlacementMarker.class)
|
||||
@Desc("Add markers to blocks in this object")
|
||||
private KList<PlacementMarker> markers = new KList<>();
|
||||
@MaxNumber(64)
|
||||
@MinNumber(-1)
|
||||
@Desc("When bore is enabled, lower min-y of the cuboid it removes")
|
||||
private int boreExtendMinY = 0;
|
||||
@Desc("If set to true, objects will place on the terrain height, ignoring the water surface.")
|
||||
private boolean underwater = false;
|
||||
@Desc("If set to true, objects will place in carvings (such as underground) or under an overhang.")
|
||||
private CarvingMode carvingSupport = CarvingMode.SURFACE_ONLY;
|
||||
@MinNumber(0)
|
||||
@MaxNumber(16)
|
||||
@Desc("Extra buffer, in blocks, around this object's base footprint that must also be solid, un-carved ground. 0 checks only the footprint itself.")
|
||||
private int surfaceSupportBuffer = 2;
|
||||
@MinNumber(1)
|
||||
@MaxNumber(16)
|
||||
@Desc("Minimum thickness, in blocks, of un-carved ground required under every column of this object's base footprint.")
|
||||
private int surfaceSupportDepth = 2;
|
||||
@Desc("Set to false to let this placement sit over carved surface openings such as cave entrances.")
|
||||
private boolean requireSurfaceSupport = true;
|
||||
@Desc("When carving placement is enabled, select which carved-space anchor this placement targets.")
|
||||
private CaveAnchorMode caveAnchorMode = CaveAnchorMode.PROFILE_DEFAULT;
|
||||
@Desc("If this is defined, this object wont place on the terrain heightmap, but instead on this virtual heightmap")
|
||||
private IrisNoiseGenerator heightmap;
|
||||
@Desc("If set to true, Iris will try to fill the insides of 'rooms' and 'pockets' where air should fit based off of raytrace checks. This prevents a village house placing in an area where a tree already exists, and instead replaces the parts of the tree where the interior of the structure is. \n\nThis operation does not affect warmed-up generation speed however it does slow down loading objects.")
|
||||
private boolean smartBore = false;
|
||||
@Desc("If set to true, Blocks placed underwater that could be waterlogged are waterlogged.")
|
||||
private boolean waterloggable = false;
|
||||
@Desc("If set to true, objects will place on the fluid height level Such as boats.")
|
||||
private boolean onwater = false;
|
||||
@Desc("If set to true, this object will only place parts of itself where blocks already exist. Warning: Melding is very performance intensive!")
|
||||
private boolean meld = false;
|
||||
@Desc("If set to true, this object will get placed from the bottom of the world up")
|
||||
private boolean fromBottom;
|
||||
@Desc("If set to true, this object will place from the ground up instead of height checks when not y locked to the surface. This is not compatable with X and Z axis rotations (it may look off)")
|
||||
private boolean bottom = false;
|
||||
@Desc("If set to true, air will be placed before the schematic places.")
|
||||
private boolean bore = false;
|
||||
@Desc("Use a generator to warp the field of coordinates. Using simplex for example would make a square placement warp like a flag")
|
||||
private IrisGeneratorStyle warp = new IrisGeneratorStyle(NoiseStyle.FLAT);
|
||||
@Desc("The placement mode")
|
||||
private ObjectPlaceMode mode = ObjectPlaceMode.CENTER_HEIGHT;
|
||||
@ArrayType(min = 1, type = ObjectReplace.class)
|
||||
@Desc("Find and replace blocks")
|
||||
private KList<ObjectReplace> edit = new KList<>();
|
||||
@Desc("Translate this object's placement")
|
||||
private IrisObjectTranslate translate = new IrisObjectTranslate();
|
||||
@Desc("Scale Objects")
|
||||
private IrisObjectScale scale = new IrisObjectScale();
|
||||
@ArrayType(min = 1, type = ObjectLoot.class)
|
||||
@Desc("The loot tables to apply to these objects")
|
||||
private KList<ObjectLoot> loot = new KList<>();
|
||||
@ArrayType(min = 1, type = ObjectVanillaLoot.class)
|
||||
@Desc("The vanilla loot tables to apply to these objects")
|
||||
private KList<ObjectVanillaLoot> vanillaLoot = new KList<>();
|
||||
@Desc("Whether the given loot tables override any and all other loot tables available in the dimension, region or biome.")
|
||||
private boolean overrideGlobalLoot = false;
|
||||
@Desc("This object / these objects override the following trees when they grow...")
|
||||
@ArrayType(min = 1, type = TreeOverride.class)
|
||||
private KList<TreeOverride> trees = new KList<>();
|
||||
@RegistryListResource(IrisObject.class)
|
||||
@ArrayType(type = String.class)
|
||||
@Desc("List of objects to this object is allowed to collied with")
|
||||
private KList<String> allowedCollisions = new KList<>();
|
||||
@RegistryListResource(IrisObject.class)
|
||||
@ArrayType(type = String.class)
|
||||
@Desc("List of objects to this object is forbidden to collied with")
|
||||
private KList<String> forbiddenCollisions = new KList<>();
|
||||
@Desc("Ignore any placement restrictions for this object")
|
||||
@SerializedName(value = "forcePlace", alternate = {"force"})
|
||||
private boolean forcePlace = false;
|
||||
/** The pack modules' settings this placement declares, decoded with it. */
|
||||
private transient ModuleSettings moduleSettings = ModuleSettings.NONE;
|
||||
|
||||
/** A placement that stamps each object exactly at the position it is given, as a structure piece. */
|
||||
public static IrisObjectPlacement stampingStructurePieces() {
|
||||
return new IrisObjectPlacement().setMode(ObjectPlaceMode.STRUCTURE_PIECE);
|
||||
}
|
||||
|
||||
public IrisObjectPlacement toPlacement(String... place) {
|
||||
IrisObjectPlacement p = new IrisObjectPlacement();
|
||||
p.setPlace(new KList<>(place));
|
||||
p.setMode(mode);
|
||||
p.setEdit(edit);
|
||||
p.setTranslate(translate);
|
||||
p.setScale(scale);
|
||||
p.setWarp(warp);
|
||||
p.setBore(bore);
|
||||
p.setMeld(meld);
|
||||
p.setWaterloggable(waterloggable);
|
||||
p.setOnwater(onwater);
|
||||
p.setFromBottom(fromBottom);
|
||||
p.setBottom(bottom);
|
||||
p.setSmartBore(smartBore);
|
||||
p.setCarvingSupport(carvingSupport);
|
||||
p.setSurfaceSupportBuffer(surfaceSupportBuffer);
|
||||
p.setSurfaceSupportDepth(surfaceSupportDepth);
|
||||
p.setRequireSurfaceSupport(requireSurfaceSupport);
|
||||
p.setCaveAnchorMode(caveAnchorMode);
|
||||
p.setUnderwater(underwater);
|
||||
p.setHeightmap(heightmap);
|
||||
p.setBoreExtendMaxY(boreExtendMaxY);
|
||||
p.setBoreExtendMinY(boreExtendMinY);
|
||||
p.setStiltSettings(stiltSettings);
|
||||
p.setVacuumSettings(vacuumSettings);
|
||||
p.setDensity(density);
|
||||
p.setDensityStyle(densityStyle);
|
||||
p.setChance(chance);
|
||||
p.setSnow(snow);
|
||||
p.setClamp(clamp);
|
||||
p.setRotation(rotation);
|
||||
p.setSlopeCondition(slopeCondition);
|
||||
p.setRotateTowardsSlope(rotateTowardsSlope);
|
||||
p.setDolphinTarget(isDolphinTarget);
|
||||
p.setMarkers(markers);
|
||||
p.setLoot(loot);
|
||||
p.setVanillaLoot(vanillaLoot);
|
||||
p.setOverrideGlobalLoot(overrideGlobalLoot);
|
||||
p.setTrees(trees);
|
||||
p.setAllowedCollisions(allowedCollisions);
|
||||
p.setForbiddenCollisions(forbiddenCollisions);
|
||||
p.setForcePlace(forcePlace);
|
||||
p.setModuleSettings(moduleSettings);
|
||||
return p;
|
||||
}
|
||||
|
||||
public CNG getSurfaceWarp(RNG rng, IrisData data) {
|
||||
return getSurfaceWarp(rng, data, data.getEngine());
|
||||
}
|
||||
|
||||
public CNG getSurfaceWarp(RNG rng, IrisData data, @Nullable Engine engine) {
|
||||
long seed = engine == null ? rng.getSeed() : engine.getSeedManager().getComponent() + 1024L;
|
||||
SurfaceWarpCacheKey key = new SurfaceWarpCacheKey(data, engine, seed);
|
||||
return surfaceWarpCache.computeIfAbsent(key,
|
||||
ignored -> getWarp().create(new RNG(seed), data, engine));
|
||||
}
|
||||
|
||||
public double warp(RNG rng, double x, double y, double z, IrisData data) {
|
||||
return getSurfaceWarp(rng, data).fitDouble(-(getWarp().getMultiplier() / 2D), (getWarp().getMultiplier() / 2D), x, y, z);
|
||||
}
|
||||
|
||||
public IrisObject getObject(DataProvider g, RNG random) {
|
||||
if (place.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return g.getData().getObjectLoader().load(place.get(random.nextInt(place.size())));
|
||||
}
|
||||
|
||||
/** Whether a tree placement grows the species the platform calls {@code species} for a sapling area of {@code width} by {@code depth}. */
|
||||
public boolean matches(int width, int depth, String species) {
|
||||
for (TreeOverride tree : getTrees()) {
|
||||
if (tree.matches(width, depth, species)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getDensity() {
|
||||
if (densityStyle == null) {
|
||||
return density;
|
||||
}
|
||||
return densityStyle.getMid();
|
||||
}
|
||||
|
||||
public int getDensity(RNG rng, double x, double z, IrisData data) {
|
||||
if (densityStyle == null) {
|
||||
return density;
|
||||
}
|
||||
|
||||
return (int) Math.round(densityStyle.get(rng, x, z, data));
|
||||
}
|
||||
|
||||
private static final class SurfaceWarpCacheKey {
|
||||
private final IrisData data;
|
||||
private final Engine engine;
|
||||
private final long seed;
|
||||
|
||||
private SurfaceWarpCacheKey(IrisData data, Engine engine, long seed) {
|
||||
this.data = data;
|
||||
this.engine = engine;
|
||||
this.seed = seed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (!(other instanceof SurfaceWarpCacheKey key)) {
|
||||
return false;
|
||||
}
|
||||
return data == key.data && engine == key.engine && seed == key.seed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = System.identityHashCode(data);
|
||||
result = 31 * result + System.identityHashCode(engine);
|
||||
return 31 * result + Long.hashCode(seed);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* 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.placement;
|
||||
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.modules.IrisPackResources;
|
||||
import art.arcane.iris.core.modules.IrisValues;
|
||||
import art.arcane.iris.core.modules.ModuleSettings;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.noise.IrisGeneratorStyle;
|
||||
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;
|
||||
|
||||
/**
|
||||
* What Iris makes of one object placement: the module settings its JSON declares, and its noise as Iris's own
|
||||
* generators, which keep the noise they build. Made once per placement and kept on it, so copies made with
|
||||
* {@link ObjectPlacement#toBuilder()} share it until their noise changes.
|
||||
*/
|
||||
public final class IrisPlacementForm {
|
||||
private static final int SURFACE_WARP_CACHE_SIZE = 8;
|
||||
private static final long SURFACE_WARP_SEED_OFFSET = 1024L;
|
||||
|
||||
private final ModuleSettings moduleSettings;
|
||||
private final IrisGeneratorStyle warp;
|
||||
private final IrisStyledRange densityStyle;
|
||||
private final IrisNoiseGenerator heightmap;
|
||||
private final LazyBoundedCache<SurfaceWarpKey, CNG> surfaceWarps = new LazyBoundedCache<>(SURFACE_WARP_CACHE_SIZE);
|
||||
|
||||
private IrisPlacementForm(ModuleSettings moduleSettings, IrisGeneratorStyle warp, IrisStyledRange densityStyle,
|
||||
IrisNoiseGenerator heightmap) {
|
||||
this.moduleSettings = moduleSettings;
|
||||
this.warp = warp;
|
||||
this.densityStyle = densityStyle;
|
||||
this.heightmap = heightmap;
|
||||
}
|
||||
|
||||
/** Iris's form of {@code placement}, made the first time it is asked for. */
|
||||
public static IrisPlacementForm of(ObjectPlacement placement, IrisData data) {
|
||||
if (placement.hostForm() instanceof IrisPlacementForm kept) {
|
||||
return kept;
|
||||
}
|
||||
IrisPlacementForm made = make(placement, data);
|
||||
placement.hostForm(made);
|
||||
return made;
|
||||
}
|
||||
|
||||
private static IrisPlacementForm make(ObjectPlacement placement, IrisData data) {
|
||||
IrisPackResources resources = (IrisPackResources) data.getPackResources();
|
||||
return new IrisPlacementForm(moduleSettingsOf(placement, data),
|
||||
IrisValues.generatorStyle(placement.warp(), resources),
|
||||
placement.densityStyle().map(range -> IrisValues.styledRange(range, resources)).orElse(null),
|
||||
placement.heightmap().map(noise -> IrisValues.noiseGenerator(noise, resources)).orElse(null));
|
||||
}
|
||||
|
||||
private static ModuleSettings moduleSettingsOf(ObjectPlacement placement, IrisData data) {
|
||||
if (placement.json() == null) {
|
||||
return ModuleSettings.NONE;
|
||||
}
|
||||
return data.getModules().settings().decode(Level.PLACEMENT, new JSONObject(placement.json()), "object placement");
|
||||
}
|
||||
|
||||
/** The settings the pack's modules declare on the placement. */
|
||||
public ModuleSettings moduleSettings() {
|
||||
return moduleSettings;
|
||||
}
|
||||
|
||||
public IrisGeneratorStyle warp() {
|
||||
return warp;
|
||||
}
|
||||
|
||||
/** The virtual heightmap the objects place on, or null to place on the terrain. */
|
||||
public @Nullable IrisNoiseGenerator heightmap() {
|
||||
return heightmap;
|
||||
}
|
||||
|
||||
/** How many objects to place at the given column: the fixed density, or the one the density style picks there. */
|
||||
public int density(ObjectPlacement placement, RNG rng, double x, double z, IrisData data) {
|
||||
if (densityStyle == null) {
|
||||
return placement.density();
|
||||
}
|
||||
return (int) Math.round(densityStyle.get(rng, x, z, data));
|
||||
}
|
||||
|
||||
/** The noise that warps the surface the objects sit on, built once per world seed. */
|
||||
public CNG surfaceWarp(RNG rng, IrisData data, @Nullable Engine engine) {
|
||||
long seed = engine == null ? rng.getSeed() : engine.getSeedManager().getComponent() + SURFACE_WARP_SEED_OFFSET;
|
||||
return surfaceWarps.computeIfAbsent(new SurfaceWarpKey(data, engine, seed),
|
||||
ignored -> warp.create(new RNG(seed), data, engine));
|
||||
}
|
||||
|
||||
private record SurfaceWarpKey(IrisData data, Engine engine, long seed) {
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
return other instanceof SurfaceWarpKey key && data == key.data && engine == key.engine && seed == key.seed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = System.identityHashCode(data);
|
||||
result = 31 * result + System.identityHashCode(engine);
|
||||
return 31 * result + Long.hashCode(seed);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,15 +27,18 @@ import art.arcane.iris.builtin.objects.UpperObjectsForceSettings;
|
||||
import art.arcane.iris.builtin.objects.UpperObjectsSettings;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.loader.IrisRegistrant;
|
||||
import art.arcane.iris.engine.object.prefab.IrisObject;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
/**
|
||||
* The object placements a region or biome declares, as Iris places them: the module settings of
|
||||
* {@code iris:objects}, made into Iris's own placements once and kept for as long as the settings live.
|
||||
* The object placements a region or biome declares in the module settings of {@code iris:objects}, sorted by where
|
||||
* they place once and kept for as long as the settings live, and the dimension's object settings.
|
||||
*/
|
||||
public final class ObjectPlacements {
|
||||
private static final Map<ObjectSettings, Placements> PLACEMENTS = Collections.synchronizedMap(new WeakHashMap<>());
|
||||
@@ -44,17 +47,17 @@ public final class ObjectPlacements {
|
||||
}
|
||||
|
||||
/** Every placement {@code owner} declares. */
|
||||
public static KList<IrisObjectPlacement> all(IrisRegistrant owner) {
|
||||
public static KList<ObjectPlacement> all(IrisRegistrant owner) {
|
||||
return placementsOf(owner).all;
|
||||
}
|
||||
|
||||
/** The placements of {@code owner} that place on the surface. */
|
||||
public static KList<IrisObjectPlacement> surface(IrisRegistrant owner) {
|
||||
public static KList<ObjectPlacement> surface(IrisRegistrant owner) {
|
||||
return placementsOf(owner).surface;
|
||||
}
|
||||
|
||||
/** The placements of {@code owner} that place in carvings. */
|
||||
public static KList<IrisObjectPlacement> carving(IrisRegistrant owner) {
|
||||
public static KList<ObjectPlacement> carving(IrisRegistrant owner) {
|
||||
return placementsOf(owner).carving;
|
||||
}
|
||||
|
||||
@@ -85,15 +88,13 @@ public final class ObjectPlacements {
|
||||
return dimension.getModuleSettings().find(TreeGrowthSettings.class).orElse(NO_TREE_GROWTH);
|
||||
}
|
||||
|
||||
/** Iris's placement for the settings {@code placement}, read from the JSON it was written as. */
|
||||
public static IrisObjectPlacement host(ObjectPlacement placement, IrisData data) {
|
||||
Object kept = placement.hostForm();
|
||||
if (kept instanceof IrisObjectPlacement hostPlacement) {
|
||||
return hostPlacement;
|
||||
/** One of the objects {@code placement} places, picked by {@code rng} and loaded from the pack; null when it names none. */
|
||||
public static IrisObject pickObject(ObjectPlacement placement, IrisData data, RNG rng) {
|
||||
List<String> keys = placement.place();
|
||||
if (keys.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
IrisObjectPlacement made = data.getGson().fromJson(placement.json(), IrisObjectPlacement.class);
|
||||
placement.hostForm(made);
|
||||
return made;
|
||||
return data.getObjectLoader().load(keys.get(rng.nextInt(keys.size())));
|
||||
}
|
||||
|
||||
private static final RequireSurfaceSupportSettings NO_SURFACE_SUPPORT_REQUIREMENT = new RequireSurfaceSupportSettings();
|
||||
@@ -107,19 +108,18 @@ public final class ObjectPlacements {
|
||||
if (found != null) {
|
||||
return found;
|
||||
}
|
||||
return PLACEMENTS.computeIfAbsent(settings, declared -> new Placements(declared, owner.getLoader()));
|
||||
return PLACEMENTS.computeIfAbsent(settings, Placements::new);
|
||||
}
|
||||
|
||||
private record Placements(KList<IrisObjectPlacement> all, KList<IrisObjectPlacement> surface, KList<IrisObjectPlacement> carving) {
|
||||
Placements(ObjectSettings settings, IrisData data) {
|
||||
private record Placements(KList<ObjectPlacement> all, KList<ObjectPlacement> surface, KList<ObjectPlacement> carving) {
|
||||
Placements(ObjectSettings settings) {
|
||||
this(new KList<>(), new KList<>(), new KList<>());
|
||||
for (ObjectPlacement declared : settings.objects()) {
|
||||
IrisObjectPlacement placement = host(declared, data);
|
||||
for (ObjectPlacement placement : settings.objects()) {
|
||||
all.add(placement);
|
||||
if (placement.getCarvingSupport().supportsSurface()) {
|
||||
if (placement.carvingSupport().supportsSurface()) {
|
||||
surface.add(placement);
|
||||
}
|
||||
if (placement.getCarvingSupport().supportsCarving()) {
|
||||
if (placement.carvingSupport().supportsCarving()) {
|
||||
carving.add(placement);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,276 @@
|
||||
/*
|
||||
* 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.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;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.collection.KMap;
|
||||
import art.arcane.volmlib.util.math.IrisBlockVector;
|
||||
import org.bukkit.Axis;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Directional;
|
||||
import org.bukkit.block.data.MultipleFacing;
|
||||
import org.bukkit.block.data.Orientable;
|
||||
import org.bukkit.block.data.Rotatable;
|
||||
import org.bukkit.block.data.type.RedstoneWire;
|
||||
import org.bukkit.block.data.type.Wall;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
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 ObjectRotation} that turns the object's positions. 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. */
|
||||
public interface StateRotator {
|
||||
PlatformBlockState rotate(ObjectRotation rotation, PlatformBlockState state, int spinX, int spinY, int spinZ);
|
||||
}
|
||||
|
||||
/** Holds the Bukkit faces apart so a platform without Bukkit can load this class and bind its own rotator. */
|
||||
private static final class Faces {
|
||||
private static final List<BlockFace> WALL_FACES = List.of(BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST);
|
||||
}
|
||||
|
||||
private BlockStateRotation() {
|
||||
}
|
||||
|
||||
public static synchronized StateRotator bindPlatformRotator(StateRotator rotator) {
|
||||
StateRotator previous = platformRotator;
|
||||
platformRotator = Objects.requireNonNull(rotator, "rotator");
|
||||
return previous;
|
||||
}
|
||||
|
||||
public static synchronized void restorePlatformRotator(StateRotator rotator) {
|
||||
platformRotator = rotator;
|
||||
}
|
||||
|
||||
/** {@code state} turned by {@code rotation}; 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 (state == null) {
|
||||
return null;
|
||||
}
|
||||
StateRotator rotator = platformRotator;
|
||||
if (rotator != null) {
|
||||
return rotator.rotate(rotation, state, spinX, spinY, spinZ);
|
||||
}
|
||||
BlockData original = (BlockData) state.nativeHandle();
|
||||
if (!rotation.canRotate() || !canRotateBlockData(original)) {
|
||||
return state;
|
||||
}
|
||||
BlockData rotated = rotate(rotation, original.clone(), spinX, spinY, spinZ);
|
||||
return rotated == null ? null : BukkitBlockState.of(rotated);
|
||||
}
|
||||
|
||||
private static boolean canRotateBlockData(BlockData data) {
|
||||
return data instanceof Directional
|
||||
|| data instanceof Rotatable
|
||||
|| data instanceof Orientable
|
||||
|| data instanceof MultipleFacing
|
||||
|| data instanceof Wall
|
||||
|| 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) {
|
||||
BlockData d = data;
|
||||
try {
|
||||
int spinX = wholeQuarterTurns(spinXDegrees);
|
||||
int spinY = wholeQuarterTurns(spinYDegrees);
|
||||
int spinZ = wholeQuarterTurns(spinZDegrees);
|
||||
|
||||
if (!rotation.canRotate()) {
|
||||
return d;
|
||||
}
|
||||
|
||||
if (d instanceof Directional g) {
|
||||
BlockFace f = g.getFacing();
|
||||
IrisBlockVector bv = rotation.rotate(new IrisBlockVector(f.getModX(), f.getModY(), f.getModZ()), spinX, spinY, spinZ);
|
||||
BlockFace t = faceOf(bv);
|
||||
|
||||
if (g.getFaces().contains(t)) {
|
||||
g.setFacing(t);
|
||||
} else if (!g.getMaterial().isSolid()) {
|
||||
d = null;
|
||||
}
|
||||
} else if (d instanceof Rotatable g) {
|
||||
BlockFace f = g.getRotation();
|
||||
IrisBlockVector bv = rotation.rotate(new IrisBlockVector(f.getModX(), 0, f.getModZ()), spinX, spinY, spinZ);
|
||||
g.setRotation(sixteenWayFaceOf(bv));
|
||||
} else if (d instanceof Orientable g) {
|
||||
BlockFace f = faceOf(g.getAxis());
|
||||
IrisBlockVector bv = rotation.rotate(new IrisBlockVector(f.getModX(), f.getModY(), f.getModZ()), spinX, spinY, spinZ);
|
||||
Axis a = axisOf(bv);
|
||||
|
||||
if (!a.equals(g.getAxis()) && g.getAxes().contains(a)) {
|
||||
g.setAxis(a);
|
||||
}
|
||||
} else if (d instanceof MultipleFacing g) {
|
||||
List<BlockFace> faces = new KList<>();
|
||||
|
||||
for (BlockFace i : g.getFaces()) {
|
||||
IrisBlockVector bv = rotation.rotate(new IrisBlockVector(i.getModX(), i.getModY(), i.getModZ()), spinX, spinY, spinZ);
|
||||
BlockFace r = faceOf(bv);
|
||||
|
||||
if (g.getAllowedFaces().contains(r)) {
|
||||
faces.add(r);
|
||||
}
|
||||
}
|
||||
|
||||
for (BlockFace i : g.getFaces()) {
|
||||
g.setFace(i, false);
|
||||
}
|
||||
|
||||
for (BlockFace i : faces) {
|
||||
g.setFace(i, true);
|
||||
}
|
||||
} else if (d instanceof Wall wall) {
|
||||
KMap<BlockFace, Wall.Height> faces = new KMap<>();
|
||||
|
||||
for (BlockFace i : Faces.WALL_FACES) {
|
||||
Wall.Height h = wall.getHeight(i);
|
||||
IrisBlockVector bv = rotation.rotate(new IrisBlockVector(i.getModX(), i.getModY(), i.getModZ()), spinX, spinY, spinZ);
|
||||
BlockFace r = faceOf(bv);
|
||||
if (Faces.WALL_FACES.contains(r)) {
|
||||
faces.put(r, h);
|
||||
}
|
||||
}
|
||||
|
||||
for (BlockFace i : Faces.WALL_FACES) {
|
||||
wall.setHeight(i, faces.getOrDefault(i, Wall.Height.NONE));
|
||||
}
|
||||
} else if (d instanceof RedstoneWire wire) {
|
||||
Map<BlockFace, RedstoneWire.Connection> faces = new HashMap<>();
|
||||
|
||||
Set<BlockFace> allowed = wire.getAllowedFaces();
|
||||
for (BlockFace i : allowed) {
|
||||
RedstoneWire.Connection connection = wire.getFace(i);
|
||||
IrisBlockVector bv = rotation.rotate(new IrisBlockVector(i.getModX(), i.getModY(), i.getModZ()), spinX, spinY, spinZ);
|
||||
BlockFace r = faceOf(bv);
|
||||
if (allowed.contains(r)) {
|
||||
faces.put(r, connection);
|
||||
}
|
||||
}
|
||||
|
||||
for (BlockFace i : allowed) {
|
||||
wire.setFace(i, faces.getOrDefault(i, RedstoneWire.Connection.NONE));
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
IrisLogging.reportError(e);
|
||||
}
|
||||
|
||||
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());
|
||||
int z = (int) Math.round(v.getZ());
|
||||
|
||||
if (x == 0 && z == -1) {
|
||||
return BlockFace.NORTH;
|
||||
}
|
||||
if (x == 0 && z == 1) {
|
||||
return BlockFace.SOUTH;
|
||||
}
|
||||
if (x == 1 && z == 0) {
|
||||
return BlockFace.EAST;
|
||||
}
|
||||
if (x == -1 && z == 0) {
|
||||
return BlockFace.WEST;
|
||||
}
|
||||
if (y > 0) {
|
||||
return BlockFace.UP;
|
||||
}
|
||||
if (y < 0) {
|
||||
return BlockFace.DOWN;
|
||||
}
|
||||
return BlockFace.SOUTH;
|
||||
}
|
||||
|
||||
private static BlockFace sixteenWayFaceOf(IrisBlockVector v) {
|
||||
int x = v.getBlockX();
|
||||
int y = v.getBlockY();
|
||||
int z = v.getBlockZ();
|
||||
|
||||
if (x == 0 && z == -1) return BlockFace.NORTH;
|
||||
if (x == 1 && z == -2) return BlockFace.NORTH_NORTH_EAST;
|
||||
if (x == 1 && z == -1) return BlockFace.NORTH_EAST;
|
||||
if (x == 2 && z == -1) return BlockFace.EAST_NORTH_EAST;
|
||||
if (x == 1 && z == 0) return BlockFace.EAST;
|
||||
if (x == 2 && z == 1) return BlockFace.EAST_SOUTH_EAST;
|
||||
if (x == 1 && z == 1) return BlockFace.SOUTH_EAST;
|
||||
if (x == 1 && z == 2) return BlockFace.SOUTH_SOUTH_EAST;
|
||||
if (x == 0 && z == 1) return BlockFace.SOUTH;
|
||||
if (x == -1 && z == 2) return BlockFace.SOUTH_SOUTH_WEST;
|
||||
if (x == -1 && z == 1) return BlockFace.SOUTH_WEST;
|
||||
if (x == -2 && z == 1) return BlockFace.WEST_SOUTH_WEST;
|
||||
if (x == -1 && z == 0) return BlockFace.WEST;
|
||||
if (x == -2 && z == -1) return BlockFace.WEST_NORTH_WEST;
|
||||
if (x == -1 && z == -1) return BlockFace.NORTH_WEST;
|
||||
if (x == -1 && z == -2) return BlockFace.NORTH_NORTH_WEST;
|
||||
|
||||
if (y > 0) {
|
||||
return BlockFace.UP;
|
||||
}
|
||||
if (y < 0) {
|
||||
return BlockFace.DOWN;
|
||||
}
|
||||
return BlockFace.SOUTH;
|
||||
}
|
||||
|
||||
private static Axis axisOf(IrisBlockVector v) {
|
||||
if (Math.abs(v.getBlockX()) > Math.max(Math.abs(v.getBlockY()), Math.abs(v.getBlockZ()))) {
|
||||
return Axis.X;
|
||||
}
|
||||
if (Math.abs(v.getBlockY()) > Math.max(Math.abs(v.getBlockX()), Math.abs(v.getBlockZ()))) {
|
||||
return Axis.Y;
|
||||
}
|
||||
if (Math.abs(v.getBlockZ()) > Math.max(Math.abs(v.getBlockX()), Math.abs(v.getBlockY()))) {
|
||||
return Axis.Z;
|
||||
}
|
||||
return Axis.Y;
|
||||
}
|
||||
|
||||
private static BlockFace faceOf(Axis axis) {
|
||||
return switch (axis) {
|
||||
case X -> BlockFace.EAST;
|
||||
case Y -> BlockFace.UP;
|
||||
case Z -> BlockFace.SOUTH;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -19,9 +19,11 @@
|
||||
package art.arcane.iris.engine.object.prefab;
|
||||
|
||||
import art.arcane.iris.builtin.objects.PlaceableObject;
|
||||
import art.arcane.iris.builtin.objects.ScaleInterpolation;
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
import art.arcane.iris.engine.object.placement.FloatingObjectFootprint;
|
||||
import art.arcane.iris.engine.object.placement.IObjectPlacer;
|
||||
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
|
||||
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;
|
||||
@@ -258,24 +260,24 @@ public class IrisObject extends IrisRegistrant implements PlaceableObject {
|
||||
forgetDerivedShapes();
|
||||
}
|
||||
|
||||
public int place(int x, int z, IObjectPlacer placer, IrisObjectPlacement config, RNG rng, IrisData rdata) {
|
||||
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, IrisObjectPlacement config, RNG rng, CarveResult c, IrisData 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, IrisObjectPlacement config, RNG rng, IrisData 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, IrisObjectPlacement config, RNG rng, IrisData 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, IrisObjectPlacement config, RNG rng, BiConsumer<BlockPosition, PlatformBlockState> listener, CarveResult c, IrisData rdata) {
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -319,11 +321,11 @@ public class IrisObject extends IrisRegistrant implements PlaceableObject {
|
||||
});
|
||||
}
|
||||
|
||||
public IrisObject rotateCopy(IrisObjectRotation rt) {
|
||||
public IrisObject rotateCopy(ObjectRotation rt) {
|
||||
return IrisObjectTransforms.rotateCopy(this, rt);
|
||||
}
|
||||
|
||||
public IrisObject scaled(double scale, IrisObjectPlacementScaleInterpolator interpolation) {
|
||||
public IrisObject scaled(double scale, ScaleInterpolation interpolation) {
|
||||
return IrisObjectTransforms.scaled(this, scale, interpolation);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,518 +0,0 @@
|
||||
/*
|
||||
* 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.engine.object.prefab;
|
||||
|
||||
import art.arcane.iris.builtin.prepare.AxisRotationClamp;
|
||||
import art.arcane.iris.engine.object.value.IrisDirection;
|
||||
import art.arcane.iris.engine.object.value.IrisPosition;
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
import art.arcane.iris.engine.object.annotations.Snippet;
|
||||
import art.arcane.iris.platform.bukkit.BukkitBlockState;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.volmlib.util.math.IrisBlockVector;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.collection.KMap;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.bukkit.Axis;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Directional;
|
||||
import org.bukkit.block.data.MultipleFacing;
|
||||
import org.bukkit.block.data.Orientable;
|
||||
import org.bukkit.block.data.Rotatable;
|
||||
import org.bukkit.block.data.type.RedstoneWire;
|
||||
import org.bukkit.block.data.type.Wall;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
@Snippet("object-rotator")
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Desc("Configures rotation for iris")
|
||||
@Data
|
||||
public class IrisObjectRotation {
|
||||
private static volatile StateRotator PLATFORM_ROTATOR = null;
|
||||
|
||||
public interface StateRotator {
|
||||
PlatformBlockState rotate(IrisObjectRotation rotation, PlatformBlockState state, int spinx, int spiny, int spinz);
|
||||
}
|
||||
|
||||
public static synchronized StateRotator bindPlatformRotator(StateRotator rotator) {
|
||||
StateRotator previous = PLATFORM_ROTATOR;
|
||||
PLATFORM_ROTATOR = Objects.requireNonNull(rotator, "rotator");
|
||||
return previous;
|
||||
}
|
||||
|
||||
public static synchronized void restorePlatformRotator(StateRotator rotator) {
|
||||
PLATFORM_ROTATOR = rotator;
|
||||
}
|
||||
|
||||
private static final class Faces {
|
||||
private static final List<BlockFace> WALL_FACES = List.of(BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST);
|
||||
}
|
||||
|
||||
@Desc("If this rotator is enabled or not")
|
||||
private boolean enabled = true;
|
||||
|
||||
@Desc("The x axis rotation")
|
||||
private AxisRotationClamp xAxis = new AxisRotationClamp();
|
||||
|
||||
@Desc("The y axis rotation")
|
||||
private AxisRotationClamp yAxis = AxisRotationClamp.of(true, false, 0, 0, 90);
|
||||
|
||||
@Desc("The z axis rotation")
|
||||
private AxisRotationClamp zAxis = new AxisRotationClamp();
|
||||
|
||||
public static IrisObjectRotation xFlip180() {
|
||||
IrisObjectRotation rt = new IrisObjectRotation();
|
||||
rt.setEnabled(true);
|
||||
rt.setXAxis(AxisRotationClamp.locked(true, 180, 0));
|
||||
rt.setYAxis(new AxisRotationClamp());
|
||||
rt.setZAxis(new AxisRotationClamp());
|
||||
return rt;
|
||||
}
|
||||
|
||||
public static IrisObjectRotation xFlip180RandomY() {
|
||||
IrisObjectRotation rt = xFlip180();
|
||||
rt.setYAxis(AxisRotationClamp.of(true, false, 0, 0, 90));
|
||||
return rt;
|
||||
}
|
||||
|
||||
public static IrisObjectRotation xFlip180WithY(double y) {
|
||||
IrisObjectRotation rt = xFlip180();
|
||||
rt.setYAxis(AxisRotationClamp.locked(true, y, 90));
|
||||
return rt;
|
||||
}
|
||||
|
||||
public static IrisObjectRotation of(double x, double y, double z) {
|
||||
IrisObjectRotation rt = new IrisObjectRotation();
|
||||
rt.setEnabled(x != 0 || y != 0 || z != 0);
|
||||
rt.setXAxis(AxisRotationClamp.locked(x != 0, x, 90));
|
||||
rt.setYAxis(AxisRotationClamp.locked(y != 0, y, 90));
|
||||
rt.setZAxis(AxisRotationClamp.locked(z != 0, z, 90));
|
||||
|
||||
return rt;
|
||||
}
|
||||
|
||||
public double getYRotation(int spin) {
|
||||
return getRotation(spin, yAxis);
|
||||
}
|
||||
|
||||
public double getXRotation(int spin) {
|
||||
return getRotation(spin, xAxis);
|
||||
}
|
||||
|
||||
public double getZRotation(int spin) {
|
||||
return getRotation(spin, zAxis);
|
||||
}
|
||||
|
||||
public IrisObject rotateCopy(IrisObject e) {
|
||||
if (e == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return e.rotateCopy(this);
|
||||
}
|
||||
|
||||
public IrisBlockVector rotate(IrisBlockVector direction) {
|
||||
return rotate(direction, 0, 0, 0);
|
||||
}
|
||||
|
||||
public IrisDirection rotate(IrisDirection direction) {
|
||||
IrisBlockVector v = rotate(new IrisBlockVector(direction.x(), direction.y(), direction.z()));
|
||||
double m = Double.MAX_VALUE;
|
||||
IrisDirection s = null;
|
||||
|
||||
for (IrisDirection i : IrisDirection.values()) {
|
||||
double g = new IrisBlockVector(i.x(), i.y(), i.z()).distance(v);
|
||||
|
||||
if (g < m) {
|
||||
m = g;
|
||||
s = i;
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
public double getRotation(int spin, AxisRotationClamp clamp) {
|
||||
if (!enabled) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!clamp.enabled()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return clamp.getRadians(spin);
|
||||
}
|
||||
|
||||
public BlockFace getFace(IrisBlockVector v) {
|
||||
int x = (int) Math.round(v.getX());
|
||||
int y = (int) Math.round(v.getY());
|
||||
int z = (int) Math.round(v.getZ());
|
||||
|
||||
if (x == 0 && z == -1) {
|
||||
return BlockFace.NORTH;
|
||||
}
|
||||
|
||||
if (x == 0 && z == 1) {
|
||||
return BlockFace.SOUTH;
|
||||
}
|
||||
|
||||
if (x == 1 && z == 0) {
|
||||
return BlockFace.EAST;
|
||||
}
|
||||
|
||||
if (x == -1 && z == 0) {
|
||||
return BlockFace.WEST;
|
||||
}
|
||||
|
||||
if (y > 0) {
|
||||
return BlockFace.UP;
|
||||
}
|
||||
|
||||
if (y < 0) {
|
||||
return BlockFace.DOWN;
|
||||
}
|
||||
|
||||
return BlockFace.SOUTH;
|
||||
}
|
||||
|
||||
public BlockFace getHexFace(IrisBlockVector v) {
|
||||
int x = v.getBlockX();
|
||||
int y = v.getBlockY();
|
||||
int z = v.getBlockZ();
|
||||
|
||||
if (x == 0 && z == -1) return BlockFace.NORTH;
|
||||
if (x == 1 && z == -2) return BlockFace.NORTH_NORTH_EAST;
|
||||
if (x == 1 && z == -1) return BlockFace.NORTH_EAST;
|
||||
if (x == 2 && z == -1) return BlockFace.EAST_NORTH_EAST;
|
||||
if (x == 1 && z == 0) return BlockFace.EAST;
|
||||
if (x == 2 && z == 1) return BlockFace.EAST_SOUTH_EAST;
|
||||
if (x == 1 && z == 1) return BlockFace.SOUTH_EAST;
|
||||
if (x == 1 && z == 2) return BlockFace.SOUTH_SOUTH_EAST;
|
||||
if (x == 0 && z == 1) return BlockFace.SOUTH;
|
||||
if (x == -1 && z == 2) return BlockFace.SOUTH_SOUTH_WEST;
|
||||
if (x == -1 && z == 1) return BlockFace.SOUTH_WEST;
|
||||
if (x == -2 && z == 1) return BlockFace.WEST_SOUTH_WEST;
|
||||
if (x == -1 && z == 0) return BlockFace.WEST;
|
||||
if (x == -2 && z == -1) return BlockFace.WEST_NORTH_WEST;
|
||||
if (x == -1 && z == -1) return BlockFace.NORTH_WEST;
|
||||
if (x == -1 && z == -2) return BlockFace.NORTH_NORTH_WEST;
|
||||
|
||||
if (y > 0) {
|
||||
return BlockFace.UP;
|
||||
}
|
||||
|
||||
if (y < 0) {
|
||||
return BlockFace.DOWN;
|
||||
}
|
||||
|
||||
return BlockFace.SOUTH;
|
||||
}
|
||||
|
||||
public BlockFace faceForAxis(Axis axis) {
|
||||
return switch (axis) {
|
||||
case X -> BlockFace.EAST;
|
||||
case Y -> BlockFace.UP;
|
||||
case Z -> BlockFace.NORTH;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
public Axis axisFor(BlockFace f) {
|
||||
return switch (f) {
|
||||
case NORTH, SOUTH -> Axis.Z;
|
||||
case EAST, WEST -> Axis.X;
|
||||
default -> Axis.Y;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
public Axis axisFor2D(BlockFace f) {
|
||||
return switch (f) {
|
||||
case EAST, WEST, UP, DOWN -> Axis.X;
|
||||
default -> Axis.Z;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
public PlatformBlockState rotate(PlatformBlockState state, int spinx, int spiny, int spinz) {
|
||||
if (state == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
StateRotator rotator = PLATFORM_ROTATOR;
|
||||
if (rotator != null) {
|
||||
return rotator.rotate(this, state, spinx, spiny, spinz);
|
||||
}
|
||||
|
||||
BlockData original = (BlockData) state.nativeHandle();
|
||||
if (!canRotate() || !canRotateBlockData(original)) {
|
||||
return state;
|
||||
}
|
||||
|
||||
BlockData raw = original.clone();
|
||||
BlockData rotated = rotate(raw, spinx, spiny, spinz);
|
||||
return rotated == null ? null : BukkitBlockState.of(rotated);
|
||||
}
|
||||
|
||||
private static boolean canRotateBlockData(BlockData data) {
|
||||
return data instanceof Directional
|
||||
|| data instanceof Rotatable
|
||||
|| data instanceof Orientable
|
||||
|| data instanceof MultipleFacing
|
||||
|| data instanceof Wall
|
||||
|| data instanceof RedstoneWire;
|
||||
}
|
||||
|
||||
public BlockData rotate(BlockData dd, int spinxx, int spinyy, int spinzz) {
|
||||
BlockData d = dd;
|
||||
try {
|
||||
int spinx = (int) (90D * (Math.ceil(Math.abs((spinxx % 360D) / 90D))));
|
||||
int spiny = (int) (90D * (Math.ceil(Math.abs((spinyy % 360D) / 90D))));
|
||||
int spinz = (int) (90D * (Math.ceil(Math.abs((spinzz % 360D) / 90D))));
|
||||
|
||||
if (!canRotate()) {
|
||||
return d;
|
||||
}
|
||||
|
||||
if (d instanceof Directional g) {
|
||||
BlockFace f = g.getFacing();
|
||||
IrisBlockVector bv = new IrisBlockVector(f.getModX(), f.getModY(), f.getModZ());
|
||||
bv = rotate(bv.clone(), spinx, spiny, spinz);
|
||||
BlockFace t = getFace(bv);
|
||||
|
||||
if (g.getFaces().contains(t)) {
|
||||
g.setFacing(t);
|
||||
} else if (!g.getMaterial().isSolid()) {
|
||||
d = null;
|
||||
}
|
||||
} else if (d instanceof Rotatable g) {
|
||||
BlockFace f = g.getRotation();
|
||||
|
||||
IrisBlockVector bv = new IrisBlockVector(f.getModX(), 0, f.getModZ());
|
||||
bv = rotate(bv.clone(), spinx, spiny, spinz);
|
||||
BlockFace face = getHexFace(bv);
|
||||
|
||||
g.setRotation(face);
|
||||
|
||||
} else if (d instanceof Orientable g) {
|
||||
BlockFace f = getFace(g.getAxis());
|
||||
IrisBlockVector bv = new IrisBlockVector(f.getModX(), f.getModY(), f.getModZ());
|
||||
bv = rotate(bv.clone(), spinx, spiny, spinz);
|
||||
Axis a = getAxis(bv);
|
||||
|
||||
if (!a.equals(g.getAxis()) && g.getAxes().contains(a)) {
|
||||
g.setAxis(a);
|
||||
}
|
||||
} else if (d instanceof MultipleFacing g) {
|
||||
List<BlockFace> faces = new KList<>();
|
||||
|
||||
for (BlockFace i : g.getFaces()) {
|
||||
IrisBlockVector bv = new IrisBlockVector(i.getModX(), i.getModY(), i.getModZ());
|
||||
bv = rotate(bv.clone(), spinx, spiny, spinz);
|
||||
BlockFace r = getFace(bv);
|
||||
|
||||
if (g.getAllowedFaces().contains(r)) {
|
||||
faces.add(r);
|
||||
}
|
||||
}
|
||||
|
||||
for (BlockFace i : g.getFaces()) {
|
||||
g.setFace(i, false);
|
||||
}
|
||||
|
||||
for (BlockFace i : faces) {
|
||||
g.setFace(i, true);
|
||||
}
|
||||
} else if (d instanceof Wall wall) {
|
||||
KMap<BlockFace, Wall.Height> faces = new KMap<>();
|
||||
|
||||
for (BlockFace i : Faces.WALL_FACES) {
|
||||
Wall.Height h = wall.getHeight(i);
|
||||
IrisBlockVector bv = new IrisBlockVector(i.getModX(), i.getModY(), i.getModZ());
|
||||
bv = rotate(bv.clone(), spinx, spiny, spinz);
|
||||
BlockFace r = getFace(bv);
|
||||
if (Faces.WALL_FACES.contains(r)) {
|
||||
faces.put(r, h);
|
||||
}
|
||||
}
|
||||
|
||||
for (BlockFace i : Faces.WALL_FACES) {
|
||||
wall.setHeight(i, faces.getOrDefault(i, Wall.Height.NONE));
|
||||
}
|
||||
} else if (d instanceof RedstoneWire wire) {
|
||||
Map<BlockFace, RedstoneWire.Connection> faces = new HashMap<>();
|
||||
|
||||
Set<BlockFace> allowed = wire.getAllowedFaces();
|
||||
for (BlockFace i : allowed) {
|
||||
RedstoneWire.Connection connection = wire.getFace(i);
|
||||
IrisBlockVector bv = new IrisBlockVector(i.getModX(), i.getModY(), i.getModZ());
|
||||
bv = rotate(bv.clone(), spinx, spiny, spinz);
|
||||
BlockFace r = getFace(bv);
|
||||
if (allowed.contains(r))
|
||||
faces.put(r, connection);
|
||||
}
|
||||
|
||||
for (BlockFace i : allowed) {
|
||||
wire.setFace(i, faces.getOrDefault(i, RedstoneWire.Connection.NONE));
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
IrisLogging.reportError(e);
|
||||
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
public Axis getAxis(IrisBlockVector v) {
|
||||
if (Math.abs(v.getBlockX()) > Math.max(Math.abs(v.getBlockY()), Math.abs(v.getBlockZ()))) {
|
||||
return Axis.X;
|
||||
}
|
||||
|
||||
if (Math.abs(v.getBlockY()) > Math.max(Math.abs(v.getBlockX()), Math.abs(v.getBlockZ()))) {
|
||||
return Axis.Y;
|
||||
}
|
||||
|
||||
if (Math.abs(v.getBlockZ()) > Math.max(Math.abs(v.getBlockX()), Math.abs(v.getBlockY()))) {
|
||||
return Axis.Z;
|
||||
}
|
||||
|
||||
return Axis.Y;
|
||||
}
|
||||
|
||||
private BlockFace getFace(Axis axis) {
|
||||
return switch (axis) {
|
||||
case X -> BlockFace.EAST;
|
||||
case Y -> BlockFace.UP;
|
||||
case Z -> BlockFace.SOUTH;
|
||||
};
|
||||
}
|
||||
|
||||
public IrisPosition rotate(IrisPosition b) {
|
||||
return rotate(b, 0, 0, 0);
|
||||
}
|
||||
|
||||
public IrisPosition rotate(IrisPosition b, int spinx, int spiny, int spinz) {
|
||||
IrisBlockVector v = rotate(new IrisBlockVector(b.getX(), b.getY(), b.getZ()), spinx, spiny, spinz);
|
||||
return new IrisPosition(v.getBlockX(), v.getBlockY(), v.getBlockZ());
|
||||
}
|
||||
|
||||
public IrisBlockVector rotate(IrisBlockVector b, int spinx, int spiny, int spinz) {
|
||||
if (!canRotate()) {
|
||||
return b;
|
||||
}
|
||||
|
||||
IrisBlockVector v = b.clone();
|
||||
|
||||
if (canRotateX()) {
|
||||
if (getXAxis().isLocked()) {
|
||||
if (Math.abs(getXAxis().max()) % 360D == 180D) {
|
||||
v.setZ(-v.getZ());
|
||||
v.setY(-v.getY());
|
||||
} else if (getXAxis().max() % 360D == 90D || getXAxis().max() % 360D == -270D) {
|
||||
double z = v.getZ();
|
||||
v.setZ(v.getY());
|
||||
v.setY(-z);
|
||||
} else if (getXAxis().max() == -90D || getXAxis().max() % 360D == 270D) {
|
||||
double z = v.getZ();
|
||||
v.setZ(-v.getY());
|
||||
v.setY(z);
|
||||
} else {
|
||||
v.rotateAroundX(getXRotation(spinx));
|
||||
}
|
||||
} else {
|
||||
v.rotateAroundX(getXRotation(spinx));
|
||||
}
|
||||
}
|
||||
|
||||
if (canRotateZ()) {
|
||||
if (getZAxis().isLocked()) {
|
||||
if (Math.abs(getZAxis().max()) % 360D == 180D) {
|
||||
v.setY(-v.getY());
|
||||
v.setX(-v.getX());
|
||||
} else if (getZAxis().max() % 360D == 90D || getZAxis().max() % 360D == -270D) {
|
||||
double y = v.getY();
|
||||
v.setY(v.getX());
|
||||
v.setX(-y);
|
||||
} else if (getZAxis().max() == -90D || getZAxis().max() % 360D == 270D) {
|
||||
double y = v.getY();
|
||||
v.setY(-v.getX());
|
||||
v.setX(y);
|
||||
} else {
|
||||
v.rotateAroundZ(getZRotation(spinz));
|
||||
}
|
||||
} else {
|
||||
v.rotateAroundZ(getZRotation(spinz));
|
||||
}
|
||||
}
|
||||
|
||||
if (canRotateY()) {
|
||||
if (getYAxis().isLocked()) {
|
||||
if (Math.abs(getYAxis().max()) % 360D == 180D) {
|
||||
v.setX(-v.getX());
|
||||
v.setZ(-v.getZ());
|
||||
} else if (getYAxis().max() % 360D == 90D || getYAxis().max() % 360D == -270D) {
|
||||
double x = v.getX();
|
||||
v.setX(v.getZ());
|
||||
v.setZ(-x);
|
||||
} else if (getYAxis().max() == -90D || getYAxis().max() % 360D == 270D) {
|
||||
double x = v.getX();
|
||||
v.setX(-v.getZ());
|
||||
v.setZ(x);
|
||||
} else {
|
||||
v.rotateAroundY(getYRotation(spiny));
|
||||
}
|
||||
} else {
|
||||
v.rotateAroundY(getYRotation(spiny));
|
||||
}
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
public boolean canRotateX() {
|
||||
return enabled && xAxis.enabled();
|
||||
}
|
||||
|
||||
public boolean canRotateY() {
|
||||
return enabled && yAxis.enabled();
|
||||
}
|
||||
|
||||
public boolean canRotateZ() {
|
||||
return enabled && zAxis.enabled();
|
||||
}
|
||||
|
||||
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||
public boolean canRotate() {
|
||||
return canRotateX() || canRotateY() || canRotateZ();
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
package art.arcane.iris.engine.object.prefab;
|
||||
|
||||
import art.arcane.iris.builtin.objects.ScaleInterpolation;
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
import art.arcane.iris.engine.object.value.IrisPosition;
|
||||
import art.arcane.iris.spi.PlatformBlockState;
|
||||
import art.arcane.iris.util.common.data.B;
|
||||
@@ -38,19 +40,19 @@ final class IrisObjectTransforms {
|
||||
private IrisObjectTransforms() {
|
||||
}
|
||||
|
||||
static IrisObject rotateCopy(IrisObject self, IrisObjectRotation rt) {
|
||||
static IrisObject rotateCopy(IrisObject self, ObjectRotation rt) {
|
||||
IrisObject copy = self.copy();
|
||||
rotate(copy, rt, 0, 0, 0);
|
||||
return copy;
|
||||
}
|
||||
|
||||
static void rotate(IrisObject self, IrisObjectRotation r, int spinx, int spiny, int spinz) {
|
||||
static void rotate(IrisObject self, ObjectRotation r, int spinx, int spiny, int spinz) {
|
||||
self.writeLock.lock();
|
||||
try {
|
||||
VectorMap<PlatformBlockState> d = new VectorMap<>();
|
||||
|
||||
for (var entry : self.blocks) {
|
||||
d.put(r.rotate(entry.getKey(), spinx, spiny, spinz), r.rotate(entry.getValue(), spinx, spiny, spinz));
|
||||
d.put(r.rotate(entry.getKey(), spinx, spiny, spinz), BlockStateRotation.rotate(r, entry.getValue(), spinx, spiny, spinz));
|
||||
}
|
||||
|
||||
VectorMap<TileData> dx = new VectorMap<>();
|
||||
@@ -69,9 +71,9 @@ final class IrisObjectTransforms {
|
||||
}
|
||||
}
|
||||
|
||||
static IrisObject scaled(IrisObject self, double scale, IrisObjectPlacementScaleInterpolator interpolation) {
|
||||
static IrisObject scaled(IrisObject self, double scale, ScaleInterpolation interpolation) {
|
||||
if (interpolation == null) {
|
||||
interpolation = IrisObjectPlacementScaleInterpolator.NONE;
|
||||
interpolation = ScaleInterpolation.NONE;
|
||||
}
|
||||
IrisVector sm1 = new IrisVector(scale - 1, scale - 1, scale - 1);
|
||||
scale = Math.max(0.001, Math.min(50, scale));
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
* 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.engine.object.prefab;
|
||||
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
import art.arcane.iris.engine.object.annotations.MaxNumber;
|
||||
import art.arcane.iris.engine.object.annotations.MinNumber;
|
||||
import art.arcane.iris.engine.object.annotations.Required;
|
||||
import art.arcane.iris.engine.object.annotations.Snippet;
|
||||
import art.arcane.volmlib.util.math.IrisBlockVector;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Snippet("object-translator")
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Desc("Translate objects")
|
||||
@Data
|
||||
public class IrisObjectTranslate {
|
||||
@MinNumber(-128)
|
||||
@MaxNumber(128)
|
||||
@Desc("The x shift in blocks")
|
||||
private int x = 0;
|
||||
|
||||
@Required
|
||||
@MinNumber(-128)
|
||||
@MaxNumber(128)
|
||||
@Desc("The y shift in blocks")
|
||||
private int y = 0;
|
||||
|
||||
@MinNumber(-128)
|
||||
@MaxNumber(128)
|
||||
@Desc("Adds an additional amount of height randomly (translateY + rand(0 - yRandom))")
|
||||
private int yRandom = 0;
|
||||
|
||||
@MinNumber(-128)
|
||||
@MaxNumber(128)
|
||||
@Desc("The z shift in blocks")
|
||||
private int z = 0;
|
||||
|
||||
public boolean canTranslate() {
|
||||
return x != 0 || y != 0 || z != 0;
|
||||
}
|
||||
|
||||
public IrisBlockVector translate(IrisBlockVector i) {
|
||||
if (canTranslate()) {
|
||||
return (IrisBlockVector) i.clone().add(new IrisBlockVector(x, y, z));
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
public IrisBlockVector translate(IrisBlockVector clone, IrisObjectRotation rotation, int sx, int sy, int sz) {
|
||||
if (canTranslate()) {
|
||||
return (IrisBlockVector) clone.clone().add(rotation.rotate(new IrisBlockVector(x, y, z), sx, sy, sz));
|
||||
}
|
||||
|
||||
return clone;
|
||||
}
|
||||
}
|
||||
+18
-68
@@ -18,17 +18,11 @@
|
||||
|
||||
package art.arcane.iris.engine.object.prefab;
|
||||
|
||||
import art.arcane.iris.builtin.objects.ObjectScale;
|
||||
import art.arcane.iris.builtin.objects.ScaleInterpolation;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.object.annotations.Desc;
|
||||
import art.arcane.iris.engine.object.annotations.MaxNumber;
|
||||
import art.arcane.iris.engine.object.annotations.MinNumber;
|
||||
import art.arcane.iris.engine.object.annotations.Snippet;
|
||||
import art.arcane.volmlib.util.math.Vector3i;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.lang.ref.ReferenceQueue;
|
||||
import java.lang.ref.WeakReference;
|
||||
@@ -36,71 +30,38 @@ import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Snippet("object-scale")
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Desc("Scale objects")
|
||||
@Data
|
||||
public class IrisObjectScale {
|
||||
/**
|
||||
* The scaled variants of objects a world places: each variant an {@link ObjectScale} picks is built once and kept in
|
||||
* the world's cache, within a memory budget, until its origin object is collected.
|
||||
*/
|
||||
public final class ScaledObjects {
|
||||
private static final long CACHE_MIN_ESTIMATED_BYTES = 16L * 1024L * 1024L;
|
||||
private static final long CACHE_MAX_ESTIMATED_BYTES = 64L * 1024L * 1024L;
|
||||
private static final long CACHE_ENTRY_ESTIMATED_BYTES = 512L;
|
||||
private static final long CACHE_VARIANT_ESTIMATED_BYTES = 256L;
|
||||
private static final long CACHE_ESTIMATED_BYTES_PER_VOXEL = 128L;
|
||||
private static final int CACHE_LOAD_LOCK_COUNT = 256;
|
||||
private static final int NO_VARIATIONS = 1;
|
||||
|
||||
@MinNumber(0.01)
|
||||
@MaxNumber(50)
|
||||
@Desc("Fixed scale multiplier for this object. 0.5 shrinks to half size, 2.0 doubles the size. When set to anything other than 1, this overrides minimumScale and maximumScale. Leave at 1 to use the minimumScale/maximumScale range.")
|
||||
private double size = 1;
|
||||
|
||||
@MinNumber(1)
|
||||
@MaxNumber(32)
|
||||
@Desc("Iris Objects are scaled and cached to speed up placements. Because of this extra memory is used, so we evenly distribute variations across the defined scale range, then pick one randomly. If the differences is small, use a lower number. For more possibilities on the scale spectrum, increase this at the cost of memory.")
|
||||
private int variations = 7;
|
||||
|
||||
@MinNumber(0.01)
|
||||
@MaxNumber(50)
|
||||
@Desc("The minimum scale. Used when size is 1 to pick a random scale per placement.")
|
||||
private double minimumScale = 1;
|
||||
|
||||
@MinNumber(0.01)
|
||||
@MaxNumber(50)
|
||||
@Desc("The maximum scale. Used when size is 1 to pick a random scale per placement.")
|
||||
private double maximumScale = 1;
|
||||
|
||||
@Desc("If this object is scaled up beyond its origin size, specify a 3D interpolator. NONE keeps blocky scaled output, TRILINEAR (LERP) smooths with linear interpolation, TRICUBIC and TRIHERMITE produce smoother but slower output.")
|
||||
private IrisObjectPlacementScaleInterpolator interpolation = IrisObjectPlacementScaleInterpolator.NONE;
|
||||
|
||||
public boolean shouldScale() {
|
||||
if (size != 1) {
|
||||
return true;
|
||||
}
|
||||
if (variations <= 0) {
|
||||
return false;
|
||||
}
|
||||
return minimumScale != 1 || maximumScale != 1;
|
||||
private ScaledObjects() {
|
||||
}
|
||||
|
||||
public int getMaxSizeFor(int indim) {
|
||||
return (int) Math.ceil(getMaxScale() * indim);
|
||||
/** The scaled variant of {@code origin} that {@code scale} picks; {@code origin} itself when it does not scale. */
|
||||
public static IrisObject variant(ObjectScale scale, RNG rng, IrisObject origin, Engine engine) {
|
||||
return variant(new ScaleRequest(scale.size(), scale.minimumScale(), scale.maximumScale(), scale.variations(),
|
||||
scale.interpolation()), rng, origin, engine);
|
||||
}
|
||||
|
||||
public double getMaxScale() {
|
||||
if (size != 1) {
|
||||
return size;
|
||||
}
|
||||
return Math.max(minimumScale, maximumScale);
|
||||
/** {@code origin} scaled by exactly {@code factor}, without interpolation. */
|
||||
public static IrisObject resized(IrisObject origin, double factor, RNG rng, Engine engine) {
|
||||
return variant(new ScaleRequest(factor, 1D, 1D, NO_VARIATIONS, ScaleInterpolation.NONE), rng, origin, engine);
|
||||
}
|
||||
|
||||
/** The scaled variant of {@code origin} this scale picks, built once per world and kept in the world's cache. */
|
||||
public IrisObject get(RNG rng, IrisObject origin, Engine engine) {
|
||||
static IrisObject variant(ScaleRequest request, RNG rng, IrisObject origin, Engine engine) {
|
||||
if (origin == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ScaleRequest request = snapshotRequest();
|
||||
if (!request.shouldScale()) {
|
||||
return origin;
|
||||
}
|
||||
@@ -129,17 +90,6 @@ public class IrisObjectScale {
|
||||
return engine.getGeneration().state(ScaleCache.class, world -> new ScaleCache(resolveCacheMaximumEstimatedBytes()));
|
||||
}
|
||||
|
||||
public boolean canScaleBeyond() {
|
||||
return shouldScale() && getMaxScale() > 1;
|
||||
}
|
||||
|
||||
private ScaleRequest snapshotRequest() {
|
||||
IrisObjectPlacementScaleInterpolator configuredInterpolation = interpolation == null
|
||||
? IrisObjectPlacementScaleInterpolator.NONE
|
||||
: interpolation;
|
||||
return new ScaleRequest(size, minimumScale, maximumScale, variations, configuredInterpolation);
|
||||
}
|
||||
|
||||
private static long estimateVariant(IrisObject variant) {
|
||||
long width = Math.max(1L, variant.getW());
|
||||
long height = Math.max(1L, variant.getH());
|
||||
@@ -174,7 +124,7 @@ public class IrisObjectScale {
|
||||
}
|
||||
|
||||
record ScaleRequest(double size, double minimumScale, double maximumScale, int variations,
|
||||
IrisObjectPlacementScaleInterpolator interpolation) {
|
||||
ScaleInterpolation interpolation) {
|
||||
boolean shouldScale() {
|
||||
if (size != 1D) {
|
||||
return true;
|
||||
+3
-3
@@ -23,7 +23,7 @@ import art.arcane.iris.builtin.decorant.DecoratorLoad;
|
||||
import art.arcane.iris.builtin.terrain.LayerLoad;
|
||||
import art.arcane.iris.builtin.terrain.LayersSettings;
|
||||
import art.arcane.iris.engine.object.placement.ObjectPlacements;
|
||||
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.engine.framework.Engine;
|
||||
import art.arcane.iris.engine.framework.render.RenderType;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
@@ -71,8 +71,8 @@ final class IrisBiomeColorRenderer {
|
||||
return biome.getCacheColorObjectDensity().aquire(() -> {
|
||||
double density = 0;
|
||||
|
||||
for (IrisObjectPlacement i : ObjectPlacements.all(biome)) {
|
||||
density += i.getDensity() * i.getChance();
|
||||
for (ObjectPlacement i : ObjectPlacements.all(biome)) {
|
||||
density += i.middleDensity() * i.chance();
|
||||
}
|
||||
|
||||
return Color.getHSBColor(0.225f, (float) (density / engine.getMaxBiomeObjectDensity()), 1f);
|
||||
|
||||
+9
-8
@@ -20,7 +20,8 @@ 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.engine.object.prefab.IrisObjectRotation;
|
||||
import art.arcane.iris.builtin.prepare.ObjectRotation;
|
||||
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;
|
||||
import art.arcane.iris.engine.object.prefab.TileData;
|
||||
@@ -462,7 +463,7 @@ public final class JigsawStudioGenerator extends EnginedStudioGenerator {
|
||||
"object '" + variant.objectKey() + "' does not fit workcell '" + workcell.stableId() + "'");
|
||||
}
|
||||
|
||||
IrisObjectRotation rotation = IrisObjectRotation.of(0, -90.0D * quarterTurns, 0);
|
||||
ObjectRotation rotation = ObjectRotation.of(0, -90.0D * quarterTurns, 0);
|
||||
List<RenderedBlock> blocks = renderBlocks(object, dimensions, quarterTurns, rotation);
|
||||
if (blocks == null) {
|
||||
return RenderedBay.invalid(
|
||||
@@ -481,7 +482,7 @@ public final class JigsawStudioGenerator extends EnginedStudioGenerator {
|
||||
IrisObject object,
|
||||
JigsawStudioCellDimensions dimensions,
|
||||
int quarterTurns,
|
||||
IrisObjectRotation rotation
|
||||
ObjectRotation rotation
|
||||
) {
|
||||
VectorMap<PlatformBlockState> sourceBlocks = object.getBlocks();
|
||||
VectorMap<TileData> sourceTiles = object.getStates();
|
||||
@@ -513,7 +514,7 @@ public final class JigsawStudioGenerator extends EnginedStudioGenerator {
|
||||
}
|
||||
PlatformBlockState blockState = quarterTurns == 0
|
||||
? entry.getValue()
|
||||
: rotation.rotate(entry.getValue(), 0, 0, 0);
|
||||
: BlockStateRotation.rotate(rotation, entry.getValue(), 0, 0, 0);
|
||||
if (blockState == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -533,7 +534,7 @@ public final class JigsawStudioGenerator extends EnginedStudioGenerator {
|
||||
IrisObject object,
|
||||
JigsawStudioCellDimensions dimensions,
|
||||
int quarterTurns,
|
||||
IrisObjectRotation rotation
|
||||
ObjectRotation rotation
|
||||
) {
|
||||
KList<IrisJigsawConnector> sourceConnectors = piece.getConnectors();
|
||||
if (sourceConnectors == null) {
|
||||
@@ -602,7 +603,7 @@ public final class JigsawStudioGenerator extends EnginedStudioGenerator {
|
||||
|
||||
private static String rotatedFinalState(
|
||||
String finalState,
|
||||
IrisObjectRotation rotation,
|
||||
ObjectRotation rotation,
|
||||
int quarterTurns
|
||||
) {
|
||||
PlatformBlockState state = B.getStateOrNull(finalState, false);
|
||||
@@ -612,7 +613,7 @@ public final class JigsawStudioGenerator extends EnginedStudioGenerator {
|
||||
if (quarterTurns == 0) {
|
||||
return state.key();
|
||||
}
|
||||
PlatformBlockState rotated = rotation.rotate(state, 0, 0, 0);
|
||||
PlatformBlockState rotated = BlockStateRotation.rotate(rotation, state, 0, 0, 0);
|
||||
return rotated == null ? null : rotated.key();
|
||||
}
|
||||
|
||||
@@ -921,7 +922,7 @@ public final class JigsawStudioGenerator extends EnginedStudioGenerator {
|
||||
|
||||
@FunctionalInterface
|
||||
interface FinalStateRenderer {
|
||||
String render(String finalState, IrisObjectRotation rotation, int quarterTurns);
|
||||
String render(String finalState, ObjectRotation rotation, int quarterTurns);
|
||||
}
|
||||
|
||||
record RotatedPosition(int x, int y, int z) {
|
||||
|
||||
Reference in new issue
Block a user