mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-21 20:42:35 +00:00
#19 prevent bees and butterflies from converting leaves when checking
This commit is contained in:
1 parent
e0737d2851
commit
bf2da35086
9 files changed
+204
-43
No files matched your search
@@ -42,14 +42,17 @@ public class FlowerProvider implements IFlowerProvider {
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedPollinatable(World world, IPollinatable pollinatable) {
|
||||
EnumSet<EnumPlantType> types = pollinatable.getPlantType();
|
||||
return isAcceptedPollinatable(world, pollinatable.getPlantType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedPollinatable(World world, EnumSet<EnumPlantType> plantTypes) {
|
||||
if (flowerType.equals(FlowerManager.FlowerTypeNether)) {
|
||||
return types.contains(EnumPlantType.Nether);
|
||||
return plantTypes.contains(EnumPlantType.Nether);
|
||||
} else if (flowerType.equals(FlowerManager.FlowerTypeCacti)) {
|
||||
return types.contains(EnumPlantType.Desert);
|
||||
return plantTypes.contains(EnumPlantType.Desert);
|
||||
} else {
|
||||
return types.size() > 1 || !types.contains(EnumPlantType.Nether);
|
||||
return plantTypes.size() > 1 || !plantTypes.contains(EnumPlantType.Nether);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ import forestry.api.genetics.IFlowerProvider;
|
||||
import forestry.api.genetics.IGenome;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.api.genetics.IPollinatable;
|
||||
import forestry.arboriculture.genetics.ICheckPollinatable;
|
||||
import forestry.core.EnumErrorCode;
|
||||
import forestry.core.config.Defaults;
|
||||
import forestry.core.genetics.Chromosome;
|
||||
@@ -720,19 +721,21 @@ public class Bee extends IndividualLiving implements IBee {
|
||||
Vect randomPos = Vect.getRandomPositionInArea(random, area);
|
||||
Vect posBlock = Vect.add(housingPos, randomPos, offset);
|
||||
|
||||
IPollinatable receiver = GeneticsUtil.getOrCreatePollinatable(housing.getOwnerName(), world, posBlock.x, posBlock.y, posBlock.z);
|
||||
if (receiver == null) {
|
||||
ICheckPollinatable checkPollinatable = GeneticsUtil.getCheckPollinatable(world, posBlock.x, posBlock.y, posBlock.z);
|
||||
if (checkPollinatable == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!genome.getFlowerProvider().isAcceptedPollinatable(world, receiver)) {
|
||||
if (!genome.getFlowerProvider().isAcceptedPollinatable(world, checkPollinatable.getPlantType())) {
|
||||
continue;
|
||||
}
|
||||
if (!receiver.canMateWith(pollen)) {
|
||||
if (!checkPollinatable.canMateWith(pollen)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
receiver.mateWith(pollen);
|
||||
IPollinatable realPollinatable = GeneticsUtil.getOrCreatePollinatable(housing.getOwnerName(), world, posBlock.x, posBlock.y, posBlock.z);
|
||||
|
||||
realPollinatable.mateWith(pollen);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*******************************************************************************
|
||||
* 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;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraftforge.common.EnumPlantType;
|
||||
|
||||
import forestry.api.genetics.IIndividual;
|
||||
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 IIndividual getPollen() {
|
||||
return pollinatable.getPollen();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canMateWith(IIndividual pollen) {
|
||||
return pollinatable.canMateWith(pollen);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +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;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraftforge.common.EnumPlantType;
|
||||
|
||||
import forestry.api.arboriculture.ITree;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
|
||||
public class CheckPollinatableTree implements ICheckPollinatable {
|
||||
|
||||
private final ITree tree;
|
||||
|
||||
public CheckPollinatableTree(ITree tree) {
|
||||
this.tree = tree;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumSet<EnumPlantType> getPlantType() {
|
||||
return tree.getPlantTypes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIndividual getPollen() {
|
||||
return tree;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canMateWith(IIndividual pollen) {
|
||||
if (tree.getMate() != null) {
|
||||
return false;
|
||||
}
|
||||
if (!(pollen instanceof ITree)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !tree.isGeneticEqual(pollen);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*******************************************************************************
|
||||
* 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;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraftforge.common.EnumPlantType;
|
||||
|
||||
import forestry.api.genetics.IIndividual;
|
||||
|
||||
/** Just like IPollinatible 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
|
||||
*/
|
||||
IIndividual 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(IIndividual pollen);
|
||||
}
|
||||
@@ -31,6 +31,11 @@ import forestry.api.core.IArmorNaturalist;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.api.genetics.IPollinatable;
|
||||
import forestry.api.lepidopterology.IButterfly;
|
||||
import forestry.api.lepidopterology.IButterflyNursery;
|
||||
import forestry.arboriculture.genetics.CheckPollinatable;
|
||||
import forestry.arboriculture.genetics.CheckPollinatableTree;
|
||||
import forestry.arboriculture.genetics.ICheckPollinatable;
|
||||
import forestry.core.genetics.ItemGE;
|
||||
import forestry.plugins.PluginArboriculture;
|
||||
|
||||
@@ -61,6 +66,36 @@ public class GeneticsUtil {
|
||||
&& ((IArmorNaturalist) armorItem.getItem()).canSeePollination(player, armorItem, true);
|
||||
}
|
||||
|
||||
public static boolean canNurse(IButterfly butterfly, World world, final int x, final int y, final int z) {
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
|
||||
if (tile instanceof IButterflyNursery) {
|
||||
return ((IButterflyNursery) tile).canNurse(butterfly);
|
||||
}
|
||||
|
||||
// vanilla leaves can always be converted and then nurse
|
||||
return getErsatzPollen(world, x, y, z) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an ICheckPollinatable that can be checked but not mated.
|
||||
* Used to check for pollination traits without altering the world by changing vanilla leaves to forestry ones.
|
||||
*/
|
||||
public static ICheckPollinatable getCheckPollinatable(World world, final int x, final int y, final int z) {
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
|
||||
if (tile instanceof IPollinatable) {
|
||||
return new CheckPollinatable((IPollinatable) tile);
|
||||
}
|
||||
|
||||
ITree pollen = getErsatzPollen(world, x, y, z);
|
||||
if (pollen != null) {
|
||||
return new CheckPollinatableTree(pollen);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static IPollinatable getOrCreatePollinatable(GameProfile owner, World world, final int x, final int y, final int z) {
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
******************************************************************************/
|
||||
package forestry.lepidopterology.entities;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import forestry.api.genetics.IPollinatable;
|
||||
import forestry.api.lepidopterology.IButterflyNursery;
|
||||
import forestry.core.utils.GeneticsUtil;
|
||||
@@ -35,34 +33,21 @@ public class AIButterflyMate extends AIButterflyInteract {
|
||||
return false;
|
||||
}
|
||||
|
||||
TileEntity tile = entity.worldObj.getTileEntity(rest.posX, rest.posY, rest.posZ);
|
||||
IButterflyNursery nursery = null;
|
||||
|
||||
if (tile instanceof IButterflyNursery) {
|
||||
nursery = (IButterflyNursery) tile;
|
||||
} else {
|
||||
IPollinatable pollinatable = GeneticsUtil.getOrCreatePollinatable(null, entity.worldObj, rest.posX, rest.posY, rest.posZ);
|
||||
if (pollinatable instanceof IButterflyNursery) {
|
||||
nursery = (IButterflyNursery) pollinatable;
|
||||
}
|
||||
}
|
||||
|
||||
if (nursery == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return nursery.canNurse(entity.getButterfly());
|
||||
return GeneticsUtil.canNurse(entity.getButterfly(), entity.worldObj, rest.posX, rest.posY, rest.posZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTask() {
|
||||
if (continueExecuting()) {
|
||||
IButterflyNursery tile = (IButterflyNursery) entity.worldObj.getTileEntity(rest.posX, rest.posY, rest.posZ);
|
||||
if (tile.canNurse(entity.getButterfly())) {
|
||||
tile.setCaterpillar(entity.getButterfly().spawnCaterpillar(tile));
|
||||
// Proxies.log.finest("A butterfly '%s' laid an egg at %s/%s/%s.", entity.getButterfly().getIdent(), rest.posX, rest.posY, rest.posZ);
|
||||
if (entity.getRNG().nextFloat() < 1.0f / entity.getButterfly().getGenome().getFertility()) {
|
||||
entity.setHealth(0);
|
||||
IPollinatable tile = GeneticsUtil.getOrCreatePollinatable(null, entity.worldObj, rest.posX, rest.posY, rest.posZ);
|
||||
if (tile instanceof IButterflyNursery) {
|
||||
IButterflyNursery nursery = (IButterflyNursery) tile;
|
||||
if (nursery.canNurse(entity.getButterfly())) {
|
||||
nursery.setCaterpillar(entity.getButterfly().spawnCaterpillar(nursery));
|
||||
// Proxies.log.finest("A butterfly '%s' laid an egg at %s/%s/%s.", entity.getButterfly().getIdent(), rest.posX, rest.posY, rest.posZ);
|
||||
if (entity.getRNG().nextFloat() < 1.0f / entity.getButterfly().getGenome().getFertility()) {
|
||||
entity.setHealth(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
setHasInteracted();
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
package forestry.lepidopterology.entities;
|
||||
|
||||
import forestry.api.genetics.IPollinatable;
|
||||
import forestry.arboriculture.genetics.ICheckPollinatable;
|
||||
import forestry.core.utils.GeneticsUtil;
|
||||
|
||||
public class AIButterflyPollinate extends AIButterflyInteract {
|
||||
@@ -28,27 +29,28 @@ public class AIButterflyPollinate extends AIButterflyInteract {
|
||||
return false;
|
||||
}
|
||||
|
||||
IPollinatable pollinatable = GeneticsUtil.getOrCreatePollinatable(null, entity.worldObj, rest.posX, rest.posY, rest.posZ);
|
||||
if (pollinatable == null) {
|
||||
ICheckPollinatable checkPollinatable = GeneticsUtil.getCheckPollinatable(entity.worldObj, rest.posX, rest.posY, rest.posZ);
|
||||
if (checkPollinatable == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!entity.getButterfly().getGenome().getFlowerProvider().isAcceptedPollinatable(entity.worldObj, pollinatable)) {
|
||||
if (!entity.getButterfly().getGenome().getFlowerProvider().isAcceptedPollinatable(entity.worldObj, checkPollinatable.getPlantType())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return entity.getPollen() == null || pollinatable.canMateWith(entity.getPollen());
|
||||
return entity.getPollen() == null || checkPollinatable.canMateWith(entity.getPollen());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTask() {
|
||||
if (continueExecuting()) {
|
||||
IPollinatable pollinatable = (IPollinatable) entity.worldObj.getTileEntity(rest.posX, rest.posY, rest.posZ);
|
||||
ICheckPollinatable checkPollinatable = GeneticsUtil.getCheckPollinatable(entity.worldObj, rest.posX, rest.posY, rest.posZ);
|
||||
if (entity.getPollen() == null) {
|
||||
entity.setPollen(pollinatable.getPollen());
|
||||
entity.setPollen(checkPollinatable.getPollen());
|
||||
// Proxies.log.finest("A butterfly '%s' grabbed a pollen '%s' at %s/%s/%s.", entity.getButterfly().getIdent(), entity.getPollen().getIdent(), rest.posX, rest.posY, rest.posZ);
|
||||
} else if (pollinatable.canMateWith(entity.getPollen())) {
|
||||
pollinatable.mateWith(entity.getPollen());
|
||||
} else if (checkPollinatable.canMateWith(entity.getPollen())) {
|
||||
IPollinatable realPollinatable = GeneticsUtil.getOrCreatePollinatable(null, entity.worldObj, rest.posX, rest.posY, rest.posZ);
|
||||
realPollinatable.mateWith(entity.getPollen());
|
||||
// Proxies.log.finest("A butterfly '%s' unloaded pollen '%s' at %s/%s/%s.", entity.getButterfly().getIdent(), entity.getPollen().getIdent(), rest.posX, rest.posY, rest.posZ);
|
||||
entity.setPollen(null);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user