Search in sources :

Example 1 with FakeBlast

use of icbm.classic.command.FakeBlast in project ICBM-Classic by BuiltBrokenModding.

the class CommandBlastTriggerTest method setupBeforeTest.

@BeforeEach
public void setupBeforeTest() {
    ICBMClassicAPI.EXPLOSIVE_REGISTRY = new ExplosiveRegistry();
    fakeExData = ICBMClassicAPI.EXPLOSIVE_REGISTRY.register(new ResourceLocation("tree", "small"), EnumTier.ONE, () -> {
        FakeBlast fakeBlast = new FakeBlast(triggerState);
        blastsCreated.add(fakeBlast);
        return fakeBlast;
    });
}
Also used : ExplosiveRegistry(icbm.classic.lib.explosive.reg.ExplosiveRegistry) FakeBlast(icbm.classic.command.FakeBlast) ResourceLocation(net.minecraft.util.ResourceLocation) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with FakeBlast

use of icbm.classic.command.FakeBlast in project ICBM-Classic by BuiltBrokenModding.

the class CommandBlastTriggerTest method validateBlastTrigger.

private void validateBlastTrigger(World world, int x, int y, int z, int size, int count) {
    // Should generate a single blast
    Assertions.assertEquals(count, blastsCreated.size(), "Expected the blast creation queue to contain " + count + " blast(s)");
    final FakeBlast blast = blastsCreated.poll();
    // Check position data
    Assertions.assertEquals(x, blast.xi(), "X position of the blast is incorrect");
    Assertions.assertEquals(y, blast.yi(), "Y position of the blast is incorrect");
    Assertions.assertEquals(z, blast.zi(), "Z position of the blast is incorrect");
    // Check world data
    Assertions.assertEquals(world, blast.world(), "World of the blast is incorrect");
    // Check explosive settings
    Assertions.assertEquals(fakeExData, blast.getExplosiveData(), "Explosive data does not match");
    Assertions.assertNull(blast.customData, "Explosive custom data should be empty");
    Assertions.assertEquals(size, (int) Math.floor(blast.getBlastRadius()), "Explosive radius should be 2");
}
Also used : FakeBlast(icbm.classic.command.FakeBlast)

Example 3 with FakeBlast

use of icbm.classic.command.FakeBlast in project ICBM-Classic by BuiltBrokenModding.

the class CommandLagTest method command_removeBlasts.

@Test
void command_removeBlasts() {
    dummyCommandSender.position = new Vec3d(100, 20, 100);
    // Spawn some sheep to act as decoys
    TestUtils.sheep(testManager.getWorld(), 100, 20, 100);
    TestUtils.sheep(testManager.getWorld(), 100, 30, 100);
    TestUtils.sheep(testManager.getWorld(), 100, 40, 100);
    ExplosiveHandler.activeBlasts.add(new FakeBlast(null).setBlastPosition(100, 20, 100).setBlastWorld(testManager.getWorld()));
    ExplosiveHandler.activeBlasts.add(new FakeBlast(null).setBlastPosition(100, 20, 100).setBlastWorld(testManager.getWorld()));
    // Validate start condition
    Assertions.assertEquals(3, testManager.getWorld().loadedEntityList.size(), "Should start with 3 entities");
    // Trigger command
    Assertions.assertDoesNotThrow(() -> command.handleCommand(testManager.getServer(), dummyCommandSender, new String[0]));
    // Validate output
    Assertions.assertEquals(1, dummyCommandSender.messages.size(), "Should have 1 chat message");
    Assertions.assertEquals(CommandLag.TRANSLATION_LAG_REMOVE, dummyCommandSender.pollLastMessage(), "Should get translation");
    // Should still have 3 sheep
    Assertions.assertEquals(3, testManager.getWorld().loadedEntityList.size(), "Should end with 3 entities");
    Assertions.assertEquals(0, ExplosiveHandler.activeBlasts.size(), "Should end with 0 blasts");
}
Also used : FakeBlast(icbm.classic.command.FakeBlast) Vec3d(net.minecraft.util.math.Vec3d) Test(org.junit.jupiter.api.Test)

