mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
Merged pack authoring features
- Biome effects choose their sound category on every platform - Hanging vines keep supported authored side faces on every platform - Inland water above sea level keeps its land biome - River reaches take the policy fluid of their upstream end - Fluid profiles can name a seam that lines their edge against other fluids
This commit is contained in:
commit
2d4ede41dd
23 files changed
+1007
-76
No files matched your search
+10
-1
@@ -55,6 +55,7 @@ public final class ModdedEngineEffects extends EngineAssignedComponent implement
|
||||
private static final double PLAYER_REFRESH_CHANCE = 0.02D;
|
||||
private static final Set<String> UNKNOWN_POTIONS = ConcurrentHashMap.newKeySet();
|
||||
private static final Set<String> UNKNOWN_SOUNDS = ConcurrentHashMap.newKeySet();
|
||||
private static final Set<String> UNKNOWN_SOUND_CATEGORIES = ConcurrentHashMap.newKeySet();
|
||||
private static final Set<String> UNKNOWN_PARTICLES = ConcurrentHashMap.newKeySet();
|
||||
private static final Set<String> UNSUPPORTED_PARTICLES = ConcurrentHashMap.newKeySet();
|
||||
|
||||
@@ -252,6 +253,14 @@ public final class ModdedEngineEffects extends EngineAssignedComponent implement
|
||||
warnUnknown(UNKNOWN_SOUNDS, "sound", key);
|
||||
return;
|
||||
}
|
||||
String categoryKey = effect.getSoundCategoryKey();
|
||||
NativePlayerEffects.SoundCategory category = NativePlayerEffects.soundCategory(categoryKey);
|
||||
if (category == null) {
|
||||
if (UNKNOWN_SOUND_CATEGORIES.add(categoryKey)) {
|
||||
IrisLogging.warn("Unknown sound category: \"" + categoryKey + "\".");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int distance = effect.getSoundDistance();
|
||||
double x = player.x() + RNG.r.i(-distance, distance);
|
||||
@@ -260,7 +269,7 @@ public final class ModdedEngineEffects extends EngineAssignedComponent implement
|
||||
float volume = (float) effect.getVolume();
|
||||
float pitch = (float) RNG.r.d(effect.getMinPitch(), effect.getMaxPitch());
|
||||
NativePlayerEffects.sound(player, sound, new NativePlayerEffects.SoundEmission(
|
||||
x, y, z, volume, pitch, ThreadLocalRandom.current().nextLong()));
|
||||
category, x, y, z, volume, pitch, ThreadLocalRandom.current().nextLong()));
|
||||
}
|
||||
|
||||
private void applyParticles(NativeWorld level, NativeProtocolPlayer player, IrisEffect effect) {
|
||||
|
||||
+142
@@ -1,14 +1,32 @@
|
||||
package art.arcane.iris.modded;
|
||||
|
||||
import art.arcane.iris.generation.mantle.EngineMantle;
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.ModdedBlockState;
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.NativeBlockFaces;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.util.hunk.Hunk;
|
||||
import art.arcane.volmlib.util.mantle.runtime.Mantle;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.server.Bootstrap;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
@@ -17,6 +35,12 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class ModdedDecoratorHooksTest {
|
||||
@BeforeClass
|
||||
public static void bootstrap() {
|
||||
SharedConstants.tryDetectVersion();
|
||||
Bootstrap.bootStrap();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void faceFixingExcludesTheUpperBoundaryWhileKeepingTheLastRowAccessible() {
|
||||
NativeBlockState state = mock(NativeBlockState.class);
|
||||
@@ -41,4 +65,122 @@ public class ModdedDecoratorHooksTest {
|
||||
verify(hunk, never()).get(1, 4, 2);
|
||||
verify(hunk).get(1, 3, 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stackedVineCurtainHangsFromTheWallItsTopStrandFaces() {
|
||||
Hunk<NativeBlockState> hunk = Hunk.newArrayHunk(16, 8, 16);
|
||||
hunk.set(8, 6, 8, stone());
|
||||
hunk.set(8, 5, 7, stone());
|
||||
hunk.set(9, 4, 8, stone());
|
||||
NativeBlockState vine = state(Blocks.VINE, Direction.NORTH);
|
||||
|
||||
for (int y = 5; y >= 3; y--) {
|
||||
hunk.set(8, y, 8, fix(vine, hunk, y));
|
||||
}
|
||||
|
||||
assertEquals(EnumSet.of(Direction.NORTH, Direction.UP), faces(hunk.get(8, 5, 8)));
|
||||
assertEquals(EnumSet.of(Direction.NORTH), faces(hunk.get(8, 4, 8)));
|
||||
assertEquals(EnumSet.of(Direction.NORTH), faces(hunk.get(8, 3, 8)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stackedVineCurtainHangsUnderAnOpenCeiling() {
|
||||
Hunk<NativeBlockState> hunk = Hunk.newArrayHunk(16, 8, 16);
|
||||
hunk.set(8, 6, 8, stone());
|
||||
NativeBlockState vine = state(Blocks.VINE, Direction.NORTH);
|
||||
|
||||
for (int y = 5; y >= 3; y--) {
|
||||
hunk.set(8, y, 8, fix(vine, hunk, y));
|
||||
}
|
||||
|
||||
assertEquals(EnumSet.of(Direction.NORTH, Direction.UP), faces(hunk.get(8, 5, 8)));
|
||||
assertEquals(EnumSet.of(Direction.NORTH), faces(hunk.get(8, 4, 8)));
|
||||
assertEquals(EnumSet.of(Direction.NORTH), faces(hunk.get(8, 3, 8)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unsupportedAuthoredSideFaceOnALoneVineIsDroppedAndReattached() {
|
||||
NativeBlockState vine = state(Blocks.VINE, Direction.NORTH);
|
||||
Hunk<NativeBlockState> walled = Hunk.newArrayHunk(16, 8, 16);
|
||||
walled.set(9, 3, 8, stone());
|
||||
|
||||
assertEquals(EnumSet.of(Direction.EAST), faces(fix(vine, walled, 3)));
|
||||
assertEquals(EnumSet.of(Direction.UP), faces(fix(vine, Hunk.newArrayHunk(16, 8, 16), 3)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void glowLichenSideFaceIsNotHeldByTheLichenAboveIt() {
|
||||
NativeBlockState lichen = state(Blocks.GLOW_LICHEN, Direction.NORTH);
|
||||
Hunk<NativeBlockState> hunk = Hunk.newArrayHunk(16, 8, 16);
|
||||
hunk.set(8, 2, 8, stone());
|
||||
hunk.set(8, 4, 8, state(Blocks.GLOW_LICHEN, Direction.NORTH));
|
||||
|
||||
assertEquals(EnumSet.of(Direction.DOWN), faces(fix(lichen, hunk, 3)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportedAuthoredSideFaceKeepsItsDirection() {
|
||||
NativeBlockState vine = state(Blocks.VINE, Direction.NORTH);
|
||||
Hunk<NativeBlockState> hunk = Hunk.newArrayHunk(16, 8, 16);
|
||||
hunk.set(8, 3, 7, stone());
|
||||
hunk.set(9, 3, 8, stone());
|
||||
|
||||
assertEquals(EnumSet.of(Direction.NORTH), faces(fix(vine, hunk, 3)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void vineWithoutAuthoredSideFaceReattachesToEverySturdyNeighbour() {
|
||||
NativeBlockState vine = state(Blocks.VINE, Direction.UP);
|
||||
Hunk<NativeBlockState> hunk = Hunk.newArrayHunk(16, 8, 16);
|
||||
hunk.set(7, 3, 8, stone());
|
||||
hunk.set(8, 3, 9, stone());
|
||||
hunk.set(8, 4, 8, stone());
|
||||
|
||||
assertEquals(EnumSet.of(Direction.SOUTH, Direction.WEST, Direction.UP), faces(fix(vine, hunk, 3)));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static NativeBlockState fix(NativeBlockState state, Hunk<NativeBlockState> hunk, int y) {
|
||||
EngineMantle mantle = mock(EngineMantle.class);
|
||||
Mantle<Matter> storage = mock(Mantle.class);
|
||||
NativeBlockState air = ModdedBlockState.of(Blocks.AIR.defaultBlockState(), null);
|
||||
when(mantle.getMantle()).thenReturn(storage);
|
||||
when(storage.get(anyInt(), anyInt(), anyInt(), eq(NativeBlockState.class))).thenReturn(air);
|
||||
return new ModdedDecoratorHooks().fixFaces(state, hunk, 8, 8, 8, y, 8, mantle);
|
||||
}
|
||||
|
||||
private static NativeBlockState stone() {
|
||||
return ModdedBlockState.of(Blocks.STONE.defaultBlockState(), null);
|
||||
}
|
||||
|
||||
private static NativeBlockState state(Block block, Direction... faces) {
|
||||
BlockState state = block.defaultBlockState();
|
||||
for (Direction face : faces) {
|
||||
state = state.setValue(property(face), Boolean.TRUE);
|
||||
}
|
||||
return ModdedBlockState.of(state, null);
|
||||
}
|
||||
|
||||
private static Set<Direction> faces(NativeBlockState state) {
|
||||
BlockState handle = (BlockState) state.nativeHandle();
|
||||
EnumSet<Direction> faces = EnumSet.noneOf(Direction.class);
|
||||
for (Direction face : Direction.values()) {
|
||||
BooleanProperty property = property(face);
|
||||
if (handle.hasProperty(property) && handle.getValue(property)) {
|
||||
faces.add(face);
|
||||
}
|
||||
}
|
||||
return faces;
|
||||
}
|
||||
|
||||
private static BooleanProperty property(Direction face) {
|
||||
return switch (face) {
|
||||
case NORTH -> BlockStateProperties.NORTH;
|
||||
case EAST -> BlockStateProperties.EAST;
|
||||
case SOUTH -> BlockStateProperties.SOUTH;
|
||||
case WEST -> BlockStateProperties.WEST;
|
||||
case UP -> BlockStateProperties.UP;
|
||||
case DOWN -> BlockStateProperties.DOWN;
|
||||
};
|
||||
}
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
package art.arcane.volmlib.nativelib.minecraft26_2.modded;
|
||||
|
||||
import art.arcane.iris.world.entity.IrisEffect;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.network.protocol.game.ClientboundSoundPacket;
|
||||
import net.minecraft.server.Bootstrap;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
public class NativePlayerEffectsTest {
|
||||
private static final String SOUND = "minecraft:block.amethyst_block.chime";
|
||||
|
||||
@BeforeClass
|
||||
public static void bootstrap() {
|
||||
SharedConstants.tryDetectVersion();
|
||||
Bootstrap.bootStrap();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void everyVanillaSoundSourceIsReachableByItsName() {
|
||||
for (SoundSource source : SoundSource.values()) {
|
||||
assertSame(source.getName(), source, sentSource(NativePlayerEffects.soundCategory(source.getName())));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void effectCategoryNamesResolveIgnoringCase() {
|
||||
assertSame(SoundSource.AMBIENT, sentSource(category(" Ambient ")));
|
||||
assertSame(SoundSource.RECORDS, sentSource(category("RECORD")));
|
||||
assertSame(SoundSource.MASTER, sentSource(category(null)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unknownCategoryNamesDoNotResolve() {
|
||||
assertNull(category("ambiant"));
|
||||
assertNull(category("records"));
|
||||
assertNull(category("players"));
|
||||
}
|
||||
|
||||
private static NativePlayerEffects.SoundCategory category(String authored) {
|
||||
return NativePlayerEffects.soundCategory(new IrisEffect().setSoundCategory(authored).getSoundCategoryKey());
|
||||
}
|
||||
|
||||
private static SoundSource sentSource(NativePlayerEffects.SoundCategory category) {
|
||||
assertNotNull(category);
|
||||
NativePlayerEffects.Sound sound = NativePlayerEffects.sound(SOUND);
|
||||
assertNotNull(sound);
|
||||
ServerPlayer handle = mock(ServerPlayer.class);
|
||||
ServerGamePacketListenerImpl connection = mock(ServerGamePacketListenerImpl.class);
|
||||
handle.connection = connection;
|
||||
|
||||
NativePlayerEffects.sound(NativeProtocolPlayer.fromHandle(handle), sound,
|
||||
new NativePlayerEffects.SoundEmission(category, 1.0D, 64.0D, -3.0D, 1.0F, 1.0F, 7L));
|
||||
|
||||
ArgumentCaptor<ClientboundSoundPacket> packet = ArgumentCaptor.forClass(ClientboundSoundPacket.class);
|
||||
verify(connection).send(packet.capture());
|
||||
return packet.getValue().getSource();
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,7 @@ final class DecoratorCore {
|
||||
|
||||
private static final long SEED_OFFSET = 29356788L;
|
||||
private static final long PART_FACTOR = 10439677L;
|
||||
private static final String VINE = "minecraft:vine";
|
||||
private static final String WEEPING_VINES = "minecraft:weeping_vines";
|
||||
private static final String WEEPING_VINES_PLANT = "minecraft:weeping_vines_plant";
|
||||
private static final String TWISTING_VINES = "minecraft:twisting_vines";
|
||||
@@ -454,43 +455,22 @@ final class DecoratorCore {
|
||||
if (fixer != null) {
|
||||
return fixer.fixFaces(b, hunk, rX, rZ, x, y, z, mantle);
|
||||
}
|
||||
BlockData rawB = (BlockData) b.nativeHandle();
|
||||
BlockData cloned = rawB.clone();
|
||||
BlockData cloned = ((BlockData) b.nativeHandle()).clone();
|
||||
MultipleFacing data = (MultipleFacing) cloned;
|
||||
data.getFaces().forEach(f -> data.setFace(f, false));
|
||||
if (keepSupportedSides(data, VINE.equals(IrisProceduralBlocks.materialKey(b)), hunk, rX, rZ, x, y, z, mantle)) {
|
||||
return BukkitBlockState.of(cloned);
|
||||
}
|
||||
for (BlockFace f : Faces.CARTESIAN) {
|
||||
if (data.hasFace(f)) {
|
||||
data.setFace(f, false);
|
||||
}
|
||||
}
|
||||
|
||||
boolean found = false;
|
||||
for (BlockFace f : BlockFace.values()) {
|
||||
if (!f.isCartesian()) {
|
||||
continue;
|
||||
}
|
||||
int yy = y + f.getModY();
|
||||
|
||||
NativeBlockState rs = null;
|
||||
if (mantle != null) {
|
||||
rs = mantle.getMantle().get(x + f.getModX(), yy, z + f.getModZ(), NativeBlockState.class);
|
||||
}
|
||||
BlockData r = rs == null ? (BlockData) EngineMantle.AIR.get().nativeHandle() : (BlockData) rs.nativeHandle();
|
||||
if (r.isFaceSturdy(f.getOppositeFace(), BlockSupport.FULL)) {
|
||||
if (data.getAllowedFaces().contains(f)) {
|
||||
found = true;
|
||||
data.setFace(f, true);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
int xx = rX + f.getModX();
|
||||
int zz = rZ + f.getModZ();
|
||||
if (xx < 0 || xx > 15 || zz < 0 || zz > 15 || yy < 0 || yy >= hunk.getHeight()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
r = (BlockData) hunk.get(xx, yy, zz).nativeHandle();
|
||||
if (r.isFaceSturdy(f.getOppositeFace(), BlockSupport.FULL)) {
|
||||
if (data.getAllowedFaces().contains(f)) {
|
||||
found = true;
|
||||
data.setFace(f, true);
|
||||
}
|
||||
for (BlockFace f : Faces.CARTESIAN) {
|
||||
if (data.getAllowedFaces().contains(f) && sturdy(f, hunk, rX, rZ, x, y, z, mantle)) {
|
||||
found = true;
|
||||
data.setFace(f, true);
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
@@ -502,6 +482,61 @@ final class DecoratorCore {
|
||||
return BukkitBlockState.of(cloned);
|
||||
}
|
||||
|
||||
private static boolean keepSupportedSides(MultipleFacing data, boolean vine, Hunk<NativeBlockState> hunk,
|
||||
int rX, int rZ, int x, int y, int z, EngineMantle mantle) {
|
||||
boolean ceiling = sturdy(BlockFace.UP, hunk, rX, rZ, x, y, z, mantle);
|
||||
boolean side = false;
|
||||
for (BlockFace f : Faces.SIDES) {
|
||||
if (!data.hasFace(f)) {
|
||||
continue;
|
||||
}
|
||||
if (sturdy(f, hunk, rX, rZ, x, y, z, mantle) || vine && (ceiling || vineAboveCarries(f, hunk, rX, rZ, x, y, z, mantle))) {
|
||||
side = true;
|
||||
} else {
|
||||
data.setFace(f, false);
|
||||
}
|
||||
}
|
||||
if (!side) {
|
||||
return false;
|
||||
}
|
||||
if (data.getAllowedFaces().contains(BlockFace.UP)) {
|
||||
data.setFace(BlockFace.UP, ceiling);
|
||||
}
|
||||
if (data.hasFace(BlockFace.DOWN) && !sturdy(BlockFace.DOWN, hunk, rX, rZ, x, y, z, mantle)) {
|
||||
data.setFace(BlockFace.DOWN, false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean sturdy(BlockFace f, Hunk<NativeBlockState> hunk, int rX, int rZ, int x, int y, int z, EngineMantle mantle) {
|
||||
int yy = y + f.getModY();
|
||||
BlockFace attached = f.getOppositeFace();
|
||||
if (mantle != null && sturdy(mantle.getMantle().get(x + f.getModX(), yy, z + f.getModZ(), NativeBlockState.class), attached)) {
|
||||
return true;
|
||||
}
|
||||
int xx = rX + f.getModX();
|
||||
int zz = rZ + f.getModZ();
|
||||
return xx >= 0 && xx <= 15 && zz >= 0 && zz <= 15 && yy >= 0 && yy < hunk.getHeight()
|
||||
&& sturdy(hunk.get(xx, yy, zz), attached);
|
||||
}
|
||||
|
||||
private static boolean sturdy(NativeBlockState state, BlockFace attached) {
|
||||
return state != null && ((BlockData) state.nativeHandle()).isFaceSturdy(attached, BlockSupport.FULL);
|
||||
}
|
||||
|
||||
private static boolean vineAboveCarries(BlockFace f, Hunk<NativeBlockState> hunk, int rX, int rZ,
|
||||
int x, int y, int z, EngineMantle mantle) {
|
||||
if (mantle != null && carries(mantle.getMantle().get(x, y + 1, z, NativeBlockState.class), f)) {
|
||||
return true;
|
||||
}
|
||||
return y + 1 < hunk.getHeight() && carries(hunk.get(rX, y + 1, rZ), f);
|
||||
}
|
||||
|
||||
private static boolean carries(NativeBlockState state, BlockFace f) {
|
||||
return state != null && state.nativeHandle() instanceof MultipleFacing facing
|
||||
&& VINE.equals(IrisProceduralBlocks.materialKey(state)) && facing.hasFace(f);
|
||||
}
|
||||
|
||||
static boolean canGoOn(NativeBlockState decorator, NativeBlockState surface) {
|
||||
if (!B.canPlaceOnto(decorator, surface)) {
|
||||
return false;
|
||||
@@ -589,4 +624,10 @@ final class DecoratorCore {
|
||||
default -> state;
|
||||
};
|
||||
}
|
||||
|
||||
private static final class Faces {
|
||||
private static final BlockFace[] SIDES = {BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST};
|
||||
private static final BlockFace[] CARTESIAN = {BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST,
|
||||
BlockFace.UP, BlockFace.DOWN};
|
||||
}
|
||||
}
|
||||
@@ -19,4 +19,7 @@ public class IrisFluidProfile {
|
||||
@Required
|
||||
@Description("Blocks that fill the water feature.")
|
||||
private IrisMaterialPalette palette = new IrisMaterialPalette().qclear().qadd("minecraft:water");
|
||||
|
||||
@Description("Name of another fluid profile that lines this fluid's edge where it touches a different fluid or the sea, such as obsidian where lava meets water. The seam profile may hold solid blocks and serves only as a seam. Unset leaves the two fluids side by side.")
|
||||
private String seam = null;
|
||||
}
|
||||
+1
-4
@@ -173,10 +173,7 @@ public final class HydrologyRuntime {
|
||||
if (fluid == null) {
|
||||
continue;
|
||||
}
|
||||
if (!settings.fluids().containsKey(fluid)) {
|
||||
throw new IllegalArgumentException("Biome '" + biome.getLoadKey() + "' hydrologyPolicy.fluid names '" + fluid
|
||||
+ "', which is not one of the hydrology fluids " + settings.fluids().keySet());
|
||||
}
|
||||
settings.requireFillingFluid(fluid, "biome '" + biome.getLoadKey() + "' hydrologyPolicy.fluid");
|
||||
named = true;
|
||||
}
|
||||
return named;
|
||||
|
||||
+8
-4
@@ -86,7 +86,12 @@ public final class IrisHydrologyTerrainSource implements HydrologyTerrainSource,
|
||||
|
||||
@Override
|
||||
public String channelFluid(int x, int z) {
|
||||
return policy(biomes.get(x, z), regions.get(x, z)).fluid();
|
||||
ChunkBakeCache.enterSparse();
|
||||
try {
|
||||
return policy(biomes.get(x, z), regions.get(x, z)).fluid();
|
||||
} finally {
|
||||
ChunkBakeCache.exitSparse();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -203,9 +208,8 @@ public final class IrisHydrologyTerrainSource implements HydrologyTerrainSource,
|
||||
boolean climateZones = inherited(biome, region, IrisHydrologyPolicy::getClimateZones, Boolean.TRUE);
|
||||
requireMultiplier("rainfall", rainfall, biome, region);
|
||||
requireMultiplier("pondDensity", pondDensity, biome, region);
|
||||
if (fluid != null && !settings.fluids().containsKey(fluid)) {
|
||||
throw new IllegalArgumentException("Hydrology policy for " + where(biome, region) + " names fluid '" + fluid
|
||||
+ "', which is not one of the hydrology fluids " + settings.fluids().keySet());
|
||||
if (fluid != null) {
|
||||
settings.requireFillingFluid(fluid, "the hydrology policy for " + where(biome, region));
|
||||
}
|
||||
return new Policy((float) rainfall, (float) pondDensity, permission(streams, ponds), fluid, climateZones);
|
||||
}
|
||||
|
||||
+34
-3
@@ -61,6 +61,7 @@ public final class HydrologySettings {
|
||||
private final Deformation deformation;
|
||||
private final Underground underground;
|
||||
private final Map<String, IrisMaterialPalette> fluids;
|
||||
private final Map<String, String> seams;
|
||||
private final int prefetchRings;
|
||||
private final boolean persist;
|
||||
private final long fingerprint;
|
||||
@@ -83,6 +84,7 @@ public final class HydrologySettings {
|
||||
this.deformation = deformation(config.getDeformation());
|
||||
this.underground = underground(config.getUnderground());
|
||||
this.fluids = fluids(config.getFluids());
|
||||
this.seams = seams(config.getFluids());
|
||||
this.prefetchRings = config.getPrefetchRings();
|
||||
this.persist = config.isPersist();
|
||||
requireFluidReferences();
|
||||
@@ -167,6 +169,10 @@ public final class HydrologySettings {
|
||||
return fluids;
|
||||
}
|
||||
|
||||
public Map<String, String> seams() {
|
||||
return seams;
|
||||
}
|
||||
|
||||
public int prefetchRings() {
|
||||
return prefetchRings;
|
||||
}
|
||||
@@ -340,6 +346,16 @@ public final class HydrologySettings {
|
||||
return Collections.unmodifiableMap(compiled);
|
||||
}
|
||||
|
||||
private static Map<String, String> seams(List<IrisFluidProfile> profiles) {
|
||||
Map<String, String> seams = new LinkedHashMap<>();
|
||||
for (IrisFluidProfile profile : profiles) {
|
||||
if (profile.getSeam() != null && !profile.getSeam().isBlank()) {
|
||||
seams.put(profile.getName(), profile.getSeam());
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableMap(seams);
|
||||
}
|
||||
|
||||
private static IrisMaterialPalette requirePalette(IrisFluidProfile profile, String field) {
|
||||
IrisMaterialPalette palette = profile.getPalette();
|
||||
if (palette == null || unwritten(palette)) {
|
||||
@@ -476,11 +492,26 @@ public final class HydrologySettings {
|
||||
}
|
||||
|
||||
private void requireFluidReferences() {
|
||||
for (Map.Entry<String, String> seam : seams.entrySet()) {
|
||||
requireFluid(seam.getValue(), "the seam of fluid '" + seam.getKey() + "'");
|
||||
if (seams.containsKey(seam.getValue())) {
|
||||
throw new IllegalArgumentException("Hydrology fluid '" + seam.getValue() + "' is the seam of fluid '" + seam.getKey()
|
||||
+ "' and cannot name a seam of its own");
|
||||
}
|
||||
}
|
||||
for (HydrologyTier tier : tiers) {
|
||||
requireFluid(tier.fluid(), "the fluid of tier '" + tier.name() + "'");
|
||||
requireFillingFluid(tier.fluid(), "the fluid of tier '" + tier.name() + "'");
|
||||
}
|
||||
requireFillingFluid(ponds.fluid(), "ponds.fluid");
|
||||
requireFillingFluid(underground.cavePools().fluid(), "underground.cavePools.fluid");
|
||||
}
|
||||
|
||||
public void requireFillingFluid(String name, String field) {
|
||||
requireFluid(name, field);
|
||||
if (seams.containsValue(name)) {
|
||||
throw new IllegalArgumentException("Hydrology fluid '" + name + "' in " + field
|
||||
+ " is a seam profile; seams only line the edges of other fluids");
|
||||
}
|
||||
requireFluid(ponds.fluid(), "ponds.fluid");
|
||||
requireFluid(underground.cavePools().fluid(), "underground.cavePools.fluid");
|
||||
}
|
||||
|
||||
private void requireFluid(String name, String field) {
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
package art.arcane.iris.generation.hydrology.raster;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.grid.CellHash;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public final class FluidSeams {
|
||||
private static final int CHUNK = 16;
|
||||
private static final int RING = 2;
|
||||
private static final int WINDOW = CHUNK + 2 * RING;
|
||||
private static final int CELLS = WINDOW * WINDOW;
|
||||
private static final long SALT_SEAM = 0x5345414d4c4eL;
|
||||
private static final double SPREAD = 0.6D;
|
||||
private static final byte UNKNOWN = 0;
|
||||
private static final byte LAND = 1;
|
||||
private static final byte SEA = 2;
|
||||
|
||||
private FluidSeams() {
|
||||
}
|
||||
|
||||
public static String[] seal(Map<String, String> seams, long seed, int chunkX, int chunkZ, Columns columns) {
|
||||
if (seams.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
int originX = chunkX * CHUNK - RING;
|
||||
int originZ = chunkZ * CHUNK - RING;
|
||||
String[] fluid = new String[CELLS];
|
||||
boolean sealable = false;
|
||||
for (int cell = 0; cell < CELLS; cell++) {
|
||||
fluid[cell] = columns.fluid(originX + cell % WINDOW, originZ + cell / WINDOW);
|
||||
sealable |= fluid[cell] != null && seams.containsKey(fluid[cell]);
|
||||
}
|
||||
if (!sealable) {
|
||||
return null;
|
||||
}
|
||||
byte[] sea = new byte[CELLS];
|
||||
boolean[] contact = new boolean[CELLS];
|
||||
for (int gz = 1; gz < WINDOW - 1; gz++) {
|
||||
for (int gx = 1; gx < WINDOW - 1; gx++) {
|
||||
int cell = gz * WINDOW + gx;
|
||||
contact[cell] = touchesOther(cell, fluid, seams, sea, columns, originX, originZ);
|
||||
}
|
||||
}
|
||||
String[] sealed = null;
|
||||
for (int lz = 0; lz < CHUNK; lz++) {
|
||||
for (int lx = 0; lx < CHUNK; lx++) {
|
||||
int cell = (lz + RING) * WINDOW + lx + RING;
|
||||
String seam = fluid[cell] == null ? null : seams.get(fluid[cell]);
|
||||
if (seam == null || !contact[cell] && !spreads(cell, fluid, contact, seed, originX, originZ)) {
|
||||
continue;
|
||||
}
|
||||
if (sealed == null) {
|
||||
sealed = new String[CHUNK * CHUNK];
|
||||
}
|
||||
sealed[lz << 4 | lx] = seam;
|
||||
}
|
||||
}
|
||||
return sealed;
|
||||
}
|
||||
|
||||
private static boolean touchesOther(int cell, String[] fluid, Map<String, String> seams, byte[] sea, Columns columns,
|
||||
int originX, int originZ) {
|
||||
String own = fluid[cell];
|
||||
String seam = own == null ? null : seams.get(own);
|
||||
if (seam == null) {
|
||||
return false;
|
||||
}
|
||||
for (int dz = -1; dz <= 1; dz++) {
|
||||
for (int dx = -1; dx <= 1; dx++) {
|
||||
if (dx == 0 && dz == 0) {
|
||||
continue;
|
||||
}
|
||||
int next = cell + dz * WINDOW + dx;
|
||||
String other = fluid[next];
|
||||
if (other == null ? sea(next, sea, columns, originX, originZ) : !other.equals(own) && !other.equals(seam)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean spreads(int cell, String[] fluid, boolean[] contact, long seed, int originX, int originZ) {
|
||||
int x = originX + cell % WINDOW;
|
||||
int z = originZ + cell / WINDOW;
|
||||
if (CellHash.unit(CellHash.mix(seed, SALT_SEAM, x, z)) >= SPREAD) {
|
||||
return false;
|
||||
}
|
||||
for (int dz = -1; dz <= 1; dz++) {
|
||||
for (int dx = -1; dx <= 1; dx++) {
|
||||
int next = cell + dz * WINDOW + dx;
|
||||
if (next != cell && contact[next] && fluid[cell].equals(fluid[next])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean sea(int cell, byte[] sea, Columns columns, int originX, int originZ) {
|
||||
if (sea[cell] == UNKNOWN) {
|
||||
sea[cell] = columns.sea(originX + cell % WINDOW, originZ + cell / WINDOW) ? SEA : LAND;
|
||||
}
|
||||
return sea[cell] == SEA;
|
||||
}
|
||||
|
||||
public interface Columns {
|
||||
String fluid(int x, int z);
|
||||
|
||||
boolean sea(int x, int z);
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,8 @@ import art.arcane.iris.generation.hydrology.water.Reach;
|
||||
import art.arcane.iris.generation.hydrology.water.ReachStyle;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
final class RasterComposer {
|
||||
private static final int CHUNK = 16;
|
||||
@@ -42,6 +44,7 @@ final class RasterComposer {
|
||||
private final HydrologyTier[] nearTier = new HydrologyTier[CELLS];
|
||||
private final ReachCursor cursor = new ReachCursor();
|
||||
private final int[] inletColumn = new int[2];
|
||||
private final Map<Long, String> reachFluids = new HashMap<>();
|
||||
private NaturalHeights naturalHeight;
|
||||
|
||||
RasterComposer(HydrologySettings settings, ChunkFeatures features, ChannelFluids channelFluids, int chunkX, int chunkZ) {
|
||||
@@ -136,13 +139,19 @@ final class RasterComposer {
|
||||
ReachCursor.Choice hit = cursor.channel;
|
||||
Reach reach = hit.reach;
|
||||
int point = hit.point();
|
||||
String area = channelFluids.channelFluid(x, z);
|
||||
head[cell] = level(reach.grade()[point]);
|
||||
terrain[cell] = bed(hit, head[cell], ground, variation, BedProfile.detail(settings.seed(), x, z));
|
||||
role[cell] = role(reach.style()[point]);
|
||||
feature[cell] = reach.id();
|
||||
tier[cell] = reach.tier();
|
||||
fluid[cell] = area != null ? area : reach.tier().fluid();
|
||||
fluid[cell] = reachFluid(reach);
|
||||
}
|
||||
|
||||
private String reachFluid(Reach reach) {
|
||||
return reachFluids.computeIfAbsent(reach.id(), id -> {
|
||||
String area = channelFluids.channelFluid((int) Math.floor(reach.xs()[0]), (int) Math.floor(reach.zs()[0]));
|
||||
return area != null ? area : reach.tier().fluid();
|
||||
});
|
||||
}
|
||||
|
||||
private static int bed(ReachCursor.Choice hit, int surface, int ground, double variation, double detail) {
|
||||
|
||||
@@ -64,18 +64,20 @@ final class EffectiveWater {
|
||||
}
|
||||
|
||||
static final class Chunk {
|
||||
static final Chunk EMPTY = new Chunk(null, null, null, null);
|
||||
static final Chunk EMPTY = new Chunk(null, null, null, null, null);
|
||||
|
||||
private final long[] columns;
|
||||
private final WaterRole[] roles;
|
||||
private final boolean[] owned;
|
||||
private final ChunkWaterRaster raster;
|
||||
private final String[] seams;
|
||||
|
||||
Chunk(long[] columns, WaterRole[] roles, boolean[] owned, ChunkWaterRaster raster) {
|
||||
Chunk(long[] columns, WaterRole[] roles, boolean[] owned, ChunkWaterRaster raster, String[] seams) {
|
||||
this.columns = columns;
|
||||
this.roles = roles;
|
||||
this.owned = owned;
|
||||
this.raster = raster;
|
||||
this.seams = seams;
|
||||
}
|
||||
|
||||
long column(int lx, int lz) {
|
||||
@@ -93,6 +95,11 @@ final class EffectiveWater {
|
||||
ChunkWaterRaster raster() {
|
||||
return raster;
|
||||
}
|
||||
|
||||
String fluid(int lx, int lz) {
|
||||
String seam = seams == null ? null : seams[lz << 4 | lx];
|
||||
return seam != null ? seam : raster.fluid(lx, lz);
|
||||
}
|
||||
}
|
||||
|
||||
static final class Chunks {
|
||||
|
||||
@@ -50,7 +50,9 @@ import art.arcane.iris.generation.decoration.HydrologyVegetation;
|
||||
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveCell;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrologyMaterials;
|
||||
import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
|
||||
import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
import art.arcane.iris.generation.hydrology.raster.FluidSeams;
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.generation.hydrology.water.HydrologyTier;
|
||||
import art.arcane.iris.generation.image.IrisImageMapApplication;
|
||||
@@ -493,7 +495,7 @@ public class IrisComplex implements DataProvider {
|
||||
naturalTrueBiomeStream = new BakedStream<>(bakeCache, BakePlane.NATURAL_TRUE_BIOME, naturalTrueBiomeSource);
|
||||
shoreBiomes = new HydrologyShoreBiomes(engine.getDimension(), data, engine.getSeedManager().getBodies());
|
||||
hydrologyRuntime = HydrologyRuntime.create(engine, this);
|
||||
waterFluidStreams = hydrologyRuntime.enabled() ? createWaterFluidStreams(hydrologyRuntime.settings().fluids()) : Map.of();
|
||||
waterFluidStreams = hydrologyRuntime.enabled() ? createWaterFluidStreams(hydrologyRuntime.settings().fluids(), hydrologyRuntime.settings().seams().values()) : Map.of();
|
||||
pondMaterials = hydrologyRuntime.enabled() ? hydrologyRuntime.settings().ponds().materials() : null;
|
||||
waterVegetation = hydrologyRuntime.enabled() ? HydrologyVegetationSource.create(engine.getDimension(), hydrologyRuntime.settings(), data,
|
||||
engine.getDimension().getAllRegions(engine), engine.getDimension().getReachableBiomes(engine)) : HydrologyVegetationSource.NONE;
|
||||
@@ -710,7 +712,31 @@ public class IrisComplex implements DataProvider {
|
||||
roles[index] = effectiveRole(own, x, z, columns[index]);
|
||||
owned[index] = owns(own, x, z, columns[index]);
|
||||
}
|
||||
return new EffectiveWater.Chunk(columns, roles, owned, own);
|
||||
return new EffectiveWater.Chunk(columns, roles, owned, own, sealedFluids(chunkX, chunkZ, around));
|
||||
}
|
||||
|
||||
private String[] sealedFluids(int chunkX, int chunkZ, ChunkWaterRaster[] around) {
|
||||
HydrologySettings settings = hydrologyRuntime.settings();
|
||||
if (settings.seams().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return FluidSeams.seal(settings.seams(), settings.seed(), chunkX, chunkZ, new FluidSeams.Columns() {
|
||||
@Override
|
||||
public String fluid(int x, int z) {
|
||||
ChunkWaterRaster raster = around[aroundSlot(chunkX, chunkZ, x, z)];
|
||||
if (raster.empty() || seamWeight(x, z) == 0D || !raster.role(x & 15, z & 15).wet()) {
|
||||
return null;
|
||||
}
|
||||
return raster.fluid(x & 15, z & 15);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sea(int x, int z) {
|
||||
ChunkWaterRaster raster = around[aroundSlot(chunkX, chunkZ, x, z)];
|
||||
int ground = raster.empty() || seamWeight(x, z) == 0D ? naturalTrueHeight(x, z) : raster.terrainHeight(x & 15, z & 15);
|
||||
return ground < transitionFluidHeight(x, z, fluidHeight);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private long waterColumn(int blockX, int blockZ) {
|
||||
@@ -1242,12 +1268,13 @@ public class IrisComplex implements DataProvider {
|
||||
public record BiomePick(IrisBiome biome, InferredType type) {
|
||||
}
|
||||
|
||||
private Map<String, ProceduralStream<NativeBlockState>> createWaterFluidStreams(Map<String, IrisMaterialPalette> fluids) {
|
||||
private Map<String, ProceduralStream<NativeBlockState>> createWaterFluidStreams(Map<String, IrisMaterialPalette> fluids,
|
||||
Collection<String> seams) {
|
||||
Map<String, ProceduralStream<NativeBlockState>> streams = new HashMap<>();
|
||||
int index = 0;
|
||||
for (Map.Entry<String, IrisMaterialPalette> fluid : fluids.entrySet()) {
|
||||
streams.put(fluid.getKey(), configuredFluidStream(fluid.getValue(), rng.nextParallelRNG(10900 + index),
|
||||
"hydrology fluid " + fluid.getKey()));
|
||||
"hydrology fluid " + fluid.getKey(), seams.contains(fluid.getKey())));
|
||||
index++;
|
||||
}
|
||||
return Map.copyOf(streams);
|
||||
@@ -1256,7 +1283,8 @@ public class IrisComplex implements DataProvider {
|
||||
private ProceduralStream<NativeBlockState> configuredFluidStream(
|
||||
IrisMaterialPalette palette,
|
||||
RNG fluidRng,
|
||||
String configurationName
|
||||
String configurationName,
|
||||
boolean allowSolids
|
||||
) {
|
||||
Objects.requireNonNull(palette, configurationName + " fluidPalette must be configured");
|
||||
KList<NativeBlockState> blocks = palette.getBlockData(data);
|
||||
@@ -1265,7 +1293,7 @@ public class IrisComplex implements DataProvider {
|
||||
configurationName + " fluidPalette must resolve at least one fluid block");
|
||||
}
|
||||
for (NativeBlockState block : blocks) {
|
||||
if (block == null || !block.isFluid()) {
|
||||
if (block == null || !allowSolids && !block.isFluid()) {
|
||||
throw new IllegalArgumentException(
|
||||
configurationName + " fluidPalette may contain only fluid blocks");
|
||||
}
|
||||
@@ -1294,7 +1322,8 @@ public class IrisComplex implements DataProvider {
|
||||
}
|
||||
|
||||
public NativeBlockState resolveWaterFluid(int x, int z) {
|
||||
String profile = chunkRasterAt(x, z).fluid(x & 15, z & 15);
|
||||
EffectiveWater.Chunk chunk = effectiveChunk(x >> 4, z >> 4);
|
||||
String profile = chunk != null && chunk.raster() != null ? chunk.fluid(x & 15, z & 15) : hydrologyRasterAt(x, z).fluid(x & 15, z & 15);
|
||||
if (profile == null) {
|
||||
throw new IllegalStateException("Column " + x + "," + z + " has no water fluid in its hydrology raster");
|
||||
}
|
||||
@@ -1743,9 +1772,13 @@ public class IrisComplex implements DataProvider {
|
||||
if (mapped != null) {
|
||||
return mapped;
|
||||
}
|
||||
IrisBiome base = baseBiomeStream.get(x, z);
|
||||
if (base.getInferredType() == InferredType.LAND && inlandWater(x, z)) {
|
||||
return base;
|
||||
}
|
||||
return fixBiomeType(
|
||||
terrainHeight,
|
||||
baseBiomeStream.get(x, z),
|
||||
base,
|
||||
regionStream.get(x, z),
|
||||
x,
|
||||
z,
|
||||
@@ -1753,6 +1786,18 @@ public class IrisComplex implements DataProvider {
|
||||
);
|
||||
}
|
||||
|
||||
private boolean inlandWater(double x, double z) {
|
||||
int blockX = blockCoordinate(x);
|
||||
int blockZ = blockCoordinate(z);
|
||||
ChunkWaterRaster raster = hydrologyRasterAt(blockX, blockZ);
|
||||
if (raster.empty()) {
|
||||
return false;
|
||||
}
|
||||
WaterRole role = raster.role(blockX & 15, blockZ & 15);
|
||||
return role.wet() && role != WaterRole.MOUTH && role != WaterRole.INLET && seamWeight(blockX, blockZ) != 0D
|
||||
&& raster.waterHead(blockX & 15, blockZ & 15) > transitionFluidHeight(x, z, fluidHeight);
|
||||
}
|
||||
|
||||
private IrisBiome hydrologyShoreBiome(double terrainHeight, double x, double z) {
|
||||
int blockX = blockCoordinate(x);
|
||||
int blockZ = blockCoordinate(z);
|
||||
|
||||
@@ -79,13 +79,14 @@ final class PackHydrologyValidator {
|
||||
int reported = errors.size();
|
||||
validateRanges(path, hydrology, errors);
|
||||
Set<String> fluids = fluidNames(hydrology);
|
||||
Set<String> seams = seamNames(hydrology);
|
||||
validateFluidReferences(path, hydrology, fluids, errors);
|
||||
IrisData loaded = data == null ? IrisData.openDatapackCompiler(packFolder) : data;
|
||||
IrisDimension loadedDimension = loaded.getDimensionLoader().load(dimensionKey, false);
|
||||
if (loadedDimension == null) {
|
||||
return loaded;
|
||||
}
|
||||
validatePolicies(path, dimensionKey, loaded, loadedDimension, fluids, errors);
|
||||
validatePolicies(path, dimensionKey, loaded, loadedDimension, new PolicyFluids(fluids, seams), errors);
|
||||
if (errors.size() == reported && validateCompile(path, loadedDimension, errors)) {
|
||||
validateDecoratorBlocks(path, loaded, loadedDimension.getHydrology(), errors);
|
||||
}
|
||||
@@ -190,6 +191,22 @@ final class PackHydrologyValidator {
|
||||
return names;
|
||||
}
|
||||
|
||||
private static Set<String> seamNames(JSONObject hydrology) {
|
||||
JSONArray profiles = hydrology.optJSONArray("fluids");
|
||||
if (profiles == null) {
|
||||
return Set.of();
|
||||
}
|
||||
Set<String> seams = new LinkedHashSet<>();
|
||||
for (int index = 0; index < profiles.length(); index++) {
|
||||
JSONObject profile = profiles.optJSONObject(index);
|
||||
String seam = profile == null ? null : profile.optString("seam", null);
|
||||
if (seam != null && !seam.isBlank()) {
|
||||
seams.add(seam);
|
||||
}
|
||||
}
|
||||
return seams;
|
||||
}
|
||||
|
||||
private static void validateFluidReferences(String path, JSONObject hydrology, Set<String> fluids, List<String> errors) {
|
||||
JSONArray tiers = hydrology.optJSONArray("tiers");
|
||||
if (tiers == null) {
|
||||
@@ -208,7 +225,7 @@ final class PackHydrologyValidator {
|
||||
}
|
||||
}
|
||||
|
||||
private static void validatePolicies(String path, String dimensionKey, IrisData data, IrisDimension dimension, Set<String> fluids,
|
||||
private static void validatePolicies(String path, String dimensionKey, IrisData data, IrisDimension dimension, PolicyFluids fluids,
|
||||
List<String> errors) {
|
||||
validatePolicy("Dimension '" + dimensionKey + "'." + POLICY, dimension.getHydrologyPolicy(), data, fluids, path, errors);
|
||||
List<IrisRegion> regions = new ArrayList<>(dimension.getAllRegions(() -> data));
|
||||
@@ -227,13 +244,17 @@ final class PackHydrologyValidator {
|
||||
}
|
||||
}
|
||||
|
||||
private static void validatePolicy(String field, IrisHydrologyPolicy policy, IrisData data, Set<String> fluids, String configPath,
|
||||
private static void validatePolicy(String field, IrisHydrologyPolicy policy, IrisData data, PolicyFluids fluids, String configPath,
|
||||
List<String> errors) {
|
||||
if (policy == null) {
|
||||
return;
|
||||
}
|
||||
if (policy.getFluid() != null) {
|
||||
requireFluid(field + ".fluid", policy.getFluid(), fluids, configPath, errors);
|
||||
String fluid = policy.getFluid();
|
||||
if (fluid != null) {
|
||||
requireFluid(field + ".fluid", fluid, fluids.defined(), configPath, errors);
|
||||
if (fluids.seams().contains(fluid)) {
|
||||
errors.add(field + ".fluid names fluid '" + fluid + "', which is a seam profile; seams only line the edges of other fluids.");
|
||||
}
|
||||
}
|
||||
if (policy.getDecorators() != null) {
|
||||
validateDecorators(field + ".decorators", policy.getDecorators(), data, errors);
|
||||
@@ -283,4 +304,7 @@ final class PackHydrologyValidator {
|
||||
warnings = List.copyOf(warnings);
|
||||
}
|
||||
}
|
||||
|
||||
private record PolicyFluids(Set<String> defined, Set<String> seams) {
|
||||
}
|
||||
}
|
||||
@@ -44,12 +44,17 @@ import org.bukkit.World;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.SoundCategory;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Snippet("effect")
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@@ -57,6 +62,9 @@ import org.bukkit.util.Vector;
|
||||
@Description("An iris effect")
|
||||
@Data
|
||||
public class IrisEffect {
|
||||
private static final String MASTER_SOUND_CATEGORY = "master";
|
||||
private static final Set<String> UNKNOWN_SOUND_CATEGORIES = ConcurrentHashMap.newKeySet();
|
||||
|
||||
private final transient AtomicCache<PotionEffectType> pt = new AtomicCache<>();
|
||||
private final transient AtomicCache<ChronoLatch> latch = new AtomicCache<>();
|
||||
private final transient AtomicCache<Particle> particleEffectResolved = new AtomicCache<>();
|
||||
@@ -117,6 +125,9 @@ public class IrisEffect {
|
||||
@MaxNumber(512)
|
||||
@Description("The sound volume.")
|
||||
private double volume = 1.5D;
|
||||
@DependsOn({"sound"})
|
||||
@Description("The sound category the sound plays in, which picks the client volume slider that controls it: master, music, record, weather, block, hostile, neutral, player, ambient, voice or ui.")
|
||||
private String soundCategory = MASTER_SOUND_CATEGORY;
|
||||
@DependsOn({"particleEffect"})
|
||||
@MinNumber(0)
|
||||
@MaxNumber(512)
|
||||
@@ -181,6 +192,10 @@ public class IrisEffect {
|
||||
return sound;
|
||||
}
|
||||
|
||||
public String getSoundCategoryKey() {
|
||||
return soundCategory == null || soundCategory.isBlank() ? MASTER_SOUND_CATEGORY : soundCategory.trim().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
public Particle getParticleEffect() {
|
||||
if (particleEffect == null) {
|
||||
return null;
|
||||
@@ -195,6 +210,32 @@ public class IrisEffect {
|
||||
return soundResolved.aquire(() -> resolveKeyed(Sound.class, sound));
|
||||
}
|
||||
|
||||
static SoundCategory bukkitSoundCategory(String key) {
|
||||
return switch (key) {
|
||||
case "master" -> SoundCategory.MASTER;
|
||||
case "music" -> SoundCategory.MUSIC;
|
||||
case "record" -> SoundCategory.RECORDS;
|
||||
case "weather" -> SoundCategory.WEATHER;
|
||||
case "block" -> SoundCategory.BLOCKS;
|
||||
case "hostile" -> SoundCategory.HOSTILE;
|
||||
case "neutral" -> SoundCategory.NEUTRAL;
|
||||
case "player" -> SoundCategory.PLAYERS;
|
||||
case "ambient" -> SoundCategory.AMBIENT;
|
||||
case "voice" -> SoundCategory.VOICE;
|
||||
case "ui" -> SoundCategory.UI;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
||||
private SoundCategory resolveSoundCategory() {
|
||||
String key = getSoundCategoryKey();
|
||||
SoundCategory category = bukkitSoundCategory(key);
|
||||
if (category == null && UNKNOWN_SOUND_CATEGORIES.add(key)) {
|
||||
IrisLogging.warn("Unknown sound category: \"" + key + "\".");
|
||||
}
|
||||
return category;
|
||||
}
|
||||
|
||||
private static <T> T resolveKeyed(Class<T> type, String key) {
|
||||
NamespacedKey namespacedKey = NamespacedKey.fromString(key);
|
||||
return namespacedKey == null ? null : RegistryUtil.lookup(type).get(namespacedKey);
|
||||
@@ -238,9 +279,10 @@ public class IrisEffect {
|
||||
BukkitFx.run(p, () -> {
|
||||
Sound soundType = getSound();
|
||||
Particle particleType = getParticleEffect();
|
||||
if (soundType != null) {
|
||||
SoundCategory category = soundType == null ? null : resolveSoundCategory();
|
||||
if (category != null) {
|
||||
Location part = p.getLocation().clone().add(RNG.r.i(-soundDistance, soundDistance), RNG.r.i(-soundDistance, soundDistance), RNG.r.i(-soundDistance, soundDistance));
|
||||
p.playSound(part, soundType, (float) volume, (float) RNG.r.d(minPitch, maxPitch));
|
||||
p.playSound(part, soundType, category, (float) volume, (float) RNG.r.d(minPitch, maxPitch));
|
||||
}
|
||||
|
||||
if (particleType != null) {
|
||||
@@ -315,9 +357,10 @@ public class IrisEffect {
|
||||
J.runEntity(p, () -> {
|
||||
Sound soundType = getSound();
|
||||
Particle particleType = getParticleEffect();
|
||||
if (soundType != null) {
|
||||
SoundCategory category = soundType == null ? null : resolveSoundCategory();
|
||||
if (category != null) {
|
||||
Location part = p.getLocation().clone().add(RNG.r.i(-soundDistance, soundDistance), RNG.r.i(-soundDistance, soundDistance), RNG.r.i(-soundDistance, soundDistance));
|
||||
p.getWorld().playSound(part, soundType, (float) volume, (float) RNG.r.d(minPitch, maxPitch));
|
||||
p.getWorld().playSound(part, soundType, category, (float) volume, (float) RNG.r.d(minPitch, maxPitch));
|
||||
}
|
||||
|
||||
if (particleType != null) {
|
||||
|
||||
@@ -11,11 +11,15 @@ import art.arcane.volmlib.util.math.RNG;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockSupport;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.MultipleFacing;
|
||||
import org.junit.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -25,15 +29,23 @@ import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyDouble;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.CALLS_REAL_METHODS;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class DecoratorCoreTest {
|
||||
private static final String VINE = "minecraft:vine";
|
||||
private static final String GLOW_LICHEN = "minecraft:glow_lichen";
|
||||
private static final Set<BlockFace> VINE_FACES = EnumSet.of(BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH,
|
||||
BlockFace.WEST, BlockFace.UP);
|
||||
private static final Set<BlockFace> LICHEN_FACES = EnumSet.of(BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH,
|
||||
BlockFace.WEST, BlockFace.UP, BlockFace.DOWN);
|
||||
|
||||
@Test
|
||||
public void partSeed_differsByPartOrdinal() {
|
||||
@@ -741,6 +753,141 @@ public class DecoratorCoreTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stackedVineCurtainHangsFromTheWallItsTopStrandFaces() {
|
||||
IrisDecorator decorator = mock(IrisDecorator.class);
|
||||
IrisData data = mock(IrisData.class);
|
||||
NativeBlockState vine = facingState(VINE, VINE_FACES, EnumSet.of(BlockFace.NORTH));
|
||||
when(decorator.getHeight(any(RNG.class), anyDouble(), anyDouble(), eq(data))).thenReturn(3);
|
||||
when(decorator.getTopThreshold()).thenReturn(1.0);
|
||||
when(decorator.pickBlockData(any(RNG.class), eq(data), anyDouble(), anyDouble())).thenReturn(vine);
|
||||
when(decorator.pickBlockDataTop(any(RNG.class), eq(data), anyDouble(), anyDouble())).thenReturn(vine);
|
||||
Hunk<NativeBlockState> output = Hunk.newArrayHunk(16, 8, 16);
|
||||
output.set(8, 6, 8, sturdyState());
|
||||
output.set(8, 5, 7, sturdyState());
|
||||
output.set(9, 4, 8, sturdyState());
|
||||
|
||||
DecoratorCore.placeStackDown(decorator, 8, 8, 8, 8, 5, 0, output, new RNG(1L), data, 3,
|
||||
new DecoratorCore.PlaceOpts(), null);
|
||||
|
||||
assertEquals(EnumSet.of(BlockFace.NORTH, BlockFace.UP), faces(output.get(8, 5, 8)));
|
||||
assertEquals(EnumSet.of(BlockFace.NORTH), faces(output.get(8, 4, 8)));
|
||||
assertEquals(EnumSet.of(BlockFace.NORTH), faces(output.get(8, 3, 8)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stackedVineCurtainHangsUnderAnOpenCeiling() {
|
||||
IrisDecorator decorator = mock(IrisDecorator.class);
|
||||
IrisData data = mock(IrisData.class);
|
||||
NativeBlockState vine = facingState(VINE, VINE_FACES, EnumSet.of(BlockFace.NORTH));
|
||||
when(decorator.getHeight(any(RNG.class), anyDouble(), anyDouble(), eq(data))).thenReturn(3);
|
||||
when(decorator.getTopThreshold()).thenReturn(1.0);
|
||||
when(decorator.pickBlockData(any(RNG.class), eq(data), anyDouble(), anyDouble())).thenReturn(vine);
|
||||
when(decorator.pickBlockDataTop(any(RNG.class), eq(data), anyDouble(), anyDouble())).thenReturn(vine);
|
||||
Hunk<NativeBlockState> output = Hunk.newArrayHunk(16, 8, 16);
|
||||
output.set(8, 6, 8, sturdyState());
|
||||
|
||||
DecoratorCore.placeStackDown(decorator, 8, 8, 8, 8, 5, 0, output, new RNG(1L), data, 3,
|
||||
new DecoratorCore.PlaceOpts(), null);
|
||||
|
||||
assertEquals(EnumSet.of(BlockFace.NORTH, BlockFace.UP), faces(output.get(8, 5, 8)));
|
||||
assertEquals(EnumSet.of(BlockFace.NORTH), faces(output.get(8, 4, 8)));
|
||||
assertEquals(EnumSet.of(BlockFace.NORTH), faces(output.get(8, 3, 8)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unsupportedAuthoredSideFaceOnALoneVineIsDroppedAndReattached() {
|
||||
NativeBlockState vine = facingState(VINE, VINE_FACES, EnumSet.of(BlockFace.NORTH));
|
||||
Hunk<NativeBlockState> walled = Hunk.newArrayHunk(16, 8, 16);
|
||||
walled.set(9, 3, 8, sturdyState());
|
||||
|
||||
assertEquals(EnumSet.of(BlockFace.EAST), faces(DecoratorCore.fixFacesForHunk(vine, walled, 8, 8, 8, 3, 8, null)));
|
||||
assertEquals(EnumSet.of(BlockFace.UP),
|
||||
faces(DecoratorCore.fixFacesForHunk(vine, Hunk.newArrayHunk(16, 8, 16), 8, 8, 8, 3, 8, null)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void glowLichenSideFaceIsNotHeldByTheLichenAboveIt() {
|
||||
NativeBlockState lichen = facingState(GLOW_LICHEN, LICHEN_FACES, EnumSet.of(BlockFace.NORTH));
|
||||
Hunk<NativeBlockState> output = Hunk.newArrayHunk(16, 8, 16);
|
||||
output.set(8, 2, 8, sturdyState());
|
||||
output.set(8, 4, 8, facingState(GLOW_LICHEN, LICHEN_FACES, EnumSet.of(BlockFace.NORTH)));
|
||||
|
||||
assertEquals(EnumSet.of(BlockFace.DOWN), faces(DecoratorCore.fixFacesForHunk(lichen, output, 8, 8, 8, 3, 8, null)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supportedAuthoredSideFaceKeepsItsDirection() {
|
||||
NativeBlockState vine = facingState(VINE, VINE_FACES, EnumSet.of(BlockFace.NORTH));
|
||||
Hunk<NativeBlockState> output = Hunk.newArrayHunk(16, 8, 16);
|
||||
output.set(8, 3, 7, sturdyState());
|
||||
output.set(9, 3, 8, sturdyState());
|
||||
|
||||
assertEquals(EnumSet.of(BlockFace.NORTH), faces(DecoratorCore.fixFacesForHunk(vine, output, 8, 8, 8, 3, 8, null)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void vineWithoutAuthoredSideFaceReattachesToEverySturdyNeighbour() {
|
||||
NativeBlockState vine = facingState(VINE, VINE_FACES, EnumSet.of(BlockFace.UP));
|
||||
Hunk<NativeBlockState> output = Hunk.newArrayHunk(16, 8, 16);
|
||||
output.set(7, 3, 8, sturdyState());
|
||||
output.set(8, 3, 9, sturdyState());
|
||||
output.set(8, 4, 8, sturdyState());
|
||||
|
||||
assertEquals(EnumSet.of(BlockFace.SOUTH, BlockFace.WEST, BlockFace.UP),
|
||||
faces(DecoratorCore.fixFacesForHunk(vine, output, 8, 8, 8, 3, 8, null)));
|
||||
}
|
||||
|
||||
private NativeBlockState facingState(String material, Set<BlockFace> allowed, Set<BlockFace> faces) {
|
||||
MultipleFacing handle = facing(material, allowed, faces);
|
||||
String key = handle.getAsString();
|
||||
NativeBlockState state = mock(NativeBlockState.class);
|
||||
when(state.isVineBlock()).thenReturn(true);
|
||||
when(state.materialKey()).thenReturn(material);
|
||||
when(state.key()).thenReturn(key);
|
||||
when(state.nativeHandle()).thenReturn(handle);
|
||||
return state;
|
||||
}
|
||||
|
||||
private static MultipleFacing facing(String material, Set<BlockFace> allowed, Set<BlockFace> faces) {
|
||||
EnumSet<BlockFace> current = EnumSet.noneOf(BlockFace.class);
|
||||
current.addAll(faces);
|
||||
MultipleFacing data = mock(MultipleFacing.class);
|
||||
when(data.getAllowedFaces()).thenReturn(allowed);
|
||||
when(data.getFaces()).thenAnswer(invocation -> EnumSet.copyOf(current));
|
||||
when(data.hasFace(any(BlockFace.class))).thenAnswer(invocation -> current.contains(invocation.<BlockFace>getArgument(0)));
|
||||
doAnswer(invocation -> {
|
||||
BlockFace face = invocation.getArgument(0);
|
||||
if (!allowed.contains(face)) {
|
||||
throw new IllegalArgumentException(face + " is not allowed on " + material);
|
||||
}
|
||||
if (invocation.<Boolean>getArgument(1)) {
|
||||
current.add(face);
|
||||
} else {
|
||||
current.remove(face);
|
||||
}
|
||||
return null;
|
||||
}).when(data).setFace(any(BlockFace.class), anyBoolean());
|
||||
when(data.clone()).thenAnswer(invocation -> facing(material, allowed, current));
|
||||
when(data.getAsString()).thenAnswer(invocation -> {
|
||||
StringBuilder key = new StringBuilder(material).append('[');
|
||||
for (BlockFace face : allowed) {
|
||||
if (key.charAt(key.length() - 1) != '[') {
|
||||
key.append(',');
|
||||
}
|
||||
key.append(face.name().toLowerCase(Locale.ROOT)).append('=').append(current.contains(face));
|
||||
}
|
||||
return key.append(']').toString();
|
||||
});
|
||||
return data;
|
||||
}
|
||||
|
||||
private static Set<BlockFace> faces(NativeBlockState state) {
|
||||
EnumSet<BlockFace> faces = EnumSet.noneOf(BlockFace.class);
|
||||
faces.addAll(((MultipleFacing) state.nativeHandle()).getFaces());
|
||||
return faces;
|
||||
}
|
||||
|
||||
private NativeBlockState airState() {
|
||||
NativeBlockState air = mock(NativeBlockState.class);
|
||||
when(air.isAir()).thenReturn(true);
|
||||
|
||||
+38
@@ -3,6 +3,7 @@ package art.arcane.iris.generation.hydrology.plan;
|
||||
import art.arcane.iris.generation.block.IrisBlockData;
|
||||
import art.arcane.iris.generation.decoration.IrisDecorationPart;
|
||||
import art.arcane.iris.generation.decoration.IrisDecorator;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisFluidProfile;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrologyMaterials;
|
||||
import art.arcane.iris.generation.hydrology.water.HydrologyTier;
|
||||
@@ -17,6 +18,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -250,6 +252,33 @@ public class HydrologySettingsTest {
|
||||
assertRejected(config, "lava");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seamsLeaveTheFingerprintAlone() {
|
||||
assertEquals(compile(lavaAndCrust(null)).fingerprint(), compile(lavaAndCrust("crust")).fingerprint());
|
||||
assertEquals(Map.of("lava", "crust"), compile(lavaAndCrust("crust")).seams());
|
||||
assertTrue(compile(lavaAndCrust(null)).seams().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compileRejectsAnUnknownSeam() {
|
||||
assertRejected(lavaAndCrust("ash"), "ash");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compileRejectsASeamThatAlsoFillsWater() {
|
||||
IrisHydrology tier = lavaAndCrust("crust");
|
||||
tier.getTiers().get(2).setFluid("crust");
|
||||
assertRejected(tier, "crust");
|
||||
|
||||
IrisHydrology ponds = lavaAndCrust("crust");
|
||||
ponds.getPonds().setFluid("crust");
|
||||
assertRejected(ponds, "crust");
|
||||
|
||||
IrisHydrology chained = lavaAndCrust("crust");
|
||||
chained.getFluids().get(2).setSeam("lava");
|
||||
assertRejected(chained, "crust");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compileRejectsMalformedRange() {
|
||||
IrisHydrology inverted = new IrisHydrology();
|
||||
@@ -554,6 +583,15 @@ public class HydrologySettingsTest {
|
||||
assertTrue(failure.getMessage(), failure.getMessage().contains("\"palette\" list is missing, misspelt or empty"));
|
||||
}
|
||||
|
||||
private static IrisHydrology lavaAndCrust(String seam) {
|
||||
IrisHydrology config = new IrisHydrology();
|
||||
config.getFluids().add(new IrisFluidProfile().setName("lava").setSeam(seam)
|
||||
.setPalette(new IrisMaterialPalette().qclear().qadd("minecraft:lava")));
|
||||
config.getFluids().add(new IrisFluidProfile().setName("crust")
|
||||
.setPalette(new IrisMaterialPalette().qclear().qadd("minecraft:obsidian")));
|
||||
return config;
|
||||
}
|
||||
|
||||
private static HydrologySettings compile(IrisHydrology config) {
|
||||
return HydrologySettings.compile(config, SEED, SEA_LEVEL, MIN_Y, MAX_Y);
|
||||
}
|
||||
|
||||
+9
-6
@@ -465,11 +465,14 @@ public class ChunkWaterRasterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void channelTakesTheAreaFluidWhereOneIsSet() {
|
||||
public void reachKeepsThePolicyFluidOfItsUpstreamEnd() {
|
||||
HydrologySettings settings = settings(new IrisHydrology());
|
||||
Reach reach = line(61L, tier("stream", 1.5f, 0.5f, 0, IrisBankStyle.SMOOTH), 0L, 400f, 400f, 480f, 400f, (x, z) -> 69);
|
||||
HydrologyTier stream = tier("stream", 1.5f, 0.5f, 0, IrisBankStyle.SMOOTH);
|
||||
Reach outflow = line(61L, stream, 0L, 400f, 403f, 480f, 403f, (x, z) -> 69);
|
||||
Reach inflow = line(62L, stream, 0L, 480f, 412f, 400f, 412f, (x, z) -> 69);
|
||||
WindowKey key = new WindowKey(0, 0);
|
||||
IndexedWindow own = new IndexedWindow(new WindowPlan(key, List.of(reach), List.of(), List.of()), ReachIndex.build(List.of(reach), List.of()));
|
||||
IndexedWindow own = new IndexedWindow(new WindowPlan(key, List.of(outflow, inflow), List.of(), List.of()),
|
||||
ReachIndex.build(List.of(outflow, inflow), List.of()));
|
||||
ChannelFluids volcanic = (x, z) -> x < 440 ? "lava" : null;
|
||||
ChunkWaterRaster raster = new ChunkRasterizer(settings, volcanic).rasterize(27, 25, (x, z) -> 70, List.of(own), regions(27, 25, List.of()));
|
||||
int lava = 0;
|
||||
@@ -479,9 +482,9 @@ public class ChunkWaterRasterTest {
|
||||
if (!isChannel(raster.role(lx, lz))) {
|
||||
continue;
|
||||
}
|
||||
boolean inside = 27 * 16 + lx < 440;
|
||||
assertEquals("column " + lx + "," + lz, inside ? "lava" : "water", raster.fluid(lx, lz));
|
||||
if (inside) {
|
||||
boolean startsVolcanic = raster.featureId(lx, lz) == 61L;
|
||||
assertEquals("column " + lx + "," + lz, startsVolcanic ? "lava" : "water", raster.fluid(lx, lz));
|
||||
if (startsVolcanic) {
|
||||
lava++;
|
||||
} else {
|
||||
water++;
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package art.arcane.iris.generation.hydrology.raster;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.IntFunction;
|
||||
import java.util.function.IntPredicate;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class FluidSeamsTest {
|
||||
private static final long SEED = 4242L;
|
||||
private static final Map<String, String> LAVA_CRUST = Map.of("lava", "crust");
|
||||
|
||||
@Test
|
||||
public void lavaSealsEveryColumnTouchingWater() {
|
||||
FluidSeams.Columns columns = columns(x -> x < 100 ? "lava" : "water", x -> false);
|
||||
String[] sealed = FluidSeams.seal(LAVA_CRUST, SEED, 6, 0, columns);
|
||||
int spread = 0;
|
||||
for (int lz = 0; lz < 16; lz++) {
|
||||
for (int lx = 0; lx < 16; lx++) {
|
||||
int x = 96 + lx;
|
||||
String seam = sealed[lz << 4 | lx];
|
||||
if (x == 99) {
|
||||
assertEquals("touching column " + x + "," + lz, "crust", seam);
|
||||
} else if (x == 98) {
|
||||
spread += seam == null ? 0 : 1;
|
||||
} else {
|
||||
assertNull("column " + x + "," + lz, seam);
|
||||
}
|
||||
}
|
||||
}
|
||||
assertTrue("spread columns " + spread, spread > 0 && spread < 16);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void spreadReachesAcrossTheChunkEdge() {
|
||||
FluidSeams.Columns columns = columns(x -> x < 97 ? "lava" : "water", x -> false);
|
||||
int spread = 0;
|
||||
int rows = 0;
|
||||
for (int chunkZ = 0; chunkZ < 8; chunkZ++) {
|
||||
String[] west = FluidSeams.seal(LAVA_CRUST, SEED, 5, chunkZ, columns);
|
||||
String[] east = FluidSeams.seal(LAVA_CRUST, SEED, 6, chunkZ, columns);
|
||||
for (int lz = 0; lz < 16; lz++) {
|
||||
rows++;
|
||||
assertEquals("crust", east[lz << 4]);
|
||||
assertNull(west[lz << 4 | 14]);
|
||||
spread += west[lz << 4 | 15] == null ? 0 : 1;
|
||||
}
|
||||
}
|
||||
double fraction = spread / (double) rows;
|
||||
assertTrue("spread fraction at the chunk edge " + fraction, fraction > 0.45D && fraction < 0.75D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dryGroundBelowSeaLevelCountsAsTheSea() {
|
||||
String[] sea = FluidSeams.seal(LAVA_CRUST, SEED, 6, 0, columns(x -> x < 100 ? "lava" : null, x -> x >= 100));
|
||||
for (int lz = 0; lz < 16; lz++) {
|
||||
assertEquals("crust", sea[lz << 4 | 3]);
|
||||
}
|
||||
assertNull(FluidSeams.seal(LAVA_CRUST, SEED, 6, 0, columns(x -> x < 100 ? "lava" : null, x -> false)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nothingSealsWithoutASeamOrAnotherFluid() {
|
||||
assertNull(FluidSeams.seal(Map.of(), SEED, 6, 0, columns(x -> x < 100 ? "lava" : "water", x -> false)));
|
||||
assertNull(FluidSeams.seal(LAVA_CRUST, SEED, 6, 0, columns(x -> "water", x -> true)));
|
||||
assertNull(FluidSeams.seal(LAVA_CRUST, SEED, 6, 0, columns(x -> "lava", x -> false)));
|
||||
assertNull(FluidSeams.seal(LAVA_CRUST, SEED, 6, 0, columns(x -> x < 100 ? "lava" : "crust", x -> false)));
|
||||
}
|
||||
|
||||
private static FluidSeams.Columns columns(IntFunction<String> fluid, IntPredicate sea) {
|
||||
return new FluidSeams.Columns() {
|
||||
@Override
|
||||
public String fluid(int x, int z) {
|
||||
return fluid.apply(x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sea(int x, int z) {
|
||||
return sea.test(x);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package art.arcane.iris.generation.runtime;
|
||||
|
||||
import art.arcane.iris.generation.context.ChunkContext;
|
||||
import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.generation.hydrology.water.Pond;
|
||||
import art.arcane.iris.generation.hydrology.water.Reach;
|
||||
@@ -159,11 +160,25 @@ public class EffectiveWaterTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sealedColumnsTakeTheirSeamAndTheRestKeepTheRasterFluid() {
|
||||
ChunkWaterRaster raster = mock(ChunkWaterRaster.class);
|
||||
when(raster.fluid(anyInt(), anyInt())).thenReturn("lava");
|
||||
String[] seams = new String[256];
|
||||
seams[3 << 4 | 2] = "crust";
|
||||
EffectiveWater.Chunk sealed = new EffectiveWater.Chunk(new long[256], new WaterRole[256], new boolean[256], raster, seams);
|
||||
EffectiveWater.Chunk open = new EffectiveWater.Chunk(new long[256], new WaterRole[256], new boolean[256], raster, null);
|
||||
|
||||
assertEquals("crust", sealed.fluid(2, 3));
|
||||
assertEquals("lava", sealed.fluid(3, 2));
|
||||
assertEquals("lava", open.fluid(2, 3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void chunksSharingACacheSlotNeverAnswerForEachOther() {
|
||||
EffectiveWater.Chunks chunks = new EffectiveWater.Chunks();
|
||||
EffectiveWater.Chunk first = new EffectiveWater.Chunk(new long[256], new WaterRole[256], new boolean[256], null);
|
||||
EffectiveWater.Chunk second = new EffectiveWater.Chunk(new long[256], new WaterRole[256], new boolean[256], null);
|
||||
EffectiveWater.Chunk first = new EffectiveWater.Chunk(new long[256], new WaterRole[256], new boolean[256], null, null);
|
||||
EffectiveWater.Chunk second = new EffectiveWater.Chunk(new long[256], new WaterRole[256], new boolean[256], null, null);
|
||||
|
||||
chunks.put(0, 0, first);
|
||||
assertSame(first, chunks.get(0, 0));
|
||||
|
||||
+22
@@ -24,6 +24,7 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@@ -39,6 +40,8 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class IrisComplexSurfaceBiomeTest {
|
||||
private static final int INLAND_SEA_LEVEL = 85;
|
||||
|
||||
@ClassRule
|
||||
public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean();
|
||||
@Rule
|
||||
@@ -208,6 +211,25 @@ public class IrisComplexSurfaceBiomeTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(timeout = 120_000L)
|
||||
public void pondAboveSeaLevelKeepsTheLandBiomeOverAFloorBelowIt() throws Exception {
|
||||
Path pack = HydrologyFixture.pack(temporaryFolder.newFolder().toPath(), null, null);
|
||||
Files.writeString(pack.resolve("dimensions/main.json"), """
|
||||
{"regions":["plain"],"landChance":1,"fluidHeight":%d,"carvingEnabled":false}
|
||||
""".formatted(INLAND_SEA_LEVEL));
|
||||
Files.writeString(pack.resolve("regions/plain.json"), "{\"landBiomes\":[\"plain\"],\"seaBiomes\":[\"ocean\"]}");
|
||||
Files.writeString(pack.resolve("biomes/ocean.json"), "{\"generators\":[{\"generator\":\"flat\",\"min\":10,\"max\":10}]}");
|
||||
try (HydrologyFixture fixture = new HydrologyFixture(pack)) {
|
||||
ChunkWaterRaster raster = fixture.hydrology.runtime.raster(0, 0);
|
||||
int sea = fixture.engine.getDimension().getFluidHeight();
|
||||
assertEquals(WaterRole.POND, raster.role(8, 8));
|
||||
assertTrue("the pond floor sits below sea level", raster.terrainHeight(8, 8) < sea);
|
||||
assertTrue("the pond surface sits above sea level", raster.waterHead(8, 8) > sea);
|
||||
assertTrue("the land around the pond sits above sea level", HydrologyFixture.NATURAL > sea);
|
||||
assertEquals("plain", fixture.complex.getTrueBiomeStream().get(8, 8).getLoadKey());
|
||||
}
|
||||
}
|
||||
|
||||
private static int shoreColumn(HydrologyFixture fixture, int distance) {
|
||||
for (int x = 0; x < 64; x++) {
|
||||
ChunkWaterRaster raster = fixture.hydrology.runtime.raster(x >> 4, 0);
|
||||
|
||||
@@ -93,6 +93,31 @@ public class PackHydrologyValidatorTest {
|
||||
assertEquals(validation.errors().toString(), 6, validation.errors().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsPoliciesThatFillWaterWithASeamProfile() throws Exception {
|
||||
File pack = pack(dimension("""
|
||||
{
|
||||
"enabled": true,
|
||||
"fluids": [
|
||||
{"name": "water"},
|
||||
{"name": "lava", "palette": {"palette": [{"block": "minecraft:lava"}]}, "seam": "crust"},
|
||||
{"name": "crust", "palette": {"palette": [{"block": "minecraft:obsidian"}]}}
|
||||
]
|
||||
}
|
||||
""", ""));
|
||||
write(pack, "regions/region.json", """
|
||||
{"landBiomes": ["biome"], "hydrologyPolicy": {"fluid": "lava"}}
|
||||
""");
|
||||
write(pack, "biomes/biome.json", """
|
||||
{"name": "Biome", "hydrologyPolicy": {"fluid": "crust"}}
|
||||
""");
|
||||
|
||||
List<String> errors = validate(pack).errors();
|
||||
|
||||
assertContains(errors, "Biome 'biome'.hydrologyPolicy.fluid names fluid 'crust', which is a seam profile");
|
||||
assertEquals(errors.toString(), 1, errors.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsFluidReferencesTheFluidProfilesDoNotDefine() throws Exception {
|
||||
File pack = pack(dimension("""
|
||||
|
||||
@@ -84,7 +84,7 @@ public class SchemaBuilderIdentityTest {
|
||||
@ClassRule
|
||||
public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean();
|
||||
|
||||
private static final String EXPECTED_SCHEMA_DIGEST = "2224e73a1e9d76231d4df8bb1992451340e5f533b3fbafae9f4e1437747e666c";
|
||||
private static final String EXPECTED_SCHEMA_DIGEST = "0b7bc58cb81a7e630d13662b2157868bd306f3afef571942dc5b8e667323a250";
|
||||
|
||||
private static final List<Class<?>> SCHEMA_ROOTS = List.of(
|
||||
IrisDimension.class,
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package art.arcane.iris.world.entity;
|
||||
|
||||
import org.bukkit.SoundCategory;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
public class IrisEffectSoundCategoryTest {
|
||||
private static final Map<String, SoundCategory> VANILLA_CATEGORIES = Map.ofEntries(
|
||||
Map.entry("master", SoundCategory.MASTER),
|
||||
Map.entry("music", SoundCategory.MUSIC),
|
||||
Map.entry("record", SoundCategory.RECORDS),
|
||||
Map.entry("weather", SoundCategory.WEATHER),
|
||||
Map.entry("block", SoundCategory.BLOCKS),
|
||||
Map.entry("hostile", SoundCategory.HOSTILE),
|
||||
Map.entry("neutral", SoundCategory.NEUTRAL),
|
||||
Map.entry("player", SoundCategory.PLAYERS),
|
||||
Map.entry("ambient", SoundCategory.AMBIENT),
|
||||
Map.entry("voice", SoundCategory.VOICE),
|
||||
Map.entry("ui", SoundCategory.UI));
|
||||
|
||||
@Test
|
||||
public void soundCategoryIsStoredAsAPlainStringField() throws NoSuchFieldException {
|
||||
assertEquals(String.class, IrisEffect.class.getDeclaredField("soundCategory").getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void soundCategoryDefaultsToMaster() {
|
||||
assertEquals("master", new IrisEffect().getSoundCategoryKey());
|
||||
assertEquals("master", new IrisEffect().setSoundCategory(null).getSoundCategoryKey());
|
||||
assertEquals("master", new IrisEffect().setSoundCategory(" ").getSoundCategoryKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void soundCategoryKeyIgnoresCaseAndSurroundingSpace() {
|
||||
assertEquals("ambient", new IrisEffect().setSoundCategory(" Ambient ").getSoundCategoryKey());
|
||||
assertEquals("music", new IrisEffect().setSoundCategory("MUSIC").getSoundCategoryKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void everyVanillaCategoryNameResolvesToItsBukkitCategory() {
|
||||
for (Map.Entry<String, SoundCategory> entry : VANILLA_CATEGORIES.entrySet()) {
|
||||
assertSame(entry.getKey(), entry.getValue(), IrisEffect.bukkitSoundCategory(entry.getKey()));
|
||||
}
|
||||
assertEquals(SoundCategory.values().length, VANILLA_CATEGORIES.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unknownCategoryNamesDoNotResolve() {
|
||||
assertNull(IrisEffect.bukkitSoundCategory("ambiant"));
|
||||
assertNull(IrisEffect.bukkitSoundCategory("records"));
|
||||
assertNull(IrisEffect.bukkitSoundCategory("players"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user