Skip to content

Commit

Permalink
Add integration test for adding/removing lots of smoothables at the s…
Browse files Browse the repository at this point in the history
…ame time
  • Loading branch information
Cadiboo committed Feb 21, 2023
1 parent 2dee1e2 commit 4c25e54
Showing 1 changed file with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package io.github.cadiboo.nocubes.integrationtesting;

import io.github.cadiboo.nocubes.NoCubes;
import io.github.cadiboo.nocubes.config.NoCubesConfig;
import io.github.cadiboo.nocubes.config.NoCubesConfig.Server.MesherType;
import io.github.cadiboo.nocubes.util.Area;
import io.github.cadiboo.nocubes.util.Face;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.data.registries.VanillaRegistries;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.registries.ForgeRegistries;

import java.util.Arrays;
import java.util.function.Predicate;

import static net.minecraft.world.level.block.Blocks.*;

/**
* Integration tests
*
Expand All @@ -24,17 +28,30 @@ record Test(String name, Runnable action) {}
static Test[] createTests() {
return new Test[]{
// test("the version in mods.toml should have been replaced by gradle", () -> assertFalse(0 == ModList.get().getModFileById(NoCubes.MOD_ID).getMods().get(0).getVersion().getMajorVersion())),
test("stone should be smoothable", () -> assertTrue(NoCubes.smoothableHandler.isSmoothable(STONE.defaultBlockState()))),
test("dirt should be smoothable", () -> assertTrue(NoCubes.smoothableHandler.isSmoothable(DIRT.defaultBlockState()))),
test("air should not be smoothable", () -> assertFalse(NoCubes.smoothableHandler.isSmoothable(AIR.defaultBlockState()))),
test("stone should be smoothable", () -> assertTrue(NoCubes.smoothableHandler.isSmoothable(Blocks.STONE.defaultBlockState()))),
test("dirt should be smoothable", () -> assertTrue(NoCubes.smoothableHandler.isSmoothable(Blocks.DIRT.defaultBlockState()))),
test("air should not be smoothable", () -> assertFalse(NoCubes.smoothableHandler.isSmoothable(Blocks.AIR.defaultBlockState()))),
test("removing smoothable should work", () -> {
var dirt = DIRT.defaultBlockState();
var dirt = Blocks.DIRT.defaultBlockState();
var oldValue = NoCubes.smoothableHandler.isSmoothable(dirt);
NoCubes.smoothableHandler.setSmoothable(false, dirt);
assertFalse(NoCubes.smoothableHandler.isSmoothable(dirt));
if (oldValue)
NoCubes.smoothableHandler.setSmoothable(true, dirt);
}),
test("adding then removing lots of smoothables at once should work", () -> {
var states = ForgeRegistries.BLOCKS.getValues().stream()
.skip(20) // Skip air, stone, dirt etc. which we test above
.limit(1000)
.map(Block::defaultBlockState)
.toArray(BlockState[]::new);

NoCubesConfig.Server.updateSmoothable(true, states);
assertTrue(Arrays.stream(states).allMatch(NoCubes.smoothableHandler::isSmoothable));

NoCubesConfig.Server.updateSmoothable(false, states);
assertTrue(Arrays.stream(states).noneMatch(NoCubes.smoothableHandler::isSmoothable));
}),
test("area sanity check", NoCubesTests::areaSanityCheck),
test("mesher sanity check", NoCubesTests::mesherSanityCheck),
};
Expand All @@ -51,15 +68,15 @@ private static void areaSanityCheck() {
}

private static void mesherSanityCheck() {
Predicate<BlockState> isSmoothable = $ -> $ == STONE.defaultBlockState();
Predicate<BlockState> isSmoothable = $ -> $ == Blocks.STONE.defaultBlockState();

var start = new BlockPos(100, 50, 25);
var area = new Area(null, start, new BlockPos(5, 5, 5)) {
@Override
public BlockState[] getAndCacheBlocks() {
BlockState[] states = new BlockState[numBlocks()];
for (int i = 0; i < states.length; i++)
states[i] = i % 2 == 0 ? STONE.defaultBlockState() : AIR.defaultBlockState();
states[i] = i % 2 == 0 ? Blocks.STONE.defaultBlockState() : Blocks.AIR.defaultBlockState();
return states;
}

Expand Down

0 comments on commit 4c25e54

Please sign in to comment.