public static < T , U extends T > T toTagValue ( Tag < ? > t , Class < ? extends T > clazz , U defaultValue ) { Object o = toTagValue ( t ) ; if ( o == null ) { return defaultValue ; } try { T value = clazz . cast ( o ) ; return value ; } catch ( ClassCastException e ) { return defaultValue ; } }
Takes in an NBT tag sanely checks null status and then returns it value . This method will return null if the value cannot be cast to the default value .