Search in sources :

Example 1 with PrefixGameTestTemplate

use of net.minecraftforge.gametest.PrefixGameTestTemplate in project MinecraftForge by MinecraftForge.

the class GameTestTest method testHopperPickup.

@PrefixGameTestTemplate(false)
@GameTest(templateNamespace = MODID, template = "empty3x3x3")
public static void testHopperPickup(GameTestHelper helper) {
    BlockPos hopperPos = new BlockPos(1, 1, 1);
    // Sets (1,1,1) to a hopper and spawns a golden apple one block above it
    helper.setBlock(hopperPos, Blocks.HOPPER);
    helper.spawnItem(Items.GOLDEN_APPLE, 1, 2, 1);
    // Waits 20 ticks before checking that the hopper contains the golden apple
    helper.assertAtTickTimeContainerContains(20, hopperPos, Items.GOLDEN_APPLE);
    // Succeeds at 21 ticks if the previous check didn't throw an exception
    helper.runAtTickTime(21, helper::succeed);
}
Also used : BlockPos(net.minecraft.core.BlockPos) GameTest(net.minecraft.gametest.framework.GameTest) PrefixGameTestTemplate(net.minecraftforge.gametest.PrefixGameTestTemplate)

Example 2 with PrefixGameTestTemplate

use of net.minecraftforge.gametest.PrefixGameTestTemplate in project MinecraftForge by MinecraftForge.

the class GameTestTest method testEnergyStorage.

@PrefixGameTestTemplate(false)
@GameTest(templateNamespace = MODID, template = "empty3x3x3")
public static void testEnergyStorage(GameTestHelper helper) {
    BlockPos energyPos = new BlockPos(1, 1, 1);
    // Sets (1,1,1) to our custom energy block
    helper.setBlock(energyPos, ENERGY_BLOCK.get());
    // Queries the energy capability
    LazyOptional<IEnergyStorage> energyHolder = helper.getBlockEntity(energyPos).getCapability(CapabilityEnergy.ENERGY);
    // Adds 2000 FE, but our energy storage can only hold 1000 FE
    energyHolder.ifPresent(energyStorage -> energyStorage.receiveEnergy(2000, false));
    // Fails test if stored energy is not equal to 1000 FE
    int energy = energyHolder.map(IEnergyStorage::getEnergyStored).orElse(0);
    int target = 1000;
    if (energy != target) {
        helper.fail("Expected energy=" + target + " but it was energy=" + energy, energyPos);
    }
    helper.succeed();
}
Also used : IEnergyStorage(net.minecraftforge.energy.IEnergyStorage) BlockPos(net.minecraft.core.BlockPos) GameTest(net.minecraft.gametest.framework.GameTest) PrefixGameTestTemplate(net.minecraftforge.gametest.PrefixGameTestTemplate)

Aggregations

BlockPos (net.minecraft.core.BlockPos)2 GameTest (net.minecraft.gametest.framework.GameTest)2 PrefixGameTestTemplate (net.minecraftforge.gametest.PrefixGameTestTemplate)2 IEnergyStorage (net.minecraftforge.energy.IEnergyStorage)1