mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 08:14:45 +00:00
Add Mantle.carved, the host-owned layer of carved voids
CarvedVoid says what fills a carved block (open, fluid, lava or air) and optionally the biome it shows; the plain fills are shared constants so a carver allocates nothing per block. A mantle stage writes the layer, a chunk stage reads it and its writes throw. Placements and edits see it read-only.
This commit is contained in:
1 parent
cf0e49e34d
commit
6c8fa31a7b
10 files changed
+151
-28
No files matched your search
@@ -0,0 +1,64 @@
|
||||
package com.volmit.mantle;
|
||||
|
||||
import com.volmit.resource.ResourceId;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/** A block the mantle holds as carved out: what fills the void once the chunk takes it over, and optionally the biome it shows.
|
||||
* Instances are immutable and the four plain fills are shared constants ({@link #of}), so a carver marking thousands of blocks
|
||||
* allocates nothing.
|
||||
*
|
||||
* @param fill what fills the void
|
||||
* @param biome a pack biome the void shows instead of the cave biome its column would get; empty for the usual one
|
||||
*/
|
||||
public record CarvedVoid(Fill fill, Optional<ResourceId> biome) {
|
||||
/** Cut open, and left to the dimension. */
|
||||
public static final CarvedVoid OPEN = new CarvedVoid(Fill.OPEN, Optional.empty());
|
||||
|
||||
/** Filled with the dimension's fluid. */
|
||||
public static final CarvedVoid FLUID = new CarvedVoid(Fill.FLUID, Optional.empty());
|
||||
|
||||
/** Filled with lava. */
|
||||
public static final CarvedVoid LAVA = new CarvedVoid(Fill.LAVA, Optional.empty());
|
||||
|
||||
/** Filled with air, at any height. */
|
||||
public static final CarvedVoid AIR = new CarvedVoid(Fill.AIR, Optional.empty());
|
||||
|
||||
public CarvedVoid {
|
||||
Objects.requireNonNull(fill, "fill");
|
||||
Objects.requireNonNull(biome, "biome");
|
||||
}
|
||||
|
||||
/** The shared void of a fill, with no biome of its own. */
|
||||
public static CarvedVoid of(Fill fill) {
|
||||
return switch (Objects.requireNonNull(fill, "fill")) {
|
||||
case OPEN -> OPEN;
|
||||
case FLUID -> FLUID;
|
||||
case LAVA -> LAVA;
|
||||
case AIR -> AIR;
|
||||
};
|
||||
}
|
||||
|
||||
/** This void's fill, showing {@code biome}. */
|
||||
public CarvedVoid withBiome(ResourceId biome) {
|
||||
return new CarvedVoid(fill, Optional.of(biome));
|
||||
}
|
||||
|
||||
/** What fills a carved void. */
|
||||
public enum Fill {
|
||||
/** The solid is cut away and the dimension decides what is left: cave air, or lava at and below its lava height.
|
||||
* Air and fluid the terrain already has there stay.
|
||||
*/
|
||||
OPEN,
|
||||
|
||||
/** The dimension's fluid, replacing what the terrain has there. */
|
||||
FLUID,
|
||||
|
||||
/** Lava, replacing what the terrain has there. */
|
||||
LAVA,
|
||||
|
||||
/** Cave air at any height, replacing fluid and lava as well. */
|
||||
AIR
|
||||
}
|
||||
}
|
||||
@@ -34,9 +34,16 @@ public interface Mantle {
|
||||
*/
|
||||
MantleLayer<BlockState> blocks();
|
||||
|
||||
/** Whether the mantle holds a carved void at the position for the chunk to take over: a cave's air or fluid, planned
|
||||
* before the chunks were generated. Also true where the chunk's own blocks show no void, such as under a dimension
|
||||
* stacked above. The host owns the carving; stages only ask. A dimension that keeps no mantle carves nothing.
|
||||
/** The voids the mantle holds for chunks to take over: a cave's air or fluid, planned before the chunks were generated.
|
||||
* Mantle stages write it ({@code set} plans a void, {@code remove} takes it back); a chunk stage only reads it, around
|
||||
* its chunk as far as its mantle reaches, and its writes throw UnsupportedOperationException. A chunk stage takes the
|
||||
* voids over into its chunk (Iris's {@code iris:carve} cuts them out of the terrain). The host owns this layer and keeps
|
||||
* it in its own form, so it needs no registration. A dimension that keeps no mantle carves nothing.
|
||||
*/
|
||||
MantleLayer<CarvedVoid> carved();
|
||||
|
||||
/** Whether the mantle holds a carved void at the position, whether or not the chunk's own blocks show it, such as
|
||||
* under a dimension stacked above: the same as {@code carved().get(x, y, z) != null}, for a stage that only asks.
|
||||
*/
|
||||
boolean isCarved(int x, int y, int z);
|
||||
|
||||
|
||||
@@ -48,4 +48,26 @@ class MantleValueTest {
|
||||
assertThrows(NullPointerException.class, () -> new MantleKey<>("a:b", null));
|
||||
assertThrows(IllegalArgumentException.class, () -> new MantleKey<>("a:b", int.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void carvedVoidsOfAPlainFillAreTheSharedConstants() {
|
||||
for (var fill : CarvedVoid.Fill.values()) {
|
||||
assertSame(CarvedVoid.of(fill), CarvedVoid.of(fill));
|
||||
assertEquals(fill, CarvedVoid.of(fill).fill());
|
||||
assertTrue(CarvedVoid.of(fill).biome().isEmpty());
|
||||
}
|
||||
assertSame(CarvedVoid.LAVA, CarvedVoid.of(CarvedVoid.Fill.LAVA));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aCarvedVoidMayShowABiomeAndHasValueEquality() {
|
||||
var biome = new com.volmit.resource.ResourceId("pack", "cave/lush");
|
||||
var lush = CarvedVoid.AIR.withBiome(biome);
|
||||
assertEquals(CarvedVoid.Fill.AIR, lush.fill());
|
||||
assertEquals(biome, lush.biome().orElseThrow());
|
||||
assertEquals(CarvedVoid.AIR.withBiome(biome), lush);
|
||||
assertNotEquals(CarvedVoid.AIR, lush);
|
||||
assertThrows(NullPointerException.class, () -> new CarvedVoid(null, java.util.Optional.empty()));
|
||||
assertThrows(NullPointerException.class, () -> new CarvedVoid(CarvedVoid.Fill.OPEN, null));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user