if(entity.getButterfly().getMate() == null)
return false;
TileEntity tile = entity.worldObj.getTileEntity(rest.posX, rest.posY, rest.posZ);
IButterflyNursery nursery = null;
if(tile instanceof IButterflyNursery)
nursery = (IButterflyNursery)tile;
else {
for (Map.Entry<ItemStack, IIndividual> entry : AlleleManager.ersatzSpecimen.entrySet()) {
if (!StackUtils.equals(entity.worldObj.getBlock(rest.posX, rest.posY, rest.posZ), entry.getKey()))
continue;
int meta = entity.worldObj.getBlockMetadata(rest.posX, rest.posY, rest.posZ);
if (StackUtils.equals(Blocks.leaves, entry.getKey()))
meta = meta & 3;
if (entry.getKey().getItemDamage() != meta)
continue;
// We matched, replace the leaf block with ours and set the ersatz genome
((ITreeRoot)AlleleManager.alleleRegistry.getSpeciesRoot("rootTrees")).setLeaves(entity.worldObj, entry.getValue(), null, rest.posX, rest.posY, rest.posZ);
// Now let's pollinate
nursery = (IButterflyNursery)entity.worldObj.getTileEntity(rest.posX, rest.posY, rest.posZ);
}
}
if(nursery == null)
return false;
return nursery.canNurse(entity.getButterfly());
}