diff --git a/src/main/java/forestry/arboriculture/genetics/pollination/ICheckPollinatable.java b/src/main/java/forestry/api/genetics/ICheckPollinatable.java similarity index 74% rename from src/main/java/forestry/arboriculture/genetics/pollination/ICheckPollinatable.java rename to src/main/java/forestry/api/genetics/ICheckPollinatable.java index 710bcc229..01f2f409f 100644 --- a/src/main/java/forestry/arboriculture/genetics/pollination/ICheckPollinatable.java +++ b/src/main/java/forestry/api/genetics/ICheckPollinatable.java @@ -1,43 +1,50 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.arboriculture.genetics.pollination; - -import java.util.EnumSet; - -import net.minecraftforge.common.EnumPlantType; - -import forestry.api.arboriculture.ITree; - -/** Just like IPollinatable but for checking only, it can't be mated */ -public interface ICheckPollinatable { - - /** - * @return plant types this pollinatable is classified as. (Can be used by bees to determine whether to interact or not. - */ - EnumSet getPlantType(); - - /** - * @return IIndividual containing the genetic information of this IPollinatable - */ - ITree getPollen(); - - /** - * Checks whether this can mate with the given pollen. - * - * Must be the one to check genetic equivalency. - * - * @param pollen IIndividual representing the pollen. - * @return true if mating is possible, false otherwise. - */ - boolean canMateWith(ITree pollen); - - boolean isPollinated(); -} +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.api.genetics; + +import java.util.EnumSet; + +import net.minecraftforge.common.EnumPlantType; + +import forestry.api.arboriculture.ITree; + +/** + * Used to check for pollination traits without altering the world by changing vanilla leaves to forestry ones. + * For a normal pollinatable that can be mated, see {@link IPollinatable}. + */ +public interface ICheckPollinatable { + + /** + * @return plant types this pollinatable is classified as. + * (Can be used by bees to determine whether to interact or not.) + */ + EnumSet getPlantType(); + + /** + * @return IIndividual containing the genetic information of this IPollinatable + */ + ITree getPollen(); + + /** + * Checks whether this can mate with the given pollen. + * + * Must be the one to check genetic equivalency. + * + * @param pollen IIndividual representing the pollen. + * @return true if mating is possible, false otherwise. + */ + boolean canMateWith(ITree pollen); + + /** + * @return true if this has already been pollinated. + */ + boolean isPollinated(); +} diff --git a/src/main/java/forestry/api/genetics/IFlowerProvider.java b/src/main/java/forestry/api/genetics/IFlowerProvider.java index f13e2a8a9..b50ace224 100644 --- a/src/main/java/forestry/api/genetics/IFlowerProvider.java +++ b/src/main/java/forestry/api/genetics/IFlowerProvider.java @@ -11,7 +11,7 @@ import net.minecraft.world.World; public interface IFlowerProvider { - boolean isAcceptedPollinatable(World world, IPollinatable pollinatable); + boolean isAcceptedPollinatable(World world, ICheckPollinatable pollinatable); /** * @return The unique type used for the IFlowerRegistry diff --git a/src/main/java/forestry/api/genetics/IPollinatable.java b/src/main/java/forestry/api/genetics/IPollinatable.java index 03226e3a6..782aece05 100644 --- a/src/main/java/forestry/api/genetics/IPollinatable.java +++ b/src/main/java/forestry/api/genetics/IPollinatable.java @@ -5,10 +5,6 @@ ******************************************************************************/ package forestry.api.genetics; -import java.util.EnumSet; - -import net.minecraftforge.common.EnumPlantType; - import forestry.api.arboriculture.ITree; /** @@ -16,28 +12,7 @@ import forestry.api.arboriculture.ITree; * * @author SirSengir */ -public interface IPollinatable { - - /** - * @return plant types this pollinatable is classified as. (Can be used by bees to determine whether to interact or not. - */ - EnumSet getPlantType(); - - /** - * @return IIndividual containing the genetic information of this IPollinatable - */ - ITree getPollen(); - - /** - * Checks whether this {@link IPollinatable} can mate with the given pollen. - * - * Must be the one to check genetic equivalency. - * - * @param pollen - * IIndividual representing the pollen. - * @return true if mating is possible, false otherwise. - */ - boolean canMateWith(ITree pollen); +public interface IPollinatable extends ICheckPollinatable { /** * Pollinates this entity. @@ -46,10 +21,4 @@ public interface IPollinatable { * IIndividual representing the pollen. */ void mateWith(ITree pollen); - - /** - * @return true if this IPollinatable has already been pollinated. - * @since Forestry 4.1.0 - */ - boolean isPollinated(); } diff --git a/src/main/java/forestry/apiculture/flowers/FlowerProvider.java b/src/main/java/forestry/apiculture/flowers/FlowerProvider.java index f4416855a..d8f390743 100644 --- a/src/main/java/forestry/apiculture/flowers/FlowerProvider.java +++ b/src/main/java/forestry/apiculture/flowers/FlowerProvider.java @@ -19,9 +19,9 @@ import net.minecraft.world.World; import net.minecraftforge.common.EnumPlantType; import forestry.api.apiculture.FlowerManager; +import forestry.api.genetics.ICheckPollinatable; import forestry.api.genetics.IFlowerProvider; import forestry.api.genetics.IIndividual; -import forestry.api.genetics.IPollinatable; import forestry.core.utils.Translator; public class FlowerProvider implements IFlowerProvider { @@ -40,7 +40,7 @@ public class FlowerProvider implements IFlowerProvider { } @Override - public boolean isAcceptedPollinatable(World world, IPollinatable pollinatable) { + public boolean isAcceptedPollinatable(World world, ICheckPollinatable pollinatable) { EnumSet plantTypes = pollinatable.getPlantType(); diff --git a/src/main/java/forestry/apiculture/genetics/Bee.java b/src/main/java/forestry/apiculture/genetics/Bee.java index b8ea32abd..4cd5e51c6 100644 --- a/src/main/java/forestry/apiculture/genetics/Bee.java +++ b/src/main/java/forestry/apiculture/genetics/Bee.java @@ -52,14 +52,13 @@ import forestry.api.genetics.AlleleManager; import forestry.api.genetics.EnumTolerance; import forestry.api.genetics.IAllele; import forestry.api.genetics.IAlleleTolerance; +import forestry.api.genetics.ICheckPollinatable; import forestry.api.genetics.IChromosome; import forestry.api.genetics.IEffectData; import forestry.api.genetics.IFlowerProvider; import forestry.api.genetics.IIndividual; import forestry.api.genetics.IMutation; import forestry.api.genetics.IPollinatable; -import forestry.arboriculture.genetics.pollination.FakePollinatable; -import forestry.arboriculture.genetics.pollination.ICheckPollinatable; import forestry.core.config.Config; import forestry.core.config.Constants; import forestry.core.errors.EnumErrorCode; @@ -739,7 +738,7 @@ public class Bee extends IndividualLiving implements IBee { continue; } - if (!genome.getFlowerProvider().isAcceptedPollinatable(world, new FakePollinatable(checkPollinatable))) { + if (!genome.getFlowerProvider().isAcceptedPollinatable(world, checkPollinatable)) { continue; } if (!checkPollinatable.canMateWith(pollen)) { diff --git a/src/main/java/forestry/arboriculture/genetics/pollination/CheckPollinatable.java b/src/main/java/forestry/arboriculture/genetics/pollination/CheckPollinatable.java deleted file mode 100644 index 8315882ab..000000000 --- a/src/main/java/forestry/arboriculture/genetics/pollination/CheckPollinatable.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.arboriculture.genetics.pollination; - -import java.util.EnumSet; - -import net.minecraftforge.common.EnumPlantType; - -import forestry.api.arboriculture.ITree; -import forestry.api.genetics.IPollinatable; - -public class CheckPollinatable implements ICheckPollinatable { - - private final IPollinatable pollinatable; - - public CheckPollinatable(IPollinatable pollinatable) { - this.pollinatable = pollinatable; - } - - @Override - public EnumSet getPlantType() { - return pollinatable.getPlantType(); - } - - @Override - public ITree getPollen() { - return pollinatable.getPollen(); - } - - @Override - public boolean canMateWith(ITree pollen) { - return pollinatable.canMateWith(pollen); - } - - @Override - public boolean isPollinated() { - return pollinatable.isPollinated(); - } -} diff --git a/src/main/java/forestry/arboriculture/genetics/pollination/CheckPollinatableTree.java b/src/main/java/forestry/arboriculture/genetics/pollination/CheckPollinatableTree.java index 3766fe4db..78c02c45f 100644 --- a/src/main/java/forestry/arboriculture/genetics/pollination/CheckPollinatableTree.java +++ b/src/main/java/forestry/arboriculture/genetics/pollination/CheckPollinatableTree.java @@ -15,6 +15,7 @@ import java.util.EnumSet; import net.minecraftforge.common.EnumPlantType; import forestry.api.arboriculture.ITree; +import forestry.api.genetics.ICheckPollinatable; public class CheckPollinatableTree implements ICheckPollinatable { diff --git a/src/main/java/forestry/arboriculture/genetics/pollination/FakePollinatable.java b/src/main/java/forestry/arboriculture/genetics/pollination/FakePollinatable.java deleted file mode 100644 index d69bc2e37..000000000 --- a/src/main/java/forestry/arboriculture/genetics/pollination/FakePollinatable.java +++ /dev/null @@ -1,42 +0,0 @@ -package forestry.arboriculture.genetics.pollination; - -import java.util.EnumSet; - -import net.minecraftforge.common.EnumPlantType; - -import forestry.api.arboriculture.ITree; -import forestry.api.genetics.IPollinatable; - -public class FakePollinatable implements IPollinatable { - - private final ICheckPollinatable checkPollinatable; - - public FakePollinatable(ICheckPollinatable checkPollinatable) { - this.checkPollinatable = checkPollinatable; - } - - @Override - public EnumSet getPlantType() { - return checkPollinatable.getPlantType(); - } - - @Override - public ITree getPollen() { - return checkPollinatable.getPollen(); - } - - @Override - public boolean canMateWith(ITree pollen) { - return checkPollinatable.canMateWith(pollen); - } - - @Override - public void mateWith(ITree pollen) { - - } - - @Override - public boolean isPollinated() { - return checkPollinatable.isPollinated(); - } -} diff --git a/src/main/java/forestry/arboriculture/items/ItemGermlingGE.java b/src/main/java/forestry/arboriculture/items/ItemGermlingGE.java index 14aee0ef3..1424ddd8f 100755 --- a/src/main/java/forestry/arboriculture/items/ItemGermlingGE.java +++ b/src/main/java/forestry/arboriculture/items/ItemGermlingGE.java @@ -37,13 +37,13 @@ import forestry.api.core.Tabs; import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IAllele; import forestry.api.genetics.IAlleleSpecies; +import forestry.api.genetics.ICheckPollinatable; import forestry.api.genetics.IIndividual; import forestry.api.genetics.IPollinatable; import forestry.api.recipes.IVariableFermentable; import forestry.arboriculture.genetics.Tree; import forestry.arboriculture.genetics.TreeDefinition; import forestry.arboriculture.genetics.TreeGenome; -import forestry.arboriculture.genetics.pollination.ICheckPollinatable; import forestry.core.config.Config; import forestry.core.genetics.ItemGE; import forestry.core.items.IColoredItem; diff --git a/src/main/java/forestry/arboriculture/tiles/TileLeaves.java b/src/main/java/forestry/arboriculture/tiles/TileLeaves.java index 1e37533d8..86fd4c835 100644 --- a/src/main/java/forestry/arboriculture/tiles/TileLeaves.java +++ b/src/main/java/forestry/arboriculture/tiles/TileLeaves.java @@ -22,6 +22,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.math.BlockPos; + import net.minecraftforge.common.EnumPlantType; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -282,7 +283,7 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru @Override public void mateWith(ITree individual) { ITree tree = getTree(); - if (tree == null) { + if (tree == null || worldObj == null) { return; } diff --git a/src/main/java/forestry/core/utils/GeneticsUtil.java b/src/main/java/forestry/core/utils/GeneticsUtil.java index 70eeba09d..925d41cad 100644 --- a/src/main/java/forestry/core/utils/GeneticsUtil.java +++ b/src/main/java/forestry/core/utils/GeneticsUtil.java @@ -32,15 +32,14 @@ import forestry.api.arboriculture.TreeManager; import forestry.api.core.IArmorNaturalist; import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IAlleleSpecies; +import forestry.api.genetics.ICheckPollinatable; import forestry.api.genetics.IChromosomeType; import forestry.api.genetics.IIndividual; import forestry.api.genetics.IMutation; import forestry.api.genetics.IPollinatable; import forestry.api.lepidopterology.IButterfly; import forestry.api.lepidopterology.IButterflyNursery; -import forestry.arboriculture.genetics.pollination.CheckPollinatable; import forestry.arboriculture.genetics.pollination.CheckPollinatableTree; -import forestry.arboriculture.genetics.pollination.ICheckPollinatable; import forestry.core.config.Config; import forestry.core.genetics.ItemGE; @@ -103,7 +102,7 @@ public class GeneticsUtil { TileEntity tile = world.getTileEntity(pos); if (tile instanceof IPollinatable) { - return new CheckPollinatable((IPollinatable) tile); + return (IPollinatable) tile; } ITree pollen = getErsatzPollen(world, pos); @@ -114,6 +113,9 @@ public class GeneticsUtil { return null; } + /** + * Returns an IPollinatable that can be mated. This will convert vanilla leaves to Forestry leaves. + */ public static IPollinatable getOrCreatePollinatable(GameProfile owner, World world, final BlockPos pos) { TileEntity tile = world.getTileEntity(pos); diff --git a/src/main/java/forestry/lepidopterology/entities/AIButterflyPollinate.java b/src/main/java/forestry/lepidopterology/entities/AIButterflyPollinate.java index 22f1e14f6..d5a309a62 100644 --- a/src/main/java/forestry/lepidopterology/entities/AIButterflyPollinate.java +++ b/src/main/java/forestry/lepidopterology/entities/AIButterflyPollinate.java @@ -10,9 +10,8 @@ ******************************************************************************/ package forestry.lepidopterology.entities; +import forestry.api.genetics.ICheckPollinatable; import forestry.api.genetics.IPollinatable; -import forestry.arboriculture.genetics.pollination.FakePollinatable; -import forestry.arboriculture.genetics.pollination.ICheckPollinatable; import forestry.core.utils.GeneticsUtil; import forestry.lepidopterology.PluginLepidopterology; @@ -36,7 +35,7 @@ public class AIButterflyPollinate extends AIButterflyInteract { return false; } - if (!entity.getButterfly().getGenome().getFlowerProvider().isAcceptedPollinatable(entity.worldObj, new FakePollinatable(checkPollinatable))) { + if (!entity.getButterfly().getGenome().getFlowerProvider().isAcceptedPollinatable(entity.worldObj, checkPollinatable)) { return false; }