mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-07 15:42:19 -07:00
#1020: Cast instead of using #typed when getting BlockType and ItemType to better work with testing / mocks
By: DerFrZocker <derrieple@gmail.com>
This commit is contained in:
@@ -3409,11 +3409,12 @@ public interface BlockType extends Keyed, Translatable {
|
||||
//</editor-fold>
|
||||
|
||||
@NotNull
|
||||
private static <B extends BlockData> BlockType.Typed<B> getBlockType(@NotNull String key) {
|
||||
private static <B extends BlockType> B getBlockType(@NotNull String key) {
|
||||
NamespacedKey namespacedKey = NamespacedKey.minecraft(key);
|
||||
BlockType.Typed<?> blockType = Registry.BLOCK.get(namespacedKey).typed();
|
||||
BlockType blockType = Registry.BLOCK.get(namespacedKey);
|
||||
Preconditions.checkNotNull(blockType, "No BlockType found for %s. This is a bug.", namespacedKey);
|
||||
return (BlockType.Typed<B>) blockType;
|
||||
// Cast instead of using BlockType#typed, since block type can be a mock during testing and would return null
|
||||
return (B) blockType;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -2257,11 +2257,12 @@ public interface ItemType extends Keyed, Translatable {
|
||||
//</editor-fold>
|
||||
|
||||
@NotNull
|
||||
private static <M extends ItemMeta> Typed<M> getItemType(@NotNull String key) {
|
||||
private static <M extends ItemType> M getItemType(@NotNull String key) {
|
||||
NamespacedKey namespacedKey = NamespacedKey.minecraft(key);
|
||||
Typed<?> itemType = Registry.ITEM.get(namespacedKey).typed();
|
||||
ItemType itemType = Registry.ITEM.get(namespacedKey);
|
||||
Preconditions.checkNotNull(itemType, "No ItemType found for %s. This is a bug.", namespacedKey);
|
||||
return (Typed<M>) itemType;
|
||||
// Cast instead of using ItemType#typed, since item type can be a mock during testing and would return null
|
||||
return (M) itemType;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user