diff --git a/testframework/src/main/java/net/neoforged/testframework/gametest/ExtendedGameTestHelper.java b/testframework/src/main/java/net/neoforged/testframework/gametest/ExtendedGameTestHelper.java index 666ac4252d..8f77d3b69a 100644 --- a/testframework/src/main/java/net/neoforged/testframework/gametest/ExtendedGameTestHelper.java +++ b/testframework/src/main/java/net/neoforged/testframework/gametest/ExtendedGameTestHelper.java @@ -49,6 +49,7 @@ import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.Vec3; import net.neoforged.bus.api.Event; +import net.neoforged.neoforge.capabilities.BlockCapability; import net.neoforged.neoforge.common.NeoForge; import net.neoforged.neoforge.event.entity.living.LivingKnockBackEvent; import net.neoforged.neoforge.network.registration.NetworkRegistry; @@ -188,6 +189,19 @@ public T requireBlockEntity(int x, int y, int z, Class T getCapability(BlockCapability cap, BlockPos pos, C context) { + return getLevel().getCapability(cap, absolutePos(pos), context); + } + + public T requireCapability(BlockCapability cap, BlockPos pos, C context) { + final var capability = getCapability(cap, pos, context); + if (capability == null) { + throw new GameTestAssertPosException("Expected capability " + cap + " but there was none", absolutePos(pos), pos, getTick()); + } + return capability; + } + public ParametrizedGameTestSequence startSequence(Supplier value) { return new ParametrizedGameTestSequence<>(this.testInfo, this.startSequence(), value); }