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);
}
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();
}
Aggregations