Fix #1190 crash on pollination. Also rearrange IPollinatable classes

This commit is contained in:
mezz committed 2016-05-19 01:41:51 -07:00
1 parent 8981384385
commit 3a829c9990
12 files changed
+67 -178

No files matched your search

@@ -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<EnumPlantType> 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<EnumPlantType> 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();
}
@@ -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
@@ -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<EnumPlantType> 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();
}
@@ -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<EnumPlantType> plantTypes = pollinatable.getPlantType();
@@ -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)) {
@@ -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<EnumPlantType> 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();
}
}
@@ -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 {
@@ -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<EnumPlantType> 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();
}
}
@@ -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;
@@ -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;
}
@@ -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);
@@ -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;
}