5656public class BlueMapBanners implements ModInitializer {
5757
5858 public static final Logger LOGGER = LoggerFactory .getLogger ("BlueMap Banners" );
59- public static String VERSION = FabricLoader .getInstance ().getModContainer ("bluemap-banners" ).get ().getMetadata ().getVersion ().getFriendlyString ();
59+ public static String VERSION = FabricLoader .getInstance ().getModContainer ("bluemap-banners" ).orElseThrow ().getMetadata ().getVersion ().getFriendlyString ();
6060 MarkerManager markerManager ;
6161 MapIcons bannerMapIcons ;
6262 ConfigManager configManager ;
6363 Timer daemonTimer ;
6464
6565 @ Override
66+ @ SuppressWarnings ("ResultOfMethodCallIgnored" )
6667 public void onInitialize () {
6768 LOGGER .info ("Loading BlueMap Banners v{}" , VERSION );
6869
@@ -102,6 +103,7 @@ public void run() {
102103 daemonTimer .scheduleAtFixedRate (metricsTask , TimeUnit .MINUTES .toMillis (1 ), TimeUnit .MINUTES .toMillis (30 ));
103104 }
104105
106+ @ SuppressWarnings ("SameReturnValue" )
105107 private InteractionResult useBlock (Player player , Level world , InteractionHand hand , BlockHitResult hitResult ) {
106108 if (player .isSpectator () ||
107109 (player .getMainHandItem ().isEmpty () && player .getOffhandItem ().isEmpty ()) ||
@@ -110,8 +112,11 @@ private InteractionResult useBlock(Player player, Level world, InteractionHand h
110112 }
111113 if (player .getMainHandItem ().is (Items .MAP ) || player .getOffhandItem ().is (Items .MAP ) || player .getMainHandItem ().is (Items .FILLED_MAP ) || player .getOffhandItem ().is (Items .FILLED_MAP )) {
112114 BlockState blockState = world .getBlockState (hitResult .getBlockPos ());
113- BannerBlockEntity bannerBlockEntity = (BannerBlockEntity ) world .getBlockEntity (hitResult .getBlockPos ());
114- if (blockState != null && blockState .is (BlockTags .BANNERS ) && bannerBlockEntity != null ) {
115+ BannerBlockEntity bannerBlockEntity = null ;
116+ try {
117+ bannerBlockEntity = (BannerBlockEntity ) world .getBlockEntity (hitResult .getBlockPos ());
118+ } catch (ClassCastException ignored ) {}
119+ if (blockState .is (BlockTags .BANNERS ) && bannerBlockEntity != null ) {
115120 try {
116121 if (!markerManager .doesMarkerExist (bannerBlockEntity )) {
117122 markerManager .addMarker (blockState , bannerBlockEntity , player );
0 commit comments