mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 16:54:04 +00:00
Batch 7 stage 3: objects and placement through the api
The api describes a pack's objects and lets a module place one through the pack's placement graph: PlaceableObject, PackObjects (PackResources.objects()), ScaleMethod, and Placements.place(PlacementRun) on PackWorld with PlacementTerrain, StructureVolumes and PlacementOutcome, which moves here from the host. Stages read PlacementContext.placementTerrain() and input(type); mantle stages get MantleGenerationContext.placementTerrain(). BlockRegistry gains rotate (BlockTurn), merge, withProperty and matches; BlockTrait gains STORAGE; ModuleLog gains debugging(); PackSettings gains resources(); RunningWorld gains placementAt. README, DESIGN and CONTRACTS describe them, and the extension ledger drops ObjectHost and ObjectPlacement.
This commit is contained in:
1 parent
398f3879ae
commit
f1eb619344
34 files changed
+423
-27
No files matched your search
@@ -21,12 +21,17 @@ final class LabelledModuleLog implements ModuleLog {
|
||||
|
||||
@Override
|
||||
public void debug(String message) {
|
||||
if (!logger.isLoggable(Level.DEBUG)) {
|
||||
if (!debugging()) {
|
||||
return;
|
||||
}
|
||||
logger.log(Level.DEBUG, label + message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean debugging() {
|
||||
return logger.isLoggable(Level.DEBUG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String message) {
|
||||
logger.log(Level.INFO, label + message);
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.volmit.config.FeatureSettings;
|
||||
import com.volmit.config.SettingsStack;
|
||||
import com.volmit.generation.MantleGenerationContext;
|
||||
import com.volmit.mantle.Mantle;
|
||||
import com.volmit.placement.PlacementTerrain;
|
||||
import com.volmit.random.WorldRandom;
|
||||
import com.volmit.world.PackWorld;
|
||||
import com.volmit.stage.MantleStageContext;
|
||||
@@ -62,6 +63,11 @@ final class MantleInvocation implements MantleStageContext {
|
||||
return inputs.mantle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlacementTerrain placementTerrain() {
|
||||
return inputs.placementTerrain();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackWorld world() {
|
||||
return stages.world(inputs.world());
|
||||
|
||||
@@ -30,6 +30,11 @@ public final class ModuleLogs {
|
||||
public void debug(String message) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean debugging() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(String message) {
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.volmit.host;
|
||||
|
||||
import com.volmit.ModuleLog;
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.placement.Placements;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.PackWorld;
|
||||
@@ -61,6 +62,11 @@ final class ModuleWorld implements PackWorld {
|
||||
return world.running();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Placements placements() {
|
||||
return world.placements();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T state(Class<T> type, Function<? super PackWorld, ? extends T> create) {
|
||||
Objects.requireNonNull(create, "create");
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.volmit.object.ObjectTransformer;
|
||||
import com.volmit.placement.PlacementAccess;
|
||||
import com.volmit.placement.PlacementContext;
|
||||
import com.volmit.placement.PlacementRequest;
|
||||
import com.volmit.placement.PlacementTerrain;
|
||||
import com.volmit.random.WorldRandom;
|
||||
import com.volmit.world.PackWorld;
|
||||
import com.volmit.stage.BlockStageContext;
|
||||
@@ -149,6 +150,16 @@ final class PlacementInvocation implements BlockStageContext {
|
||||
return inputs.blocks();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlacementTerrain placementTerrain() {
|
||||
return inputs.placementTerrain();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Optional<T> input(Class<T> type) {
|
||||
return inputs.input(type);
|
||||
}
|
||||
|
||||
private void requireBlockPass() {
|
||||
if (blockStatus == BlockStatus.OUTSIDE_PASS) {
|
||||
throw new IllegalStateException("The current block is only available to block stages");
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.volmit.host;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/** Result of one placement attempt. A rejected attempt committed nothing. */
|
||||
public record PlacementOutcome(Status status, Optional<String> rejection) {
|
||||
public enum Status { PLACED, REJECTED }
|
||||
|
||||
public PlacementOutcome {
|
||||
Objects.requireNonNull(status, "status");
|
||||
Objects.requireNonNull(rejection, "rejection");
|
||||
if ((status == Status.REJECTED) != rejection.isPresent()) {
|
||||
throw new IllegalArgumentException("Only rejected placements carry a rejection reason");
|
||||
}
|
||||
}
|
||||
|
||||
static PlacementOutcome placed() {
|
||||
return new PlacementOutcome(Status.PLACED, Optional.empty());
|
||||
}
|
||||
|
||||
static PlacementOutcome rejected(String reason) {
|
||||
return new PlacementOutcome(Status.REJECTED, Optional.of(reason));
|
||||
}
|
||||
|
||||
public boolean isPlaced() {
|
||||
return status == Status.PLACED;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.volmit.host;
|
||||
|
||||
import com.volmit.placement.PlacementContext;
|
||||
import com.volmit.placement.PlacementEdit;
|
||||
import com.volmit.placement.PlacementOutcome;
|
||||
import com.volmit.placement.PlacementRequest;
|
||||
import com.volmit.stage.Pipeline;
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.volmit.config.PackSettings;
|
||||
import com.volmit.generation.GenerationContext;
|
||||
import com.volmit.hunk.Hunk;
|
||||
import com.volmit.mantle.Mantle;
|
||||
import com.volmit.placement.Placements;
|
||||
import com.volmit.random.WorldRandom;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
@@ -88,6 +89,7 @@ class ExtensionsTest {
|
||||
public PackSettings settings() { throw new AssertionError("Unused settings"); }
|
||||
public int minWorldY() { return 0; }
|
||||
public Optional<RunningWorld> running() { return Optional.empty(); }
|
||||
public Placements placements() { throw new AssertionError("Unused placements"); }
|
||||
public <T> T state(Class<T> type, Function<? super PackWorld, ? extends T> create) { return states.state(type, () -> create.apply(this)); }
|
||||
public ModuleLog log() { return ModuleLogs.discarding(); }
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import com.volmit.object.GeneratedObject;
|
||||
import com.volmit.object.ObjectBlock;
|
||||
import com.volmit.placement.PlacedBlock;
|
||||
import com.volmit.placement.PlacementEdit;
|
||||
import com.volmit.placement.PlacementOutcome;
|
||||
import com.volmit.placement.PlacementRequest;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.stage.BlockStageContext;
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.volmit.IrisFeature;
|
||||
import com.volmit.config.FeatureSettings.Entry;
|
||||
import com.volmit.config.PackSettings;
|
||||
import com.volmit.config.SettingsStack;
|
||||
import com.volmit.resource.PackResources;
|
||||
import java.util.List;
|
||||
|
||||
/** A pack's settings as a fixed list of declarations, for reach tests. */
|
||||
@@ -24,4 +25,9 @@ public final class DeclaredSettings implements PackSettings {
|
||||
.map(entry -> (Entry<F>) entry)
|
||||
.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackResources resources() {
|
||||
return new EmptyResources();
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.volmit.support;
|
||||
import com.volmit.block.BlockRegistry;
|
||||
import com.volmit.item.ItemRegistry;
|
||||
import com.volmit.noise.NoiseFactory;
|
||||
import com.volmit.object.PackObjects;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.resource.ResourceKind;
|
||||
@@ -39,6 +40,11 @@ public final class EmptyResources implements PackResources {
|
||||
throw new AssertionError("Unused noise");
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackObjects objects() {
|
||||
throw new AssertionError("Unused objects");
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Optional<T> find(ResourceKind<T> kind, ResourceId id) {
|
||||
return Optional.empty();
|
||||
|
||||
@@ -8,6 +8,8 @@ import com.volmit.hunk.Hunk;
|
||||
import com.volmit.mantle.Mantle;
|
||||
import com.volmit.object.ObjectTransformer;
|
||||
import com.volmit.placement.PlacementContext;
|
||||
import com.volmit.placement.PlacementTerrain;
|
||||
import java.util.Optional;
|
||||
import com.volmit.world.TerrainSampler;
|
||||
import com.volmit.world.BlockView;
|
||||
import com.volmit.world.PackWorld;
|
||||
@@ -52,6 +54,7 @@ public final class TestContexts {
|
||||
public TerrainSampler terrain() { throw new AssertionError("Unused terrain"); }
|
||||
public FeatureSettings settings() { return settings; }
|
||||
public Mantle mantle() { return mantle; }
|
||||
public PlacementTerrain placementTerrain() { throw new AssertionError("Unused placement terrain"); }
|
||||
};
|
||||
}
|
||||
|
||||
@@ -69,6 +72,8 @@ public final class TestContexts {
|
||||
if (blocks == null) throw new AssertionError("Unused blocks");
|
||||
return blocks;
|
||||
}
|
||||
public PlacementTerrain placementTerrain() { throw new AssertionError("Unused placement terrain"); }
|
||||
public <T> Optional<T> input(Class<T> type) { return Optional.empty(); }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.volmit.config.SettingsStack;
|
||||
import com.volmit.host.ModuleLogs;
|
||||
import com.volmit.host.WorldStates;
|
||||
import com.volmit.random.WorldRandom;
|
||||
import com.volmit.placement.Placements;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.PackWorld;
|
||||
@@ -49,6 +50,10 @@ public final class TestWorld implements PackWorld, AutoCloseable {
|
||||
public <F extends IrisFeature> SettingsStack<F> declared(Class<F> featureType) {
|
||||
return SettingsStack.empty();
|
||||
}
|
||||
|
||||
public PackResources resources() {
|
||||
return TestWorld.this.resources();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -62,6 +67,11 @@ public final class TestWorld implements PackWorld, AutoCloseable {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Placements placements() {
|
||||
throw new AssertionError("Unused placements");
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T state(Class<T> type, Function<? super PackWorld, ? extends T> create) {
|
||||
return states.state(type, () -> create.apply(this));
|
||||
|
||||
Reference in new issue
Block a user