Skip to content

Commit

Permalink
Add capabilities methods to ExtendedGameTestHelper (neoforged#760)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sirttas authored Apr 1, 2024
1 parent 1754aac commit 8503ec2
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -188,6 +189,19 @@ public <T extends BlockEntity> T requireBlockEntity(int x, int y, int z, Class<T
return requireBlockEntity(new BlockPos(x, y, z), type);
}

@Nullable
public <T, C> T getCapability(BlockCapability<T, C> cap, BlockPos pos, C context) {
return getLevel().getCapability(cap, absolutePos(pos), context);
}

public <T, C> T requireCapability(BlockCapability<T, C> 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 <T> ParametrizedGameTestSequence<T> startSequence(Supplier<T> value) {
return new ParametrizedGameTestSequence<>(this.testInfo, this.startSequence(), value);
}
Expand Down

0 comments on commit 8503ec2

Please sign in to comment.