mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-12-03 19:51:49 +00:00
Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e3b595a712 | ||
|
|
ecc4413d19 | ||
|
|
c7a2af98a5 | ||
|
|
94648946d9 | ||
|
|
ba9694083b | ||
|
|
02f6379808 | ||
|
|
f7084b244f | ||
|
|
1bc7843a52 | ||
|
|
b0b6e54d2d |
No files matched your search
+262
@@ -0,0 +1,262 @@
|
||||
package art.arcane.iris.probe;
|
||||
|
||||
import art.arcane.volmlib.nativelib.common.block.GroundSurvival;
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.ModdedBlockState;
|
||||
import art.arcane.volmlib.nativelib.block.SurvivalAnswer;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/** Both platforms ask the server's own canSurvive rule where a plant may stand, against the real block tags. */
|
||||
public final class HeadlessGroundSurvivalTest {
|
||||
private static final Logger NATIVE_LOG = Logger.getLogger("VolmLib-Native");
|
||||
|
||||
@BeforeClass
|
||||
public static void bootstrap() {
|
||||
HeadlessNativeBootstrap.initialize();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void grassStandsOnSoilButNotOnStone() {
|
||||
assertPlacement(true, Blocks.SHORT_GRASS, Blocks.GRASS_BLOCK);
|
||||
assertPlacement(true, Blocks.SHORT_GRASS, Blocks.PODZOL);
|
||||
assertPlacement(false, Blocks.SHORT_GRASS, Blocks.STONE);
|
||||
assertPlacement(false, Blocks.POPPY, Blocks.STONE);
|
||||
assertPlacement(false, Blocks.FERN, Blocks.OAK_LEAVES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cactusNeedsSandOrCactus() {
|
||||
for (Block ground : new Block[]{Blocks.CACTUS, Blocks.SAND, Blocks.RED_SAND}) {
|
||||
assertPlacement(true, Blocks.CACTUS, ground);
|
||||
}
|
||||
assertPlacement(false, Blocks.CACTUS, Blocks.STONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sugarCaneNeedsItsSubstrate() {
|
||||
for (Block ground : new Block[]{Blocks.SUGAR_CANE, Blocks.GRASS_BLOCK, Blocks.DIRT, Blocks.COARSE_DIRT,
|
||||
Blocks.PODZOL, Blocks.MYCELIUM, Blocks.ROOTED_DIRT, Blocks.MOSS_BLOCK, Blocks.PALE_MOSS_BLOCK,
|
||||
Blocks.MUD, Blocks.MUDDY_MANGROVE_ROOTS, Blocks.SAND, Blocks.RED_SAND, Blocks.SUSPICIOUS_SAND}) {
|
||||
assertPlacement(true, Blocks.SUGAR_CANE, ground);
|
||||
}
|
||||
for (Block ground : new Block[]{Blocks.STONE, Blocks.GRAVEL, Blocks.CLAY, Blocks.DIRT_PATH,
|
||||
Blocks.FARMLAND, Blocks.AIR, Blocks.WATER}) {
|
||||
assertPlacement(false, Blocks.SUGAR_CANE, ground);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void netherGroundCoverAcceptsNyliumAndSoulSoilButRejectsBarrenBlocks() {
|
||||
for (Block plant : new Block[]{Blocks.CRIMSON_ROOTS, Blocks.WARPED_ROOTS, Blocks.NETHER_SPROUTS}) {
|
||||
for (Block ground : new Block[]{Blocks.CRIMSON_NYLIUM, Blocks.WARPED_NYLIUM, Blocks.SOUL_SOIL}) {
|
||||
assertPlacement(true, plant, ground);
|
||||
}
|
||||
for (Block ground : new Block[]{Blocks.NETHERRACK, Blocks.STONE, Blocks.GRAVEL, Blocks.AIR}) {
|
||||
assertPlacement(false, plant, ground);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void blocksThatRestOnNoGroundStillFit() {
|
||||
assertPlacement(true, Blocks.WALL_TORCH, Blocks.STONE);
|
||||
assertPlacement(true, Blocks.VINE, Blocks.SAND);
|
||||
assertPlacement(true, Blocks.COCOA, Blocks.STONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deadBushStaysOffGrassAsPacksExpect() {
|
||||
assertPlacement(true, Blocks.DEAD_BUSH, Blocks.SAND);
|
||||
assertPlacement(false, Blocks.DEAD_BUSH, Blocks.GRASS_BLOCK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nothingStandsOnAir() {
|
||||
assertPlacement(false, Blocks.VINE, Blocks.AIR);
|
||||
assertPlacement(false, Blocks.SHORT_GRASS, Blocks.CAVE_AIR);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void plantsThatReadMoreOfTheLevelAreAnsweredByTheirOwnRule() {
|
||||
List<LogRecord> warnings = warningsDuring(() -> {
|
||||
assertPlacement(true, Blocks.BAMBOO, Blocks.GRASS_BLOCK);
|
||||
assertPlacement(false, Blocks.BAMBOO, Blocks.STONE);
|
||||
assertPlacement(true, Blocks.KELP, Blocks.STONE);
|
||||
assertPlacement(false, Blocks.KELP, Blocks.MAGMA_BLOCK);
|
||||
assertPlacement(true, Blocks.SEAGRASS, Blocks.SAND);
|
||||
assertPlacement(false, Blocks.SEAGRASS, Blocks.MAGMA_BLOCK);
|
||||
assertPlacement(true, Blocks.LILY_PAD, Blocks.WATER);
|
||||
assertPlacement(false, Blocks.LILY_PAD, Blocks.STONE);
|
||||
assertPlacement(true, Blocks.SWEET_BERRY_BUSH, Blocks.GRASS_BLOCK);
|
||||
assertPlacement(false, Blocks.SWEET_BERRY_BUSH, Blocks.STONE);
|
||||
assertPlacement(true, Blocks.BROWN_MUSHROOM, Blocks.STONE);
|
||||
assertPlacement(true, Blocks.RED_MUSHROOM, Blocks.MYCELIUM);
|
||||
assertPlacement(false, Blocks.BROWN_MUSHROOM, Blocks.GLASS);
|
||||
assertPlacement(true, Blocks.CRIMSON_FUNGUS, Blocks.CRIMSON_NYLIUM);
|
||||
assertPlacement(false, Blocks.WARPED_FUNGUS, Blocks.NETHERRACK);
|
||||
assertPlacement(true, Blocks.WHEAT, Blocks.FARMLAND);
|
||||
assertPlacement(false, Blocks.CARROTS, Blocks.DIRT);
|
||||
});
|
||||
assertEquals(messages(warnings), 0, warnings.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void everyVanillaBlockIsAnsweredWithoutFailingOpen() {
|
||||
GroundSurvival survival = new GroundSurvival();
|
||||
List<LogRecord> warnings = warningsDuring(() -> {
|
||||
for (Block plant : BuiltInRegistries.BLOCK) {
|
||||
if (needsARunningPaperServer(plant)) {
|
||||
continue;
|
||||
}
|
||||
for (Block ground : new Block[]{Blocks.GRASS_BLOCK, Blocks.STONE, Blocks.WATER}) {
|
||||
survival.canSurviveOn(plant.defaultBlockState(), ground.defaultBlockState());
|
||||
}
|
||||
}
|
||||
});
|
||||
assertEquals(messages(warnings), 0, warnings.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aRuleThatThrowsIsLeftUnansweredAndWarnsOncePerBlock() {
|
||||
BlockState firstState = throwingStateOf(Blocks.SHORT_GRASS);
|
||||
BlockState secondState = throwingStateOf(Blocks.SHORT_GRASS);
|
||||
GroundSurvival survival = new GroundSurvival();
|
||||
List<LogRecord> warnings = warningsDuring(() -> {
|
||||
for (BlockState plant : new BlockState[]{firstState, secondState}) {
|
||||
for (Block ground : new Block[]{Blocks.STONE, Blocks.SAND, Blocks.GRASS_BLOCK}) {
|
||||
assertEquals(SurvivalAnswer.UNANSWERED, survival.canSurviveOn(plant, ground.defaultBlockState()));
|
||||
}
|
||||
}
|
||||
});
|
||||
assertEquals(messages(warnings), 1, warnings.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aRuleThatThrowsFallsBackToThePlacementTable() {
|
||||
ModdedBlockState grass = ModdedBlockState.deferred(throwingStateOf(Blocks.SHORT_GRASS), Map.of(), "iris:test");
|
||||
warningsDuring(() -> {
|
||||
assertTrue(grass.canPlaceOnto(wrap(Blocks.GRASS_BLOCK)));
|
||||
assertFalse(grass.canPlaceOnto(wrap(Blocks.STONE)));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aRuleThatOnlyAnswersForSomeGroundsDoesNotPassAsAWallBlock() {
|
||||
BlockState plant = mock(BlockState.class);
|
||||
when(plant.getBlock()).thenReturn(Blocks.SHORT_GRASS);
|
||||
when(plant.canSurvive(any(), any())).thenAnswer(asked -> {
|
||||
LevelReader level = asked.getArgument(0);
|
||||
BlockPos plantPos = asked.getArgument(1);
|
||||
if (level.getBlockState(plantPos.below()).is(Blocks.STONE)) {
|
||||
return false;
|
||||
}
|
||||
throw new IllegalStateException("custom rule failed");
|
||||
});
|
||||
GroundSurvival survival = new GroundSurvival();
|
||||
warningsDuring(() -> assertEquals(SurvivalAnswer.UNANSWERED,
|
||||
survival.canSurviveOn(plant, Blocks.STONE.defaultBlockState())));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generatorThreadsAskingAtOnceGetTheSameAnswers() {
|
||||
Block[] plants = {Blocks.SHORT_GRASS, Blocks.CACTUS, Blocks.SUGAR_CANE, Blocks.VINE, Blocks.BROWN_MUSHROOM};
|
||||
Block[] grounds = {Blocks.GRASS_BLOCK, Blocks.SAND, Blocks.STONE, Blocks.WATER};
|
||||
GroundSurvival alone = new GroundSurvival();
|
||||
GroundSurvival shared = new GroundSurvival();
|
||||
List<Integer> threads = Arrays.asList(new Integer[16]);
|
||||
threads.parallelStream().forEach(ignored -> {
|
||||
for (Block plant : plants) {
|
||||
for (Block ground : grounds) {
|
||||
assertEquals(plant + " on " + ground,
|
||||
alone.canSurviveOn(plant.defaultBlockState(), ground.defaultBlockState()),
|
||||
shared.canSurviveOn(plant.defaultBlockState(), ground.defaultBlockState()));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Paper's chorus plant reads Paper's global configuration, which only a running server loads.
|
||||
private static boolean needsARunningPaperServer(Block plant) {
|
||||
return plant == Blocks.CHORUS_PLANT;
|
||||
}
|
||||
|
||||
private static BlockState throwingStateOf(Block block) {
|
||||
BlockState state = mock(BlockState.class);
|
||||
when(state.getBlock()).thenReturn(block);
|
||||
when(state.isSingletonState()).thenReturn(true);
|
||||
when(state.canSurvive(any(), any())).thenThrow(new IllegalStateException("custom rule failed"));
|
||||
return state;
|
||||
}
|
||||
|
||||
private static void assertPlacement(boolean expected, Block plant, Block ground) {
|
||||
String pair = plant + " on " + ground;
|
||||
assertEquals("modded " + pair, expected, moddedPlacement(plant, ground));
|
||||
assertEquals("bukkit native " + pair, expected ? SurvivalAnswer.SURVIVES : SurvivalAnswer.FAILS,
|
||||
new GroundSurvival().canSurviveOn(plant.defaultBlockState(), ground.defaultBlockState()));
|
||||
}
|
||||
|
||||
private static boolean moddedPlacement(Block plant, Block ground) {
|
||||
return wrap(plant).canPlaceOnto(wrap(ground));
|
||||
}
|
||||
|
||||
private static ModdedBlockState wrap(Block block) {
|
||||
return ModdedBlockState.deferred(block.defaultBlockState(), Map.of(), "iris:test");
|
||||
}
|
||||
|
||||
private static List<LogRecord> warningsDuring(Runnable checks) {
|
||||
List<LogRecord> warnings = new CopyOnWriteArrayList<>();
|
||||
Handler capture = new Handler() {
|
||||
@Override
|
||||
public void publish(LogRecord record) {
|
||||
if (record.getLevel().intValue() >= Level.WARNING.intValue()) {
|
||||
warnings.add(record);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
}
|
||||
};
|
||||
NATIVE_LOG.addHandler(capture);
|
||||
try {
|
||||
checks.run();
|
||||
} finally {
|
||||
NATIVE_LOG.removeHandler(capture);
|
||||
}
|
||||
return warnings;
|
||||
}
|
||||
|
||||
private static String messages(List<LogRecord> warnings) {
|
||||
StringBuilder text = new StringBuilder();
|
||||
for (LogRecord warning : warnings) {
|
||||
text.append(warning.getMessage()).append(" (").append(warning.getThrown()).append(")\n");
|
||||
}
|
||||
return text.toString();
|
||||
}
|
||||
}
|
||||
@@ -58,6 +58,7 @@ import art.arcane.iris.platform.agent.AttachSignal;
|
||||
import art.arcane.iris.platform.bootstrap.Bindings;
|
||||
import art.arcane.iris.platform.bootstrap.ServerProperties;
|
||||
import art.arcane.iris.platform.bootstrap.SlimJar;
|
||||
import art.arcane.iris.platform.bukkit.BlockRulesSVC;
|
||||
import art.arcane.iris.platform.bukkit.BoardSVC;
|
||||
import art.arcane.iris.platform.bukkit.BukkitPlatform;
|
||||
import art.arcane.iris.platform.bukkit.api.IrisApiEventSVC;
|
||||
@@ -681,6 +682,7 @@ public final class IrisRuntime implements IrisPluginRuntime {
|
||||
new GlobalCacheSVC(),
|
||||
new LogFilterSVC(),
|
||||
new ExternalDataSVC(),
|
||||
new BlockRulesSVC(),
|
||||
new EditSVC(),
|
||||
new ObjectSVC(),
|
||||
new ObjectStudioSaveService(),
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package art.arcane.iris.platform.bukkit;
|
||||
|
||||
import art.arcane.iris.platform.bukkit.nms.INMS;
|
||||
import art.arcane.iris.platform.bukkit.plugin.IrisService;
|
||||
import io.papermc.paper.event.server.ServerResourcesReloadedEvent;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
/** Lets the server's placement rules apply again after a resource reload, which may have changed the block tags they read. */
|
||||
public class BlockRulesSVC implements IrisService {
|
||||
@Override
|
||||
public void onEnable() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onResourcesReloaded(ServerResourcesReloadedEvent event) {
|
||||
if (INMS.isBound()) {
|
||||
INMS.get().forgetBlockRules();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,7 +104,7 @@ repositories {
|
||||
name = 'FabricMC'
|
||||
url = uri('https://maven.fabricmc.net/')
|
||||
}
|
||||
maven { url = uri('https://repo.codemc.org/repository/maven-public/') }
|
||||
maven { url = uri('https://repo.codemc.io/repository/maven-public/') }
|
||||
maven { url = uri('https://jitpack.io') }
|
||||
maven { url = uri('https://hub.spigotmc.org/nexus/content/repositories/snapshots/') }
|
||||
}
|
||||
@@ -331,7 +331,6 @@ tasks.named('shadowJar', ShadowJar).configure {
|
||||
if ((int) irisModTarget.java == 21) {
|
||||
exclude(java21RuntimeExclusions)
|
||||
}
|
||||
exclude('META-INF/maven/**')
|
||||
exclude('META-INF/proguard/**')
|
||||
exclude('META-INF/*.SF')
|
||||
exclude('META-INF/*.DSA')
|
||||
@@ -415,6 +414,7 @@ tasks.named('assemble').configure {
|
||||
}
|
||||
|
||||
pluginPackaging {
|
||||
nativeBoundaryChecks = true
|
||||
artifacts {
|
||||
create('distribution') {
|
||||
taskName = irisModTarget.fabricRemap ? 'remapJar' : 'shadowJar'
|
||||
|
||||
@@ -121,7 +121,7 @@ repositories {
|
||||
maven fg.forgeMaven
|
||||
maven fg.minecraftLibsMaven
|
||||
mavenCentral()
|
||||
maven { url = uri('https://repo.codemc.org/repository/maven-public/') }
|
||||
maven { url = uri('https://repo.codemc.io/repository/maven-public/') }
|
||||
maven { url = uri('https://jitpack.io') }
|
||||
maven { url = uri('https://hub.spigotmc.org/nexus/content/repositories/snapshots/') }
|
||||
}
|
||||
@@ -320,7 +320,6 @@ tasks.named('shadowJar', ShadowJar).configure {
|
||||
if ((int) irisModTarget.java == 21) {
|
||||
exclude(java21RuntimeExclusions)
|
||||
}
|
||||
exclude('META-INF/maven/**')
|
||||
exclude('META-INF/proguard/**')
|
||||
exclude('META-INF/*.SF')
|
||||
exclude('META-INF/*.DSA')
|
||||
@@ -377,6 +376,7 @@ tasks.named('assemble').configure {
|
||||
}
|
||||
|
||||
pluginPackaging {
|
||||
nativeBoundaryChecks = true
|
||||
artifacts {
|
||||
create('distribution') {
|
||||
taskName = 'shadowJar'
|
||||
|
||||
@@ -105,7 +105,7 @@ repositories {
|
||||
name = 'NeoForged'
|
||||
url = uri('https://maven.neoforged.net/releases/')
|
||||
}
|
||||
maven { url = uri('https://repo.codemc.org/repository/maven-public/') }
|
||||
maven { url = uri('https://repo.codemc.io/repository/maven-public/') }
|
||||
maven { url = uri('https://jitpack.io') }
|
||||
maven { url = uri('https://hub.spigotmc.org/nexus/content/repositories/snapshots/') }
|
||||
}
|
||||
@@ -304,7 +304,6 @@ tasks.named('shadowJar', ShadowJar).configure {
|
||||
if ((int) irisModTarget.java == 21) {
|
||||
exclude(java21RuntimeExclusions)
|
||||
}
|
||||
exclude('META-INF/maven/**')
|
||||
exclude('META-INF/proguard/**')
|
||||
exclude('META-INF/*.SF')
|
||||
exclude('META-INF/*.DSA')
|
||||
@@ -361,6 +360,7 @@ tasks.named('assemble').configure {
|
||||
}
|
||||
|
||||
pluginPackaging {
|
||||
nativeBoundaryChecks = true
|
||||
artifacts {
|
||||
create('distribution') {
|
||||
taskName = 'shadowJar'
|
||||
|
||||
+7
-8
@@ -1,5 +1,4 @@
|
||||
import art.arcane.volmit.packaging.PackedJar
|
||||
import art.arcane.volmit.packaging.PackagingMode
|
||||
import art.arcane.volmit.packaging.NativeDevelopmentTargets
|
||||
import io.papermc.paperweight.userdev.PaperweightUser
|
||||
import io.papermc.paperweight.userdev.PaperweightUserDependenciesExtension
|
||||
@@ -654,7 +653,7 @@ allprojects {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven { url = uri('https://repo.papermc.io/repository/maven-public/') }
|
||||
maven { url = uri('https://repo.codemc.org/repository/maven-public/') }
|
||||
maven { url = uri('https://repo.codemc.io/repository/maven-public/') }
|
||||
|
||||
maven {
|
||||
url = uri('https://jitpack.io')
|
||||
@@ -759,11 +758,6 @@ pluginPackaging {
|
||||
packedJarAccessors = ['art/arcane/iris/platform/bukkit/plugin/VolmitPlugin#getJarFile']
|
||||
packedPayloadOnlyPrefixes = ['iris-language-guides/', 'META-INF/iris/generation-kernels/abi-', 'iris/icons/views/', 'iris/datapack/']
|
||||
packedMaximumBootstrapClasses = 90
|
||||
stripDirectories = true
|
||||
stripLocalVariables = true
|
||||
releaseCompression = providers.gradleProperty('compactRelease')
|
||||
.map { String value -> value.toBoolean() }
|
||||
.getOrElse(!PackagingMode.resolve(providers).development())
|
||||
prunePrefixes = ['art/arcane/volmlib/']
|
||||
keepPrefixes = ['art/arcane/volmlib/util/matter/slices/', 'art/arcane/volmlib/nativelib/']
|
||||
shrinkRules = [file('packaging/shrink.pro'), nativeRuntimeRules.get().asFile]
|
||||
@@ -1010,7 +1004,12 @@ tasks.withType(PackedJar).configureEach {
|
||||
dependsOn(tasks.named('verifyBukkitArtifact'), nativeRuntime)
|
||||
nativeArtifacts.set(providers.provider { embeddedNatives() })
|
||||
doLast { PackedJar task ->
|
||||
NativeRuntimeArtifacts.verifyPacked(task.outputJar.get().asFile, nativeRuntimeModules, embeddedNatives())
|
||||
File artifact = task.outputJar.get().asFile
|
||||
Map<String, byte[]> outer = NativeRuntimeArtifacts.entries(artifact)
|
||||
Map<String, byte[]> runtime = outer.containsKey('META-INF/volmit/runtime.properties')
|
||||
? PackedJar.readRuntime(artifact.toPath()) : outer
|
||||
NativeRuntimeArtifacts.verifyPacked(runtime, outer.get(NativeRuntimeArtifacts.MANIFEST), nativeRuntimeModules,
|
||||
embeddedNatives())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,6 @@ dependencies {
|
||||
implementation(gradleApi())
|
||||
implementation('org.ow2.asm:asm:9.10.1')
|
||||
implementation('org.apache.commons:commons-compress:1.28.0')
|
||||
implementation('org.tukaani:xz:1.10')
|
||||
implementation('io.papermc.paperweight:paperweight-userdev:2.0.0-beta.21')
|
||||
testImplementation('junit:junit:4.13.2')
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
import org.gradle.api.GradleException;
|
||||
import org.tukaani.xz.XZInputStream;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
@@ -28,7 +27,6 @@ import java.util.zip.ZipInputStream;
|
||||
public final class NativeRuntimeArtifacts {
|
||||
public static final String MANIFEST = "META-INF/iris/native-runtime.properties";
|
||||
public static final String RESOURCES = "META-INF/iris/native/";
|
||||
private static final String PAYLOAD = "META-INF/volmit/runtime.jar.xz";
|
||||
private static final String GROUP = "com.github.VolmitSoftware.VolmLib";
|
||||
private static final String NATIVE = "art/arcane/volmlib/nativelib/";
|
||||
|
||||
@@ -99,35 +97,20 @@ public final class NativeRuntimeArtifacts {
|
||||
}
|
||||
}
|
||||
|
||||
public static void verifyPacked(File artifact, List<String> modules, Map<String, File> natives) throws IOException {
|
||||
/** Checks the native providers inside {@code runtime}, the entries the plugin runs from, against the resolved build. */
|
||||
public static void verifyPacked(Map<String, byte[]> runtime, byte[] outerManifest, List<String> modules,
|
||||
Map<String, File> natives) throws IOException {
|
||||
requireModules(natives, modules);
|
||||
Map<String, byte[]> contents;
|
||||
try (JarFile jar = new JarFile(artifact)) {
|
||||
JarEntry payload = jar.getJarEntry(PAYLOAD);
|
||||
if (payload == null) {
|
||||
contents = read(Files.newInputStream(artifact.toPath()));
|
||||
} else {
|
||||
try (InputStream input = new XZInputStream(jar.getInputStream(payload))) {
|
||||
contents = read(new ByteArrayInputStream(input.readAllBytes()));
|
||||
}
|
||||
JarEntry outer = jar.getJarEntry(MANIFEST);
|
||||
byte[] embedded = contents.get(MANIFEST);
|
||||
if (outer != null && embedded != null) {
|
||||
try (InputStream input = jar.getInputStream(outer)) {
|
||||
if (!Arrays.equals(input.readAllBytes(), embedded)) {
|
||||
throw new GradleException("Packed native runtime manifests differ");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
byte[] manifest = contents.get(MANIFEST);
|
||||
byte[] manifest = runtime.get(MANIFEST);
|
||||
if (manifest == null) {
|
||||
throw new GradleException("Missing native runtime dependency manifest");
|
||||
}
|
||||
if (outerManifest != null && !Arrays.equals(outerManifest, manifest)) {
|
||||
throw new GradleException("Packed native runtime manifests differ");
|
||||
}
|
||||
verifyManifest(manifest, natives);
|
||||
for (String module : natives.keySet()) {
|
||||
byte[] provider = contents.get(RESOURCES + module + ".jar");
|
||||
byte[] provider = runtime.get(RESOURCES + module + ".jar");
|
||||
if (provider == null) {
|
||||
throw new GradleException("Missing embedded native provider: " + module);
|
||||
}
|
||||
@@ -137,6 +120,18 @@ public final class NativeRuntimeArtifacts {
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<String, byte[]> entries(File artifact) throws IOException {
|
||||
Map<String, byte[]> contents = new TreeMap<>();
|
||||
try (ZipInputStream archive = new ZipInputStream(Files.newInputStream(artifact.toPath()))) {
|
||||
for (ZipEntry entry = archive.getNextEntry(); entry != null; entry = archive.getNextEntry()) {
|
||||
if (!entry.isDirectory()) {
|
||||
contents.put(entry.getName(), archive.readAllBytes());
|
||||
}
|
||||
}
|
||||
}
|
||||
return contents;
|
||||
}
|
||||
|
||||
private static void verifyManifest(byte[] bytes, Map<String, File> natives) throws IOException {
|
||||
Properties manifest = new Properties();
|
||||
manifest.load(new ByteArrayInputStream(bytes));
|
||||
@@ -163,18 +158,6 @@ public final class NativeRuntimeArtifacts {
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<String, byte[]> read(InputStream source) throws IOException {
|
||||
Map<String, byte[]> contents = new TreeMap<>();
|
||||
try (ZipInputStream archive = new ZipInputStream(source)) {
|
||||
for (ZipEntry entry = archive.getNextEntry(); entry != null; entry = archive.getNextEntry()) {
|
||||
if (!entry.isDirectory()) {
|
||||
contents.put(entry.getName(), archive.readAllBytes());
|
||||
}
|
||||
}
|
||||
}
|
||||
return contents;
|
||||
}
|
||||
|
||||
private static boolean implementation(String name) {
|
||||
if (!name.startsWith(NATIVE)) {
|
||||
return false;
|
||||
|
||||
@@ -4,13 +4,11 @@ import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.tukaani.xz.LZMA2Options;
|
||||
import org.tukaani.xz.XZOutputStream;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.MessageDigest;
|
||||
@@ -22,6 +20,7 @@ import java.util.TreeMap;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarOutputStream;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
@@ -89,15 +88,35 @@ public class NativeRuntimeArtifactsTest {
|
||||
public void verifiesTheEmbeddedProviderBytesInsideThePackedRuntime() throws Exception {
|
||||
Map<String, File> natives = natives();
|
||||
Map<String, byte[]> runtime = runtime(natives, natives);
|
||||
NativeRuntimeArtifacts.verifyPacked(packed(runtime), MODULES, natives);
|
||||
NativeRuntimeArtifacts.verifyPacked(jar("ordinary.jar", runtime), MODULES, natives);
|
||||
byte[] manifest = runtime.get(NativeRuntimeArtifacts.MANIFEST);
|
||||
NativeRuntimeArtifacts.verifyPacked(runtime, manifest, MODULES, natives);
|
||||
NativeRuntimeArtifacts.verifyPacked(runtime, null, MODULES, natives);
|
||||
Map<String, File> rebuilt = new TreeMap<>(natives);
|
||||
rebuilt.put("native-v26_2_R1", provider("rebuilt.jar", "art/arcane/volmlib/util/collection/KMap"));
|
||||
assertThrows(GradleException.class, () -> NativeRuntimeArtifacts.verifyPacked(packed(runtime(natives, rebuilt)),
|
||||
MODULES, natives));
|
||||
assertThrows(GradleException.class, () -> NativeRuntimeArtifacts.verifyPacked(runtime(natives, rebuilt),
|
||||
manifest, MODULES, natives));
|
||||
Map<String, byte[]> missing = new TreeMap<>(runtime);
|
||||
missing.remove(NativeRuntimeArtifacts.RESOURCES + "native-v26_2_R1.jar");
|
||||
assertThrows(GradleException.class, () -> NativeRuntimeArtifacts.verifyPacked(packed(missing), MODULES, natives));
|
||||
assertThrows(GradleException.class, () -> NativeRuntimeArtifacts.verifyPacked(missing, manifest, MODULES, natives));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsAnOuterManifestThatDiffersFromTheRuntimeOne() throws Exception {
|
||||
Map<String, File> natives = natives();
|
||||
Map<String, byte[]> runtime = runtime(natives, natives);
|
||||
byte[] outer = (new String(runtime.get(NativeRuntimeArtifacts.MANIFEST), StandardCharsets.UTF_8) + "extra=1\n")
|
||||
.getBytes(StandardCharsets.UTF_8);
|
||||
assertThrows(GradleException.class, () -> NativeRuntimeArtifacts.verifyPacked(runtime, outer, MODULES, natives));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readsEveryFileEntryOfAnOrdinaryJar() throws Exception {
|
||||
Map<String, byte[]> runtime = runtime(natives(), natives());
|
||||
Map<String, byte[]> read = NativeRuntimeArtifacts.entries(jar("ordinary.jar", runtime));
|
||||
assertEquals(runtime.keySet(), read.keySet());
|
||||
for (Map.Entry<String, byte[]> entry : runtime.entrySet()) {
|
||||
assertArrayEquals(entry.getValue(), read.get(entry.getKey()));
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, File> natives() throws IOException {
|
||||
@@ -137,17 +156,6 @@ public class NativeRuntimeArtifactsTest {
|
||||
return contents;
|
||||
}
|
||||
|
||||
private File packed(Map<String, byte[]> runtime) throws IOException {
|
||||
ByteArrayOutputStream compressed = new ByteArrayOutputStream();
|
||||
try (XZOutputStream xz = new XZOutputStream(compressed, new LZMA2Options(1))) {
|
||||
xz.write(Files.readAllBytes(jar("payload.jar", runtime).toPath()));
|
||||
}
|
||||
Map<String, byte[]> outer = new TreeMap<>();
|
||||
outer.put(NativeRuntimeArtifacts.MANIFEST, runtime.get(NativeRuntimeArtifacts.MANIFEST));
|
||||
outer.put("META-INF/volmit/runtime.jar.xz", compressed.toByteArray());
|
||||
return jar("packed.jar", outer);
|
||||
}
|
||||
|
||||
private File jar(String name, Map<String, byte[]> contents) throws IOException {
|
||||
Path file = temporary.newFolder().toPath().resolve(name);
|
||||
try (JarOutputStream jar = new JarOutputStream(Files.newOutputStream(file))) {
|
||||
|
||||
@@ -18,27 +18,37 @@
|
||||
|
||||
package art.arcane.iris.generation.biome;
|
||||
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.runtime.SeedTable;
|
||||
import art.arcane.volmlib.util.noise.CNG;
|
||||
|
||||
/**
|
||||
* What one engine derives from an {@link IrisBiomePaletteLayer}: the block selection and depth generators of the
|
||||
* seeds that sample it.
|
||||
* seeds that sample it. A column walk asks for one layer seed per depth, so the layer table holds the layer's whole
|
||||
* thickness for a few parent seeds instead of rebuilding a generator on every depth step.
|
||||
*/
|
||||
public final class PaletteLayerRuntime {
|
||||
private static final int LAYER_SEED_CAPACITY = 32;
|
||||
private static final int LAYER_RECENT_SLOTS = 32;
|
||||
private static final int MAX_LAYER_RECENT_SLOTS = 4096;
|
||||
private static final int PARENT_SEEDS_PER_LAYER = 4;
|
||||
private static final int HEIGHT_SEED_CAPACITY = 32;
|
||||
|
||||
private final PackRuntime runtime;
|
||||
private final SeedTable<CNG> layerGenerators;
|
||||
private final SeedTable<CNG> heightGenerators;
|
||||
private final boolean shareGenerator;
|
||||
|
||||
public PaletteLayerRuntime(IrisBiomePaletteLayer layer, PackRuntime runtime) {
|
||||
this.runtime = runtime;
|
||||
this.layerGenerators = new SeedTable<>(LAYER_SEED_CAPACITY, LAYER_RECENT_SLOTS,
|
||||
seed -> layer.createLayerGenerator(seed, runtime));
|
||||
IrisGeneratorStyle style = layer.getStyle();
|
||||
// A seeded style rolls from its own seed and the world seed, never the caller's, so every depth builds the same noise.
|
||||
this.shareGenerator = style != null
|
||||
&& (style.isSeeded() || style.canShareExpressionGenerator(runtime.data()));
|
||||
int depthSeeds = Math.max(1, Math.max(layer.getMinHeight(), layer.getMaxHeight()));
|
||||
this.layerGenerators = new SeedTable<>(Math.max(LAYER_SEED_CAPACITY, depthSeeds * PARENT_SEEDS_PER_LAYER),
|
||||
recentSlots(depthSeeds), seed -> layer.createLayerGenerator(seed, runtime));
|
||||
this.heightGenerators = new SeedTable<>(HEIGHT_SEED_CAPACITY, IrisBiomePaletteLayer::createHeightGenerator);
|
||||
}
|
||||
|
||||
@@ -48,10 +58,16 @@ public final class PaletteLayerRuntime {
|
||||
}
|
||||
|
||||
public CNG layerGenerator(long seed) {
|
||||
return layerGenerators.get(seed);
|
||||
return layerGenerators.get(shareGenerator ? 0L : seed);
|
||||
}
|
||||
|
||||
public CNG heightGenerator(long seed) {
|
||||
return heightGenerators.get(seed);
|
||||
}
|
||||
|
||||
/** Consecutive depth seeds land in distinct slots when the slot count covers the thickness. */
|
||||
private static int recentSlots(int depthSeeds) {
|
||||
int covering = Integer.highestOneBit(Math.min(depthSeeds, MAX_LAYER_RECENT_SLOTS) - 1) << 1;
|
||||
return Math.clamp(covering, LAYER_RECENT_SLOTS, MAX_LAYER_RECENT_SLOTS);
|
||||
}
|
||||
}
|
||||
@@ -71,11 +71,8 @@ import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.iris.generation.block.DataProvider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
@@ -89,7 +86,6 @@ import java.util.function.BiConsumer;
|
||||
public class MantleObjectComponent extends IrisMantleComponent {
|
||||
private static final long CAVE_REJECT_LOG_THROTTLE_MS = 5000L;
|
||||
private static final int BEDROCK_CLEARANCE = 6;
|
||||
private static final long OBJECT_SEPARATION_SEED_SALT = 0x5E9A2A7E0B1EC75L;
|
||||
static final byte LIQUID_FORCED_AIR = 3;
|
||||
private static final Map<String, CaveRejectLogState> CAVE_REJECT_LOG_STATE = new ConcurrentHashMap<>();
|
||||
private static final String MISSING_LOAD_KEY_KIND = "marker-missing-load-key";
|
||||
@@ -493,17 +489,29 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
|
||||
for (IrisObjectPlacement i : surfaceBiome.getSurfaceObjects()) {
|
||||
biomeSurfaceChecked++;
|
||||
Optional<ObjectPlacementResult> triggered = placeSurfacePlacement(writer, rng, x, z, i, complex, traceRegen, "biome-surface", surfaceBiome.getLoadKey());
|
||||
if (triggered.isEmpty()) {
|
||||
continue;
|
||||
boolean chance = rng.chance(i.getChance() + rng.d(-0.005, 0.005)) && !i.isCompatExcluded(getData());
|
||||
if (traceRegen) {
|
||||
IrisLogging.debug("Regen object placer chance: chunk=" + x + "," + z
|
||||
+ " scope=biome-surface"
|
||||
+ " chanceResult=" + chance
|
||||
+ " chanceBase=" + i.getChance()
|
||||
+ " densityMid=" + i.getDensity()
|
||||
+ " objects=" + i.getPlace().size());
|
||||
}
|
||||
if (chance) {
|
||||
biomeSurfaceTriggered++;
|
||||
try {
|
||||
ObjectPlacementResult result = placeObject(writer, rng, x << 4, z << 4, i, complex, traceRegen, x, z, "biome-surface");
|
||||
attempts += result.attempts();
|
||||
placed += result.placed();
|
||||
rejected += result.rejected();
|
||||
nullObjects += result.nullObjects();
|
||||
errors += result.errors();
|
||||
} catch (Throwable e) {
|
||||
GenerationFailures.skipPlacement(e, "object", i.getPlace().toString(", "), x << 4, -1, z << 4, surfaceBiome.getLoadKey());
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
biomeSurfaceTriggered++;
|
||||
ObjectPlacementResult result = triggered.get();
|
||||
attempts += result.attempts();
|
||||
placed += result.placed();
|
||||
rejected += result.rejected();
|
||||
nullObjects += result.nullObjects();
|
||||
errors += result.errors();
|
||||
}
|
||||
|
||||
for (IrisObjectPlacement i : caveBiome.getCarvingObjects()) {
|
||||
@@ -538,17 +546,29 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
|
||||
for (IrisObjectPlacement i : region.getSurfaceObjects()) {
|
||||
regionSurfaceChecked++;
|
||||
Optional<ObjectPlacementResult> triggered = placeSurfacePlacement(writer, rng, x, z, i, complex, traceRegen, "region-surface", region.getLoadKey());
|
||||
if (triggered.isEmpty()) {
|
||||
continue;
|
||||
boolean chance = rng.chance(i.getChance() + rng.d(-0.005, 0.005)) && !i.isCompatExcluded(getData());
|
||||
if (traceRegen) {
|
||||
IrisLogging.debug("Regen object placer chance: chunk=" + x + "," + z
|
||||
+ " scope=region-surface"
|
||||
+ " chanceResult=" + chance
|
||||
+ " chanceBase=" + i.getChance()
|
||||
+ " densityMid=" + i.getDensity()
|
||||
+ " objects=" + i.getPlace().size());
|
||||
}
|
||||
if (chance) {
|
||||
regionSurfaceTriggered++;
|
||||
try {
|
||||
ObjectPlacementResult result = placeObject(writer, rng, x << 4, z << 4, i, complex, traceRegen, x, z, "region-surface");
|
||||
attempts += result.attempts();
|
||||
placed += result.placed();
|
||||
rejected += result.rejected();
|
||||
nullObjects += result.nullObjects();
|
||||
errors += result.errors();
|
||||
} catch (Throwable e) {
|
||||
GenerationFailures.skipPlacement(e, "object", i.getPlace().toString(", "), x << 4, -1, z << 4, region.getLoadKey());
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
regionSurfaceTriggered++;
|
||||
ObjectPlacementResult result = triggered.get();
|
||||
attempts += result.attempts();
|
||||
placed += result.placed();
|
||||
rejected += result.rejected();
|
||||
nullObjects += result.nullObjects();
|
||||
errors += result.errors();
|
||||
}
|
||||
|
||||
for (IrisObjectPlacement i : region.getCarvingObjects()) {
|
||||
@@ -957,194 +977,86 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
IrisObject v = objectPlacement.scaleObject(rng, objectPlacement.getObject(complex, rng), getDimension());
|
||||
if (v == null) {
|
||||
nullObjects++;
|
||||
traceNullObject(traceRegen, chunkX, chunkZ, scope, i, density, objectPlacement);
|
||||
if (traceRegen) {
|
||||
IrisLogging.debug("Regen object placement null object: chunk=" + chunkX + "," + chunkZ
|
||||
+ " scope=" + scope
|
||||
+ " densityIndex=" + i
|
||||
+ " density=" + density
|
||||
+ " placementKeys=" + objectPlacement.getPlace().toString(","));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
int xx = rng.i(x, x + 16);
|
||||
int zz = rng.i(z, z + 16);
|
||||
ObjectPlacementResult result = placeObjectAt(writer, rng, v, xx, zz, objectPlacement, complex, traceRegen, chunkX, chunkZ, scope, i, density);
|
||||
placed += result.placed();
|
||||
rejected += result.rejected();
|
||||
errors += result.errors();
|
||||
IrisObjectPlacement effectivePlacement = resolveEffectivePlacement(objectPlacement, v);
|
||||
if (!allowsObjectPlacement(complex, v, effectivePlacement, xx, zz)) {
|
||||
rejected++;
|
||||
continue;
|
||||
}
|
||||
boolean treePlacement = isTreePlacement(v, effectivePlacement);
|
||||
int id = rng.i(0, Integer.MAX_VALUE);
|
||||
IObjectPlacer placePlacer = golden ? new GoldenDebugObjectPlacer(writer, scope + "/" + v.getLoadKey()) : writer;
|
||||
if (golden) {
|
||||
IrisLogging.debug("Goldendebug object attempt: chunk=" + chunkX + "," + chunkZ
|
||||
+ " scope=" + scope
|
||||
+ " object=" + v.getLoadKey()
|
||||
+ " densityIndex=" + i
|
||||
+ " xx=" + xx
|
||||
+ " zz=" + zz
|
||||
+ " mode=" + effectivePlacement.getMode());
|
||||
}
|
||||
try {
|
||||
String marker = placementMarker(v, id, "surface");
|
||||
int continuation = writer.beginObjectPlacement(effectivePlacement.waterRule());
|
||||
int result = v.place(xx, zz, placePlacer, effectivePlacement, rng, (b, data) -> {
|
||||
if (marker != null) {
|
||||
writer.setData(b.getX(), b.getY(), b.getZ(), marker);
|
||||
}
|
||||
if (treePlacement && marker != null) {
|
||||
writeTreeMaterial(writer, b.getX(), b.getY(), b.getZ(), data);
|
||||
}
|
||||
if (effectivePlacement.isDolphinTarget() && effectivePlacement.isUnderwater() && B.isStorageChest(data)) {
|
||||
writer.setData(b.getX(), b.getY(), b.getZ(), MatterStructurePOI.BURIED_TREASURE);
|
||||
}
|
||||
}, null, getData());
|
||||
|
||||
if (result >= 0) {
|
||||
writer.recordObjectPlacement(continuation);
|
||||
placed++;
|
||||
} else {
|
||||
rejected++;
|
||||
}
|
||||
|
||||
if (golden) {
|
||||
IrisLogging.debug("Goldendebug object result: chunk=" + chunkX + "," + chunkZ
|
||||
+ " scope=" + scope
|
||||
+ " object=" + v.getLoadKey()
|
||||
+ " resultY=" + result
|
||||
+ " fallback=surface");
|
||||
}
|
||||
|
||||
if (traceRegen) {
|
||||
IrisLogging.debug("Regen object placement result: chunk=" + chunkX + "," + chunkZ
|
||||
+ " scope=" + scope
|
||||
+ " object=" + v.getLoadKey()
|
||||
+ " resultY=" + result
|
||||
+ " px=" + xx
|
||||
+ " pz=" + zz
|
||||
+ " fallback=surface"
|
||||
+ " densityIndex=" + i
|
||||
+ " density=" + density);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
GenerationFailures.skipPlacement(e, "object", v.getLoadKey(), chunkX << 4, -1, chunkZ << 4, scope);
|
||||
errors++;
|
||||
} finally {
|
||||
writer.endObjectPlacement();
|
||||
}
|
||||
}
|
||||
|
||||
return new ObjectPlacementResult(attempts, placed, rejected, nullObjects, errors);
|
||||
}
|
||||
|
||||
private void traceNullObject(boolean traceRegen, int chunkX, int chunkZ, String scope, int densityIndex, int density, IrisObjectPlacement objectPlacement) {
|
||||
if (!traceRegen) {
|
||||
return;
|
||||
}
|
||||
IrisLogging.debug("Regen object placement null object: chunk=" + chunkX + "," + chunkZ
|
||||
+ " scope=" + scope
|
||||
+ " densityIndex=" + densityIndex
|
||||
+ " density=" + density
|
||||
+ " placementKeys=" + objectPlacement.getPlace().toString(","));
|
||||
}
|
||||
|
||||
@BlockCoordinates
|
||||
private ObjectPlacementResult placeObjectAt(
|
||||
ObjectPassPlacer writer,
|
||||
RNG rng,
|
||||
IrisObject v,
|
||||
int xx,
|
||||
int zz,
|
||||
IrisObjectPlacement objectPlacement,
|
||||
IrisComplex complex,
|
||||
boolean traceRegen,
|
||||
int chunkX,
|
||||
int chunkZ,
|
||||
String scope,
|
||||
int densityIndex,
|
||||
int density
|
||||
) {
|
||||
IrisObjectPlacement effectivePlacement = resolveEffectivePlacement(objectPlacement, v);
|
||||
if (!allowsObjectPlacement(complex, v, effectivePlacement, xx, zz)) {
|
||||
return new ObjectPlacementResult(0, 0, 1, 0, 0);
|
||||
}
|
||||
boolean golden = GoldenDebugObjectPlacer.isGoldenDebugChunk(chunkX, chunkZ);
|
||||
boolean treePlacement = isTreePlacement(v, effectivePlacement);
|
||||
int id = rng.i(0, Integer.MAX_VALUE);
|
||||
IObjectPlacer placePlacer = golden ? new GoldenDebugObjectPlacer(writer, scope + "/" + v.getLoadKey()) : writer;
|
||||
if (golden) {
|
||||
IrisLogging.debug("Goldendebug object attempt: chunk=" + chunkX + "," + chunkZ
|
||||
+ " scope=" + scope
|
||||
+ " object=" + v.getLoadKey()
|
||||
+ " densityIndex=" + densityIndex
|
||||
+ " xx=" + xx
|
||||
+ " zz=" + zz
|
||||
+ " mode=" + effectivePlacement.getMode());
|
||||
}
|
||||
try {
|
||||
String marker = placementMarker(v, id, "surface");
|
||||
int continuation = writer.beginObjectPlacement(effectivePlacement.waterRule());
|
||||
int result = v.place(xx, zz, placePlacer, effectivePlacement, rng, (b, data) -> {
|
||||
if (marker != null) {
|
||||
writer.setData(b.getX(), b.getY(), b.getZ(), marker);
|
||||
}
|
||||
if (treePlacement && marker != null) {
|
||||
writeTreeMaterial(writer, b.getX(), b.getY(), b.getZ(), data);
|
||||
}
|
||||
if (effectivePlacement.isDolphinTarget() && effectivePlacement.isUnderwater() && B.isStorageChest(data)) {
|
||||
writer.setData(b.getX(), b.getY(), b.getZ(), MatterStructurePOI.BURIED_TREASURE);
|
||||
}
|
||||
}, null, getData());
|
||||
|
||||
if (result >= 0) {
|
||||
writer.recordObjectPlacement(continuation);
|
||||
}
|
||||
|
||||
if (golden) {
|
||||
IrisLogging.debug("Goldendebug object result: chunk=" + chunkX + "," + chunkZ
|
||||
+ " scope=" + scope
|
||||
+ " object=" + v.getLoadKey()
|
||||
+ " resultY=" + result
|
||||
+ " fallback=surface");
|
||||
}
|
||||
|
||||
if (traceRegen) {
|
||||
IrisLogging.debug("Regen object placement result: chunk=" + chunkX + "," + chunkZ
|
||||
+ " scope=" + scope
|
||||
+ " object=" + v.getLoadKey()
|
||||
+ " resultY=" + result
|
||||
+ " px=" + xx
|
||||
+ " pz=" + zz
|
||||
+ " fallback=surface"
|
||||
+ " densityIndex=" + densityIndex
|
||||
+ " density=" + density);
|
||||
}
|
||||
return result >= 0 ? new ObjectPlacementResult(0, 1, 0, 0, 0) : new ObjectPlacementResult(0, 0, 1, 0, 0);
|
||||
} catch (Throwable e) {
|
||||
GenerationFailures.skipPlacement(e, "object", v.getLoadKey(), chunkX << 4, -1, chunkZ << 4, scope);
|
||||
return new ObjectPlacementResult(0, 0, 0, 0, 1);
|
||||
} finally {
|
||||
writer.endObjectPlacement();
|
||||
}
|
||||
}
|
||||
|
||||
private Optional<ObjectPlacementResult> placeSurfacePlacement(
|
||||
ObjectPassPlacer writer,
|
||||
RNG rng,
|
||||
int chunkX,
|
||||
int chunkZ,
|
||||
IrisObjectPlacement placement,
|
||||
IrisComplex complex,
|
||||
boolean traceRegen,
|
||||
String scope,
|
||||
String ownerKey
|
||||
) {
|
||||
try {
|
||||
if (placement.isSeparated()) {
|
||||
return placeSeparatedObject(writer, chunkX, chunkZ, placement, complex, traceRegen, scope);
|
||||
}
|
||||
double chance = objectSeparation().chanceAt(placement, (chunkX << 4) + 8, (chunkZ << 4) + 8);
|
||||
boolean passes = rng.chance(chance + rng.d(-0.005, 0.005)) && !placement.isCompatExcluded(getData());
|
||||
traceSurfaceChance(traceRegen, chunkX, chunkZ, scope, passes, placement);
|
||||
if (!passes) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(placeObject(writer, rng, chunkX << 4, chunkZ << 4, placement, complex, traceRegen, chunkX, chunkZ, scope));
|
||||
} catch (Throwable e) {
|
||||
GenerationFailures.skipPlacement(e, "object", placement.getPlace().toString(", "), chunkX << 4, -1, chunkZ << 4, ownerKey);
|
||||
return Optional.of(new ObjectPlacementResult(0, 0, 0, 0, 1));
|
||||
}
|
||||
}
|
||||
|
||||
private void traceSurfaceChance(boolean traceRegen, int chunkX, int chunkZ, String scope, boolean passes, IrisObjectPlacement placement) {
|
||||
if (!traceRegen) {
|
||||
return;
|
||||
}
|
||||
IrisLogging.debug("Regen object placer chance: chunk=" + chunkX + "," + chunkZ
|
||||
+ " scope=" + scope
|
||||
+ " chanceResult=" + passes
|
||||
+ " chanceBase=" + placement.getChance()
|
||||
+ " densityMid=" + placement.getDensity()
|
||||
+ " objects=" + placement.getPlace().size());
|
||||
}
|
||||
|
||||
private Optional<ObjectPlacementResult> placeSeparatedObject(
|
||||
ObjectPassPlacer writer,
|
||||
int chunkX,
|
||||
int chunkZ,
|
||||
IrisObjectPlacement placement,
|
||||
IrisComplex complex,
|
||||
boolean traceRegen,
|
||||
String scope
|
||||
) {
|
||||
Optional<ObjectSeparation.Candidate> kept = placement.isCompatExcluded(getData())
|
||||
? Optional.empty()
|
||||
: objectSeparation().keptCandidate(chunkX, chunkZ, placement);
|
||||
traceSurfaceChance(traceRegen, chunkX, chunkZ, scope, kept.isPresent(), placement);
|
||||
if (kept.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
ObjectSeparation.Candidate candidate = kept.get();
|
||||
IrisObject object = placement.scaleObject(candidate.rng(), placement.getObject(complex, candidate.rng()), getDimension());
|
||||
if (object == null) {
|
||||
traceNullObject(traceRegen, chunkX, chunkZ, scope, 0, 1, placement);
|
||||
return Optional.of(new ObjectPlacementResult(1, 0, 0, 1, 0));
|
||||
}
|
||||
ObjectPlacementResult result = placeObjectAt(writer, candidate.rng(), object, candidate.x(), candidate.z(), placement, complex, traceRegen, chunkX, chunkZ, scope, 0, 1);
|
||||
return Optional.of(new ObjectPlacementResult(1, result.placed(), result.rejected(), 0, result.errors()));
|
||||
}
|
||||
|
||||
private ObjectSeparation objectSeparation() {
|
||||
return new ObjectSeparation(seed() + OBJECT_SEPARATION_SEED_SALT, PackRuntime.of(getEngineMantle().getEngine(), getData()), this::surfacePlacementsAt);
|
||||
}
|
||||
|
||||
private List<IrisObjectPlacement> surfacePlacementsAt(int chunkX, int chunkZ) {
|
||||
IrisComplex complex = getComplex();
|
||||
if (!complex.allowsNewGenerationChunk(chunkX, chunkZ)) {
|
||||
return List.of();
|
||||
}
|
||||
int blockX = (chunkX << 4) + 8;
|
||||
int blockZ = (chunkZ << 4) + 8;
|
||||
List<IrisObjectPlacement> placements = new ArrayList<>(complex.getTrueBiomeStream().get(blockX, blockZ).getSurfaceObjects());
|
||||
placements.addAll(complex.getRegionStream().get(blockX, blockZ).getSurfaceObjects());
|
||||
placements.removeIf(placement -> placement.isCompatExcluded(getData()));
|
||||
return placements;
|
||||
}
|
||||
|
||||
@ChunkCoordinates
|
||||
private boolean caveAnchorBiomeConflicts(int x, int y, int z, String expectedCaveBiomeKey) {
|
||||
if (expectedCaveBiomeKey == null) {
|
||||
@@ -1852,34 +1764,21 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
IrisBiome biome = getComplex().getTrueBiomeStream().get(blockX, blockZ);
|
||||
IrisRegion region = getComplex().getRegionStream().get(blockX, blockZ);
|
||||
Set<String> v = new KSet<>();
|
||||
guessSurfaceKeys(rng, x, z, biome.getSurfaceObjects(), v);
|
||||
guessSurfaceKeys(rng, x, z, region.getSurfaceObjects(), v);
|
||||
for (IrisObjectPlacement i : biome.getSurfaceObjects()) {
|
||||
if (rng.chance(i.getChance() + rng.d(-0.005, 0.005)) && !i.isCompatExcluded(getData())) {
|
||||
v.addAll(guessPlacedKeys(rng, x, z, i));
|
||||
}
|
||||
}
|
||||
|
||||
for (IrisObjectPlacement i : region.getSurfaceObjects()) {
|
||||
if (rng.chance(i.getChance() + rng.d(-0.005, 0.005)) && !i.isCompatExcluded(getData())) {
|
||||
v.addAll(guessPlacedKeys(rng, x, z, i));
|
||||
}
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
private void guessSurfaceKeys(RNG rng, int x, int z, List<IrisObjectPlacement> placements, Set<String> keys) {
|
||||
ObjectSeparation separation = objectSeparation();
|
||||
for (IrisObjectPlacement i : placements) {
|
||||
if (i.isSeparated()) {
|
||||
guessSeparatedKey(separation, x, z, i).ifPresent(keys::add);
|
||||
continue;
|
||||
}
|
||||
double chance = separation.chanceAt(i, (x << 4) + 8, (z << 4) + 8);
|
||||
if (rng.chance(chance + rng.d(-0.005, 0.005)) && !i.isCompatExcluded(getData())) {
|
||||
keys.addAll(guessPlacedKeys(rng, x, z, i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Optional<String> guessSeparatedKey(ObjectSeparation separation, int x, int z, IrisObjectPlacement placement) {
|
||||
if (placement.isCompatExcluded(getData())) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return separation.keptCandidate(x, z, placement)
|
||||
.map(candidate -> placement.scaleObject(candidate.rng(), placement.getObject(getComplex(), candidate.rng()), getDimension()))
|
||||
.map(IrisObject::getLoadKey);
|
||||
}
|
||||
|
||||
protected int computeRadius() {
|
||||
KSet<String> warnedLargeObjects = new KSet<>();
|
||||
PlacementReach reach = new ReachScan(getDimension(), this::getData, warnedLargeObjects).dimension();
|
||||
|
||||
@@ -1,137 +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.generation.mantle;
|
||||
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.structure.object.IrisObjectPlacement;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* The chance and spacing of surface object placements.
|
||||
*
|
||||
* <p>A separated placement rolls one candidate spot per chunk. The candidate stands only when no candidate of a lower rank,
|
||||
* from a placement with the same objects, lies closer than the separation. Spots and ranks come from the seed, the chunk
|
||||
* and the objects alone, so every chunk agrees on them across chunk, biome and region borders, and objects never stand
|
||||
* closer than the separation, whatever order chunks generate in.
|
||||
*/
|
||||
final class ObjectSeparation {
|
||||
private static final int CHUNK_WIDTH_BLOCKS = 16;
|
||||
private static final int CHUNK_SHIFT = 4;
|
||||
|
||||
private final long seed;
|
||||
private final PackRuntime runtime;
|
||||
private final SurfacePlacements surfacePlacements;
|
||||
|
||||
ObjectSeparation(long seed, PackRuntime runtime, SurfacePlacements surfacePlacements) {
|
||||
this.seed = seed;
|
||||
this.runtime = runtime;
|
||||
this.surfacePlacements = surfacePlacements;
|
||||
}
|
||||
|
||||
/** The placements a chunk places on the surface, in placing order. A chunk places the biome's before the region's. */
|
||||
@FunctionalInterface
|
||||
interface SurfacePlacements {
|
||||
List<IrisObjectPlacement> at(int chunkX, int chunkZ);
|
||||
}
|
||||
|
||||
/** Where a chunk would place, in block coordinates, with the random that picks and places the object there. */
|
||||
record Candidate(int x, int z, long rank, RNG rng) {
|
||||
boolean isCloserThan(Candidate other, int blocks) {
|
||||
long dx = x - other.x;
|
||||
long dz = z - other.z;
|
||||
return dx * dx + dz * dz < (long) blocks * blocks;
|
||||
}
|
||||
}
|
||||
|
||||
/** The chance to place at the block column: the placement's chance, multiplied by its chance noise when it has one. */
|
||||
double chanceAt(IrisObjectPlacement placement, double x, double z) {
|
||||
IrisGeneratorStyle style = placement.getChanceStyle();
|
||||
if (style == null) {
|
||||
return placement.getChance();
|
||||
}
|
||||
return placement.getChance() * style.create(seed, runtime).fitDouble(0D, 1D, x, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* The candidate the chunk places for the separated placement; empty when it rolled none or a lower ranked one is too
|
||||
* close.
|
||||
*/
|
||||
Optional<Candidate> keptCandidate(int chunkX, int chunkZ, IrisObjectPlacement placement) {
|
||||
Optional<Candidate> own = candidateOf(chunkX, chunkZ, placement);
|
||||
if (own.isEmpty() || isOutranked(own.get(), chunkX, chunkZ, placement)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return own;
|
||||
}
|
||||
|
||||
private boolean isOutranked(Candidate own, int chunkX, int chunkZ, IrisObjectPlacement placement) {
|
||||
int reach = placement.getSeparation();
|
||||
int minimumChunkX = Math.floorDiv(own.x() - reach, CHUNK_WIDTH_BLOCKS);
|
||||
int maximumChunkX = Math.floorDiv(own.x() + reach, CHUNK_WIDTH_BLOCKS);
|
||||
int minimumChunkZ = Math.floorDiv(own.z() - reach, CHUNK_WIDTH_BLOCKS);
|
||||
int maximumChunkZ = Math.floorDiv(own.z() + reach, CHUNK_WIDTH_BLOCKS);
|
||||
for (int x = minimumChunkX; x <= maximumChunkX; x++) {
|
||||
for (int z = minimumChunkZ; z <= maximumChunkZ; z++) {
|
||||
if ((x != chunkX || z != chunkZ) && isOutrankedBy(x, z, own, placement)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isOutrankedBy(int rivalChunkX, int rivalChunkZ, Candidate own, IrisObjectPlacement placement) {
|
||||
Optional<Candidate> rival = placementOfSameObjectsAt(rivalChunkX, rivalChunkZ, placement)
|
||||
.flatMap(other -> candidateOf(rivalChunkX, rivalChunkZ, other));
|
||||
return rival.isPresent() && rival.get().rank() < own.rank() && rival.get().isCloserThan(own, placement.getSeparation());
|
||||
}
|
||||
|
||||
private Optional<IrisObjectPlacement> placementOfSameObjectsAt(int chunkX, int chunkZ, IrisObjectPlacement placement) {
|
||||
return surfacePlacements.at(chunkX, chunkZ).stream()
|
||||
.filter(other -> other.isSeparated() && other.getPlace().equals(placement.getPlace()))
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
private Optional<Candidate> candidateOf(int chunkX, int chunkZ, IrisObjectPlacement placement) {
|
||||
RNG rng = new RNG(chunkSeed(chunkX, chunkZ, placement.getPlace().hashCode()));
|
||||
int x = (chunkX << CHUNK_SHIFT) + rng.nextInt(CHUNK_WIDTH_BLOCKS);
|
||||
int z = (chunkZ << CHUNK_SHIFT) + rng.nextInt(CHUNK_WIDTH_BLOCKS);
|
||||
if (!rng.chance(chanceAt(placement, x, z))) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(new Candidate(x, z, rng.nextLong(), rng));
|
||||
}
|
||||
|
||||
// Each input is mixed in after the previous one: XORing scaled coordinates gave chunk x,z and -x,-z the same seed
|
||||
// whenever both were odd.
|
||||
private long chunkSeed(int chunkX, int chunkZ, int objectsHash) {
|
||||
return splitMix(splitMix(splitMix(seed + objectsHash) + chunkX) + chunkZ);
|
||||
}
|
||||
|
||||
private static long splitMix(long value) {
|
||||
long mixed = value + 0x9E3779B97F4A7C15L;
|
||||
mixed = (mixed ^ (mixed >>> 30)) * 0xBF58476D1CE4E5B9L;
|
||||
mixed = (mixed ^ (mixed >>> 27)) * 0x94D049BB133111EBL;
|
||||
return mixed ^ (mixed >>> 31);
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ package art.arcane.iris.generation.noise;
|
||||
import art.arcane.iris.generation.image.IrisImageMap;
|
||||
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.pack.loading.ResourceLoader;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.world.history.GenerationKernelRegistry;
|
||||
@@ -42,7 +43,9 @@ import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Snippet("style")
|
||||
@@ -99,6 +102,46 @@ public class IrisGeneratorStyle {
|
||||
return createNoCache(rng, runtime, 1, 0, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this style can share an expression generator across caller seeds within a pack runtime.
|
||||
*/
|
||||
public boolean canShareExpressionGenerator(IrisData data) {
|
||||
return expression != null && canShareExpressionGenerator(data, new HashSet<>());
|
||||
}
|
||||
|
||||
private boolean canShareExpressionGenerator(IrisData data, Set<String> activeExpressions) {
|
||||
if (getClass() != IrisGeneratorStyle.class || expression == null || data == null
|
||||
|| fracture != null || cellularFrequency != 0D || cacheSize != 0
|
||||
|| !activeExpressions.add(expression)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
ResourceLoader<IrisExpression> loader = data.getExpressionLoader();
|
||||
IrisExpression source = loader == null ? null : loader.load(expression);
|
||||
if (source == null || source.getClass() != IrisExpression.class
|
||||
|| source.getVariables() == null || source.getFunctions() == null) {
|
||||
return false;
|
||||
}
|
||||
for (IrisExpressionLoad variable : source.getVariables()) {
|
||||
if (variable.getEngineValue() != null || variable.getEngineStreamValue() != null
|
||||
|| (variable.getStyleValue() != null
|
||||
&& !variable.getStyleValue().canShareExpressionGenerator(data, activeExpressions))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (IrisExpressionFunction function : source.getFunctions()) {
|
||||
if (function.getEngineStreamValue() != null || function.getStyleValue() == null
|
||||
|| !function.getStyleValue().canShareExpressionGenerator(data, activeExpressions)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} finally {
|
||||
activeExpressions.remove(expression);
|
||||
}
|
||||
}
|
||||
|
||||
public CNG createScaledGenerator(RNG rng, PackRuntime runtime, double scaleFactor) {
|
||||
return createNoCache(rng, runtime).bake().scale(scaleFactor).bake();
|
||||
}
|
||||
|
||||
@@ -300,14 +300,6 @@ public class IrisPostModifier extends EngineAssignedModifier<NativeBlockState> {
|
||||
setPostBlock(x, h + 1, z, result, originX, originZ, currentData);
|
||||
}
|
||||
}
|
||||
|
||||
if (B.isFoliage(b) || IrisProceduralBlocks.materialKey(b).equals("minecraft:dead_bush")) {
|
||||
NativeBlockState onto = getPostBlock(x, h, z, originX, originZ, currentData);
|
||||
|
||||
if (!B.canPlaceOnto(b, onto) && !B.isDecorant(b)) {
|
||||
setPostBlock(x, h + 1, z, AIR.get(), originX, originZ, currentData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAir(int x, int y, int z, int originX, int originZ, Hunk<NativeBlockState> currentData) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import art.arcane.iris.integration.ExternalDataSVC;
|
||||
import art.arcane.iris.generation.cache.Cache;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.platform.bukkit.BukkitBlockResolution;
|
||||
import art.arcane.iris.platform.bukkit.nms.INMS;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.spi.IrisServices;
|
||||
import art.arcane.iris.generation.block.IrisCustomData;
|
||||
@@ -83,6 +84,7 @@ public class CraftEngineDataProvider extends ExternalDataProvider implements Lis
|
||||
|
||||
@EventHandler
|
||||
public void onReload(CraftEngineReloadEvent event) {
|
||||
forgetServerBlockRules();
|
||||
if (!updateContent()) {
|
||||
return;
|
||||
}
|
||||
@@ -92,6 +94,13 @@ public class CraftEngineDataProvider extends ExternalDataProvider implements Lis
|
||||
}
|
||||
}
|
||||
|
||||
// Custom blocks carry their own placement rules, so answers about them can change with a reload.
|
||||
private static void forgetServerBlockRules() {
|
||||
if (INMS.isBound()) {
|
||||
INMS.get().forgetBlockRules();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull List<BlockProperty> getBlockProperties(@NotNull Identifier blockId) throws MissingResourceException {
|
||||
ImmutableBlockState blockState = findBlockState(blockId);
|
||||
|
||||
@@ -143,7 +143,7 @@ public class DataFixerV1217 extends DataFixerV1213 {
|
||||
attributes.put("minecraft:gameplay/bed_rule", new JSONObject()
|
||||
.put("can_set_spawn", "never")
|
||||
.put("can_sleep", "never")
|
||||
.put("destroy_on_use", true));
|
||||
.put("explodes", true));
|
||||
}
|
||||
|
||||
attributes.put("minecraft:gameplay/respawn_anchor_works", json.remove("respawn_anchor_works"));
|
||||
|
||||
@@ -49,6 +49,16 @@ public final class DataFixerV263 extends DataFixerV1217 {
|
||||
return fixed;
|
||||
}
|
||||
|
||||
/** 26.3 renamed the bed rule's explodes flag to destroy_on_use; the old key is ignored there. */
|
||||
@Override
|
||||
public void fixDimension(Dimension dimension, JSONObject json) {
|
||||
super.fixDimension(dimension, json);
|
||||
JSONObject bedRule = json.getJSONObject("attributes").optJSONObject("minecraft:gameplay/bed_rule");
|
||||
if (bedRule != null && bedRule.has("explodes")) {
|
||||
bedRule.put("destroy_on_use", bedRule.remove("explodes"));
|
||||
}
|
||||
}
|
||||
|
||||
private static void color(JSONObject object, String key) {
|
||||
if (object.opt(key) instanceof Number value) {
|
||||
object.put(key, String.format(Locale.ROOT, "#%06x", value.intValue() & 0xFFFFFF));
|
||||
|
||||
@@ -25,6 +25,7 @@ import art.arcane.iris.integration.ExternalDataSVC;
|
||||
import art.arcane.iris.structure.object.IrisObjectRotation;
|
||||
import art.arcane.volmlib.nativelib.terrain.BlockStateKey;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.nativelib.block.SurvivalAnswer;
|
||||
import art.arcane.iris.generation.block.IrisCustomData;
|
||||
import art.arcane.iris.generation.geometry.IrisBlockVector;
|
||||
import art.arcane.iris.spi.IrisServices;
|
||||
@@ -429,7 +430,18 @@ public final class BukkitBlockState implements NativeBlockState {
|
||||
|
||||
@Override
|
||||
public boolean canPlaceOnto(NativeBlockState onto) {
|
||||
return BukkitBlockResolution.canPlaceOnto(data.getMaterial(), ((BlockData) onto.nativeHandle()).getMaterial());
|
||||
BlockData plant = realBlockOf(data);
|
||||
BlockData ground = realBlockOf((BlockData) onto.nativeHandle());
|
||||
SurvivalAnswer serverRule = INMS.isBound() ? INMS.get().canSurviveOn(plant, ground) : SurvivalAnswer.UNANSWERED;
|
||||
return switch (serverRule) {
|
||||
case SURVIVES -> true;
|
||||
case FAILS -> false;
|
||||
case UNANSWERED -> BukkitBlockResolution.canPlaceOnto(plant.getMaterial(), ground.getMaterial());
|
||||
};
|
||||
}
|
||||
|
||||
private static BlockData realBlockOf(BlockData data) {
|
||||
return data instanceof IrisCustomData custom ? custom.getBase() : data;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -112,13 +112,8 @@ public class IrisObjectPlacement {
|
||||
@MaxNumber(1)
|
||||
@Description("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;
|
||||
@Description("If set, chance is multiplied by this noise (0 to 1) at the chunk, so objects gather in some areas and thin out in others.")
|
||||
private IrisGeneratorStyle chanceStyle = null;
|
||||
@MinNumber(0)
|
||||
@Description("Keeps objects of this placement at least this many blocks apart, also across chunks and biomes that place the same objects. Each chunk then places at most one. 0 turns it off. Surface placements only.")
|
||||
private int separation = 0;
|
||||
@MinNumber(1)
|
||||
@Description("If the chance check passes, place this many in a single chunk. Ignored when separation is set.")
|
||||
@Description("If the chance check passes, place this many in a single chunk")
|
||||
private int density = 1;
|
||||
@Description("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;
|
||||
@@ -343,8 +338,6 @@ public class IrisObjectPlacement {
|
||||
p.setDensity(density);
|
||||
p.setDensityStyle(densityStyle);
|
||||
p.setChance(chance);
|
||||
p.setChanceStyle(chanceStyle);
|
||||
p.setSeparation(separation);
|
||||
p.setSnow(snow);
|
||||
p.setClamp(clamp);
|
||||
p.setRotation(rotation);
|
||||
@@ -410,10 +403,6 @@ public class IrisObjectPlacement {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isSeparated() {
|
||||
return separation > 0;
|
||||
}
|
||||
|
||||
public int getDensity() {
|
||||
if (densityStyle == null) {
|
||||
return density;
|
||||
|
||||
+74
@@ -2,14 +2,20 @@ package art.arcane.iris.generation.biome;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.testsupport.MockPackData;
|
||||
import art.arcane.iris.generation.noise.IrisExpression;
|
||||
import art.arcane.iris.generation.noise.IrisExpressionFunction;
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.generation.noise.NoiseStyle;
|
||||
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.pack.loading.ResourceLoader;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.noise.CNG;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@@ -17,6 +23,9 @@ import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
@@ -28,6 +37,71 @@ public final class IrisBiomePaletteLayerGeneratorCacheTest {
|
||||
private static final int SIGNATURE = 7;
|
||||
private static final long LAYER_SIGNATURE = 2L;
|
||||
|
||||
@Test
|
||||
public void coordinateOnlyLayerSharesOneGeneratorWithoutChangingItsSamples() {
|
||||
IrisGeneratorStyle color = new IrisGeneratorStyle().setExpression("color");
|
||||
PackRuntime runtime = runtimeWithExpressions(Map.of(
|
||||
"material", new IrisExpression()
|
||||
.setExpression("if(y >= 25 + 19 * cos((x-y)/43), 0.90, color(abs(sin((x-y)/19 + z/33)), 0, 0))")
|
||||
.setFunctions(new KList<>(new IrisExpressionFunction().setName("color").setArgs(3).setStyleValue(color))),
|
||||
"color", new IrisExpression().setExpression("if(x < 0.03, 0.70, if(x < 0.07, 0.40, 0.10))")));
|
||||
IrisGeneratorStyle style = new IrisGeneratorStyle().setExpression("material");
|
||||
IrisBiomePaletteLayer layer = new IrisBiomePaletteLayer().zero().setStyle(style);
|
||||
CNG shared = layer.getLayerGenerator(new RNG(17L), 0, runtime);
|
||||
List<String> blocks = List.of("end_stone", "blackstone", "obsidian", "air");
|
||||
|
||||
for (int depth = 0; depth < 79; depth++) {
|
||||
RNG caller = new RNG(17L + depth * 41L);
|
||||
long originalSeed = caller.getSeed() + depth + LAYER_SIGNATURE;
|
||||
CNG original = style.createNoCache(new RNG(originalSeed), runtime);
|
||||
assertSame(shared, layer.getLayerGenerator(caller, depth, runtime));
|
||||
for (int x = -32; x < 32; x += 3) {
|
||||
double z = 41.5D - x;
|
||||
assertEquals(original.fit(blocks, x, depth, z), shared.fit(blocks, x, depth, z));
|
||||
assertEquals(original.noise(x, depth, z), shared.noise(x, depth, z), 0D);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nestedSeededNoiseKeepsDistinctLayerGenerators() {
|
||||
IrisGeneratorStyle style = new IrisGeneratorStyle().setExpression("seeded");
|
||||
PackRuntime runtime = runtimeWithExpressions(Map.of(
|
||||
"seeded", new IrisExpression().setExpression("noise(x, z)")
|
||||
.setFunctions(new KList<>(new IrisExpressionFunction()
|
||||
.setName("noise").setStyleValue(NoiseStyle.SIMPLEX.style())))));
|
||||
IrisBiomePaletteLayer layer = new IrisBiomePaletteLayer().zero().setStyle(style);
|
||||
CNG first = layer.getLayerGenerator(new RNG(17L), 0, runtime);
|
||||
CNG second = layer.getLayerGenerator(new RNG(29L), 0, runtime);
|
||||
|
||||
assertNotSame(first, second);
|
||||
assertEquals(style.createNoCache(new RNG(17L + LAYER_SIGNATURE), runtime).noise(-23D, 7D, 11D),
|
||||
first.noise(-23D, 7D, 11D), 0D);
|
||||
assertEquals(style.createNoCache(new RNG(29L + LAYER_SIGNATURE), runtime).noise(-23D, 7D, 11D),
|
||||
second.noise(-23D, 7D, 11D), 0D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void recursiveAndMissingExpressionReferencesDoNotQualifyForSharing() {
|
||||
IrisGeneratorStyle recursive = new IrisGeneratorStyle().setExpression("recursive");
|
||||
IrisGeneratorStyle missing = new IrisGeneratorStyle().setExpression("missing");
|
||||
PackRuntime runtime = runtimeWithExpressions(Map.of(
|
||||
"recursive", new IrisExpression().setExpression("again(x, z)")
|
||||
.setFunctions(new KList<>(new IrisExpressionFunction()
|
||||
.setName("again").setStyleValue(recursive)))));
|
||||
|
||||
assertFalse(recursive.canShareExpressionGenerator(runtime.data()));
|
||||
assertFalse(missing.canShareExpressionGenerator(runtime.data()));
|
||||
}
|
||||
|
||||
private static PackRuntime runtimeWithExpressions(Map<String, IrisExpression> contents) {
|
||||
IrisData data = MockPackData.create();
|
||||
ResourceLoader<IrisExpression> expressions = mock();
|
||||
when(data.getExpressionLoader()).thenReturn(expressions);
|
||||
when(expressions.load(any(String.class))).thenAnswer(call -> contents.get(call.getArgument(0)));
|
||||
return data.standalonePackRuntime();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void callerSeedsDoNotShareAFirstWinnerGenerator() {
|
||||
GeneratorFixture fixture = new GeneratorFixture();
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
package art.arcane.iris.generation.biome;
|
||||
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.generation.noise.NoiseStyle;
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.testsupport.MockPackData;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.volmlib.util.noise.CNG;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.ThreadMXBean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public final class PaletteLayerDepthCacheTest {
|
||||
private static final long[] PARENT_SEEDS = {0L, 17L, -9_223_372_036_854_775_807L, 8_675_309L, 1_234_567_890_123L};
|
||||
private static final int[] THICKNESSES = {1, 8, 33, 96, 300};
|
||||
private static final int LAYER_INDEX = 3;
|
||||
private static final int COLUMNS = 256;
|
||||
private static final int BENCH_THICKNESS = 96;
|
||||
private static final int BENCH_CHUNKS = 8;
|
||||
|
||||
@Test
|
||||
public void deepLayerBuildsEachDepthGeneratorOnce() {
|
||||
CountingStyle style = new CountingStyle(NoiseStyle.SIMPLEX);
|
||||
IrisBiomePaletteLayer layer = layer(style, BENCH_THICKNESS);
|
||||
PackRuntime runtime = MockPackData.create().standalonePackRuntime();
|
||||
|
||||
walkChunks(layer, runtime, new RNG(17L), BENCH_THICKNESS, 2);
|
||||
|
||||
assertEquals(BENCH_THICKNESS, style.builds.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seededLayerBuildsOneGeneratorForEveryDepthAndParent() {
|
||||
CountingStyle style = new CountingStyle(NoiseStyle.SIMPLEX);
|
||||
style.setSeed(4_242L);
|
||||
IrisBiomePaletteLayer layer = layer(style, BENCH_THICKNESS);
|
||||
PackRuntime runtime = MockPackData.create().standalonePackRuntime();
|
||||
|
||||
for (long parentSeed : PARENT_SEEDS) {
|
||||
walkChunks(layer, runtime, new RNG(parentSeed), BENCH_THICKNESS, 1);
|
||||
}
|
||||
|
||||
assertEquals(1, style.builds.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cachedDepthGeneratorsMatchFreshBuilds() {
|
||||
assertMatchesFreshBuilds(new IrisGeneratorStyle(NoiseStyle.SIMPLEX));
|
||||
assertMatchesFreshBuilds(new IrisGeneratorStyle(NoiseStyle.CELLULAR).setFracture(
|
||||
new IrisGeneratorStyle(NoiseStyle.PERLIN).zoomed(3D)).zoomed(0.5D));
|
||||
assertMatchesFreshBuilds(new IrisGeneratorStyle(NoiseStyle.SIMPLEX).setSeed(77L));
|
||||
assertMatchesFreshBuilds(new IrisGeneratorStyle(NoiseStyle.PERLIN).setSeed(-3L)
|
||||
.setFracture(new IrisGeneratorStyle(NoiseStyle.SIMPLEX)));
|
||||
}
|
||||
|
||||
/** Prints builds and thread CPU time for a deep-layer chunk walk; compare runs on the same machine. */
|
||||
@Test
|
||||
public void reportDeepLayerWalkCost() {
|
||||
ThreadMXBean threads = ManagementFactory.getThreadMXBean();
|
||||
for (int round = 0; round < 3; round++) {
|
||||
for (boolean fractured : new boolean[]{false, true}) {
|
||||
CountingStyle style = new CountingStyle(fractured ? NoiseStyle.CELLULAR : NoiseStyle.SIMPLEX);
|
||||
if (fractured) {
|
||||
style.setFracture(new IrisGeneratorStyle(NoiseStyle.PERLIN).zoomed(3D));
|
||||
}
|
||||
IrisBiomePaletteLayer layer = layer(style, BENCH_THICKNESS);
|
||||
PackRuntime runtime = MockPackData.create().standalonePackRuntime();
|
||||
long start = threads.getCurrentThreadCpuTime();
|
||||
double sink = walkChunks(layer, runtime, new RNG(17L), BENCH_THICKNESS, BENCH_CHUNKS);
|
||||
long cpu = threads.getCurrentThreadCpuTime() - start;
|
||||
System.out.printf("palette depth walk %s: thickness=%d chunks=%d builds=%d cpu=%.1fms (%.2fms/chunk) sink=%.3f%n",
|
||||
fractured ? "cellular+fracture" : "simplex", BENCH_THICKNESS, BENCH_CHUNKS, style.builds.get(),
|
||||
cpu / 1e6D, cpu / 1e6D / BENCH_CHUNKS, sink);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void assertMatchesFreshBuilds(IrisGeneratorStyle style) {
|
||||
for (int thickness : THICKNESSES) {
|
||||
IrisBiomePaletteLayer layer = layer(style, thickness);
|
||||
PackRuntime runtime = MockPackData.create().standalonePackRuntime();
|
||||
int blockCount = layer.getBlockData(runtime.data()).size();
|
||||
for (int pass = 0; pass < 2; pass++) {
|
||||
for (long parentSeed : PARENT_SEEDS) {
|
||||
RNG parent = new RNG(parentSeed);
|
||||
for (int depth = 0; depth < thickness; depth++) {
|
||||
int signature = LAYER_INDEX + depth;
|
||||
long seed = parentSeed + signature + thickness + thickness + blockCount;
|
||||
CNG fresh = style.createNoCache(new RNG(seed), runtime);
|
||||
CNG cached = layer.getLayerGenerator(parent, signature, runtime);
|
||||
for (int sample = 0; sample < 6; sample++) {
|
||||
double x = sample * 37.25D - 91D + depth;
|
||||
double z = 13.5D - sample * 19D - depth;
|
||||
assertEquals(fresh.noise(x, depth, z), cached.noise(x, depth, z), 0D);
|
||||
assertEquals(fresh.noise(x, z), cached.noise(x, z), 0D);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static double walkChunks(IrisBiomePaletteLayer layer, PackRuntime runtime, RNG parent, int thickness, int chunks) {
|
||||
double sink = 0D;
|
||||
for (int chunk = 0; chunk < chunks; chunk++) {
|
||||
for (int column = 0; column < COLUMNS; column++) {
|
||||
double x = chunk * 16 + (column & 15);
|
||||
double z = column >> 4;
|
||||
for (int depth = 0; depth < thickness; depth++) {
|
||||
sink += layer.getLayerGenerator(parent, LAYER_INDEX + depth, runtime).noise(x + depth, depth, z - depth);
|
||||
}
|
||||
}
|
||||
}
|
||||
return sink;
|
||||
}
|
||||
|
||||
private static IrisBiomePaletteLayer layer(IrisGeneratorStyle style, int thickness) {
|
||||
return new IrisBiomePaletteLayer().zero().setStyle(style).setMinHeight(thickness).setMaxHeight(thickness);
|
||||
}
|
||||
|
||||
private static final class CountingStyle extends IrisGeneratorStyle {
|
||||
private final AtomicInteger builds = new AtomicInteger();
|
||||
|
||||
private CountingStyle(NoiseStyle style) {
|
||||
super(style);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CNG createNoCache(RNG rng, PackRuntime runtime) {
|
||||
builds.incrementAndGet();
|
||||
return super.createNoCache(rng, runtime);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,141 +0,0 @@
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.iris.generation.runtime.PackRuntime;
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.generation.noise.NoiseStyle;
|
||||
import art.arcane.iris.structure.object.IrisObjectPlacement;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ObjectSeparationTest {
|
||||
private static final long SEED = 1337L;
|
||||
private static final int SEPARATION_BLOCKS = 40;
|
||||
private static final int GRID_HALF_WIDTH_CHUNKS = 24;
|
||||
|
||||
@Test
|
||||
public void keptObjectsStayApartAcrossBiomeBorders() {
|
||||
IrisObjectPlacement westBiome = separated(1, SEPARATION_BLOCKS, "tree");
|
||||
IrisObjectPlacement eastBiome = separated(1, SEPARATION_BLOCKS, "tree");
|
||||
ObjectSeparation separation = separation(
|
||||
(chunkX, chunkZ) -> List.of(chunkX < 0 ? westBiome : eastBiome));
|
||||
|
||||
List<ObjectSeparation.Candidate> kept = keptOnGrid(separation, (chunkX, chunkZ) -> chunkX < 0 ? westBiome : eastBiome);
|
||||
|
||||
assertTrue(kept.size() > 10);
|
||||
for (int first = 0; first < kept.size(); first++) {
|
||||
for (int second = first + 1; second < kept.size(); second++) {
|
||||
assertFalse(kept.get(first).isCloserThan(kept.get(second), SEPARATION_BLOCKS));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void keptObjectsDoNotDependOnQueryOrder() {
|
||||
IrisObjectPlacement placement = separated(1, SEPARATION_BLOCKS, "tree");
|
||||
ObjectSeparation separation = separation((chunkX, chunkZ) -> List.of(placement));
|
||||
|
||||
List<ObjectSeparation.Candidate> forward = keptOnGrid(separation, (chunkX, chunkZ) -> placement);
|
||||
List<Long> reversedRanks = new ArrayList<>();
|
||||
for (int chunkX = GRID_HALF_WIDTH_CHUNKS; chunkX >= -GRID_HALF_WIDTH_CHUNKS; chunkX--) {
|
||||
for (int chunkZ = GRID_HALF_WIDTH_CHUNKS; chunkZ >= -GRID_HALF_WIDTH_CHUNKS; chunkZ--) {
|
||||
separation.keptCandidate(chunkX, chunkZ, placement).ifPresent(candidate -> reversedRanks.add(candidate.rank()));
|
||||
}
|
||||
}
|
||||
|
||||
List<Long> forwardRanks = forward.stream().map(ObjectSeparation.Candidate::rank).sorted().toList();
|
||||
assertEquals(forwardRanks, reversedRanks.stream().sorted().toList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void placementsWithOtherObjectsDoNotKeepEachOtherApart() {
|
||||
IrisObjectPlacement trees = separated(1, SEPARATION_BLOCKS, "tree");
|
||||
IrisObjectPlacement rocks = separated(1, SEPARATION_BLOCKS, "rock");
|
||||
ObjectSeparation treesOnly = separation((chunkX, chunkZ) -> List.of(trees));
|
||||
ObjectSeparation both = separation((chunkX, chunkZ) -> List.of(trees, rocks));
|
||||
|
||||
assertEquals(
|
||||
keptOnGrid(treesOnly, (chunkX, chunkZ) -> trees).size(),
|
||||
keptOnGrid(both, (chunkX, chunkZ) -> trees).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void zeroChanceKeepsNothing() {
|
||||
IrisObjectPlacement placement = separated(0, SEPARATION_BLOCKS, "tree");
|
||||
ObjectSeparation separation = separation((chunkX, chunkZ) -> List.of(placement));
|
||||
|
||||
assertTrue(keptOnGrid(separation, (chunkX, chunkZ) -> placement).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wideSeparationThinsObjectsOut() {
|
||||
IrisObjectPlacement narrow = separated(1, 8, "tree");
|
||||
IrisObjectPlacement wide = separated(1, 96, "tree");
|
||||
|
||||
int narrowCount = keptOnGrid(separation((chunkX, chunkZ) -> List.of(narrow)), (chunkX, chunkZ) -> narrow).size();
|
||||
int wideCount = keptOnGrid(separation((chunkX, chunkZ) -> List.of(wide)), (chunkX, chunkZ) -> wide).size();
|
||||
|
||||
assertTrue(narrowCount > wideCount * 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void placementsStayUnchangedByDefault() {
|
||||
IrisObjectPlacement placement = new IrisObjectPlacement();
|
||||
placement.setChance(0.35);
|
||||
|
||||
assertFalse(placement.isSeparated());
|
||||
assertEquals(0.35, separation((chunkX, chunkZ) -> List.of()).chanceAt(placement, 12, -40), 0D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void chanceStyleScalesChanceWithoutRaisingIt() {
|
||||
IrisObjectPlacement placement = new IrisObjectPlacement();
|
||||
placement.setChance(0.5);
|
||||
placement.setChanceStyle(new IrisGeneratorStyle(NoiseStyle.STATIC));
|
||||
ObjectSeparation separation = separation((chunkX, chunkZ) -> List.of());
|
||||
|
||||
Optional<Double> lowest = Optional.empty();
|
||||
Optional<Double> highest = Optional.empty();
|
||||
for (int x = 0; x < 200; x += 7) {
|
||||
double chance = separation.chanceAt(placement, x, x * 3);
|
||||
assertTrue(chance >= 0D && chance <= 0.5);
|
||||
lowest = Optional.of(Math.min(chance, lowest.orElse(chance)));
|
||||
highest = Optional.of(Math.max(chance, highest.orElse(chance)));
|
||||
}
|
||||
assertTrue(highest.get() - lowest.get() > 0.1);
|
||||
}
|
||||
|
||||
private static List<ObjectSeparation.Candidate> keptOnGrid(ObjectSeparation separation, PlacementAt placementAt) {
|
||||
List<ObjectSeparation.Candidate> kept = new ArrayList<>();
|
||||
for (int chunkX = -GRID_HALF_WIDTH_CHUNKS; chunkX <= GRID_HALF_WIDTH_CHUNKS; chunkX++) {
|
||||
for (int chunkZ = -GRID_HALF_WIDTH_CHUNKS; chunkZ <= GRID_HALF_WIDTH_CHUNKS; chunkZ++) {
|
||||
separation.keptCandidate(chunkX, chunkZ, placementAt.at(chunkX, chunkZ)).ifPresent(kept::add);
|
||||
}
|
||||
}
|
||||
return kept;
|
||||
}
|
||||
|
||||
private static ObjectSeparation separation(ObjectSeparation.SurfacePlacements surfacePlacements) {
|
||||
return new ObjectSeparation(SEED, PackRuntime.standalone(null), surfacePlacements);
|
||||
}
|
||||
|
||||
private static IrisObjectPlacement separated(double chance, int separationBlocks, String... objects) {
|
||||
IrisObjectPlacement placement = new IrisObjectPlacement();
|
||||
placement.setPlace(new KList<>(objects));
|
||||
placement.setChance(chance);
|
||||
placement.setSeparation(separationBlocks);
|
||||
return placement;
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
private interface PlacementAt {
|
||||
IrisObjectPlacement at(int chunkX, int chunkZ);
|
||||
}
|
||||
}
|
||||
+32
-7
@@ -1,6 +1,7 @@
|
||||
package art.arcane.iris.pack.datapack.v1217;
|
||||
|
||||
import art.arcane.iris.pack.datapack.IDataFixer.Dimension;
|
||||
import art.arcane.iris.pack.datapack.v263.DataFixerV263;
|
||||
import art.arcane.volmlib.util.json.JSONObject;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -10,6 +11,7 @@ import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class DataFixerV1217BedRuleTest {
|
||||
private final DataFixerV1217 fixer = new DataFixerV1217();
|
||||
private final DataFixerV1217 fixer263 = new DataFixerV263();
|
||||
|
||||
@Test
|
||||
public void overworldBedsSleepWhenDark() {
|
||||
@@ -21,25 +23,48 @@ public class DataFixerV1217BedRuleTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void netherBedsAreDestroyedOnUse() {
|
||||
assertDestroyedOnUse(bedRule(Dimension.NETHER));
|
||||
public void netherBedsExplodeBefore263() {
|
||||
assertNoSleep(bedRule(fixer, Dimension.NETHER), "explodes", "destroy_on_use");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void endBedsAreDestroyedOnUse() {
|
||||
assertDestroyedOnUse(bedRule(Dimension.END));
|
||||
public void endBedsExplodeBefore263() {
|
||||
assertNoSleep(bedRule(fixer, Dimension.END), "explodes", "destroy_on_use");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void netherBedsAreDestroyedOnUseFrom263() {
|
||||
assertNoSleep(bedRule(fixer263, Dimension.NETHER), "destroy_on_use", "explodes");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void endBedsAreDestroyedOnUseFrom263() {
|
||||
assertNoSleep(bedRule(fixer263, Dimension.END), "destroy_on_use", "explodes");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void overworldBedsSleepWhenDarkFrom263() {
|
||||
JSONObject rule = bedRule(fixer263, Dimension.OVERWORLD);
|
||||
|
||||
assertEquals("when_dark", rule.getString("can_sleep"));
|
||||
assertFalse(rule.has("explodes"));
|
||||
assertFalse(rule.has("destroy_on_use"));
|
||||
}
|
||||
|
||||
private JSONObject bedRule(Dimension dimension) {
|
||||
return bedRule(fixer, dimension);
|
||||
}
|
||||
|
||||
private static JSONObject bedRule(DataFixerV1217 fixer, Dimension dimension) {
|
||||
return fixer.createDimension(dimension, -64, 384, 384, null)
|
||||
.getJSONObject("attributes")
|
||||
.getJSONObject("minecraft:gameplay/bed_rule");
|
||||
}
|
||||
|
||||
private static void assertDestroyedOnUse(JSONObject rule) {
|
||||
private static void assertNoSleep(JSONObject rule, String presentKey, String absentKey) {
|
||||
assertEquals("never", rule.getString("can_sleep"));
|
||||
assertEquals("never", rule.getString("can_set_spawn"));
|
||||
assertTrue(rule.getBoolean("destroy_on_use"));
|
||||
assertFalse(rule.has("explodes"));
|
||||
assertTrue(rule.getBoolean(presentKey));
|
||||
assertFalse(rule.has(absentKey));
|
||||
}
|
||||
}
|
||||
@@ -84,7 +84,7 @@ public class SchemaBuilderIdentityTest {
|
||||
@ClassRule
|
||||
public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean();
|
||||
|
||||
private static final String EXPECTED_SCHEMA_DIGEST = "af3c848472e7de2d87d4a0aceb52f107d967249a35485d2247c1066e75ccfbd7";
|
||||
private static final String EXPECTED_SCHEMA_DIGEST = "1a10c843c6dbe0f60b2dd2cd3a48c04407f30b0ade212cc69a6ba1c4188f25ce";
|
||||
|
||||
private static final List<Class<?>> SCHEMA_ROOTS = List.of(
|
||||
IrisDimension.class,
|
||||
|
||||
Reference in new issue
Block a user