mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-12-01 02:04:51 +00:00
Use table for unanswered rules
- Fall back to the block table when the server rule cannot answer - Drop the INMSBinding default and the copied dead bush check - Take GroundSurvival from native-common in the headless build - Restore the placement table contract tests - Test unanswered rules, air ground and concurrent lookups
This commit is contained in:
5 files changed
+108
-27
No files matched your search
+61
-8
@@ -2,13 +2,17 @@ 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.terrain.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;
|
||||
@@ -84,8 +88,14 @@ public final class HeadlessGroundSurvivalTest {
|
||||
|
||||
@Test
|
||||
public void deadBushStaysOffGrassAsPacksExpect() {
|
||||
assertTrue(moddedPlacement(Blocks.DEAD_BUSH, Blocks.SAND));
|
||||
assertFalse(moddedPlacement(Blocks.DEAD_BUSH, Blocks.GRASS_BLOCK));
|
||||
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
|
||||
@@ -129,20 +139,64 @@ public final class HeadlessGroundSurvivalTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aRuleThatThrowsLetsThePlantStandAndWarnsOncePerBlock() {
|
||||
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}) {
|
||||
assertTrue(survival.canSurviveOn(plant, ground.defaultBlockState()));
|
||||
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;
|
||||
@@ -151,6 +205,7 @@ public final class HeadlessGroundSurvivalTest {
|
||||
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;
|
||||
}
|
||||
@@ -158,10 +213,8 @@ public final class HeadlessGroundSurvivalTest {
|
||||
private static void assertPlacement(boolean expected, Block plant, Block ground) {
|
||||
String pair = plant + " on " + ground;
|
||||
assertEquals("modded " + pair, expected, moddedPlacement(plant, ground));
|
||||
if (!ground.defaultBlockState().isAir()) {
|
||||
assertEquals("bukkit native " + pair, expected,
|
||||
new GroundSurvival().canSurviveOn(plant.defaultBlockState(), ground.defaultBlockState()));
|
||||
}
|
||||
assertEquals("bukkit native " + pair, expected ? SurvivalAnswer.SURVIVES : SurvivalAnswer.FAILS,
|
||||
new GroundSurvival().canSurviveOn(plant.defaultBlockState(), ground.defaultBlockState()));
|
||||
}
|
||||
|
||||
private static boolean moddedPlacement(Block plant, Block ground) {
|
||||
|
||||
Reference in new issue
Block a user