From c56f09897c68f2bb5630861c05fc17bd2aa479cb Mon Sep 17 00:00:00 2001 From: mezz Date: Sat, 15 Aug 2015 22:41:04 -0700 Subject: [PATCH] Move BoP integration to Forestry --- .../apiculture/flowers/FlowerRegistry.java | 2 +- .../forestry/plugins/PluginBiomesOPlenty.java | 139 ++++++++++++++++-- 2 files changed, 130 insertions(+), 11 deletions(-) diff --git a/src/main/java/forestry/apiculture/flowers/FlowerRegistry.java b/src/main/java/forestry/apiculture/flowers/FlowerRegistry.java index 2ce46d535..deab7a9fa 100644 --- a/src/main/java/forestry/apiculture/flowers/FlowerRegistry.java +++ b/src/main/java/forestry/apiculture/flowers/FlowerRegistry.java @@ -248,7 +248,7 @@ public final class FlowerRegistry implements IFlowerRegistry { @Override public Collection getFlowerTypes() { - return Sets.union(defaultFlowerTypes, registeredFlowers.keySet()); + return new ArrayList(Sets.union(defaultFlowerTypes, registeredFlowers.keySet())); } private TreeMap getChancesMap(String flowerType) { diff --git a/src/main/java/forestry/plugins/PluginBiomesOPlenty.java b/src/main/java/forestry/plugins/PluginBiomesOPlenty.java index 81e062163..249bad293 100644 --- a/src/main/java/forestry/plugins/PluginBiomesOPlenty.java +++ b/src/main/java/forestry/plugins/PluginBiomesOPlenty.java @@ -17,13 +17,22 @@ import net.minecraft.block.Block; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraftforge.oredict.OreDictionary; + import cpw.mods.fml.common.event.FMLInterModComms; import cpw.mods.fml.common.registry.GameData; import cpw.mods.fml.common.registry.GameRegistry; +import forestry.api.apiculture.FlowerManager; import forestry.api.farming.Farmables; +import forestry.api.recipes.RecipeManagers; +import forestry.api.storage.BackpackManager; +import forestry.core.GameMode; import forestry.core.config.Defaults; +import forestry.core.config.ForestryItem; +import forestry.core.fluids.Fluids; import forestry.core.proxy.Proxies; +import forestry.core.utils.RecipeUtil; import forestry.farming.logic.FarmableBasicFruit; import forestry.farming.logic.FarmableGenericCrop; import forestry.farming.logic.FarmableGenericSapling; @@ -33,6 +42,11 @@ public class PluginBiomesOPlenty extends ForestryPlugin { private static final String BoP = "BiomesOPlenty"; + private static Block saplings; + private static Block colorizedSaplings; + private static Item food; + private static ItemStack persimmon; + @Override public boolean isAvailable() { return Proxies.common.isModLoaded(BoP); @@ -43,21 +57,36 @@ public class PluginBiomesOPlenty extends ForestryPlugin { return "BiomesOPlenty not found"; } + @Override + protected void preInit() { + super.preInit(); + addFlowers(); + } + @Override public void doInit() { super.doInit(); - Block boPSaplings = GameRegistry.findBlock(BoP, "saplings"); - Block boPColorizedSaplings = GameRegistry.findBlock(BoP, "colorizedSaplings"); - Item boPTurnipSeeds = GameRegistry.findItem(BoP, "turnipSeeds"); - Block boPTurnip = GameRegistry.findBlock(BoP, "turnip"); + saplings = GameRegistry.findBlock(BoP, "saplings"); + colorizedSaplings = GameRegistry.findBlock(BoP, "colorizedSaplings"); + food = GameRegistry.findItem(BoP, "food"); + if (food != null) { + persimmon = new ItemStack(food, 1, 8); + } + addFarmCrops(); + addFermenterRecipes(); + addSqueezerRecipes(); + addBlocksToBackpack(); + } + + private static void addFarmCrops() { List saplingItemKeys = new ArrayList(); - if (boPSaplings != null) { + if (saplings != null) { saplingItemKeys.add("saplings"); } - if (boPColorizedSaplings != null) { + if (colorizedSaplings != null) { saplingItemKeys.add("colorizedSaplings"); } @@ -66,10 +95,100 @@ public class PluginBiomesOPlenty extends ForestryPlugin { String saplingName = GameData.getItemRegistry().getNameForObject(saplingItem); FMLInterModComms.sendMessage(Defaults.MOD, "add-farmable-sapling", String.format("farmArboreal@%s.-1", saplingName)); } - ItemStack BoPPersimmon = new ItemStack(GameRegistry.findItem(BoP, "food"), 1, 8); - Farmables.farmables.get("farmArboreal").add(new FarmableGenericSapling(boPSaplings, 15, BoPPersimmon)); - Farmables.farmables.get("farmVegetables").add(new FarmableGenericCrop(new ItemStack(boPTurnipSeeds, 1, 0), boPTurnip, 7)); - Farmables.farmables.get("farmOrchard").add(new FarmableBasicFruit(boPTurnip, 7)); + if (saplings != null && persimmon != null) { + Farmables.farmables.get("farmArboreal").add(new FarmableGenericSapling(saplings, 15, persimmon)); + } + + Block boPTurnip = GameRegistry.findBlock(BoP, "turnip"); + if (boPTurnip != null) { + Item boPTurnipSeeds = GameRegistry.findItem(BoP, "turnipSeeds"); + if (boPTurnipSeeds != null) { + Farmables.farmables.get("farmVegetables").add(new FarmableGenericCrop(new ItemStack(boPTurnipSeeds, 1, 0), boPTurnip, 7)); + } + + Farmables.farmables.get("farmOrchard").add(new FarmableBasicFruit(boPTurnip, 7)); + } } + + private static void addFermenterRecipes() { + int saplingYield = GameMode.getGameMode().getIntegerSetting("fermenter.yield.sapling"); + + if (saplings != null) { + RecipeUtil.injectLeveledRecipe(new ItemStack(saplings, 1, OreDictionary.WILDCARD_VALUE), saplingYield, Fluids.BIOMASS); + } + + if (colorizedSaplings != null) { + RecipeUtil.injectLeveledRecipe(new ItemStack(colorizedSaplings, 1, OreDictionary.WILDCARD_VALUE), saplingYield, Fluids.BIOMASS); + } + } + + private static void addSqueezerRecipes() { + if (food != null) { + RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{new ItemStack(food)}, Fluids.JUICE.getFluid(50), ForestryItem.mulch.getItemStack(), 5); + } + + if (persimmon != null) { + RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{persimmon}, Fluids.JUICE.getFluid(200), ForestryItem.mulch.getItemStack(), 20); + } + } + + private static void addFlowers() { + Block flowers = GameRegistry.findBlock(BoP, "flowers"); + if (flowers != null) { + FlowerManager.flowerRegistry.registerPlantableFlower(flowers, OreDictionary.WILDCARD_VALUE, 1.0, FlowerManager.FlowerTypeVanilla); + } + + Block flowers2 = GameRegistry.findBlock(BoP, "flowers2"); + if (flowers2 != null) { + FlowerManager.flowerRegistry.registerPlantableFlower(flowers2, OreDictionary.WILDCARD_VALUE, 1.0, FlowerManager.FlowerTypeVanilla); + } + } + + private static void addBlocksToBackpack() { + // most blocks are covered by the oreDictionary + + final int MINER = 0; + final int DIGGER = 1; + final int FORESTER = 2; + + addBlocksToBackpack(MINER, + "driedDirt", + "overgrownNetherrack", + "cragRock", + "ashStone" + ); + + addBlocksToBackpack(DIGGER, + "bopGrass", + "newBopGrass", + "longGrass", + "mud", + "hardDirt", + "hardSand", + "originGrass", + "ash", + "newBopDirt" + ); + + addBlocksToBackpack(FORESTER, + "petals" + ); + } + + private static void addBlocksToBackpack(int backpackId, String... blockNames) { + for (String blockName : blockNames) { + addBlockToBackpack(backpackId, blockName, OreDictionary.WILDCARD_VALUE); + } + } + + private static void addBlockToBackpack(int backpackId, String blockName, int meta) { + Block block = GameRegistry.findBlock(BoP, blockName); + if (block != null) { + BackpackManager.backpackItems[backpackId].add(new ItemStack(block, 1, meta)); + } else { + Proxies.log.warning("Missing block: ", blockName); + } + } + }