mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Test more plants against the server rule
- Check every vanilla block and plants that read more of the level for failed answers - Check that a throwing rule lets the plant stand and warns once - Drop the forgetBlockRules default, the native interface has one now
This commit is contained in:
1 parent
43ce1cb038
commit
a46ab4131e
2 files changed
+116
-4
No files matched your search
+116
@@ -2,19 +2,32 @@ package art.arcane.iris.probe;
|
||||
|
||||
import art.arcane.volmlib.nativelib.common.block.GroundSurvival;
|
||||
import art.arcane.volmlib.nativelib.minecraft26_2.modded.ModdedBlockState;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
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.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();
|
||||
@@ -66,6 +79,7 @@ public final class HeadlessGroundSurvivalTest {
|
||||
public void blocksThatRestOnNoGroundStillFit() {
|
||||
assertPlacement(true, Blocks.WALL_TORCH, Blocks.STONE);
|
||||
assertPlacement(true, Blocks.VINE, Blocks.SAND);
|
||||
assertPlacement(true, Blocks.COCOA, Blocks.STONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -74,6 +88,73 @@ public final class HeadlessGroundSurvivalTest {
|
||||
assertFalse(moddedPlacement(Blocks.DEAD_BUSH, Blocks.GRASS_BLOCK));
|
||||
}
|
||||
|
||||
@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 aRuleThatThrowsLetsThePlantStandAndWarnsOncePerBlock() {
|
||||
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}) {
|
||||
assertTrue(survival.canSurviveOn(plant, ground.defaultBlockState()));
|
||||
}
|
||||
}
|
||||
});
|
||||
assertEquals(messages(warnings), 1, warnings.size());
|
||||
}
|
||||
|
||||
// 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.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));
|
||||
@@ -90,4 +171,39 @@ public final class HeadlessGroundSurvivalTest {
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -328,10 +328,6 @@ public interface INMSBinding extends NativeTerrainAccess {
|
||||
return BukkitBlockResolution.canPlaceOnto(plant.getMaterial(), ground.getMaterial());
|
||||
}
|
||||
|
||||
/** Drops answers remembered from the server's block rules, which a resource reload may have changed. */
|
||||
default void forgetBlockRules() {
|
||||
}
|
||||
|
||||
private void validateDimensionTypes(WorldCreator c) {
|
||||
if (!(c.generator() instanceof PlatformChunkGenerator generator)) {
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user