Add integration of Harvest Moon with Mystical Agriculture. (#1766)

This commit is contained in:
Michał Dominiak 2021-01-25 06:11:51 -08:00 committed by GitHub
parent e5755c0a8c
commit e349c424bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -57,6 +57,8 @@ public class HarvestHandlerPlantable implements IHarvestHandler
addThirdPartyCrop("roots", "spirit_herb", 7);
addPamCrops();
addMysticalCrops();
}
@Override
@ -149,4 +151,40 @@ public class HarvestHandlerPlantable implements IHarvestHandler
BMLog.DEFAULT.error("HarvestCraft integration cancelled; crop name lookup broke");
}
}
private static void addMysticalCrops()
{
if (!ModList.get().isLoaded("mysticalagriculture"))
return;
try
{
Class<?> mysticalAPI = Class.forName("com.blakebr0.mysticalagriculture.api.MysticalAgricultureAPI");
Method getRegistry = mysticalAPI.getMethod("getCropRegistry");
Object registry = getRegistry.invoke(null);
Class<?> mysticalRegistry = Class.forName("com.blakebr0.mysticalagriculture.api.registry.ICropRegistry");
Method getCrops = mysticalRegistry.getMethod("getCrops");
@SuppressWarnings("unchecked")
List<Object> crops = (List<Object>) getCrops.invoke(registry);
Class<?> mysticalCrop = Class.forName("com.blakebr0.mysticalagriculture.api.crop.ICrop");
Method getCrop = mysticalCrop.getMethod("getCrop");
for (Object maCrop : crops)
{
CropsBlock crop = (CropsBlock) getCrop.invoke(maCrop);
HarvestRegistry.registerStandardCrop(crop, crop.getMaxAge());
}
} catch (ClassNotFoundException e)
{
BMLog.DEFAULT.error("MysticalAgriculture integration cancelled: unable to find a class: " + e.getMessage());
} catch (NoSuchMethodException e)
{
BMLog.DEFAULT.error("MysticalAgriculture integration cancelled: unable to find a method: " + e.getMessage());
} catch (IllegalAccessException | InvocationTargetException e)
{
BMLog.DEFAULT.error("MysticalAgriculture integration cancelled: failed to invoke a method: " + e.getMessage());
}
}
}