Example 4 with FakeBlast

use of icbm.classic.command.FakeBlast in project ICBM-Classic by BuiltBrokenModding.

the class CommandBlastSpreadTest method setupBeforeTest.

@BeforeEach
public void setupBeforeTest() {
    ICBMClassicAPI.EXPLOSIVE_REGISTRY = new ExplosiveRegistry();
    fakeExData = ICBMClassicAPI.EXPLOSIVE_REGISTRY.register(new ResourceLocation("tree", "small"), EnumTier.ONE, () -> {
        FakeBlast fakeBlast = new FakeBlast(triggerState);
        blastsCreated.add(fakeBlast);
        return fakeBlast;
    });
}
Also used : ExplosiveRegistry(icbm.classic.lib.explosive.reg.ExplosiveRegistry) FakeBlast(icbm.classic.command.FakeBlast) ResourceLocation(net.minecraft.util.ResourceLocation) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with FakeBlast

use of icbm.classic.command.FakeBlast in project ICBM-Classic by BuiltBrokenModding.

the class CommandBlastSpreadTest method checkCommand.

@ParameterizedTest
@MethodSource("provideGoodCommandInputs")
void checkCommand(String[] args, int x, int y, int z, int distance) throws CommandException {
    dummyCommandSender.position = new Vec3d(x, y, z);
    command.handleCommand(testManager.getServer(), dummyCommandSender, args);
    // Validate message
    Assertions.assertEquals(1, dummyCommandSender.messages.size());
    Assertions.assertEquals(CommandBlastSpread.TRANSLATION_SPREAD_START, dummyCommandSender.pollLastMessage());
    // We should spawn 9 blasts
    Assertions.assertEquals(9, blastsCreated.size());
    final Set<BlockPos> positions = new HashSet();
    positions.add(new BlockPos(x, y, z));
    positions.add(new BlockPos(x + distance, y, z + distance));
    positions.add(new BlockPos(x - distance, y, z - distance));
    positions.add(new BlockPos(x - distance, y, z + distance));
    positions.add(new BlockPos(x + distance, y, z - distance));
    positions.add(new BlockPos(x + distance, y, z));
    positions.add(new BlockPos(x - distance, y, z));
    positions.add(new BlockPos(x, y, z + distance));
    positions.add(new BlockPos(x, y, z - distance));
    // Validate blast contents
    do {
        final FakeBlast blast = blastsCreated.poll();
        final BlockPos pos = blast.getPos();
        // Check that we match position, then remove to catch duplicate spawns
        Assertions.assertTrue(positions.contains(pos));
        positions.remove(pos);
        // Check world data
        Assertions.assertEquals(testManager.getWorld(), blast.world(), "World of the blast is incorrect");
        // Check explosive settings
        Assertions.assertEquals(fakeExData, blast.getExplosiveData(), "Explosive data does not match");
        Assertions.assertNull(blast.customData, "Explosive custom data should be empty");
        Assertions.assertEquals(2, (int) Math.floor(blast.getBlastRadius()), "Explosive radius should be 2");
    } while (!blastsCreated.isEmpty());
}
Also used : FakeBlast(icbm.classic.command.FakeBlast) BlockPos(net.minecraft.util.math.BlockPos) Vec3d(net.minecraft.util.math.Vec3d) HashSet(java.util.HashSet) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

FakeBlast (icbm.classic.command.FakeBlast)5 ExplosiveRegistry (icbm.classic.lib.explosive.reg.ExplosiveRegistry)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 Vec3d (net.minecraft.util.math.Vec3d)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 HashSet (java.util.HashSet)1 BlockPos (net.minecraft.util.math.BlockPos)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1