diff --git a/src/main/java/forestry/plugins/ForestryPluginUids.java b/src/main/java/forestry/plugins/ForestryPluginUids.java index 1659b5c1e..b9b9b66c0 100644 --- a/src/main/java/forestry/plugins/ForestryPluginUids.java +++ b/src/main/java/forestry/plugins/ForestryPluginUids.java @@ -27,4 +27,5 @@ public class ForestryPluginUids { public static final String INDUSTRIALCRAFT2 = "forestry.industrialcraft2"; public static final String ACT_ADD = "forestry.actuallyadditions"; public static final String HARVESTCRAFT = "forestry.harvestcraft"; + public static final String IMMERSIVE_ENGINEERING = "forestry.immersiveengineering"; } diff --git a/src/main/java/forestry/plugins/compat/PluginImmersiveEngineering.java b/src/main/java/forestry/plugins/compat/PluginImmersiveEngineering.java new file mode 100644 index 000000000..e63e73efb --- /dev/null +++ b/src/main/java/forestry/plugins/compat/PluginImmersiveEngineering.java @@ -0,0 +1,89 @@ +package forestry.plugins.compat; + +import forestry.api.core.ForestryAPI; +import forestry.api.farming.Farmables; +import forestry.api.farming.ICrop; +import forestry.api.recipes.RecipeManagers; +import forestry.core.config.Constants; +import forestry.core.fluids.Fluids; +import forestry.core.utils.ModUtil; +import forestry.farming.logic.CropDestroy; +import forestry.farming.logic.FarmableBase; +import forestry.plugins.BlankForestryPlugin; +import forestry.plugins.ForestryPlugin; +import forestry.plugins.ForestryPluginUids; +import net.minecraft.block.Block; +import net.minecraft.block.properties.IProperty; +import net.minecraft.block.state.IBlockState; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.fml.common.registry.ForgeRegistries; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +@ForestryPlugin(pluginID = ForestryPluginUids.IMMERSIVE_ENGINEERING, name = "ImmersiveEngineering", author = "marcin212", url = Constants.URL, unlocalizedDescription = "for.plugin.immersiveengineering.description") +public class PluginImmersiveEngineering extends BlankForestryPlugin { + private static final String IE = "immersiveengineering"; + + @Override + public boolean isAvailable() { + return ModUtil.isModLoaded(IE); + } + + @Override + public String getFailMessage() { + return "ImmersiveEngineering not found"; + } + + @Override + public void postInit() { + ItemStack hempSeed = getItemStack("seed"); + Block hempCrop = getBlock("hemp"); + int seedAmount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.seed"); + IProperty age = hempCrop.getBlockState().getProperties().stream().filter(p -> p.getName().equals("type")).findAny().get(); + + if (hempSeed != null && hempCrop != null && age != null) { + IBlockState planted = hempCrop.getDefaultState().withProperty(age, (Comparable) age.parseValue("bottom0").get()); + IBlockState mature = hempCrop.getDefaultState().withProperty(age, (Comparable) age.parseValue("top0").get()); + Farmables.farmables.get("farmWheat").add(new FarmableBase(hempSeed, planted, mature, false) { + @Override + public ICrop getCropAt(World world, BlockPos pos, IBlockState blockState) { + IBlockState stateUp = world.getBlockState(pos.up()); + if (stateUp != matureState) { + return null; + } + return new CropDestroy(world, stateUp, pos.up(), null); + } + }); + + RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{hempSeed}, Fluids.SEED_OIL.getFluid(seedAmount)); + } + } + + private static Block getBlock(@Nonnull String blockName) { + ResourceLocation key = new ResourceLocation(IE, blockName); + if (ForgeRegistries.BLOCKS.containsKey(key)) { + return ForgeRegistries.BLOCKS.getValue(key); + } else { + return null; + } + } + + @Nullable + private static ItemStack getItemStack(@Nonnull String itemName, int meta) { + ResourceLocation key = new ResourceLocation(IE, itemName); + if (ForgeRegistries.ITEMS.containsKey(key)) { + return new ItemStack(ForgeRegistries.ITEMS.getValue(key), 1, meta); + } else { + return null; + } + } + + @Nullable + private static ItemStack getItemStack(@Nonnull String itemName) { + return getItemStack(itemName, 0); + } +}