// InsaneCraft S2 - compatibility shim for the optional JEI integration.
// JEI is intentionally not shipped in the optimized profile. Some bundled
// addon scripts still register JEI informational pages, so consume those
// registrations harmlessly when JEI is absent instead of logging an error.

if (!Platform.isLoaded('jei')) {
  // KubeJS gives each script pack a child scope. Put the compatibility object
  // on the shared parent scope so bundled addon scripts can resolve the bare
  // `JEIEvents` identifier even though JEI itself is intentionally absent.
  try {
    var icKubeJS = Java.loadClass('dev.latvian.mods.kubejs.KubeJS')
    var icClientScriptManager = icKubeJS.getClientScriptManager()
    var icJeiEventsShim = {
      information: function(callback) {
        console.info('[InsaneCraft] Skipped optional JEI information integration because JEI is not installed.')
      }
    }
    icClientScriptManager.context.addToScope(icClientScriptManager.topLevelScope, 'JEIEvents', icJeiEventsShim)
  } catch (error) {
    console.warn('[InsaneCraft] Could not install the optional JEI compatibility shim: ' + error)
  }
}
