diff --git a/src/main/java/forestry/api/core/ForestryAPI.java b/src/main/java/forestry/api/core/ForestryAPI.java index 15267f529..7b2e3840e 100644 --- a/src/main/java/forestry/api/core/ForestryAPI.java +++ b/src/main/java/forestry/api/core/ForestryAPI.java @@ -8,6 +8,8 @@ package forestry.api.core; import java.util.Set; import forestry.api.climate.IClimateManager; +import forestry.api.farming.IFarmRegistry; +import forestry.api.farming.ISimpleFarmLogic; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -47,6 +49,11 @@ public class ForestryAPI { public static IClimateManager climateManager; + /** + * A registry for register fertilizers, {@link IFarmabeles}s and {@link ISimpleFarmLogic}s + */ + public static IFarmRegistry farmRegistry; + /** * The currently active {@link IGameMode}. */ diff --git a/src/main/java/forestry/api/farming/Farmables.java b/src/main/java/forestry/api/farming/Farmables.java index 1b811c041..9dc94f9d8 100644 --- a/src/main/java/forestry/api/farming/Farmables.java +++ b/src/main/java/forestry/api/farming/Farmables.java @@ -10,6 +10,8 @@ import java.util.Map; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; + +import forestry.api.core.ForestryAPI; import net.minecraft.item.ItemStack; public class Farmables { @@ -17,9 +19,15 @@ public class Farmables { * Can be used to add IFarmables to some of the vanilla farm logics. *

* Identifiers: farmArboreal farmWheat farmGourd farmInfernal farmPoales farmSucculentes farmVegetables farmShroom + * @deprecated Please use {@link IFarmRegistry#registerFarmables(String, IFarmable...)} and {@link IFarmRegistry#getFarmables(String)}. */ + @Deprecated public static final Multimap farmables = HashMultimap.create(); + /** + * @deprecated Please use {@link IFarmRegistry#registerFertilizer(ItemStack, int)} and {@link IFarmRegistry#getFertilizeValue(ItemStack)}. + */ + @Deprecated public static final Map fertilizers = new LinkedHashMap<>(); } diff --git a/src/main/java/forestry/api/farming/IFarmRegistry.java b/src/main/java/forestry/api/farming/IFarmRegistry.java new file mode 100644 index 000000000..a3a0b8f0d --- /dev/null +++ b/src/main/java/forestry/api/farming/IFarmRegistry.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright 2011-2014 SirSengir + * + * This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details. + ******************************************************************************/ +package forestry.api.farming; + +import java.util.Collection; + +import net.minecraft.item.ItemStack; + +public interface IFarmRegistry { + + /** + * Can be used to add IFarmables to some of the vanilla farm logics. + *

+ * Identifiers: farmArboreal farmWheat farmGourd farmInfernal farmPoales farmSucculentes farmVegetables farmShroom + */ + void registerFarmables(String identifier, IFarmable... farmable); + + Collection getFarmables(String identifier); + + /** + * Can be used to create a simple version of a farm logic, like the vanilla vegetable or wheat farm logic. + */ + IFarmLogic createLogic(ISimpleFarmLogic simpleFarmLogic); + + /** + * + * @param itemStack + * @param value The value of the fertitlizer.The value of the forestry fertelizer is 500. + */ + void registerFertilizer(ItemStack itemStack, int value); + + /** + * @return The value of the fertitlizer + */ + int getFertilizeValue(ItemStack itemStack); + +} diff --git a/src/main/java/forestry/api/farming/ISimpleFarmLogic.java b/src/main/java/forestry/api/farming/ISimpleFarmLogic.java new file mode 100644 index 000000000..10fef9191 --- /dev/null +++ b/src/main/java/forestry/api/farming/ISimpleFarmLogic.java @@ -0,0 +1,19 @@ +package forestry.api.farming; + +import net.minecraft.item.ItemStack; + +/** + * A simple version of the IFarmLogic. + */ +public interface ISimpleFarmLogic { + + /** + * @return the itemStack that represents this farm logic. Used as an icon for the farm logic. + */ + ItemStack getIconItemStack(); + + Iterable getSeeds(); + + String getName(); + +} diff --git a/src/main/java/forestry/farming/FarmRegistry.java b/src/main/java/forestry/farming/FarmRegistry.java new file mode 100644 index 000000000..fec54bba6 --- /dev/null +++ b/src/main/java/forestry/farming/FarmRegistry.java @@ -0,0 +1,113 @@ +package forestry.farming; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.Map.Entry; + +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Multimap; + +import forestry.api.core.ForestryAPI; +import forestry.api.core.ISpriteRegister; +import forestry.api.farming.Farmables; +import forestry.api.farming.IFarmLogic; +import forestry.api.farming.IFarmRegistry; +import forestry.api.farming.IFarmable; +import forestry.api.farming.ISimpleFarmLogic; +import forestry.core.config.LocalizedConfiguration; +import forestry.core.render.TextureManagerForestry; +import forestry.core.render.TextureMapForestry; +import forestry.core.utils.ItemStackUtil; +import forestry.core.utils.Log; +import forestry.core.utils.Translator; +import forestry.farming.logic.FarmLogicSimple; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.config.Property; +import net.minecraftforge.oredict.OreDictionary; +import scala.actors.threadpool.Arrays; + +public final class FarmRegistry implements IFarmRegistry { + + private static final FarmRegistry INSTANCE = new FarmRegistry(); + private final Multimap farmables = HashMultimap.create(); + private final Map fertilizers = new LinkedHashMap<>(); + + static { + ForestryAPI.farmRegistry = INSTANCE; + } + + public static FarmRegistry getInstance() { + return INSTANCE; + } + + @Override + public void registerFarmables(String identifier, IFarmable... farmablesArray) { + farmables.putAll(identifier, Arrays.asList(farmablesArray)); + } + + @Override + public Collection getFarmables(String identifier) { + return farmables.get(identifier); + } + + @Override + public IFarmLogic createLogic(ISimpleFarmLogic simpleFarmLogic) { + return new FarmLogicSimple(simpleFarmLogic); + } + + @Override + public void registerFertilizer(ItemStack itemStack, int value) { + fertilizers.put(itemStack, value); + } + + @Override + public int getFertilizeValue(ItemStack itemStack) { + for (Entry fertilizer : fertilizers.entrySet()) { + ItemStack fertilizerStack = fertilizer.getKey(); + if (itemStack.getItem() == fertilizerStack.getItem() + && (fertilizerStack.getItemDamage() == itemStack.getItemDamage() + || fertilizerStack.getItemDamage() == OreDictionary.WILDCARD_VALUE)) { + return fertilizer.getValue(); + } + } + return 0; + } + + public void loadConfig(LocalizedConfiguration config) { + List defaultFertilizers = new ArrayList<>(getItemStrings()); + Collections.sort(defaultFertilizers); + String[] defaultSortedFertilizers = defaultFertilizers.toArray(new String[defaultFertilizers.size()]); + Property fertilizerConf = config.get("fertilizers", "items", defaultSortedFertilizers, Translator.translateToLocal("for.config.farm.fertilizers.items")); + + fertilizers.clear(); + String[] fertilizerList = fertilizerConf.getStringList(); + for (int i = 0; i < fertilizerList.length; i++) { + try { + String fertilizer = fertilizerList[i]; + String[] fertilizers = fertilizer.split(";"); + ItemStack fertilizerItem = ItemStackUtil.parseItemStackString(fertilizers[0], OreDictionary.WILDCARD_VALUE); + int fertilizerValue = Integer.parseInt(fertilizers[1]); + registerFertilizer(fertilizerItem, fertilizerValue); + } catch (Exception e) { + Log.error("Forestry failed to parse a fertilizer entry at the farm config, at the position " + i + ".", e); + } + } + } + + private Set getItemStrings() { + Set itemStrings = new HashSet<>(fertilizers.size()); + for (Entry itemStack : fertilizers.entrySet()) { + String itemString = ItemStackUtil.getStringForItemStack(itemStack.getKey()); + itemString += ";" + itemStack.getValue(); + itemStrings.add(itemString); + } + return itemStrings; + } + +} diff --git a/src/main/java/forestry/farming/PluginFarming.java b/src/main/java/forestry/farming/PluginFarming.java index 99e4bd34e..6b2450153 100644 --- a/src/main/java/forestry/farming/PluginFarming.java +++ b/src/main/java/forestry/farming/PluginFarming.java @@ -29,6 +29,7 @@ import forestry.api.circuits.CircuitSocketType; import forestry.api.circuits.ICircuitLayout; import forestry.api.core.ForestryAPI; import forestry.api.farming.Farmables; +import forestry.api.farming.IFarmRegistry; import forestry.core.PluginCore; import forestry.core.circuits.CircuitLayout; import forestry.core.circuits.Circuits; @@ -118,42 +119,42 @@ public class PluginFarming extends BlankForestryPlugin { BlockRegistryFarming blocks = getBlocks(); MinecraftForge.EVENT_BUS.register(this); - - Farmables.farmables.put("farmArboreal", new FarmableVanillaSapling()); + IFarmRegistry registry = FarmRegistry.getInstance(); + + registry.registerFarmables("farmArboreal", new FarmableVanillaSapling()); if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.ARBORICULTURE)) { - Farmables.farmables.put("farmArboreal", new FarmableGE()); + registry.registerFarmables("farmArboreal", new FarmableGE()); } - Farmables.farmables.putAll("farmOrchard", Arrays.asList( + registry.registerFarmables("farmOrchard", new FarmableAgingCrop(new ItemStack(Items.WHEAT_SEEDS), Blocks.WHEAT, BlockCrops.AGE, 7, 0), new FarmableAgingCrop(new ItemStack(Items.POTATO), Blocks.POTATOES, BlockCrops.AGE, 7, 0), new FarmableAgingCrop(new ItemStack(Items.CARROT), Blocks.CARROTS, BlockCrops.AGE, 7, 0), - new FarmableAgingCrop(new ItemStack(Items.BEETROOT_SEEDS), Blocks.BEETROOTS, BlockBeetroot.BEETROOT_AGE, 3, 0) - )); + new FarmableAgingCrop(new ItemStack(Items.BEETROOT_SEEDS), Blocks.BEETROOTS, BlockBeetroot.BEETROOT_AGE, 3, 0)); IBlockState plantedBrownMushroom = blocks.mushroom.getDefaultState().withProperty(BlockMushroom.VARIANT, BlockMushroom.MushroomType.BROWN); - Farmables.farmables.put("farmShroom", new FarmableVanillaMushroom(new ItemStack(Blocks.BROWN_MUSHROOM), plantedBrownMushroom, Blocks.BROWN_MUSHROOM_BLOCK)); + registry.registerFarmables("farmShroom", new FarmableVanillaMushroom(new ItemStack(Blocks.BROWN_MUSHROOM), plantedBrownMushroom, Blocks.BROWN_MUSHROOM_BLOCK)); IBlockState plantedRedMushroom = blocks.mushroom.getDefaultState().withProperty(BlockMushroom.VARIANT, BlockMushroom.MushroomType.RED); - Farmables.farmables.put("farmShroom", new FarmableVanillaMushroom(new ItemStack(Blocks.RED_MUSHROOM), plantedRedMushroom, Blocks.RED_MUSHROOM_BLOCK)); + registry.registerFarmables("farmShroom", new FarmableVanillaMushroom(new ItemStack(Blocks.RED_MUSHROOM), plantedRedMushroom, Blocks.RED_MUSHROOM_BLOCK)); - Farmables.farmables.put("farmWheat", new FarmableAgingCrop(new ItemStack(Items.WHEAT_SEEDS), Blocks.WHEAT, BlockCrops.AGE, 7)); + registry.registerFarmables("farmWheat", new FarmableAgingCrop(new ItemStack(Items.WHEAT_SEEDS), Blocks.WHEAT, BlockCrops.AGE, 7)); - Farmables.farmables.put("farmGourd", new FarmableGourd(new ItemStack(Items.PUMPKIN_SEEDS), Blocks.PUMPKIN_STEM, Blocks.PUMPKIN)); - Farmables.farmables.put("farmGourd", new FarmableGourd(new ItemStack(Items.MELON_SEEDS), Blocks.MELON_STEM, Blocks.MELON_BLOCK)); + registry.registerFarmables("farmGourd", new FarmableGourd(new ItemStack(Items.PUMPKIN_SEEDS), Blocks.PUMPKIN_STEM, Blocks.PUMPKIN)); + registry.registerFarmables("farmGourd", new FarmableGourd(new ItemStack(Items.MELON_SEEDS), Blocks.MELON_STEM, Blocks.MELON_BLOCK)); - Farmables.farmables.put("farmInfernal", new FarmableAgingCrop(new ItemStack(Items.NETHER_WART), Blocks.NETHER_WART, BlockNetherWart.AGE, 3)); + registry.registerFarmables("farmInfernal", new FarmableAgingCrop(new ItemStack(Items.NETHER_WART), Blocks.NETHER_WART, BlockNetherWart.AGE, 3)); - Farmables.farmables.put("farmPoales", new FarmableStacked(new ItemStack(Items.REEDS), Blocks.REEDS, 3)); + registry.registerFarmables("farmPoales", new FarmableStacked(new ItemStack(Items.REEDS), Blocks.REEDS, 3)); - Farmables.farmables.put("farmSucculentes", new FarmableStacked(new ItemStack(Blocks.CACTUS), Blocks.CACTUS, 3)); + registry.registerFarmables("farmSucculentes", new FarmableStacked(new ItemStack(Blocks.CACTUS), Blocks.CACTUS, 3)); - Farmables.farmables.put("farmVegetables", new FarmableAgingCrop(new ItemStack(Items.POTATO), Blocks.POTATOES, BlockCrops.AGE, 7)); - Farmables.farmables.put("farmVegetables", new FarmableAgingCrop(new ItemStack(Items.CARROT), Blocks.CARROTS, BlockCrops.AGE, 7)); - Farmables.farmables.put("farmVegetables", new FarmableAgingCrop(new ItemStack(Items.BEETROOT_SEEDS), Blocks.BEETROOTS, BlockBeetroot.BEETROOT_AGE, 3)); + registry.registerFarmables("farmVegetables", new FarmableAgingCrop(new ItemStack(Items.POTATO), Blocks.POTATOES, BlockCrops.AGE, 7)); + registry.registerFarmables("farmVegetables", new FarmableAgingCrop(new ItemStack(Items.CARROT), Blocks.CARROTS, BlockCrops.AGE, 7)); + registry.registerFarmables("farmVegetables", new FarmableAgingCrop(new ItemStack(Items.BEETROOT_SEEDS), Blocks.BEETROOTS, BlockBeetroot.BEETROOT_AGE, 3)); //Forestry fertilizer - Farmables.fertilizers.put(new ItemStack(coreItems.fertilizerCompound, 1, OreDictionary.WILDCARD_VALUE), 500); + registry.registerFertilizer(new ItemStack(coreItems.fertilizerCompound, 1, OreDictionary.WILDCARD_VALUE), 500); proxy.initializeModels(); @@ -164,37 +165,6 @@ public class PluginFarming extends BlankForestryPlugin { ChipsetManager.circuitRegistry.registerLayout(layoutManual); } - private void loadConfig(LocalizedConfiguration config) { - List defaultFertilizers = new ArrayList<>(getItemStrings(Farmables.fertilizers)); - Collections.sort(defaultFertilizers); - String[] defaultSortedFertilizers = defaultFertilizers.toArray(new String[defaultFertilizers.size()]); - Property fertilizerConf = config.get("fertilizers", "items", defaultSortedFertilizers, Translator.translateToLocal("for.config.farm.fertilizers.items")); - - Farmables.fertilizers.clear(); - String[] fertilizerList = fertilizerConf.getStringList(); - for (int i = 0; i < fertilizerList.length; i++) { - try { - String fertilizer = fertilizerList[i]; - String[] fertilizers = fertilizer.split(";"); - ItemStack fertilizerItem = ItemStackUtil.parseItemStackString(fertilizers[0], OreDictionary.WILDCARD_VALUE); - int fertilizerValue = Integer.parseInt(fertilizers[1]); - Farmables.fertilizers.put(fertilizerItem, fertilizerValue); - } catch (Exception e) { - Log.error("Forestry failed to parse a fertilizer entry at the farm config, at the position " + i + ".", e); - } - } - } - - private static Set getItemStrings(Map itemStacks) { - Set itemStrings = new HashSet<>(itemStacks.size()); - for (Entry itemStack : itemStacks.entrySet()) { - String itemString = ItemStackUtil.getStringForItemStack(itemStack.getKey()); - itemString += ";" + itemStack.getValue(); - itemStrings.add(itemString); - } - return itemStrings; - } - @Override public void registerTriggers() { FarmingTriggers.initialize(); @@ -207,7 +177,7 @@ public class PluginFarming extends BlankForestryPlugin { //Load config File configFile = new File(Forestry.instance.getConfigFolder(), Config.CATEGORY_FARM + ".cfg"); LocalizedConfiguration config = new LocalizedConfiguration(configFile, "1.0.0"); - loadConfig(config); + FarmRegistry.getInstance().loadConfig(config); config.save(); GameRegistry.registerTileEntity(TileFarmPlain.class, "forestry.Farm"); diff --git a/src/main/java/forestry/farming/logic/FarmLogicArboreal.java b/src/main/java/forestry/farming/logic/FarmLogicArboreal.java index eaab5ad6e..a9a2a5785 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicArboreal.java +++ b/src/main/java/forestry/farming/logic/FarmLogicArboreal.java @@ -25,6 +25,7 @@ import forestry.api.farming.ICrop; import forestry.api.farming.IFarmHousing; import forestry.api.farming.IFarmable; import forestry.core.PluginCore; +import forestry.farming.FarmRegistry; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; @@ -38,7 +39,7 @@ public class FarmLogicArboreal extends FarmLogicHomogeneous { } public FarmLogicArboreal() { - super(new ItemStack(Blocks.DIRT), PluginCore.getBlocks().humus.getDefaultState(), Farmables.farmables.get("farmArboreal")); + super(new ItemStack(Blocks.DIRT), PluginCore.getBlocks().humus.getDefaultState(), FarmRegistry.getInstance().getFarmables("farmArboreal")); } @Override diff --git a/src/main/java/forestry/farming/logic/FarmLogicSimple.java b/src/main/java/forestry/farming/logic/FarmLogicSimple.java new file mode 100644 index 000000000..d4a5093e5 --- /dev/null +++ b/src/main/java/forestry/farming/logic/FarmLogicSimple.java @@ -0,0 +1,26 @@ +package forestry.farming.logic; + +import forestry.api.farming.IFarmable; +import forestry.api.farming.ISimpleFarmLogic; +import net.minecraft.item.ItemStack; + +public class FarmLogicSimple extends FarmLogicCrops { + + protected final ISimpleFarmLogic simpleLogic; + + public FarmLogicSimple(ISimpleFarmLogic simpleLogic) { + super(simpleLogic.getSeeds()); + this.simpleLogic = simpleLogic; + } + + @Override + public String getName() { + return simpleLogic.getName(); + } + + @Override + public ItemStack getIconItemStack() { + return simpleLogic.getIconItemStack(); + } + +} diff --git a/src/main/java/forestry/farming/multiblock/InventoryFarm.java b/src/main/java/forestry/farming/multiblock/InventoryFarm.java index 0cfeb18d4..b7833bf60 100644 --- a/src/main/java/forestry/farming/multiblock/InventoryFarm.java +++ b/src/main/java/forestry/farming/multiblock/InventoryFarm.java @@ -26,6 +26,7 @@ import forestry.core.inventory.wrappers.InventoryMapper; import forestry.core.utils.InventoryUtil; import forestry.core.utils.PlayerUtil; import forestry.core.utils.SlotUtil; +import forestry.farming.FarmRegistry; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; @@ -138,14 +139,8 @@ public class InventoryFarm extends InventoryAdapterRestricted implements IFarmIn if (itemstack.isEmpty()) { return false; } - - for (Entry fertilizer : Farmables.fertilizers.entrySet()) { - ItemStack fertilizerItem = fertilizer.getKey(); - if (itemstack.getItem() == fertilizerItem.getItem() && (fertilizerItem.getItemDamage() == itemstack.getItemDamage() || fertilizerItem.getItemDamage() == OreDictionary.WILDCARD_VALUE)) { - return true; - } - } - return false; + + return FarmRegistry.getInstance().getFertilizeValue(itemstack) > 0; } @Override @@ -221,11 +216,9 @@ public class InventoryFarm extends InventoryAdapterRestricted implements IFarmIn return 0; } - for (Entry fertilizer : Farmables.fertilizers.entrySet()) { - ItemStack fertilizerItem = fertilizer.getKey(); - if (fertilizerStack.getItem() == fertilizerItem.getItem() && (fertilizerItem.getItemDamage() == fertilizerStack.getItemDamage() || fertilizerItem.getItemDamage() == OreDictionary.WILDCARD_VALUE)) { - return fertilizer.getValue() * FERTILIZER_MODIFIER; - } + int fertilizerValue = FarmRegistry.getInstance().getFertilizeValue(fertilizerStack); + if(fertilizerValue > 0){ + return fertilizerValue * FERTILIZER_MODIFIER; } return 0; } diff --git a/src/main/java/forestry/plugins/compat/PluginActuallyAdditions.java b/src/main/java/forestry/plugins/compat/PluginActuallyAdditions.java index 1197e9f85..5700302d8 100644 --- a/src/main/java/forestry/plugins/compat/PluginActuallyAdditions.java +++ b/src/main/java/forestry/plugins/compat/PluginActuallyAdditions.java @@ -9,6 +9,7 @@ import forestry.api.recipes.RecipeManagers; import forestry.core.fluids.Fluids; import forestry.core.utils.Log; import forestry.core.utils.ModUtil; +import forestry.farming.FarmRegistry; import forestry.farming.logic.FarmableAgingCrop; import forestry.plugins.BlankForestryPlugin; import forestry.plugins.ForestryPlugin; @@ -84,9 +85,9 @@ public class PluginActuallyAdditions extends BlankForestryPlugin { Block plantBlock = getBlock(blockName); if (plantBlock != null) { FarmableAgingCrop crop = new FarmableAgingCrop(new ItemStack(seedItem), plantBlock, BlockCrops.AGE, 7); - Farmables.farmables.get("farmWheat").add(crop); + FarmRegistry.getInstance().registerFarmables("farmWheat", crop); FarmableAgingCrop cropOrchard = new FarmableAgingCrop(new ItemStack(seedItem), plantBlock, BlockCrops.AGE, 7, 0); - Farmables.farmables.get("farmOrchard").add(cropOrchard); + FarmRegistry.getInstance().registerFarmables("farmOrchard", cropOrchard); } } } diff --git a/src/main/java/forestry/plugins/compat/PluginExtraUtilities.java b/src/main/java/forestry/plugins/compat/PluginExtraUtilities.java index ef671fc8d..84da4a298 100644 --- a/src/main/java/forestry/plugins/compat/PluginExtraUtilities.java +++ b/src/main/java/forestry/plugins/compat/PluginExtraUtilities.java @@ -24,6 +24,7 @@ import forestry.core.items.EnumElectronTube; import forestry.core.utils.BlockUtil; import forestry.core.utils.Log; import forestry.core.utils.ModUtil; +import forestry.farming.FarmRegistry; import forestry.farming.circuits.CircuitFarmLogic; import forestry.farming.logic.FarmLogicEnder; import forestry.farming.logic.FarmableAgingCrop; @@ -72,7 +73,7 @@ public class PluginExtraUtilities extends BlankForestryPlugin { } else { int harvestAge = Collections.max(growthProperty.getAllowedValues()); int replantAge = enderLillyBlock.getDefaultState().getValue(growthProperty); - Farmables.farmables.put("farmEnder", new FarmableAgingCrop(new ItemStack(enderLillyItem), enderLillyBlock, growthProperty, harvestAge, replantAge)); + FarmRegistry.getInstance().registerFarmables("farmEnder", new FarmableAgingCrop(new ItemStack(enderLillyItem), enderLillyBlock, growthProperty, harvestAge, replantAge)); Circuits.farmEnderManaged = new CircuitFarmLogic("managedEnder", new FarmLogicEnder()); } } diff --git a/src/main/java/forestry/plugins/compat/PluginHarvestCraft.java b/src/main/java/forestry/plugins/compat/PluginHarvestCraft.java index 3205f6ce6..1bc1a6a50 100644 --- a/src/main/java/forestry/plugins/compat/PluginHarvestCraft.java +++ b/src/main/java/forestry/plugins/compat/PluginHarvestCraft.java @@ -15,6 +15,7 @@ import javax.annotation.Nullable; import com.google.common.collect.ImmutableList; import forestry.api.core.ForestryAPI; import forestry.api.farming.Farmables; +import forestry.api.farming.IFarmRegistry; import forestry.api.fuels.FuelManager; import forestry.api.fuels.MoistenerFuel; import forestry.api.recipes.RecipeManagers; @@ -25,6 +26,7 @@ import forestry.core.fluids.Fluids; import forestry.core.items.ItemRegistryCore; import forestry.core.recipes.RecipeUtil; import forestry.core.utils.ModUtil; +import forestry.farming.FarmRegistry; import forestry.farming.logic.FarmableAgingCrop; import forestry.plugins.BlankForestryPlugin; import forestry.plugins.ForestryPlugin; @@ -205,6 +207,8 @@ public class PluginHarvestCraft extends BlankForestryPlugin { genericCropsBuilder.addAll(herbs); genericCropsBuilder.addAll(spices); + IFarmRegistry farmRegistry = FarmRegistry.getInstance(); + ImmutableList genericCrops = genericCropsBuilder.build(); ImmutableList.Builder plants = ImmutableList.builder(); @@ -227,8 +231,8 @@ public class PluginHarvestCraft extends BlankForestryPlugin { RecipeManagers.squeezerManager.addRecipe(10, berrySeed, Fluids.SEED_OIL.getFluid(seedamount)); } if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FARMING) && berrySeed != null && berryBlock != null) { - Farmables.farmables.get("farmWheat").add(new FarmableAgingCrop(berrySeed, berryBlock, plantAGE, 3)); - Farmables.farmables.get("farmOrchard").add(new FarmableAgingCrop(berrySeed, berryBlock, plantAGE, 3, 0)); + farmRegistry.registerFarmables("farmWheat", new FarmableAgingCrop(berrySeed, berryBlock, plantAGE, 3)); + farmRegistry.registerFarmables("farmOrchard", new FarmableAgingCrop(berrySeed, berryBlock, plantAGE, 3, 0)); } plants.add(berryName); } @@ -245,8 +249,8 @@ public class PluginHarvestCraft extends BlankForestryPlugin { RecipeManagers.squeezerManager.addRecipe(10, fruitSeed, Fluids.SEED_OIL.getFluid(seedamount)); } if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FARMING) && fruitSeed != null && fruitBlock != null) { - Farmables.farmables.get("farmWheat").add(new FarmableAgingCrop(fruitSeed, fruitBlock, plantAGE, 3)); - Farmables.farmables.get("farmOrchard").add(new FarmableAgingCrop(fruitSeed, fruitBlock, plantAGE, 3, 0)); + farmRegistry.registerFarmables("farmWheat", new FarmableAgingCrop(fruitSeed, fruitBlock, plantAGE, 3)); + farmRegistry.registerFarmables("farmOrchard", new FarmableAgingCrop(fruitSeed, fruitBlock, plantAGE, 3, 0)); } plants.add(fruitName); } @@ -264,8 +268,8 @@ public class PluginHarvestCraft extends BlankForestryPlugin { RecipeManagers.squeezerManager.addRecipe(10, vegetableSeed, Fluids.SEED_OIL.getFluid(seedamount)); } if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FARMING) && vegetableSeed != null && vegetableBlock != null) { - Farmables.farmables.get("farmVegetables").add(new FarmableAgingCrop(vegetableSeed, vegetableBlock, plantAGE, 3)); - Farmables.farmables.get("farmOrchard").add(new FarmableAgingCrop(vegetableSeed, vegetableBlock, plantAGE, 3, 0)); + farmRegistry.registerFarmables("farmVegetables", new FarmableAgingCrop(vegetableSeed, vegetableBlock, plantAGE, 3)); + farmRegistry.registerFarmables("farmOrchard", new FarmableAgingCrop(vegetableSeed, vegetableBlock, plantAGE, 3, 0)); } plants.add(vegetableName); } @@ -284,8 +288,8 @@ public class PluginHarvestCraft extends BlankForestryPlugin { RecipeManagers.moistenerManager.addRecipe(grainSeed, new ItemStack(Blocks.MYCELIUM), 5000); } if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FARMING) && grainSeed != null && grainBlock != null) { - Farmables.farmables.get("farmWheat").add(new FarmableAgingCrop(grainSeed, grainBlock, plantAGE, 3)); - Farmables.farmables.get("farmOrchard").add(new FarmableAgingCrop(grainSeed, grainBlock, plantAGE, 3, 0)); + farmRegistry.registerFarmables("farmWheat", new FarmableAgingCrop(grainSeed, grainBlock, plantAGE, 3)); + farmRegistry.registerFarmables("farmOrchard", new FarmableAgingCrop(grainSeed, grainBlock, plantAGE, 3, 0)); } plants.add(grainName); } @@ -294,7 +298,7 @@ public class PluginHarvestCraft extends BlankForestryPlugin { ItemStack treeFruit = getItemStack(treeFruitName + "Item"); Block treeFruitBlock = getBlock("pam" + (Character.toUpperCase(treeFruitName.charAt(0)) + treeFruitName.substring(1))); if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FARMING) && treeFruitBlock != null) { - Farmables.farmables.get("farmOrchard").add(new FarmableAgingCrop(ItemStack.EMPTY, treeFruitBlock, fruitAGE, 2, 0)); + farmRegistry.registerFarmables("farmOrchard", new FarmableAgingCrop(ItemStack.EMPTY, treeFruitBlock, fruitAGE, 2, 0)); } if (treeFruit != null) { RecipeManagers.squeezerManager.addRecipe(10, treeFruit, Fluids.JUICE.getFluid(juiceAmount)); @@ -305,7 +309,7 @@ public class PluginHarvestCraft extends BlankForestryPlugin { for (String treeName : trees) { Block fruitBlock = getBlock("pam" + (Character.toUpperCase(treeName.charAt(0)) + treeName.substring(1))); if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FARMING) && fruitBlock != null) { - Farmables.farmables.get("farmOrchard").add(new FarmableAgingCrop(ItemStack.EMPTY, fruitBlock, fruitAGE, 2, 0)); + farmRegistry.registerFarmables("farmOrchard", new FarmableAgingCrop(ItemStack.EMPTY, fruitBlock, fruitAGE, 2, 0)); } plants.add(treeName); } @@ -313,7 +317,7 @@ public class PluginHarvestCraft extends BlankForestryPlugin { for (String treeName : treesSpecial) { Block fruitBlock = getBlock("pam" + (Character.toUpperCase(treeName.charAt(0)) + treeName.substring(1))); if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FARMING) && fruitBlock != null) { - Farmables.farmables.get("farmOrchard").add(new FarmableAgingCrop(ItemStack.EMPTY, fruitBlock, fruitAGE, 2, 0)); + farmRegistry.registerFarmables("farmOrchard", new FarmableAgingCrop(ItemStack.EMPTY, fruitBlock, fruitAGE, 2, 0)); } } @@ -324,8 +328,8 @@ public class PluginHarvestCraft extends BlankForestryPlugin { RecipeManagers.squeezerManager.addRecipe(10, genericCropSeed, Fluids.SEED_OIL.getFluid(seedamount)); } if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FARMING) && genericCropSeed != null && genericCropBlock != null) { - Farmables.farmables.get("farmWheat").add(new FarmableAgingCrop(genericCropSeed, genericCropBlock, plantAGE, 3)); - Farmables.farmables.get("farmOrchard").add(new FarmableAgingCrop(genericCropSeed, genericCropBlock, plantAGE, 3, 0)); + farmRegistry.registerFarmables("farmWheat", new FarmableAgingCrop(genericCropSeed, genericCropBlock, plantAGE, 3)); + farmRegistry.registerFarmables("farmOrchard", new FarmableAgingCrop(genericCropSeed, genericCropBlock, plantAGE, 3, 0)); } plants.add(cropName); } @@ -336,8 +340,8 @@ public class PluginHarvestCraft extends BlankForestryPlugin { RecipeManagers.squeezerManager.addRecipe(10, mustardCropSeed, Fluids.SEED_OIL.getFluid(seedamount)); } if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FARMING) && mustardCropSeed != null && mustardCropBlock != null) { - Farmables.farmables.get("farmWheat").add(new FarmableAgingCrop(mustardCropSeed, mustardCropBlock, plantAGE, 3)); - Farmables.farmables.get("farmOrchard").add(new FarmableAgingCrop(mustardCropSeed, mustardCropBlock, plantAGE, 3, 0)); + farmRegistry.registerFarmables("farmWheat", new FarmableAgingCrop(mustardCropSeed, mustardCropBlock, plantAGE, 3)); + farmRegistry.registerFarmables("farmOrchard", new FarmableAgingCrop(mustardCropSeed, mustardCropBlock, plantAGE, 3, 0)); } if (mustardFruit != null) { RecipeUtil.addFermenterRecipes(mustardFruit, ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.wheat"), Fluids.BIOMASS); @@ -358,8 +362,8 @@ public class PluginHarvestCraft extends BlankForestryPlugin { RecipeManagers.squeezerManager.addRecipe(10, cropnutSeed, Fluids.SEED_OIL.getFluid(seedamount)); } if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FARMING) && cropnutSeed != null && cropnutBlock != null) { - Farmables.farmables.get("farmWheat").add(new FarmableAgingCrop(cropnutSeed, cropnutBlock, plantAGE, 3)); - Farmables.farmables.get("farmOrchard").add(new FarmableAgingCrop(cropnutSeed, cropnutBlock, plantAGE, 3, 0)); + farmRegistry.registerFarmables("farmWheat", new FarmableAgingCrop(cropnutSeed, cropnutBlock, plantAGE, 3)); + farmRegistry.registerFarmables("farmOrchard", new FarmableAgingCrop(cropnutSeed, cropnutBlock, plantAGE, 3, 0)); } if (cropnut != null) { RecipeManagers.squeezerManager.addRecipe(20, cropnut, Fluids.SEED_OIL.getFluid(12 * seedamount)); @@ -370,7 +374,7 @@ public class PluginHarvestCraft extends BlankForestryPlugin { ItemStack nut = getItemStack(nutName + "Item"); Block nutBlock = getBlock("pam" + (Character.toUpperCase(nutName.charAt(0)) + nutName.substring(1))); if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FARMING) && nutBlock != null) { - Farmables.farmables.get("farmOrchard").add(new FarmableAgingCrop(ItemStack.EMPTY, nutBlock, fruitAGE, 2, 0)); + farmRegistry.registerFarmables("farmOrchard", new FarmableAgingCrop(ItemStack.EMPTY, nutBlock, fruitAGE, 2, 0)); } if (nut != null) { RecipeManagers.squeezerManager.addRecipe(20, nut, Fluids.SEED_OIL.getFluid(15 * seedamount));