Commits

DerFrZocker authored and md_5 committed 8d1e700a062
#1020: Cast instead of using #typed when getting BlockType and ItemType to better work with testing / mocks
No tags

src/main/java/org/bukkit/block/BlockType.java

Modified
3402 3402 /**
3403 3403 * BlockData: {@link TrialSpawner}
3404 3404 */
3405 3405 @MinecraftExperimental(Requires.UPDATE_1_21)
3406 3406 @ApiStatus.Experimental
3407 3407 BlockType.Typed<TrialSpawner> TRIAL_SPAWNER = getBlockType("trial_spawner");
3408 3408
3409 3409 //</editor-fold>
3410 3410
3411 3411 @NotNull
3412 - private static <B extends BlockData> BlockType.Typed<B> getBlockType(@NotNull String key) {
3412 + private static <B extends BlockType> B getBlockType(@NotNull String key) {
3413 3413 NamespacedKey namespacedKey = NamespacedKey.minecraft(key);
3414 - BlockType.Typed<?> blockType = Registry.BLOCK.get(namespacedKey).typed();
3414 + BlockType blockType = Registry.BLOCK.get(namespacedKey);
3415 3415 Preconditions.checkNotNull(blockType, "No BlockType found for %s. This is a bug.", namespacedKey);
3416 - return (BlockType.Typed<B>) blockType;
3416 + // Cast instead of using BlockType#typed, since block type can be a mock during testing and would return null
3417 + return (B) blockType;
3417 3418 }
3418 3419
3419 3420 /**
3420 3421 * Yields this block type as a typed version of itself with a plain {@link BlockData} representing it.
3421 3422 *
3422 3423 * @return the typed block type.
3423 3424 */
3424 3425 @NotNull
3425 3426 BlockType.Typed<BlockData> typed();
3426 3427

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut