Skip to content

Commit 8d5ffc7

Browse files
authored
Do class instance check before casting capabilities (#231)
This ensures that a ClassCastException won't be generated to improve performance
1 parent e79a936 commit 8d5ffc7

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

loader-common/src/main/java/org/cyclops/cyclopscore/helper/BlockEntityHelpersCommon.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ public <T> Optional<T> get(BlockGetter level, BlockPos pos, Class<T> targetClazz
3232
if (blockEntity == null) {
3333
return Optional.empty();
3434
}
35-
try {
35+
if (targetClazz.isInstance(blockEntity)) {
3636
return Optional.of(targetClazz.cast(blockEntity));
37-
} catch (ClassCastException e) {
37+
} else {
3838
return Optional.empty();
3939
}
4040
}

0 commit comments

Comments
 (0)